Class: M2H::Render::Document
- Inherits:
-
Object
- Object
- M2H::Render::Document
- Defined in:
- lib/m2h/render.rb
Instance Attribute Summary collapse
-
#html_body ⇒ Object
Returns the value of attribute html_body.
Instance Method Summary collapse
- #bind! ⇒ Object
- #generate_html(html_body) ⇒ Object
-
#initialize(html_body) ⇒ Document
constructor
A new instance of Document.
- #set_cover ⇒ Object
- #set_header ⇒ Object
- #set_serif ⇒ Object
- #set_toc ⇒ Object
- #write(path, enc) ⇒ Object
Constructor Details
#initialize(html_body) ⇒ Document
Returns a new instance of Document.
9 10 11 12 13 |
# File 'lib/m2h/render.rb', line 9 def initialize(html_body) @erb_template = File.open(File.dirname(__FILE__) + "/_layout.erb").read @html = generate_html(html_body) @header = false end |
Instance Attribute Details
#html_body ⇒ Object
Returns the value of attribute html_body.
7 8 9 |
# File 'lib/m2h/render.rb', line 7 def html_body @html_body end |
Instance Method Details
#bind! ⇒ Object
30 31 32 |
# File 'lib/m2h/render.rb', line 30 def bind! return ERB.new(@erb_template).result(binding) end |
#generate_html(html_body) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/m2h/render.rb', line 15 def generate_html(html_body) @title = $1 if /h1>(.+)\<\/h1./ =~ html_body @pages = html_body.split(/\/{4,}/) # page_break @page_count = @pages.size html = @pages.map.with_index { |page, i| unless (i + 1) == @page_count "<div class='page_number'>#{i+1}/#{@page_count}</div>\n" + page + "\n<div class='break'/>\n" else "<div class='page_number'>#{i+1}/#{@page_count}</div>\n" + page end }.join html.gsub!(/page_number'>/, "page_number'>#{@title} ") return html end |
#set_cover ⇒ Object
46 47 48 49 50 |
# File 'lib/m2h/render.rb', line 46 def set_cover cover = "\n<div class='cover'><h1>#{@title}</h1></div>\n" cover += "<div class='break'/>\n" @cover = cover end |
#set_header ⇒ Object
34 35 36 |
# File 'lib/m2h/render.rb', line 34 def set_header @header = true end |
#set_serif ⇒ Object
42 43 44 |
# File 'lib/m2h/render.rb', line 42 def set_serif @serif = "serif, " end |
#set_toc ⇒ Object
52 53 54 |
# File 'lib/m2h/render.rb', line 52 def set_toc @toc = true end |
#write(path, enc) ⇒ Object
38 39 40 |
# File 'lib/m2h/render.rb', line 38 def write(path, enc) File.open(path, enc).write(self.bind!) end |