lib/happy-helpers/helpers/forms.rb in happy-helpers-0.1.0.pre.1 vs lib/happy-helpers/helpers/forms.rb in happy-helpers-0.1.0.pre.2
- old
+ new
@@ -11,11 +11,11 @@
label = option
value = option
end
s << html_tag(:label) do
- html_tag(:input, type: 'radio', name: name, value: value) + label
+ html_tag(:input, :type => 'radio', :name => name, :value => value) + label
end
end
end
end
@@ -27,55 +27,55 @@
:month_formatter => ->(i) { translate("date.month_names")[i] },
:day_formatter => ->(i) { "#{i}." }
}.merge(options)
value ||= Time.now
- year_select = html_tag(:select, name: "#{name}[year]") do
+ year_select = html_tag(:select, :name => "#{name}[year]") do
options[:years].map do |year|
- html_tag(:option, value: year, selected: year == value.try(:year)) { year }
+ html_tag(:option, :value => year, :selected => year == value.try(:year)) { year }
end.join
end
- month_select = html_tag(:select, name: "#{name}[month]") do
+ month_select = html_tag(:select, :name => "#{name}[month]") do
options[:months].map do |month|
- html_tag(:option, value: month, selected: month == value.try(:month)) { options[:month_formatter].call(month) }
+ html_tag(:option, :value => month, :selected => month == value.try(:month)) { options[:month_formatter].call(month) }
end.join
end
- day_select = html_tag(:select, name: "#{name}[day]") do
+ day_select = html_tag(:select, :name => "#{name}[day]") do
options[:days].map do |day|
- html_tag(:option, value: day, selected: day == value.try(:day)) { options[:day_formatter].call(day) }
+ html_tag(:option, :value => day, :selected => day == value.try(:day)) { options[:day_formatter].call(day) }
end.join
end
- hour_select = html_tag(:select, name: "#{name}[hour]") do
+ hour_select = html_tag(:select, :name => "#{name}[hour]") do
(0..23).map do |hour|
- html_tag(:option, value: hour, selected: hour == value.try(:hour)) { sprintf "%02d", hour }
+ html_tag(:option, :value => hour, :selected => hour == value.try(:hour)) { sprintf "%02d", hour }
end.join
end
- minute_select = html_tag(:select, name: "#{name}[minute]") do
+ minute_select = html_tag(:select, :name => "#{name}[minute]") do
(0..59).map do |minute|
- html_tag(:option, value: minute, selected: minute == value.try(:min)) { sprintf "%02d", minute }
+ html_tag(:option, :value => minute, :selected => minute == value.try(:min)) { sprintf "%02d", minute }
end.join
end
"#{day_select} #{month_select} #{year_select} - #{hour_select} : #{minute_select} Uhr"
end
def checkbox_tag(name, value = false, options = {})
"".tap do |s|
- s << html_tag(:input, name: name, type: 'hidden', value: '0')
- s << html_tag(:input, name: name, type: 'checkbox', value: '1', checked: value ? true : false)
- s << html_tag(:label, class: 'for-checkbox') { options[:text] || name }
+ s << html_tag(:input, :name => name, :type => 'hidden', :value => '0')
+ s << html_tag(:input, :name => name, :type => 'checkbox', :value => '1', :checked => value ? true : false)
+ s << html_tag(:label, :class => 'for-checkbox') { options[:text] || name }
end
end
def form_for(resource, options = {}, &block)
options = {
- action: resource.new_record? ? "/#{resource.class.to_s.tableize}" : "/#{resource.class.to_s.tableize}/#{resource.id}",
- method: 'post'
+ :action => resource.new_record? ? "/#{resource.class.to_s.tableize}" : "/#{resource.class.to_s.tableize}/#{resource.id}",
+ :method => 'post'
}.merge(options)
html_tag :form, options do
capture do
yield FormBuilder.new(self, resource, options)
@@ -97,11 +97,11 @@
name = name.to_s
value = resource.send(name)
# Set default options
options = {
- label: "%s:" % label_text(name)
+ :label => "%s:" % label_text(name)
}.merge(options)
options[:as] ||= case options[:value]
when Date then :date
when DateTime, Time then :datetime
@@ -109,40 +109,40 @@
else :text
end
# Set default options for the input field
field_options = {
- name: "%s[%s]" % [@resource_name, name]
+ :name => "%s[%s]" % [@resource_name, name]
}
unless (placeholder = options.delete(:placeholder) || placeholder(name)).blank?
field_options[:placeholder] = placeholder
end
# Set default options for the wrapper element
wrapper_options = {
- class: "input #{options[:as]}"
+ :class => "input #{options[:as]}"
}
wrapper_options[:class] << " with_error" if resource.errors[name].any?
# Output wrapper tag with contents
helpers.html_tag :div, wrapper_options do
String.new.tap do |s|
# Add actual input field
case options.delete(:as).to_sym
when :textarea
- s << helpers.html_tag(:label, class: 'for-field') { options[:label] }
+ s << helpers.html_tag(:label, :class => 'for-field') { options[:label] }
s << helpers.html_tag(:textarea, field_options) { helpers.preserve(helpers.escape_html(value)) }
when :datetime
- s << helpers.html_tag(:label, class: 'for-field') { options[:label] }
+ s << helpers.html_tag(:label, :class => 'for-field') { options[:label] }
s << helpers.date_time_select_tag(field_options.delete(:name), value, options)
when :radio
s << helpers.radio_buttons(field_options.delete(:name), options: (options.delete(:options) || ['Y', 'N']))
when :checkbox
s << helpers.checkbox_tag(field_options.delete(:name), value, options.merge(:text => options[:text] || label_text(name)))
else
- s << helpers.html_tag(:label, class: 'for-field') { options[:label] }
- s << helpers.html_tag(:input, field_options.merge(type: 'text', value: value))
+ s << helpers.html_tag(:label, :class => 'for-field') { options[:label] }
+ s << helpers.html_tag(:input, field_options.merge(:type => 'text', :value => value))
end
# Add error message, if necessary
if @resource.errors[name].any?
s << helpers.html_tag(:div, :class => "error") { @resource.errors[name].first }
@@ -159,10 +159,10 @@
helpers.translate("forms.#{@resource_name}.placeholders.#{name}", :default => "")
end
def submit(label = nil)
label ||= (resource.new_record? ? 'Create' : 'Update')
- helpers.html_tag(:input, type: 'submit', value: label)
+ helpers.html_tag(:input, :type => 'submit', :value => label)
end
end
end
end
end