Class: Rad::Face::HtmlOpenObject
- Inherits:
-
OpenObject
- Object
- OpenObject
- Rad::Face::HtmlOpenObject
show all
- Defined in:
- lib/face/html_open_object.rb
Constant Summary
collapse
- HTML_ATTRIBUTES =
[:id, :class]
Class Method Summary
collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, arg = nil, &block) ⇒ Object
should threat newlines as blank
41
42
43
44
45
46
47
48
49
50
51
52
53
|
# File 'lib/face/html_open_object.rb', line 41
def method_missing m, arg = nil, &block
type = m[-1,1]
if type == '='
self[m[0..-2]] = arg
elsif type == '!'
self[m[0..-2]]
elsif type == '?'
value = self[m[0..-2]]
!(value.is_a?(String) ? (value =~ /\A\s*\z/) : value.blank?)
else
self[m]
end
end
|
Class Method Details
.initialize_from(hash, deep = false) ⇒ Object
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/face/html_open_object.rb', line 23
def self.initialize_from hash, deep = false
unless deep
::Rad::Face::HtmlOpenObject.new.update hash
else
r = ::Rad::Face::HtmlOpenObject.new
hash.each do |k, v|
r[k] = if v.is_a? Hash
v.to_openobject
else
v
end
end
r
end
end
|
Instance Method Details
#merge_html_attributes(hash = {}) ⇒ Object
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
# File 'lib/face/html_open_object.rb', line 4
def merge_html_attributes hash = {}
result = {}
HTML_ATTRIBUTES.each{|k| result[k.to_s] = self[k] if include? k}
html_attributes.each{|k, v| result[k.to_s] = v} if html_attributes?
hash.each do |k, v|
k = k.to_s
if result.include?(k) and v.is_a?(String)
string = result[k].must_be.a Symbol, String
result[k] = "#{result[k]}#{v}"
else
result[k] = v
end
end
result
end
|