Class: HtmlBook
- Inherits:
-
Object
- Object
- HtmlBook
- Defined in:
- lib/htmlbook.rb
Instance Attribute Summary collapse
-
#pages ⇒ Object
Returns the value of attribute pages.
-
#to_html ⇒ Object
readonly
Returns the value of attribute to_html.
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(filename = 'page.html', pg_height: 740, width: '700px', debug: false) ⇒ HtmlBook
constructor
A new instance of HtmlBook.
- #save(filename = @filename.sub(/\.\w+$/,'2\0')) ⇒ Object
Constructor Details
#initialize(filename = 'page.html', pg_height: 740, width: '700px', debug: false) ⇒ HtmlBook
Returns a new instance of HtmlBook.
17 18 19 20 21 22 23 24 |
# File 'lib/htmlbook.rb', line 17 def initialize(filename='page.html', pg_height: 740, width: '700px', debug: false) @filename, @pg_height, @width, @debug = filename, pg_height, width, debug @doc = build() @to_html = @doc.root.xml pretty: true end |
Instance Attribute Details
#pages ⇒ Object
Returns the value of attribute pages.
14 15 16 |
# File 'lib/htmlbook.rb', line 14 def pages @pages end |
#to_html ⇒ Object (readonly)
Returns the value of attribute to_html.
13 14 15 |
# File 'lib/htmlbook.rb', line 13 def to_html @to_html end |
Instance Method Details
#build ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/htmlbook.rb', line 26 def build() doc = Rexle.new(RXFHelper.read(@filename).first) style = Rexle::Element.new('style').add_text css style.attributes[:id] = 'tmpcss' doc.root.element('head').add style puts 'doc: ' + doc.xml.inspect if @debug pages = QndHtml2Page.new(doc, pg_height: @pg_height, debug: @debug).to_pages doc.at_css('#tmpcss').delete build_html doc, collate(pages) end |
#save(filename = @filename.sub(/\.\w+$/,'2\0')) ⇒ Object
41 42 43 44 45 46 47 48 |
# File 'lib/htmlbook.rb', line 41 def save(filename=@filename.sub(/\.\w+$/,'2\0')) css_filename = filename.sub(/\.html$/, '.css') @doc.root.element('head/link').attributes[:href] = css_filename File.write css_filename, css() File.write filename, @doc.xml(pretty: true) end |