Guest User

Untitled

a guest
Feb 20th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. class Array; alias i? include? end
  2. module Merb
  3. module SexyForms
  4. def sexify(model)
  5. T = DataMapper::Types
  6. model.class.properties.each do |p|
  7. if [T::Boolean, T::TrueClass].i?(p)
  8. label :"#{p.name}"
  9. check_box :"#{p.name}"
  10. elsif [T::String, T::Float,
  11. T::Fixnum, T::Integer,
  12. T::BigDecimal].i?(p)
  13. label :"#{p.name}"
  14. text_field :"#{p.name}"
  15. elsif [T::Text].i?(p)
  16. label :"#{p.name}"
  17. text_area :"#{p.name}"
  18. elsif [T::Date].i?(p)
  19. tag :label, :class => :date do
  20. yearc = (Time.now.year-100..Time.now.year)
  21. select :"#{p.name}_month", :collection => (1..12).to_a; puts " / "
  22. select :"#{p.name}_day" , :collection => (1..31).to_a; puts " / "
  23. select :"#{p.name}_year" , :collection => (yearc).to_a; puts " / "
  24. end
  25. end
  26. end
  27. end
  28. end
  29. end
  30. # make sure we're running inside Merb
  31. if defined?(Merb::Plugins)
  32.  
  33. # Merb gives you a Merb::Plugins.config hash...feel free to put your stuff in your piece of it
  34. Merb::Plugins.config[:sexyforms] = {
  35. :chickens => false
  36. }
  37. Merb::BootLoader.before_app_loads do
  38. Merb::Controller.send(:include, Merb::SexyForms)
  39. # require code that must be loaded before the application
  40. end
  41.  
  42. Merb::BootLoader.after_app_loads do
  43. # code that can be required after the application loads
  44. end
  45.  
  46. Merb::Plugins.add_rakefiles "sexyforms/merbtasks"
  47. end
Add Comment
Please, Sign In to add comment