-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathhtml.rb
61 lines (51 loc) · 1.3 KB
/
html.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
module Bookie
module Emitters
class HTML
def self.extension
".html"
end
def initialize
@body = ""
end
attr_reader :body
def start_new_chapter(params)
@body << "<h1>#{params[:header]}: #{params[:title]}</h1>"
end
def build_paragraph(paragraph)
@body << "<p>#{convert_inlines(paragraph.contents)}</p>"
end
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
def build_raw_text(raw_text)
@body << "<pre>#{raw_text.contents}</pre>"
end
def build_section_heading(header)
@body << "<h2>#{header.contents}</h2>"
end
def build_sub_section_heading(header)
@body << "<h3>#{header.contents}</h3>"
end
def build_list(list)
list_elements = list.contents.map { |li| "<li>#{li}</li>" }.join
@body << "<ul>"+list_elements+"</ul>"
end
def render(params)
File.open(params[:file], "w") do |file|
file << %{
<html>
<body>#{@body}</body>
</html>
}
end
end
end
end
end