1
0
Fork 0
mirror of https://github.com/heartcombo/simple_form.git synced 2022-11-09 12:19:26 -05:00

Get rid of the enabled/disabled in favor of has_*? syntax.

This commit is contained in:
José Valim 2011-12-04 12:29:53 +01:00
parent fcd049adc6
commit 6bf59dd508
18 changed files with 43 additions and 58 deletions

View file

@ -12,14 +12,6 @@ module SimpleForm
def has_disabled? def has_disabled?
options[:disabled] == true options[:disabled] == true
end end
private
alias :enabled_disabled :disabled
def disabled_disabled
nil
end
end end
end end
end end

View file

@ -11,12 +11,6 @@ module SimpleForm
protected protected
alias :enabled_error :error
def disabled_error
nil
end
def error_text def error_text
if options[:error_prefix] if options[:error_prefix]
options[:error_prefix] + " " + errors.send(error_method) options[:error_prefix] + " " + errors.send(error_method)

View file

@ -2,15 +2,13 @@ module SimpleForm
module Components module Components
module Hints module Hints
def hint def hint
(options.delete(:hint) || translate(:hints)).presence (options.delete(:hint) || translate(:hints)).presence if has_hint?
end end
private private
alias :enabled_hint :hint def has_hint?
true
def disabled_hint
nil
end end
end end
end end

View file

@ -22,6 +22,7 @@ module SimpleForm
end end
def label def label
return "" unless has_label?
if input_type_should_generate_for_attribute? if input_type_should_generate_for_attribute?
@builder.label(label_target, label_text, label_html_options) @builder.label(label_target, label_text, label_html_options)
else else
@ -45,10 +46,8 @@ module SimpleForm
protected protected
alias :enabled_label :label def has_label?
true
def disabled_label
""
end end
def raw_label_text #:nodoc: def raw_label_text #:nodoc:

View file

@ -2,21 +2,15 @@ module SimpleForm
module Components module Components
module Placeholders module Placeholders
def placeholder def placeholder
nil # This component is disabled by default.
end
def has_placeholder?
options[:placeholder] != false && placeholder_text.present?
end
private
def enabled_placeholder
input_html_options[:placeholder] ||= placeholder_text if has_placeholder? input_html_options[:placeholder] ||= placeholder_text if has_placeholder?
nil nil
end end
alias :disabled_placeholder :placeholder def has_placeholder?
placeholder_text.present?
end
private
def placeholder_text def placeholder_text
@placeholder_text ||= options[:placeholder] || translate(:placeholders) @placeholder_text ||= options[:placeholder] || translate(:placeholders)

View file

@ -15,15 +15,6 @@ module SimpleForm
include SimpleForm::Components::LabelInput include SimpleForm::Components::LabelInput
include SimpleForm::Components::Placeholders include SimpleForm::Components::Placeholders
# Enables certain components support to the given input.
def self.enable(*args)
args.each { |m| alias_method m, :"enabled_#{m}" }
end
def self.disable(*args)
args.each { |m| alias_method m, :"disabled_#{m}" }
end
attr_reader :attribute_name, :column, :input_type, :reflection, attr_reader :attribute_name, :column, :input_type, :reflection,
:options, :input_html_options, :input_html_classes :options, :input_html_options, :input_html_classes

View file

@ -9,6 +9,10 @@ module SimpleForm
def input def input
template.capture(&@block) template.capture(&@block)
end end
def has_placeholder?
false
end
end end
end end
end end

View file

@ -9,6 +9,10 @@ module SimpleForm
input + (options[:label] == false ? "" : label) input + (options[:label] == false ? "" : label)
end end
def has_placeholder?
false
end
private private
# Booleans are not required by default because in most of the cases # Booleans are not required by default because in most of the cases

View file

@ -24,6 +24,10 @@ module SimpleForm
options options
end end
def has_placeholder?
false
end
private private
def collection def collection

View file

@ -5,12 +5,16 @@ module SimpleForm
@builder.send(:"#{input_type}_select", attribute_name, input_options, input_html_options) @builder.send(:"#{input_type}_select", attribute_name, input_options, input_html_options)
end end
private def has_placeholder?
false
end
def has_required? def has_required?
false false
end end
private
def label_target def label_target
case input_type case input_type
when :date, :datetime when :date, :datetime

View file

@ -4,6 +4,10 @@ module SimpleForm
def input def input
@builder.file_field(attribute_name, input_html_options) @builder.file_field(attribute_name, input_html_options)
end end
def has_placeholder?
false
end
end end
end end
end end

View file

@ -1,12 +1,15 @@
module SimpleForm module SimpleForm
module Inputs module Inputs
class HiddenInput < Base class HiddenInput < Base
disable :label, :error, :hint
def input def input
@builder.hidden_field(attribute_name, input_html_options) @builder.hidden_field(attribute_name, input_html_options)
end end
def has_label?() false end
def has_errors?() false end
def has_hint?() false end
def has_placeholder?() false end
private private
def attribute_required? def attribute_required?

View file

@ -1,8 +1,6 @@
module SimpleForm module SimpleForm
module Inputs module Inputs
class NumericInput < Base class NumericInput < Base
enable :placeholder
def input def input
add_size! add_size!
if SimpleForm.html5 if SimpleForm.html5

View file

@ -1,8 +1,6 @@
module SimpleForm module SimpleForm
module Inputs module Inputs
class PasswordInput < Base class PasswordInput < Base
enable :placeholder
def input def input
add_size! add_size!
add_maxlength! add_maxlength!

View file

@ -10,12 +10,12 @@ module SimpleForm
options[:priority] || SimpleForm.send(:"#{input_type}_priority") options[:priority] || SimpleForm.send(:"#{input_type}_priority")
end end
protected
def has_required? def has_required?
false false
end end
protected
def skip_include_blank? def skip_include_blank?
super || input_priority.present? super || input_priority.present?
end end

View file

@ -1,8 +1,6 @@
module SimpleForm module SimpleForm
module Inputs module Inputs
class RangeInput < NumericInput class RangeInput < NumericInput
disable :placeholder
def input def input
if SimpleForm.html5 if SimpleForm.html5
input_html_options[:type] ||= "range" input_html_options[:type] ||= "range"
@ -11,6 +9,10 @@ module SimpleForm
super super
end end
def has_placeholder?
false
end
end end
end end
end end

View file

@ -1,8 +1,6 @@
module SimpleForm module SimpleForm
module Inputs module Inputs
class StringInput < Base class StringInput < Base
enable :placeholder
def input def input
input_html_options[:type] ||= input_type if SimpleForm.html5 && !string? input_html_options[:type] ||= input_type if SimpleForm.html5 && !string?
add_maxlength! add_maxlength!

View file

@ -1,8 +1,6 @@
module SimpleForm module SimpleForm
module Inputs module Inputs
class TextInput < Base class TextInput < Base
enable :placeholder
def input def input
add_maxlength! add_maxlength!
@builder.text_area(attribute_name, input_html_options) @builder.text_area(attribute_name, input_html_options)