refactor macro
parent
1f08db49c9
commit
f36767ad7f
|
@ -41,19 +41,7 @@ class MechanizeCr::Form
|
||||||
{% for singular, index in ["field", "radiobutton"] %}
|
{% for singular, index in ["field", "radiobutton"] %}
|
||||||
{% plural = "#{singular.id}s" %}
|
{% plural = "#{singular.id}s" %}
|
||||||
def {{plural.id}}_with(criteria)
|
def {{plural.id}}_with(criteria)
|
||||||
value = Hash(String,String).new
|
{{plural.id}}_with(criteria){}
|
||||||
if String === criteria
|
|
||||||
value = {"name" => criteria}
|
|
||||||
else
|
|
||||||
# TODO
|
|
||||||
# when args whose type isn't String is given
|
|
||||||
end
|
|
||||||
f = {{plural.id}}.select do |elm|
|
|
||||||
value.all? do |k,v|
|
|
||||||
v === elm.name
|
|
||||||
end
|
|
||||||
end
|
|
||||||
f.empty? ? nil : f
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def {{plural.id}}_with(criteria, &block)
|
def {{plural.id}}_with(criteria, &block)
|
||||||
|
@ -69,6 +57,7 @@ class MechanizeCr::Form
|
||||||
v === elm.name
|
v === elm.name
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
return nil if f.empty?
|
||||||
yield f
|
yield f
|
||||||
f
|
f
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue