Module: JamScriptHighlighter::Html

Defined in:
lib/jam_script_highlighter/html.rb

Class Method Summary collapse

Class Method Details

.render(string, opts = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/jam_script_highlighter/html.rb', line 4

def render string, opts={}
  @html = ''
  @section_type = 'chords'
  @processing_section = false

  js = JamScriptHighlighter.highlight(string)
  js.each do |line|
    render_line line
  end

  @html += "</div>\n" if @processing_section
  @html
end

.render_line(line_details) ⇒ Object



18
19
20
21
22
23
24
25
26
27
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/jam_script_highlighter/html.rb', line 18

def render_line line_details
  line = Line.new(line_details[:line], line_details[:type])

  @html += case line_details[:type]
  when :control
    ret = ''
    ret += "</div>\n\n" and @processing_section = false if @processing_section

    ret += line.to_html
    @section_type = line.text.downcase
    ret += "<div class=\"#{@section_type}\">"

    @processing_section = true

    ret
  when :section
    ret = ''
    ret += "</div>\n\n" and @processing_section = false if @processing_section

    ret += line.to_html
    ret += "<div class=\"#{@section_type}\">"

    @processing_section = true

    ret
  when :structure
    @section_type = 'structure'
    ret = ''
    ret += "</div>\n\n" and @processing_section = false if @processing_section

    ret += "<div class=\"group\">"
    ret += line.to_html

    @processing_section = true

    ret
  when :other
    case @section_type
    when 'chords'
      "<p class=\"#{@section_type}\">#{line.to_html.strip}</p>"
    else
      line.to_html
    end
  else
    line.to_html
  end + "\n"
end