Skip to content

Commit

Permalink
Revert all the changes introduced in commits 8d17ca4..8d8c50
Browse files Browse the repository at this point in the history
Restarting the work on rails3 compatibility with a clean branch
makes live easier - in here were a lot of changes from different
sources touching different problems without resulting in a complete
solution.
  • Loading branch information
mjonuschat committed Apr 15, 2010
1 parent 8d8c50f commit f9c1a8a
Show file tree
Hide file tree
Showing 45 changed files with 109 additions and 526 deletions.
6 changes: 0 additions & 6 deletions init.rb

This file was deleted.

57 changes: 29 additions & 28 deletions lib/formtastic.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# coding: utf-8
require File.join(File.dirname(__FILE__), *%w[formtastic i18n])
require File.join(File.dirname(__FILE__), *%w[formtastic html_safe])
require File.join(File.dirname(__FILE__), *%w[formtastic railtie]) if defined?(::Rails::Railtie)

module Formtastic #:nodoc:

Expand Down Expand Up @@ -107,7 +105,7 @@ def input(method, options = {})
send(:"inline_#{type}_for", method, options)
end.compact.join("\n")

return template.content_tag(:li, list_item_content.to_s.html_safe, wrapper_html)
return template.content_tag(:li, list_item_content, wrapper_html)
end

# Creates an input fieldset and ol tag wrapping for use around a set of inputs. It can be
Expand Down Expand Up @@ -344,7 +342,7 @@ def commit_button(*args)
element_class = ['commit', options.delete(:class)].compact.join(' ') # TODO: Add class reflecting on form action.
accesskey = (options.delete(:accesskey) || @@default_commit_button_accesskey) unless button_html.has_key?(:accesskey)
button_html = button_html.merge(:accesskey => accesskey) if accesskey
template.content_tag(:li, self.submit(text, button_html).to_s.html_safe, :class => element_class)
template.content_tag(:li, self.submit(text, button_html), :class => element_class)
end

# A thin wrapper around #fields_for to set :builder => Formtastic::SemanticFormBuilder
Expand Down Expand Up @@ -408,7 +406,7 @@ def label(method, options_or_text=nil, options=nil)
text = (options.delete(:label_prefix_for_nested_input) || "") + text

input_name = options.delete(:input_name) || method
super(input_name, text.to_s.html_safe, options)
super(input_name, text, options)
end

# Generates error messages for the given method. Errors can be shown as list,
Expand Down Expand Up @@ -454,7 +452,7 @@ def semantic_errors(*args)
return nil if full_errors.blank?
html_options[:class] ||= "errors"
template.content_tag(:ul, html_options) do
full_errors.map { |error| template.content_tag(:li, error.to_s.html_safe) }.join.to_s.html_safe
full_errors.map { |error| template.content_tag(:li, error) }.join
end
end

Expand Down Expand Up @@ -861,12 +859,12 @@ def radio_input(method, options)
html_options[:checked] = selected_value == value if selected_option_is_present

li_content = template.content_tag(:label,
"#{self.radio_button(input_name, value, html_options)} #{label}".to_s.html_safe,
"#{self.radio_button(input_name, value, html_options)} #{label}",
:for => input_id
)

li_options = value_as_class ? { :class => [method.to_s.singularize, value.to_s.downcase].join('_') } : {}
template.content_tag(:li, li_content.to_s.html_safe, li_options)
template.content_tag(:li, li_content, li_options)
end

field_set_and_list_wrapping_for_method(method, options, list_item_content)
Expand Down Expand Up @@ -1016,9 +1014,9 @@ def date_or_datetime_input(method, options)
item_label_text = labels[input] || ::I18n.t(input.to_s, :default => input.to_s.humanize, :scope => [:datetime, :prompts])

list_items_capture << template.content_tag(:li, [
!item_label_text.blank? ? template.content_tag(:label, item_label_text.to_s.html_safe, :for => input_id) : "",
!item_label_text.blank? ? template.content_tag(:label, item_label_text, :for => input_id) : "",
template.send(:"select_#{input}", datetime, opts, html_options.merge(:id => input_id))
].join("").to_s.html_safe
].join("")
)
end
end
Expand Down Expand Up @@ -1112,27 +1110,23 @@ def check_boxes_input(method, options)
selected_option_is_present = [:selected, :checked].any? { |k| options.key?(k) }
selected_values = (options.key?(:checked) ? options[:checked] : options[:selected]) if selected_option_is_present
selected_values = [*selected_values].compact

disabled_option_is_present = options.key?(:disabled)
disabled_values = [*options[:disabled]] if disabled_option_is_present


list_item_content = collection.map do |c|
label = c.is_a?(Array) ? c.first : c
value = c.is_a?(Array) ? c.last : c
input_id = generate_html_id(input_name, value.to_s.gsub(/\s/, '_').gsub(/\W/, '').downcase)
input_ids << input_id

html_options[:checked] = selected_values.include?(value) if selected_option_is_present
html_options[:disabled] = disabled_values.include?(value) if disabled_option_is_present
html_options[:id] = input_id

li_content = template.content_tag(:label,
"#{self.check_box(input_name, html_options, value, unchecked_value)} #{label}".to_s.html_safe,
"#{self.check_box(input_name, html_options, value, unchecked_value)} #{label}",
:for => input_id
)

li_options = value_as_class ? { :class => [method.to_s.singularize, value.to_s.downcase].join('_') } : {}
template.content_tag(:li, li_content.to_s.html_safe, li_options)
template.content_tag(:li, li_content, li_options)
end

field_set_and_list_wrapping_for_method(method, options, list_item_content)
Expand Down Expand Up @@ -1197,29 +1191,29 @@ def inline_input_for(method, options)
def inline_hints_for(method, options) #:nodoc:
options[:hint] = localized_string(method, options[:hint], :hint)
return if options[:hint].blank?
template.content_tag(:p, options[:hint].to_s.html_safe, :class => 'inline-hints')
template.content_tag(:p, options[:hint], :class => 'inline-hints')
end

# Creates an error sentence by calling to_sentence on the errors array.
#
def error_sentence(errors) #:nodoc:
template.content_tag(:p, errors.to_sentence.untaint.to_s.html_safe, :class => 'inline-errors')
template.content_tag(:p, errors.to_sentence.untaint, :class => 'inline-errors')
end

# Creates an error li list.
#
def error_list(errors) #:nodoc:
list_elements = []
errors.each do |error|
list_elements << template.content_tag(:li, error.untaint.to_s.html_safe)
list_elements << template.content_tag(:li, error.untaint)
end
template.content_tag(:ul, list_elements.join("\n").to_s.html_safe, :class => 'errors')
template.content_tag(:ul, list_elements.join("\n"), :class => 'errors')
end

# Creates an error sentence containing only the first error
#
def error_first(errors) #:nodoc:
template.content_tag(:p, errors.first.untaint.to_s.html_safe, :class => 'inline-errors')
template.content_tag(:p, errors.first.untaint, :class => 'inline-errors')
end

# Generates the required or optional string. If the value set is a proc,
Expand Down Expand Up @@ -1266,7 +1260,7 @@ def field_set_and_list_wrapping(*args, &block) #:nodoc:

legend = html_options.delete(:name).to_s
legend %= parent_child_index(html_options[:parent]) if html_options[:parent]
legend = template.content_tag(:legend, template.content_tag(:span, legend.to_s.html_safe)) unless legend.blank?
legend = template.content_tag(:legend, template.content_tag(:span, legend)) unless legend.blank?

if block_given?
contents = if template.respond_to?(:is_haml?) && template.is_haml?
Expand All @@ -1279,11 +1273,11 @@ def field_set_and_list_wrapping(*args, &block) #:nodoc:
# Ruby 1.9: String#to_s behavior changed, need to make an explicit join.
contents = contents.join if contents.respond_to?(:join)
fieldset = template.content_tag(:fieldset,
legend.to_s.html_safe << template.content_tag(:ol, contents.to_s.html_safe),
legend << template.content_tag(:ol, contents),
html_options.except(:builder, :parent)
)

template.concat(fieldset) if block_given? && (!defined?(Rails::VERSION) || Rails::VERSION::MAJOR == 2)
template.concat(fieldset) if block_given?
fieldset
end

Expand Down Expand Up @@ -1311,7 +1305,7 @@ def field_set_and_list_wrapping_for_method(method, options, contents) #:nodoc:
template.content_tag(:legend,
self.label(method, options_for_label(options).merge(:for => options.delete(:label_for))), :class => 'label'
) <<
template.content_tag(:ol, contents.to_s.html_safe)
template.content_tag(:ol, contents)
)
end

Expand Down Expand Up @@ -1477,7 +1471,7 @@ def generate_association_input_name(method) #:nodoc:
if [:has_and_belongs_to_many, :has_many].include?(reflection.macro)
"#{method.to_s.singularize}_ids"
else
reflection.options[:foreign_key] || "#{method}_id"
reflection.options[:foreign_key] || reflection.options[:class_name].try(:foreign_key) || "#{method}_id"
end
else
method
Expand Down Expand Up @@ -1639,11 +1633,15 @@ def set_include_blank(options)
#
# * semantic_form_for(@post)
# * semantic_fields_for(@post)
# * semantic_form_remote_for(@post)
# * semantic_remote_form_for(@post)
#
# Each of which are the equivalent of:
#
# * form_for(@post, :builder => Formtastic::SemanticFormBuilder))
# * fields_for(@post, :builder => Formtastic::SemanticFormBuilder))
# * form_remote_for(@post, :builder => Formtastic::SemanticFormBuilder))
# * remote_form_for(@post, :builder => Formtastic::SemanticFormBuilder))
#
# Example Usage:
#
Expand Down Expand Up @@ -1684,7 +1682,8 @@ def with_custom_field_error_proc(&block)
::ActionView::Base.field_error_proc = @@default_field_error_proc
result
end
[:form_for, :fields_for].each do |meth|

[:form_for, :fields_for, :remote_form_for].each do |meth|
module_eval <<-END_SRC, __FILE__, __LINE__ + 1
def semantic_#{meth}(record_or_name_or_array, *args, &proc)
options = args.extract_options!
Expand All @@ -1706,5 +1705,7 @@ def semantic_#{meth}(record_or_name_or_array, *args, &proc)
end
END_SRC
end
alias :semantic_form_remote_for :semantic_remote_form_for

end
end
7 changes: 0 additions & 7 deletions lib/formtastic/html_safe.rb

This file was deleted.

1 change: 0 additions & 1 deletion lib/formtastic/i18n.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
module Formtastic
module I18n

Expand Down
1 change: 0 additions & 1 deletion lib/formtastic/layout_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
# coding: utf-8
module Formtastic
module LayoutHelper

Expand Down
10 changes: 0 additions & 10 deletions lib/formtastic/railtie.rb

This file was deleted.

85 changes: 0 additions & 85 deletions lib/generators/formtastic/form/form_generator.rb

This file was deleted.

5 changes: 0 additions & 5 deletions lib/generators/formtastic/form/templates/_form.html.erb

This file was deleted.

4 changes: 0 additions & 4 deletions lib/generators/formtastic/form/templates/_form.html.haml

This file was deleted.

23 changes: 0 additions & 23 deletions lib/generators/formtastic/install/install_generator.rb

This file was deleted.

Loading

0 comments on commit f9c1a8a

Please sign in to comment.