Class: Paggio::HTML
- Inherits:
-
BasicObject
- Defined in:
- lib/paggio/css.rb,
lib/paggio/html.rb,
lib/paggio/script.rb,
lib/paggio/markdown.rb,
lib/paggio/html/element.rb,
lib/paggio/html/helpers.rb,
lib/paggio/html/element/a.rb,
lib/paggio/html/element/img.rb,
lib/paggio/html/element/base.rb,
lib/paggio/html/element/input.rb,
lib/paggio/html/element/button.rb,
lib/paggio/html/element/canvas.rb,
lib/paggio/html/element/blockquote.rb
Defined Under Namespace
Classes: Element
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(version = 5, &block) ⇒ HTML
Returns a new instance of HTML.
20
21
22
23
24
25
26
27
28
29
30
31
32
|
# File 'lib/paggio/html.rb', line 20
def initialize(version = 5, &block)
::Kernel.raise ::ArgumentError, 'no block given' unless block
@version = version
@roots = []
@current = nil
if block.arity == 0
instance_exec(&block)
else
block.call(self)
end
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
|
# File 'lib/paggio/html.rb', line 68
def method_missing(name, *args, &block)
if name.to_s.end_with? ?!
return super
end
if ::String === args.first
content = ::Paggio::Utils.heredoc(args.shift)
end
element = Element.new(self, name, *args)
element << content if content
if block
parent = @current
@current = element
result = block.call(self)
@current = parent
if ::String === result
element.instance_eval { @inner_html = result }
end
end
(@current || @roots) << element
element
end
|
Instance Attribute Details
#version ⇒ Object
Returns the value of attribute version.
18
19
20
|
# File 'lib/paggio/html.rb', line 18
def version
@version
end
|
Instance Method Details
#<<(what) ⇒ Object
34
35
36
|
# File 'lib/paggio/html.rb', line 34
def <<(what)
@current << what
end
|
#each(&block) ⇒ Object
64
65
66
|
# File 'lib/paggio/html.rb', line 64
def each(&block)
@roots.each(&block)
end
|
#element! ⇒ Object
46
47
48
|
# File 'lib/paggio/html.rb', line 46
def element!
@current
end
|
#extend!(element = nil, &block) ⇒ Object
50
51
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/paggio/html.rb', line 50
def extend!(element = nil, &block)
old, @current = @current, element
result = block.call(self)
if ::String === result
@current.instance_eval { @inner_html = result }
end
@current = old
self
end
|
#inspect ⇒ Object
96
97
98
99
100
101
102
|
# File 'lib/paggio/html.rb', line 96
def inspect
if @roots.empty?
"#<HTML(#@version)>"
else
"#<HTML(#@version): #{@roots.inspect[1 .. -2]}>"
end
end
|
#local_variables ⇒ Object
37
38
39
|
# File 'lib/paggio/script.rb', line 37
def local_variables(*)
[]
end
|
#markdown(string) ⇒ Object
16
17
18
19
|
# File 'lib/paggio/markdown.rb', line 16
def markdown(string)
(@current || @roots) << ::Kramdown::Document.new(
::Paggio::Utils.heredoc(string))
end
|
#root! ⇒ Object
38
39
40
|
# File 'lib/paggio/html.rb', line 38
def root!
@roots.first
end
|
#roots! ⇒ Object
42
43
44
|
# File 'lib/paggio/html.rb', line 42
def roots!
@roots
end
|
#script(*args, &block) ⇒ Object
29
30
31
32
33
34
35
|
# File 'lib/paggio/script.rb', line 29
def script(*args, &block)
if block
(@current || @roots) << Script.new(*args, &block)
else
super
end
end
|
#style(&block) ⇒ Object
79
80
81
|
# File 'lib/paggio/css.rb', line 79
def style(&block)
(@current || @roots) << CSS.new(&block)
end
|