Module: Merb::PagesHelper
- Defined in:
- app/helpers/pages_helper.rb
Instance Method Summary collapse
- #hy_guess_type(object) ⇒ Object
-
#nl(arg) ⇒ Object
This function returns its arguments with new lines.
- #sexify(object, form_definition = {}) ⇒ Object
Instance Method Details
#hy_guess_type(object) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'app/helpers/pages_helper.rb', line 29 def hy_guess_type(object) object.class.properties.each do |pr| t = DataMapper::Types inputs = {} inputs[:"#{pr.name}"] = if pr.type.is_a?(t::Boolean) || pr.type.is_a?(TrueClass); :check_box elsif [String, Float, Fixnum, Integer, BigDecimal, ].include?(pr.type); :text_field elsif pr.type == t::Text; :text_area elsif pr.type.is_a?(Date); :date end inputs end end |
#nl(arg) ⇒ Object
This function returns its arguments with new lines
45 46 47 |
# File 'app/helpers/pages_helper.rb', line 45 def nl(arg) tag(:div, "\n #{arg}\n") end |
#sexify(object, form_definition = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/pages_helper.rb', line 3 def sexify(object, form_definition = {}) f = "\n" object.class.properties.each do |pr| t = DataMapper::Types if pr.type.is_a?(t::Boolean) || pr.type.is_a?(TrueClass) f << nl(label(:"#{pr.name}")) f << nl(check_box(:"#{pr.name}")) elsif [String, Float, Fixnum, Integer, BigDecimal].include?(pr.type) f << nl(label(:"#{pr.name}")) f << nl(text_field(:"#{pr.name}")) elsif pr.type == t::Text f << nl(label( :"#{pr.name}" )) f << nl(text_area(:"#{pr.name}")) elsif pr.type.is_a?(Date) dater = "\n" f << tag(:label, :class => :date) do yearc = (Time.now.year-100..Time.now.year) dater << select(:"#{pr.name}_month", :collection => (1..12).to_a); dater << " / " dater << select(:"#{pr.name}_day" , :collection => (1..31).to_a); dater << " / " dater << select(:"#{pr.name}_year" , :collection => (yearc).to_a); dater << " / " dater end end end f end |