18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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
94
|
# File 'lib/attribeautiful/container.rb', line 18
def html_element(elem_name)
include EagerBeaver
html_element_names << elem_name
add_method_handler do |mh|
mh.match = lambda {
context.elem_name = $1 if /\A(\w+)_element\z/ =~ context.missing_method_name
return Regexp.last_match
}
mh.handle = lambda {
%Q{
def #{context.missing_method_name}
@#{context.elem_name}_element ||= Attribeautiful::Element.new
end
}
}
end
add_method_handler do |mh|
mh.match = lambda {
context.original_receiver.class.html_element_names.detect{ |elem_name|
/\A(#{elem_name})_(\w+)_attr\z/ =~ context.missing_method_name
}
context.elem_name = $1
context.attr_name = $2
return Regexp.last_match
}
mh.handle = lambda {
%Q{
def #{context.missing_method_name}
#{context.elem_name}_element.#{context.attr_name}_attr ||= Attribeautiful::Attribute.new("#{context.attr_name}")
end
}
}
end
add_method_handler do |mh|
mh.match = lambda {
context.original_receiver.class.html_element_names.detect do |elem_name|
Attribeautiful::Attribute.instance_methods.detect do |attr_action|
/\A(#{elem_name})_(\w+)_(#{attr_action})\z/ =~ context.missing_method_name
end
end
context.elem_name = $1
context.attr_name = $2
context.attr_action = $3
return Regexp.last_match
}
mh.handle = lambda {
%Q{
def #{context.missing_method_name}(*args, &block)
#{context.elem_name}_#{context.attr_name}_attr.#{context.attr_action}(*args, &block)
end
}
}
end
end
|