Class: Chordpro::HTML
- Inherits:
-
Object
- Object
- Chordpro::HTML
- Defined in:
- lib/chordpro/html.rb
Instance Method Summary collapse
- #comment(text) ⇒ Object (also: #c)
-
#initialize(song) ⇒ HTML
constructor
A new instance of HTML.
- #line(line, parts) ⇒ Object
- #linebreak(_) ⇒ Object
- #subtitle(subtitle) ⇒ Object (also: #st, #su)
- #title(title) ⇒ Object (also: #t)
- #to_s ⇒ Object
Constructor Details
#initialize(song) ⇒ HTML
Returns a new instance of HTML.
5 6 7 8 9 |
# File 'lib/chordpro/html.rb', line 5 def initialize(song) @song = song @html = Builder::XmlMarkup.new @song.accept(self) end |
Instance Method Details
#comment(text) ⇒ Object Also known as: c
70 71 72 |
# File 'lib/chordpro/html.rb', line 70 def comment(text) @html.span(text, class: "comment") end |
#line(line, parts) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/chordpro/html.rb', line 28 def line(line, parts) chords = [] lyrics = [] line.each do |element| if element.is_a?(Lyric) lyrics << element elsif element.is_a?(Chord) if chords[lyrics.size] chords << element lyrics << nil else chords[lyrics.size] = element end end end # ensure chords has same number of cells as lyrics chords[lyrics.size - 1] ||= nil if lyrics.size > 0 @html.table do |table| if chords.any? table.tr(class: "chords") do |tr| chords.each do |chord| tr.td { |td| td.text! chord.to_s } end end end if lyrics.any? table.tr do |tr| lyrics.each do |lyric| tr.td { |td| td.text! lyric.to_s } end end end end end |
#linebreak(_) ⇒ Object
66 67 68 |
# File 'lib/chordpro/html.rb', line 66 def linebreak(_) @html.br end |
#subtitle(subtitle) ⇒ Object Also known as: st, su
20 21 22 23 24 |
# File 'lib/chordpro/html.rb', line 20 def subtitle(subtitle) unless subtitle.match(/^\s*$/) @html.h2(class: "subtitle") { |h2| h2.text! subtitle } end end |
#title(title) ⇒ Object Also known as: t
15 16 17 |
# File 'lib/chordpro/html.rb', line 15 def title(title) @html.h1(class: "title") { |h1| h1.text! title } end |
#to_s ⇒ Object
11 12 13 |
# File 'lib/chordpro/html.rb', line 11 def to_s @html.target! end |