Class: SemiFormal::Builder
Instance Attribute Summary collapse
-
#instance ⇒ Object
readonly
Returns the value of attribute instance.
Instance Method Summary collapse
- #form_attributes ⇒ Object
-
#initialize(instance) ⇒ Builder
constructor
A new instance of Builder.
- #inputs ⇒ Object
- #method_overrider(doc) ⇒ Object
- #to_html ⇒ Object
Constructor Details
#initialize(instance) ⇒ Builder
Returns a new instance of Builder.
5 6 7 |
# File 'lib/semi_formal/builder.rb', line 5 def initialize(instance) @instance = instance end |
Instance Attribute Details
#instance ⇒ Object (readonly)
Returns the value of attribute instance.
3 4 5 |
# File 'lib/semi_formal/builder.rb', line 3 def instance @instance end |
Instance Method Details
#form_attributes ⇒ Object
30 31 32 |
# File 'lib/semi_formal/builder.rb', line 30 def form_attributes @form_attributes ||= Form.new(self).attributes end |
#inputs ⇒ Object
24 25 26 27 28 |
# File 'lib/semi_formal/builder.rb', line 24 def inputs @inputs ||= @instance.class.content_columns.map do |column| Input.new(@instance, column.name) end end |
#method_overrider(doc) ⇒ Object
19 20 21 22 |
# File 'lib/semi_formal/builder.rb', line 19 def method_overrider(doc) return if instance.new_record? doc.input(:type => "hidden", :name => "_method", :value => "put") end |
#to_html ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/semi_formal/builder.rb', line 9 def to_html Nokogiri::HTML::Builder.new { form(form_attributes) { method_overrider(self) inputs.each { |i| i.call(self) } input(:type => "submit") { text "Save!" } } }.doc.to_html end |