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?
options[:disabled] == true
end
private
alias :enabled_disabled :disabled
def disabled_disabled
nil
end
end
end
end

View File

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

View File

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

View File

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

View File

@ -2,21 +2,15 @@ module SimpleForm
module Components
module Placeholders
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?
nil
end
alias :disabled_placeholder :placeholder
def has_placeholder?
placeholder_text.present?
end
private
def placeholder_text
@placeholder_text ||= options[:placeholder] || translate(:placeholders)

View File

@ -15,15 +15,6 @@ module SimpleForm
include SimpleForm::Components::LabelInput
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,
:options, :input_html_options, :input_html_classes

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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