Skip to content

Commit

Permalink
refactor(form_builder): extract arguments parsing in a method
Browse files Browse the repository at this point in the history
  • Loading branch information
abe33 committed Jan 13, 2014
1 parent a7aa33d commit f6a2093
Showing 1 changed file with 13 additions and 11 deletions.
24 changes: 13 additions & 11 deletions lib/awesome_form/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ def initialize(*)
end

def inputs(*args, &block)
options = {}

attributes = args.select {|a| a.is_a? Symbol }
options_args = args.select {|a| a.is_a? Hash }
options_args.each {|h| options.merge! h }
attributes, options = filter_arguments(*args)

attributes.map {|f| input f, options }.join("\n").html_safe
end
Expand All @@ -28,13 +24,9 @@ def input(attribute, options={}, &block)
end

def actions(*args, &block)
options = {}

attributes = args.select {|a| a.is_a? Symbol }
options_args = args.select {|a| a.is_a? Hash }
options_args.each {|h| options.merge! h }
actions, options = filter_arguments(*args)

attributes.map {|f| input f, options }.join("\n").html_safe
actions.map {|f| input f, options }.join("\n").html_safe
end

def action(action, options={}, &block)
Expand Down Expand Up @@ -63,6 +55,16 @@ def view_exists?(view)

protected

def filter_arguments(*args)
options = {}

symbols = args.select {|a| a.is_a? Symbol }
options_args = args.select {|a| a.is_a? Hash }
options_args.each {|h| options.merge! h }

[symbols, options]
end

def partial_for_input(input_options)
for_type = "awesome_form/#{AwesomeForm.theme}/inputs/#{input_options[:type]}"
default_for_theme = "awesome_form/#{AwesomeForm.theme}/inputs/default"
Expand Down

0 comments on commit f6a2093

Please sign in to comment.