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/td.rb,
lib/paggio/html/element/img.rb,
lib/paggio/html/element/base.rb,
lib/paggio/html/element/link.rb,
lib/paggio/html/element/embed.rb,
lib/paggio/html/element/input.rb,
lib/paggio/html/element/button.rb,
lib/paggio/html/element/canvas.rb,
lib/paggio/html/element/object.rb,
lib/paggio/html/element/option.rb,
lib/paggio/html/element/select.rb,
lib/paggio/html/element/optgroup.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.
19
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/paggio/html.rb', line 19
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
67
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
|
# File 'lib/paggio/html.rb', line 67
def method_missing(name, *args, &block)
if name.to_s.end_with? ?!
return super
end
unless args.empty? || ::Hash === args.first
content = ::Paggio::Utils.heredoc(args.shift.to_s)
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
self << element
element
end
|
Instance Attribute Details
#version ⇒ Object
Returns the value of attribute version.
17
18
19
|
# File 'lib/paggio/html.rb', line 17
def version
@version
end
|
Instance Method Details
#<<(what) ⇒ Object
33
34
35
|
# File 'lib/paggio/html.rb', line 33
def <<(what)
(@current || @roots) << what
end
|
#each(&block) ⇒ Object
63
64
65
|
# File 'lib/paggio/html.rb', line 63
def each(&block)
@roots.each(&block)
end
|
#element! ⇒ Object
45
46
47
|
# File 'lib/paggio/html.rb', line 45
def element!
@current
end
|
#extend!(element = nil, &block) ⇒ Object
49
50
51
52
53
54
55
56
57
58
59
60
61
|
# File 'lib/paggio/html.rb', line 49
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
95
96
97
98
99
100
101
|
# File 'lib/paggio/html.rb', line 95
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
37
38
39
|
# File 'lib/paggio/html.rb', line 37
def root!
@roots.first
end
|
#roots! ⇒ Object
41
42
43
|
# File 'lib/paggio/html.rb', line 41
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
113
114
115
|
# File 'lib/paggio/css.rb', line 113
def style(&block)
(@current || @roots) << CSS.new(&block)
end
|