module FormAngular::NgOptionUtils
Public Instance Methods
build_angular_form_options(record)
click to toggle source
# File lib/form_angular/helpers/ng_option_utils.rb, line 7 def build_angular_form_options(record) angular_options = { name: "#{form_context(record)}Form", novalidate: true } end
build_angular_options(attribute_name, builder)
click to toggle source
# File lib/form_angular/helpers/ng_option_utils.rb, line 15 def build_angular_options(attribute_name, builder) begin names = builder.object_name.gsub(/\[(?<wat>[a-zA-Z][_a-zA-Z0-9]+)+\]/, '.\k<wat>').gsub("_attributes", '').split(".") names[0] = names[0].camelize(:lower) angular_options = { 'ng-model' => "#{names.join(".")}.#{attribute_name}", 'server-error' => "true" } rescue => e end end
context_name(record)
click to toggle source
# File lib/form_angular/helpers/ng_option_utils.rb, line 31 def context_name(record) if record.is_a?(String) || record.is_a?(Symbol) record else record.class.name.underscore end end
form_context(record)
click to toggle source
# File lib/form_angular/helpers/ng_option_utils.rb, line 27 def form_context(record) record.class.name.camelize(:lower) end
form_name()
click to toggle source
Find a better way to make the form name trickledown globally in the wrapper api
# File lib/form_angular/helpers/ng_option_utils.rb, line 40 def form_name name = from_html_options(:name, @builder.options) return name unless name.blank? builder = @builder until !builder || !name.blank? name = from_html_options(:name, builder.options) builder = builder.options[:parent_builder] end name end
from_html_options(key, html_options)
click to toggle source
# File lib/form_angular/helpers/ng_option_utils.rb, line 51 def from_html_options(key, html_options) if html_options[:html] html_options[:html][key] end end
ng_access_expression()
click to toggle source
# File lib/form_angular/helpers/ng_option_utils.rb, line 57 def ng_access_expression "#{form_name}['#{tag_name}']" end
ng_form_expression()
click to toggle source
# File lib/form_angular/helpers/ng_option_utils.rb, line 61 def ng_form_expression "#{form_name}" end
tag_name(multiple = false)
click to toggle source
# File lib/form_angular/helpers/ng_option_utils.rb, line 65 def tag_name(multiple = false) "#{object_name}[#{attribute_name}]" end