Class: Bookie::Emitters::HTML
- Inherits:
-
Object
- Object
- Bookie::Emitters::HTML
- Defined in:
- lib/bookie/emitters/html.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
Class Method Summary collapse
Instance Method Summary collapse
- #build_list(list) ⇒ Object
- #build_paragraph(paragraph) ⇒ Object
- #build_raw_text(raw_text) ⇒ Object
- #build_section_heading(header) ⇒ Object
- #convert_inlines(contents) ⇒ Object
-
#initialize ⇒ HTML
constructor
A new instance of HTML.
- #render(params) ⇒ Object
- #start_new_chapter(params) ⇒ Object
Constructor Details
#initialize ⇒ HTML
Returns a new instance of HTML.
8 9 10 |
# File 'lib/bookie/emitters/html.rb', line 8 def initialize @body = "" end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/bookie/emitters/html.rb', line 12 def body @body end |
Class Method Details
.extension ⇒ Object
4 5 6 |
# File 'lib/bookie/emitters/html.rb', line 4 def self.extension ".html" end |
Instance Method Details
#build_list(list) ⇒ Object
41 42 43 44 |
# File 'lib/bookie/emitters/html.rb', line 41 def build_list(list) list_elements = list.contents.map { |li| "<li>#{li}</li>" }.join @body << "<ul>"+list_elements+"</ul>" end |
#build_paragraph(paragraph) ⇒ Object
18 19 20 |
# File 'lib/bookie/emitters/html.rb', line 18 def build_paragraph(paragraph) @body << "<p>#{convert_inlines(paragraph.contents)}</p>" end |
#build_raw_text(raw_text) ⇒ Object
33 34 35 |
# File 'lib/bookie/emitters/html.rb', line 33 def build_raw_text(raw_text) @body << "<pre>#{raw_text.contents}</pre>" end |
#build_section_heading(header) ⇒ Object
37 38 39 |
# File 'lib/bookie/emitters/html.rb', line 37 def build_section_heading(header) @body << "<h2>#{header.contents}</h2>" end |
#convert_inlines(contents) ⇒ Object
22 23 24 25 26 27 28 29 30 31 |
# File 'lib/bookie/emitters/html.rb', line 22 def convert_inlines(contents) contents.map do |c| case c when Bookie::NormalText c.contents when Bookie::CodeText "<tt>#{c.contents}</tt>" end end.join.strip end |
#render(params) ⇒ Object
46 47 48 49 50 51 52 53 54 |
# File 'lib/bookie/emitters/html.rb', line 46 def render(params) File.open(params[:file], "w") do |file| file << %{ <html> <body>#{@body}</body> </html> } end end |
#start_new_chapter(params) ⇒ Object
14 15 16 |
# File 'lib/bookie/emitters/html.rb', line 14 def start_new_chapter(params) @body << "<h1>#{params[:header]}: #{params[:title]}</h1>" end |