Class: Ramaze::Form
Direct Known Subclasses
Defined Under Namespace
Modules: Layer
Constant Summary collapse
- DATE_GENERIC =
[ [ :day, DAYS ], [ :month, MONTHS ], [ :year, YEARS ] ]
- TIME_GENERIC =
[ [ :day, DAYS ], [ :month, MONTHS ], [ :year, YEARS ], [ :hour, HOURS ], [ :min, MINUTES ], [ :sec, SECONDS ] ]
Instance Attribute Summary collapse
-
#object ⇒ Object
Returns the value of attribute object.
-
#options ⇒ Object
Returns the value of attribute options.
Class Method Summary collapse
-
.pick(object, options = {}) ⇒ Object
TODO: How elegant …
Instance Method Summary collapse
-
#field_for(hash) ⇒ Object
Decide on the strucuture of the tag based on the hash.
-
#initialize(object, options = {}) ⇒ Form
constructor
Create new instance of Form plus the layer for the ORM.
-
#to_s ⇒ Object
Generate and return the final form.
Constructor Details
#initialize(object, options = {}) ⇒ Form
Create new instance of Form plus the layer for the ORM
57 58 59 60 61 62 |
# File 'lib/ramaze/helper/form.rb', line 57 def initialize(object, = {}) @object, @options = object, if layer = .delete(:layer) extend layer end end |
Instance Attribute Details
#object ⇒ Object
Returns the value of attribute object.
15 16 17 |
# File 'lib/ramaze/helper/form.rb', line 15 def object @object end |
#options ⇒ Object
Returns the value of attribute options.
15 16 17 |
# File 'lib/ramaze/helper/form.rb', line 15 def @options end |
Class Method Details
.pick(object, options = {}) ⇒ Object
TODO:
How _elegant_ ...
Tries to find the right module for extending the Form instance.
It's problematic since the boundaries of what an model instance or model
class looks like is very fuzzy, also a problem is that the ORM may not be
available/required.
Maybe we can abstract that a bit by going through an array of procs for
testing?
42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/ramaze/helper/form.rb', line 42 def self.pick(object, = {}) if defined?(Sequel::Model) if object.is_a?(Sequel::Model) [:layer] ||= Layer::Sequel InstanceForm.new(object, ) elsif object.ancestors.include?(Sequel::Model) [:layer] ||= Layer::Sequel ClassForm.new(object, ) end else raise "Unknown ORM for: %p" % object end end |
Instance Method Details
#field_for(hash) ⇒ Object
Decide on the strucuture of the tag based on the hash
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/ramaze/helper/form.rb', line 76 def field_for(hash) return if hash[:primary_key] args = args_for(hash) inner = case type = hash[:type] when :integer field_integer(*args) when :boolean field_boolean(*args) when :text field_textarea(*args) when :varchar field_input(*args) when :date field_date(*args) when :time field_time(*args) else Log.warn "Unknown field: %p" % hash field_input(*args) end "<label>#{args.first}: </label>\n#{inner}" end |
#to_s ⇒ Object
Generate and return the final form
65 66 67 68 69 70 71 72 73 |
# File 'lib/ramaze/helper/form.rb', line 65 def to_s out = "<form #{form_attributes}>" out << "<fieldset>" out << generate out << "</fieldset>" out << '<input type="submit" />' out << '<input type="reset" />' out << "</form>" end |