Class: Trellis::CoreLibrary::ObjectEditor
- Inherits:
-
Trellis::Component
- Object
- Trellis::Component
- Trellis::CoreLibrary::ObjectEditor
- Defined in:
- lib/trellis/component_library/object_editor.rb
Instance Attribute Summary collapse
-
#properties ⇒ Object
readonly
Returns the value of attribute properties.
-
#retrieve_block ⇒ Object
readonly
Returns the value of attribute retrieve_block.
-
#submit_block ⇒ Object
readonly
Returns the value of attribute submit_block.
-
#submit_text ⇒ Object
Returns the value of attribute submit_text.
Attributes inherited from Trellis::Component
Instance Method Summary collapse
-
#fields(*syms) ⇒ Object
must be called before rendering.
-
#initialize ⇒ ObjectEditor
constructor
A new instance of ObjectEditor.
- #on_submit(&block) ⇒ Object
Methods inherited from Trellis::Component
add_class_scripts_to_page, add_class_styles_to_page, add_document_modifications_to_page, add_script_links_to_page, add_scripts_to_page, add_style_links_to_page, add_styles_to_page, contained_in, depends_on, field, get_component, inherited, is_stateful, #load_component_session_information, page_contribution, register_with_tag_context, render, #save_component_session_information, tag_name
Constructor Details
#initialize ⇒ ObjectEditor
Returns a new instance of ObjectEditor.
46 47 48 |
# File 'lib/trellis/component_library/object_editor.rb', line 46 def initialize @properties = [] end |
Instance Attribute Details
#properties ⇒ Object (readonly)
Returns the value of attribute properties.
42 43 44 |
# File 'lib/trellis/component_library/object_editor.rb', line 42 def properties @properties end |
#retrieve_block ⇒ Object (readonly)
Returns the value of attribute retrieve_block.
41 42 43 |
# File 'lib/trellis/component_library/object_editor.rb', line 41 def retrieve_block @retrieve_block end |
#submit_block ⇒ Object (readonly)
Returns the value of attribute submit_block.
44 45 46 |
# File 'lib/trellis/component_library/object_editor.rb', line 44 def submit_block @submit_block end |
#submit_text ⇒ Object
Returns the value of attribute submit_text.
43 44 45 |
# File 'lib/trellis/component_library/object_editor.rb', line 43 def submit_text @submit_text end |
Instance Method Details
#fields(*syms) ⇒ Object
must be called before rendering
51 52 53 54 55 |
# File 'lib/trellis/component_library/object_editor.rb', line 51 def fields(*syms) syms.each do |sym| @properties << sym end end |
#on_submit(&block) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/trellis/component_library/object_editor.rb', line 57 def on_submit(&block) # populate the object with values from the session if page.params properties.each do |property| value = page.params[property.to_sym] @model.instance_variable_set("@#{property}".to_sym, value) end end if block_given? @submit_block = block else @submit_block.call(@model) end end |