Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Array; alias i? include? end
- module Merb
- module SexyForms
- def sexify(model)
- T = DataMapper::Types
- model.class.properties.each do |p|
- if [T::Boolean, T::TrueClass].i?(p)
- label :"#{p.name}"
- check_box :"#{p.name}"
- elsif [T::String, T::Float,
- T::Fixnum, T::Integer,
- T::BigDecimal].i?(p)
- label :"#{p.name}"
- text_field :"#{p.name}"
- elsif [T::Text].i?(p)
- label :"#{p.name}"
- text_area :"#{p.name}"
- elsif [T::Date].i?(p)
- tag :label, :class => :date do
- yearc = (Time.now.year-100..Time.now.year)
- select :"#{p.name}_month", :collection => (1..12).to_a; puts " / "
- select :"#{p.name}_day" , :collection => (1..31).to_a; puts " / "
- select :"#{p.name}_year" , :collection => (yearc).to_a; puts " / "
- end
- end
- end
- end
- end
- end
- # make sure we're running inside Merb
- if defined?(Merb::Plugins)
- # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
- Merb::Plugins.config[:sexyforms] = {
- :chickens => false
- }
- Merb::BootLoader.before_app_loads do
- Merb::Controller.send(:include, Merb::SexyForms)
- # require code that must be loaded before the application
- end
- Merb::BootLoader.after_app_loads do
- # code that can be required after the application loads
- end
- Merb::Plugins.add_rakefiles "sexyforms/merbtasks"
- end
Add Comment
Please, Sign In to add comment