Class: ToQuickform::Generator
- Includes:
- ERBTemplates
- Defined in:
- lib/to_quickform/generator.rb
Overview
Generator
Constant Summary
Constants included from ERBTemplates
ERBTemplates::BASIC_CHECKBOX_ELEMENT_TEMPLATE, ERBTemplates::BASIC_COMPARE_RULE_TEMPLATE, ERBTemplates::BASIC_CREATE_ELEMENT_TEMPLATE, ERBTemplates::BASIC_DEFAULT, ERBTemplates::BASIC_ELEMENT_TEMPLATE, ERBTemplates::BASIC_GROUP_ELEMENT_TEMPLATE, ERBTemplates::BASIC_GROUP_RULE_TEMPLATE, ERBTemplates::BASIC_RADIO_ELEMENT_TEMPLATE, ERBTemplates::BASIC_RULE_TEMPLATE, ERBTemplates::BASIC_SELECT_ELEMENT_TEMPLATE, ERBTemplates::BASIC_VALUE_ELEMENT_TEMPLATE
Instance Method Summary collapse
-
#initialize(attributes = {}) ⇒ Generator
constructor
A new instance of Generator.
- #to_add_rule ⇒ Object
- #to_create_element ⇒ Object
- #to_set_defaults ⇒ Object
Constructor Details
#initialize(attributes = {}) ⇒ Generator
Returns a new instance of Generator.
14 15 16 17 18 19 20 21 22 |
# File 'lib/to_quickform/generator.rb', line 14 def initialize(attributes = {}) if attributes.is_a?(Hash) (required_attributes + optional_attributes).each do |key| value = attributes[key] self.send "#{key}=", value end end attr_missing! end |
Instance Method Details
#to_add_rule ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/to_quickform/generator.rb', line 40 def to_add_rule elements.map do |element| if element.rule name = element.name element.rule.map do |rule| # Read template to be used template = "form_#{rule.type}_rule_template" template = nil unless respond_to? template erb = ToQuickform::ERBFactory.new(template).get_rule_instance(rule) erb.result(binding) end.join end end.join end |
#to_create_element ⇒ Object
29 30 31 32 33 34 35 36 37 38 |
# File 'lib/to_quickform/generator.rb', line 29 def to_create_element elements.map do |element| # Read template to be used template = "form_#{element.type}_element_template" template = nil unless respond_to? template erb = ToQuickform::ERBFactory.new(template).get_element_instancue(element) erb.result(binding) end.join end |
#to_set_defaults ⇒ Object
24 25 26 27 |
# File 'lib/to_quickform/generator.rb', line 24 def to_set_defaults erb = ToQuickform::ERBFactory.new(form_default_template).get_default_instance erb.result(binding) end |