Permalink
Browse files

Merge branch 'master' into refactor

Conflicts:
	lib/formtastic/form_builder.rb
	lib/formtastic/helpers/inputs_helper.rb
	lib/formtastic/helpers/label_helper.rb
	lib/formtastic/html_attributes.rb
	lib/formtastic/inputs/basic.rb
	lib/formtastic/inputs/boolean_input.rb
	lib/formtastic/inputs/check_boxes_input.rb
	lib/formtastic/inputs/country_input.rb
	lib/formtastic/inputs/date_input.rb
	lib/formtastic/inputs/datetime_input.rb
	lib/formtastic/inputs/email_input.rb
	lib/formtastic/inputs/file_input.rb
	lib/formtastic/inputs/hidden_input.rb
	lib/formtastic/inputs/numeric_input.rb
	lib/formtastic/inputs/password_input.rb
	lib/formtastic/inputs/phone_input.rb
	lib/formtastic/inputs/radio_input.rb
	lib/formtastic/inputs/search_input.rb
	lib/formtastic/inputs/select_input.rb
	lib/formtastic/inputs/string_input.rb
	lib/formtastic/inputs/text_input.rb
	lib/formtastic/inputs/time_input.rb
	lib/formtastic/inputs/time_zone_input.rb
	lib/formtastic/inputs/timeish.rb
	lib/formtastic/inputs/url_input.rb
	lib/formtastic/localized_string.rb
  • Loading branch information...
2 parents 3b7bc44 + ca118c1 commit caf88c96d801a2b0ad95d3beeb7dc0670c84adf5 @justinfrench committed Mar 28, 2011
Showing with 504 additions and 517 deletions.
  1. +7 −7 CHANGELOG
  2. +2 −2 README.textile
  3. +11 −6 lib/formtastic.rb
  4. +7 −37 lib/formtastic/form_builder.rb
  5. +12 −0 lib/formtastic/helpers.rb
  6. +25 −28 lib/formtastic/helpers/buttons_helper.rb
  7. +13 −17 lib/formtastic/helpers/errors_helper.rb
  8. +8 −8 lib/formtastic/helpers/fieldset_wrapper.rb
  9. +2 −2 lib/formtastic/helpers/file_column_detection.rb
  10. +21 −21 lib/formtastic/helpers/form_helper.rb
  11. +51 −56 lib/formtastic/helpers/inputs_helper.rb
  12. +3 −3 lib/formtastic/html_attributes.rb
  13. +28 −0 lib/formtastic/inputs.rb
  14. +15 −18 lib/formtastic/inputs/base.rb
  15. +2 −4 lib/formtastic/inputs/boolean_input.rb
  16. +8 −11 lib/formtastic/inputs/check_boxes_input.rb
  17. +6 −8 lib/formtastic/inputs/country_input.rb
  18. +0 −3 lib/formtastic/inputs/date_input.rb
  19. +0 −5 lib/formtastic/inputs/datetime_input.rb
  20. +3 −7 lib/formtastic/inputs/email_input.rb
  21. +3 −5 lib/formtastic/inputs/file_input.rb
  22. +4 −6 lib/formtastic/inputs/hidden_input.rb
  23. +19 −11 lib/formtastic/inputs/new_base.rb
  24. +3 −7 lib/formtastic/inputs/numeric_input.rb
  25. +3 −6 lib/formtastic/inputs/password_input.rb
  26. +3 −6 lib/formtastic/inputs/phone_input.rb
  27. +19 −22 lib/formtastic/inputs/radio_input.rb
  28. +3 −3 lib/formtastic/inputs/search_input.rb
  29. +14 −18 lib/formtastic/inputs/select_input.rb
  30. +2 −5 lib/formtastic/inputs/string_input.rb
  31. +2 −4 lib/formtastic/inputs/text_input.rb
  32. +0 −2 lib/formtastic/inputs/time_input.rb
  33. +4 −6 lib/formtastic/inputs/time_zone_input.rb
  34. +3 −6 lib/formtastic/inputs/url_input.rb
  35. +9 −9 lib/formtastic/localized_string.rb
  36. +0 −3 lib/formtastic/railtie.rb
  37. +1 −1 lib/formtastic/util.rb
  38. +15 −10 lib/generators/formtastic/form/form_generator.rb
  39. +2 −2 lib/generators/templates/_form.html.erb
  40. +2 −2 lib/generators/templates/_form.html.haml
  41. +7 −7 lib/generators/templates/formtastic.css
  42. +4 −4 lib/generators/templates/formtastic.rb
  43. +158 −0 sample/basic_inputs.html
  44. +0 −6 spec/support/deprecation.rb
  45. +0 −123 stylesheet_tests/basic_inputs.html
View
@@ -18,8 +18,8 @@
* Changed :boolean inputs to use Rails' check_box_checked? instead of our own logic
* Changed developer instructions in README
* Fixed :boolean inputs to disable the included hidden input when disabling the actual checkbox
-* Fixed that Formtastic was making changes to the options hash directly instead of on a duplicate, causing problems for those trying to reuse options on multiple inputs in the view
-* Fixed that tiny scroll bars were appearing on legends in date/time/radio/cbheckboxes fielsets (GH-477)
+* Fixed that Formtastic was making changes to the options hash directly instead of on a duplicate, causing problems for those trying to reuse options on multiple inputs in the view
+* Fixed that tiny scroll bars were appearing on legends in date/time/radio/cbheckboxes fielsets (GH-477)
* Fixed an issue when formtastic fails to determine if a checkbox is checked with custom checked and unchecked values (thanks to Eugene Bolshakov)
* Fixed that the hidden input rendered with a boolean checkbox did nt use the custom :name from :input_html options hash
@@ -43,7 +43,7 @@
* Removed deprecated aliased method names (input_field_set, button_field_set)
* Removed deprecated :class => 'whatever' on commit_button
* Fixed that classes in :button_html were being merged into :wrapper_html
-* Fixed that :include_blank was being ignored (always false) for multi selects
+* Fixed that :include_blank was being ignored (always false) for multi selects
* Fixed that we should reflect on allow_blank option to determine required status with validates_inclusion_of
* Added the ability to pass :input_html options be passed to the checkbox on a boolean input
* Developers: Added bundler support to for developer/contribution
@@ -89,7 +89,7 @@
* Added a fallback to Rails' helpers.label key if Formtastic label translation are not found
* Added support for default_text_area_width
* Added support for #persisted? over #new_record? (ActiveModel)
- * Added the 'required' logic to attributes with validates_inclusion_of validation, in addition to validates_presence_of
+ * Added the 'required' logic to attributes with validates_inclusion_of validation, in addition to validates_presence_of
* Added new HTML5 :as => :email input (Rails 3)
* Added new HTML5 :as => :phone input (Rails 3)
* Added new HTML5 :as => :search input (Rails 3)
@@ -103,15 +103,15 @@
* Added custom_inline_order to allow inline ordering per input type
* Added the ability to override the generator templates in Rails 3
-* Fixes
+* Fixes
* Fixed invalid HTML generated by Rails' hidden inputs on checkboxes (by rendering our own hidden tag in a more deliberate place)
* Fixed a bunch of invalid i18n key defaults
* Fixed that 'required' classes and logic were not being applied to :check_boxes and :radio inputs
* Fixed CSS bugs around Firefox's quirks with form elements that resulted in overflow/scroll bar issues
* Fixed that errors on fields with association were not marking the wrapping tag with the error class
* Fixed CSS where FF was displaying extra scroll bars on .check_boxes and .radio inputs (and the choices within them)
-
+
* Changes
* Changed that we were defaulting to a :select input for columns ending in _id, instead of columns with an appropriate associations
@@ -161,7 +161,7 @@
1.0.0.rc
-* Fixed that :checked_value and :unchecked_value options were being passed down into the HTML tags as attributes
+* Fixed that :checked_value and :unchecked_value options were being passed down into the HTML tags as attributes
1.0.0.beta4
View
@@ -95,7 +95,7 @@ Formtastic edge (2.0) will be compatible with Rails 3 only, and the gem is "host
Simply add Formtastic to your Gemfile and bundle it up:
<pre>
- gem 'formtastic', '~> 2.0.0'
+ gem 'formtastic', '~> 1.2.3'
</pre>
Optionally, run the generator to copy some stylesheets and a configuration initializer into your application:
@@ -579,7 +579,7 @@ h2. Dependencies
There are none, but...
* if you have the "ValidationReflection":http://github.com/redinger/validation_reflection plugin is installed, you won't have to specify the @:required@ option (it checks the validations on the model instead).
-* if you want to use the @:country@ input, you'll need to install the "iso-3166-country-select plugin":http://github.com/rails/iso-3166-country-select (or any other country_select plugin with the same API).
+* if you want to use the @:country@ input, you'll need to install the "country-select plugin":https://github.com/chrislerum/country_select (or any other country_select plugin with the same API).
* "rspec":http://github.com/dchelimsky/rspec/, "rspec_hpricot_matchers":http://rubyforge.org/projects/rspec-hpricot/ and "rcov":http://github.com/relevance/rcov gems (plus any of their own dependencies) are required for the test suite.
View
@@ -1,8 +1,13 @@
# encoding: utf-8
-require 'formtastic/i18n'
-require 'formtastic/util'
-require 'formtastic/railtie' if defined?(::Rails::Railtie)
-require 'formtastic/form_builder'
-require 'formtastic/semantic_form_builder' # TODO remove from 2.0
-require 'formtastic/helpers/form_helper'
+module Formtastic
+ extend ActiveSupport::Autoload
+
+ autoload :FormBuilder
+ autoload :Helpers
+ autoload :HtmlAttributes
+ autoload :I18n
+ autoload :Inputs
+ autoload :LocalizedString
+ autoload :Reflection
+end
@@ -1,40 +1,11 @@
-$LOAD_PATH.unshift(File.expand_path(File.join(File.dirname(__FILE__))))
-
-require 'html_attributes'
-
-require 'helpers/inputs_helper'
-require 'helpers/buttons_helper'
-require 'helpers/errors_helper'
-
-# TODO are these required any more?
-require 'inputs/boolean_input'
-require 'inputs/check_boxes_input'
-require 'inputs/country_input'
-require 'inputs/datetime_input'
-require 'inputs/date_input'
-require 'inputs/email_input'
-require 'inputs/file_input'
-require 'inputs/hidden_input'
-require 'inputs/numeric_input'
-require 'inputs/password_input'
-require 'inputs/phone_input'
-require 'inputs/radio_input'
-require 'inputs/search_input'
-require 'inputs/select_input'
-require 'inputs/string_input'
-require 'inputs/text_input'
-require 'inputs/time_input'
-require 'inputs/time_zone_input'
-require 'inputs/url_input'
-
module Formtastic
class FormBuilder < ActionView::Helpers::FormBuilder
-
+
def self.configure(name, value = nil)
class_attribute(name)
- self.send(:"#{name}=", value)
+ self.send(:"#{name}=", value)
end
-
+
configure :custom_namespace
configure :default_text_field_size
configure :default_text_area_height, 20
@@ -57,15 +28,14 @@ def self.configure(name, value = nil)
configure :default_inline_error_class, 'inline-errors'
configure :default_error_list_class, 'errors'
configure :default_hint_class, 'inline-hints'
-
+
attr_accessor :template
-
+
include Formtastic::HtmlAttributes
-
+
include Formtastic::Helpers::InputsHelper
include Formtastic::Helpers::ButtonsHelper
include Formtastic::Helpers::ErrorsHelper
-
end
-
+
end
View
@@ -0,0 +1,12 @@
+module Formtastic
+ module Helpers
+ autoload :ButtonsHelper, 'formtastic/helpers/buttons_helper'
+ autoload :ErrorsHelper, 'formtastic/helpers/errors_helper'
+ autoload :FieldsetWrapper, 'formtastic/helpers/fieldset_wrapper'
+ autoload :FileColumnDetection, 'formtastic/helpers/file_column_detection'
+ autoload :FormHelper, 'formtastic/helpers/form_helper'
+ autoload :InputsHelper, 'formtastic/helpers/inputs_helper'
+ autoload :LabelHelper, 'formtastic/helpers/label_helper'
+ autoload :SemanticFormHelper, 'formtastic/helpers/semantic_form_helper'
+ end
+end
@@ -1,13 +1,10 @@
-require 'helpers/fieldset_wrapper'
-require 'localized_string'
-
module Formtastic
module Helpers
-
- # ButtonsHelper encapsulates the responsibilties of the {#buttons} and {#commit_button} helpers
+
+ # ButtonsHelper encapsulates the responsibilties of the {#buttons} and {#commit_button} helpers
# for submitting forms.
#
- # {#buttons} is used to wrap the form's button(s) and actions in a `<fieldset>` and `<ol>`,
+ # {#buttons} is used to wrap the form's button(s) and actions in a `<fieldset>` and `<ol>`,
# with each item in the list containing the markup representing a single button.
#
# {#buttons} is usually called with a block containing a single {#commit_button} call:
@@ -34,12 +31,12 @@ module Helpers
#
# While this may seem slightly over-engineered, it is consistent with the way form inputs are
# handled, and makes room for other types of buttons and actions in future versions (such as
- # cancel buttons or links, reset buttons and even alternate actions like 'save and continue
+ # cancel buttons or links, reset buttons and even alternate actions like 'save and continue
# editing').
#
# It's important to note that the `semantic_form_for` and {#buttons} blocks wrap the
# standard Rails `form_for` helper and form builder, so you have full access to every standard
- # Rails form helper, with any HTML markup and ERB syntax, allowing you to "break free" from
+ # Rails form helper, with any HTML markup and ERB syntax, allowing you to "break free" from
# Formtastic when it doesn't suit to create your own buttons, links and actions:
#
# <%= semantic_form_for @post do |f| %>
@@ -59,7 +56,7 @@ module Helpers
module ButtonsHelper
include Formtastic::Helpers::FieldsetWrapper
include Formtastic::LocalizedString
-
+
# Creates a fieldset and ol tag wrapping for use around a set of buttons. It can be
# called either with a block (in which you can do the usual Rails form stuff, HTML, ERB, etc),
# or with a list of named buttons. These two examples are functionally equivalent:
@@ -71,12 +68,12 @@ module ButtonsHelper
# <%= f.commit_button %>
# <% end %>
# <% end %>
- #
+ #
# # With a list of fields:
# <% semantic_form_for @post do |f| %>
# <%= f.buttons :commit %>
# <% end %>
- #
+ #
# # Output:
# <form ...>
# <fieldset class="inputs">
@@ -88,7 +85,7 @@ module ButtonsHelper
# </fieldset>
# </form>
#
- # Only one type of named button is supported at this time (:commit), and it's assumed to be
+ # Only one type of named button is supported at this time (:commit), and it's assumed to be
# the default choice, so this is also functionally equivalent, but may change in the future:
#
# # With no args:
@@ -99,11 +96,11 @@ module ButtonsHelper
#
# While this may seem slightly over-engineered, it is consistent with the way form inputs are
# handled, and makes room for other types of buttons and actions in future versions (such as
- # cancel buttons or links, reset buttons and even alternate actions like 'save and continue
+ # cancel buttons or links, reset buttons and even alternate actions like 'save and continue
# editing').
#
# All options except `:name` and `:title` are passed down to the fieldset as HTML
- # attributes (`id`, `class`, `style`...). If provided, the `:name` or `:title` option is
+ # attributes (`id`, `class`, `style`...). If provided, the `:name` or `:title` option is
# passed into a `<legend>` inside the `<fieldset>` to name the set of buttons.
#
# @example Quickly add button(s) to the form, accepting all default values, options and behaviors
@@ -170,7 +167,7 @@ module ButtonsHelper
def buttons(*args, &block)
html_options = args.extract_options!
html_options[:class] ||= "buttons"
-
+
if block_given?
field_set_and_list_wrapping(html_options, &block)
else
@@ -179,18 +176,18 @@ def buttons(*args, &block)
field_set_and_list_wrapping(html_options, contents)
end
end
-
+
# Creates a submit input tag with the value "Save [model name]" (for existing records) or
- # "Create [model name]" (for new records) by default. The output is an `<input>` tag with the
+ # "Create [model name]" (for new records) by default. The output is an `<input>` tag with the
# `type` of `submit` and a class of either `create` or `update` (if Formtastic can determin if)
# the record is new or not) with `submit` as a fallback class. The submit button is wrapped in
# an `<li>` tag with a class of `commit`, and is intended to be rendered inside a {#buttons}
# block which wraps the button in a `fieldset` and `ol`.
#
- # The textual value of the label can be changed from this default through the `:label`
+ # The textual value of the label can be changed from this default through the `:label`
# argument or through i18n.
#
- # You can pass HTML attributes down to the `<input>` tag with the `:button_html` option, and
+ # You can pass HTML attributes down to the `<input>` tag with the `:button_html` option, and
# pass HTML attributes to the wrapping `<li>` tag with the `:wrapper_html` option.
#
# @example Basic usage
@@ -226,24 +223,24 @@ def buttons(*args, &block)
# <%= f.commit_button :label => "Go", :button_html => { :class => 'special', :id => 'whatever' } %>
# <%= f.commit_button "Go", :button_html => { :class => 'special', :id => 'whatever' } %>
#
- # @option *args :label [String, Symbol]
+ # @option *args :label [String, Symbol]
# Override the label text with a String or a symbold for an i18n translation key
#
- # @option *args :button_html [Hash]
+ # @option *args :button_html [Hash]
# Override or add to the HTML attributes to be passed down to the `<input>` tag
#
- # @option *args :wrapper_html [Hash]
+ # @option *args :wrapper_html [Hash]
# Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
#
# @todo document i18n keys
# @todo strange that `:accesskey` seems to be supported in the top level args as well as `:button_html`
def commit_button(*args)
options = args.extract_options!
text = options.delete(:label) || args.shift
-
+
if @object && (@object.respond_to?(:persisted?) || @object.respond_to?(:new_record?))
key = @object.persisted? ? :update : :create
-
+
# Deal with some complications with ActiveRecord::Base.human_name and two name models (eg UserPost)
# ActiveRecord::Base.human_name falls back to ActiveRecord::Base.name.humanize ("Userpost")
# if there's no i18n, which is pretty crappy. In this circumstance we want to detect this
@@ -260,17 +257,17 @@ def commit_button(*args)
key = :submit
object_name = @object_name.to_s.send(label_str_method)
end
-
+
text = (localized_string(key, text, :action, :model => object_name) ||
Formtastic::I18n.t(key, :model => object_name)) unless text.is_a?(::String)
-
+
button_html = options.delete(:button_html) || {}
button_html.merge!(:class => [button_html[:class], key].compact.join(' '))
-
+
wrapper_html_class = ['commit'] # TODO: Add class reflecting on form action.
wrapper_html = options.delete(:wrapper_html) || {}
wrapper_html[:class] = (wrapper_html_class << wrapper_html[:class]).flatten.compact.join(' ')
-
+
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, Formtastic::Util.html_safe(submit(text, button_html)), wrapper_html)
Oops, something went wrong.

0 comments on commit caf88c9

Please sign in to comment.