Module: TagParts
- Included in:
- HTMLParts
- Defined in:
- lib/tagparts.rb
Defined Under Namespace
Classes: TagItem
Constant Summary
collapse
- @@method_prefix =
'_'
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
144
145
146
147
148
149
150
|
# File 'lib/tagparts.rb', line 144
def method_missing m, *args
if make_unknown_tag? && (/^#{@@method_prefix}(.+)/ =~ m.to_s)
TagItem.new($1, args)
else
super
end
end
|
Class Method Details
.newtag(sym, ignore_empty, klass = TagParts) ⇒ Object
130
131
132
133
134
135
136
|
# File 'lib/tagparts.rb', line 130
def self.newtag sym, ignore_empty, klass = TagParts
klass.module_eval <<-EOS
def #{@@method_prefix}#{sym}(*args)
TagItem.new(:#{sym}, args, #{ignore_empty})
end
EOS
end
|
Instance Method Details
#ignore_empty_tag? ⇒ Boolean
98
99
100
|
# File 'lib/tagparts.rb', line 98
def ignore_empty_tag?
false
end
|
#make_unknown_tag? ⇒ Boolean
152
153
154
|
# File 'lib/tagparts.rb', line 152
def make_unknown_tag?
true
end
|
#tag_encoding(str) ⇒ Object
do nothing. please override
103
104
105
|
# File 'lib/tagparts.rb', line 103
def tag_encoding str
str
end
|
#tree2string(tag) ⇒ Object
107
108
109
|
# File 'lib/tagparts.rb', line 107
def tree2string tag
tag_encoding(tree2string_(tag))
end
|
#tree2string_(tag) ⇒ Object
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/tagparts.rb', line 111
def tree2string_ tag
bs = tag.map{|body|
if body.kind_of? TagItem
tree2string_(body)
else
CGI.escapeHTML(body.to_s)
end
}
tagname = tag.tag
attr = tag.make_attr_str
if bs.size > 0 || ignore_empty_tag?
"<#{tagname}#{attr}\n>#{bs}</#{tagname}>\n"
else
"<#{tagname}#{attr}\n/>"
end
end
|