Class: Bookie::Emitters::HTML

Inherits:
Object
  • Object
show all
Defined in:
lib/bookie/emitters.rb

Direct Known Subclasses

EPUB, MOBI

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeHTML

Returns a new instance of HTML.



20
21
22
# File 'lib/bookie/emitters.rb', line 20

def initialize
  @body = ""
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



24
25
26
# File 'lib/bookie/emitters.rb', line 24

def body
  @body
end

Instance Method Details

#build_list(list) ⇒ Object



38
39
40
41
# File 'lib/bookie/emitters.rb', line 38

def build_list(list)
  list_elements = list.contents.map { |li| "<li>#{li}</li>" }.join
  @body << "<ul>"+list_elements+"</ul>"
end

#build_paragraph(paragraph) ⇒ Object



26
27
28
# File 'lib/bookie/emitters.rb', line 26

def build_paragraph(paragraph)
  @body << "<p>#{paragraph.contents}</p>"
end

#build_raw_text(raw_text) ⇒ Object



30
31
32
# File 'lib/bookie/emitters.rb', line 30

def build_raw_text(raw_text)
  @body << "<pre>#{raw_text.contents}</pre>"
end

#build_section_heading(header) ⇒ Object



34
35
36
# File 'lib/bookie/emitters.rb', line 34

def build_section_heading(header)
  @body << "<h2>#{header.contents}</h2>"
end

#render(params) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/bookie/emitters.rb', line 43

def render(params)
  File.open(params[:file], "w") do |file|
    file << %{
      <html>
         <body><h1>#{params[:title]}</h1>#{@body}</body>
      </html>
    }
  end
end