Class: Bookify::Node::Base
- Inherits:
-
Object
- Object
- Bookify::Node::Base
show all
- Defined in:
- lib/bookify/node/base.rb
Direct Known Subclasses
Blockquote, Div, H1, H2, H3, H4, Hr, Image, List, Paragraph, Table
Constant Summary
collapse
- FONTS =
{
h1: ["Book Antiqua", size: 18, style: :bold],
h2: ["Book Antiqua", size: 13, style: :bold],
h3: ["Book Antiqua", size: 12, style: :bold],
h4: ["Book Antiqua", size: 11, style: :bold],
primary: ["Book Antiqua", size: 10]
}
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(node, pdf) ⇒ Base
Returns a new instance of Base.
21
22
23
24
|
# File 'lib/bookify/node/base.rb', line 21
def initialize(node, pdf)
self.node = node
self.pdf = pdf
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
17
18
19
|
# File 'lib/bookify/node/base.rb', line 17
def method_missing(method, *args, &block)
pdf.send(method, *args, &block)
end
|
Instance Attribute Details
#node ⇒ Object
Returns the value of attribute node.
3
4
5
|
# File 'lib/bookify/node/base.rb', line 3
def node
@node
end
|
#pdf ⇒ Object
Returns the value of attribute pdf.
3
4
5
|
# File 'lib/bookify/node/base.rb', line 3
def pdf
@pdf
end
|
Class Method Details
.render(node, pdf) ⇒ Object
13
14
15
|
# File 'lib/bookify/node/base.rb', line 13
def self.render(node, pdf)
new(node, pdf).render
end
|
Instance Method Details
#break_if_close_to_bottom(tolerance = 125) ⇒ Object
42
43
44
|
# File 'lib/bookify/node/base.rb', line 42
def break_if_close_to_bottom(tolerance = 125)
bounds.move_past_bottom if pdf.y <= tolerance
end
|
#clean_html(html) ⇒ Object
34
35
36
|
# File 'lib/bookify/node/base.rb', line 34
def clean_html(html)
html.delete("\n").gsub(/\s+/, " ")
end
|
#decode_html(html) ⇒ Object
38
39
40
|
# File 'lib/bookify/node/base.rb', line 38
def decode_html(html)
HTMLEntities.new.decode(html)
end
|
#font(name, &block) ⇒ Object
30
31
32
|
# File 'lib/bookify/node/base.rb', line 30
def font(name, &block)
pdf.font(*FONTS[name], &block)
end
|
#html_classes(element = node) ⇒ Object
26
27
28
|
# File 'lib/bookify/node/base.rb', line 26
def html_classes(element = node)
(element.attr(:class) || "").split(" ")
end
|
#page_top ⇒ Object
46
47
48
|
# File 'lib/bookify/node/base.rb', line 46
def page_top
pdf.bounds.parent.height + 50
end
|