Skip to content

Commit

Permalink
Merge branch 'master' of github.com:justinfrench/formtastic
Browse files Browse the repository at this point in the history
  • Loading branch information
dwbutler committed Aug 27, 2013
2 parents f805d61 + cd6cb88 commit 116f8b1
Show file tree
Hide file tree
Showing 39 changed files with 325 additions and 187 deletions.
36 changes: 23 additions & 13 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
before_install: gem update --system
before_install:
- gem update --system
- gem update bundler
rvm:
- 1.8.7
- ree
- 1.9.2
- 1.9.3
gemfile:
- gemfiles/rails-3.0.gemfile
- gemfiles/rails-3.1.gemfile
- gemfiles/rails-3.2.gemfile
- gemfiles/rails-4.gemfile
- gemfiles/rails_3.0.gemfile
- gemfiles/rails_3.1.gemfile
- gemfiles/rails_3.2.gemfile
env:
- DEFER_GC=false RAILS_EDGE=true
script: "rake spec"
matrix:
exclude:
- rvm: 1.8.7
gemfile: gemfiles/rails-4.gemfile
include:
- rvm: 1.9.3
gemfile: gemfiles/rails_4.gemfile
env: DEFER_GC=false RAILS_EDGE=true
- rvm: ree
gemfile: gemfiles/rails-4.gemfile
- rvm: 2.0.0
gemfile: gemfiles/rails_4.gemfile
env: DEFER_GC=false RAILS_EDGE=true
- rvm: 1.9.2
gemfile: gemfiles/rails-4.gemfile
- rvm: 1.9.3
gemfile: gemfiles/rails_edge.gemfile
env: DEFER_GC=false RAILS_EDGE=true
- rvm: 2.0.0
gemfile: gemfiles/rails_edge.gemfile
env: DEFER_GC=false RAILS_EDGE=true
allow_failures:
- rvm: 1.9.3
gemfile: gemfiles/rails_edge.gemfile
env: DEFER_GC=false RAILS_EDGE=true
- rvm: 2.0.0
gemfile: gemfiles/rails_edge.gemfile
env: DEFER_GC=false RAILS_EDGE=true

10 changes: 6 additions & 4 deletions Appraisals
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@ appraise 'rails-3.2' do
gem 'rails', '~> 3.2.0'
end

appraise 'rails-4' do
gem 'rails', '~> 4.0.0'
end

if ENV["RAILS_EDGE"] == "true"
appraise 'rails-4' do
appraise 'rails-edge' do
gem 'rails', :git => 'git://github.com/rails/rails.git'
gem 'activerecord-deprecated_finders', :git=>'https://github.com/rails/activerecord-deprecated_finders.git'
gem 'journey', :git=>'https://github.com/rails/journey.git'
end
end
end
15 changes: 15 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
2.3.0.rc2

* deprecate support for Rails < 3.2

2.3.0.rc

* Updated to support Rails 4
* Added custom HTML for the options within a checkboxes input group
* Changed the format of the `value` attribute on `datetime_picker` input to be compliant with the HTML standards
* Added `Formtastic::Helpers::FormHelper.field_error_proc=` for setting a custom proc
* Fixed checked state of checkboxes when the values are integers
* Fixed CSS to prevent numeric inputs with a `max` from stretching to full width
* Added support for `:labels => false` on time selects
* Improved documentation

2.2.1

* Rails 4 compatibilty updates
Expand Down
2 changes: 1 addition & 1 deletion Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
source :rubygems
source 'https://rubygems.org'

gemspec
17 changes: 6 additions & 11 deletions README.textile
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ h2. Documentation & Support

h2. Compatibility

* Formtastic 2.1.x is Rails 3.x compatible
* Formtastic 2.0.x is Rails 3.0.x and 3.1.x compatible only
* Formtastic 1.x is compatible with both Rails 2 and 3, and is being maintained for bug fixes in the the "1.2-stable branch":https://github.com/justinfrench/formtastic/tree/1.2-stable. View the README in that branch for installation instructions, etc.
* Formtastic 4 (master on Github) will require Rails 3.2 minimum
* Formtastic 2.3 is Rails 3 and Rails 4 compatible (Rails < 3.2 is deprecated)
* Formtastic 2.1 & 2.2 is Rails 3 and Rails 4 compatible
* Formtastic, much like Rails, is very ActiveRecord-centric. Many are successfully using other ActiveModel-like ORMs and objects (DataMapper, MongoMapper, Mongoid, Authlogic, Devise...) but we're not guaranteeing full compatibility at this stage. Patches are welcome!


Expand Down Expand Up @@ -65,7 +65,7 @@ h2. It's awesome because...

* It can handle @belongs_to@ associations (like Post belongs_to :author), rendering a select or set of radio inputs with choices from the parent model.
* It can handle @has_many@ and @has_and_belongs_to_many@ associations (like: Post has_many :tags), rendering a multi-select with choices from the child models.
* It's Rails 3 compatible (including nested forms).
* It's Rails 3/4 compatible (including nested forms).
* It has internationalization (I18n)!
* It's _really_ quick to get started with a basic form in place (4 lines), then go back to add in more detail if you need it.
* There's heaps of elements, id and class attributes for you to hook in your CSS and JS.
Expand Down Expand Up @@ -254,12 +254,7 @@ Alternatively, the current index can be accessed via the `inputs` block's argume
<pre>
<%= semantic_form_for @post do |f| %>
<%= f.inputs :for => :categories do |category, i| %>
<% if i <= 2 %>
<%= f.inputs :name => "Category ##{i}" %>
<% else %>
<%= f.inputs :name => "Category ##{i} (optional)" %>
<% end %>
<% end %>
...
<%= f.actions %>
<% end %>
</pre>
Expand Down Expand Up @@ -535,7 +530,7 @@ Values for @labels@/@hints@/@actions@ are can take values: @String@ (explicit va

h2. Semantic errors

You can show errors on base (by default) and any other attribute just passing it name to semantic_errors method:
You can show errors on base (by default) and any other attribute just by passing its name to the semantic_errors method:

<pre>
<%= semantic_form_for @post do |f| %>
Expand Down
17 changes: 0 additions & 17 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ require 'bundler/setup'
require 'appraisal'
require 'rdoc/task'
require 'rspec/core/rake_task'
require 'tasks/verify_rcov'

Bundler::GemHelper.install_tasks

Expand Down Expand Up @@ -38,19 +37,3 @@ desc 'Test the formtastic plugin with specdoc formatting and colors'
RSpec::Core::RakeTask.new('specdoc') do |t|
t.pattern = FileList['spec/**/*_spec.rb']
end

desc 'Run all examples with RCov'
RSpec::Core::RakeTask.new('rcov') do |t|
t.pattern = FileList['spec/**/*_spec.rb']
t.rcov = true
t.rcov_opts = %w(--exclude gems/*,spec/*,.bundle/*, --aggregate coverage.data)
end

RCov::VerifyTask.new(:verify_coverage) do |t|
t.require_exact_threshold = false
t.threshold = (RUBY_VERSION == "1.8.7" ? 95 : 0)
end

desc "Run all examples and verify coverage"
task :spec_and_verify_coverage => [:rcov, :verify_coverage] do
end
5 changes: 3 additions & 2 deletions formtastic.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ Gem::Specification.new do |s|

s.add_dependency(%q<actionpack>, [">= 3.0"])

s.add_development_dependency(%q<rspec-rails>, ["~> 2.8.0"])
s.add_development_dependency(%q<nokogiri>, ["< 1.6.0"]) # 1.6 requires Ruby 1.9.2, drop in v3.0
s.add_development_dependency(%q<rspec-rails>, ["~> 2.12.0"])
s.add_development_dependency(%q<rspec_tag_matchers>, [">= 1.0.0"])
s.add_development_dependency(%q<hpricot>, ["~> 0.8.3"])
s.add_development_dependency(%q<BlueCloth>) # for YARD
s.add_development_dependency(%q<yard>, ["~> 0.6"])
s.add_development_dependency(%q<rcov>, ["~> 0.9.9"])
s.add_development_dependency(%q<colored>)
s.add_development_dependency(%q<tzinfo>)
s.add_development_dependency(%q<ammeter>, ["0.2.5"])
s.add_development_dependency(%q<appraisal>)
s.add_development_dependency(%q<rake>)
s.add_development_dependency(%q<activemodel>)
end
9 changes: 0 additions & 9 deletions gemfiles/rails-4.gemfile

This file was deleted.

2 changes: 1 addition & 1 deletion gemfiles/rails-3.0.gemfile → gemfiles/rails_3.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was generated by Appraisal

source :rubygems
source "https://rubygems.org"

gem "rails", "~> 3.0.0"

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails-3.1.gemfile → gemfiles/rails_3.1.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was generated by Appraisal

source :rubygems
source "https://rubygems.org"

gem "rails", "~> 3.1.0"

Expand Down
2 changes: 1 addition & 1 deletion gemfiles/rails-3.2.gemfile → gemfiles/rails_3.2.gemfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This file was generated by Appraisal

source :rubygems
source "https://rubygems.org"

gem "rails", "~> 3.2.0"

Expand Down
7 changes: 7 additions & 0 deletions gemfiles/rails_4.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", "~> 4.0.0"

gemspec :path=>"../"
7 changes: 7 additions & 0 deletions gemfiles/rails_edge.gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# This file was generated by Appraisal

source "https://rubygems.org"

gem "rails", :git=>"git://github.com/rails/rails.git"

gemspec :path=>"../"
7 changes: 7 additions & 0 deletions lib/formtastic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,13 @@ module Formtastic
autoload :Localizer
autoload :Util

# Deprecate support for Rails < 3.2
if Util.deprecated_version_of_rails?
::ActiveSupport::Deprecation.warn(
"Support for Rails 3.0 and 3.1 will be dropped from Formtastic 3.0",
caller)
end

# @private
class UnknownInputError < NameError
end
Expand Down
15 changes: 15 additions & 0 deletions lib/formtastic/form_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,21 @@ def semantic_fields_for(record_or_name_or_array, *args, &block)
fields_for(record_or_name_or_array, *(args << options), &block)
end

def initialize(object_name, object, template, options, block=nil)
# rails 3 supported passing in the block parameter to FormBuilder
# rails 4.0 deprecated the block parameter and does nothing with it
# rails 4.1 removes the parameter completely
if Util.rails3? || Util.rails4_0?
super
else
super object_name, object, template, options
end

if respond_to?('multipart=') && options.is_a?(Hash) && options[:html]
self.multipart = options[:html][:multipart]
end
end

end

end
Expand Down
2 changes: 1 addition & 1 deletion lib/formtastic/helpers/fieldset_wrapper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def parent_child_index(parent) #:nodoc:
return duck + 1 if duck.is_a?(Fixnum)

# First try to extract key from duck Hash, then try child
i = (duck[key] || duck[child]).to_i + 1
(duck[key] || duck[child]).to_i + 1
end

end
Expand Down
18 changes: 8 additions & 10 deletions lib/formtastic/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ module FormHelper
@@default_form_class = 'formtastic'
mattr_accessor :default_form_class

# Allows to set a custom field_error_proc wrapper. By default this wrapper
# is disabled since `formtastic` already adds an error class to the LI tag
# containing the input. Change this from `config/initializers/formtastic.rb`.
@@field_error_proc = proc { |html_tag, instance_tag| html_tag }
mattr_accessor :field_error_proc

# Wrapper around Rails' own `form_for` helper to set the `:builder` option to
# `Formtastic::FormBuilder` and to set some class names on the `<form>` tag such as
# `formtastic` and the downcased and underscored model name (eg `post`).
Expand Down Expand Up @@ -155,7 +161,7 @@ def semantic_form_for(record_or_name_or_array, *args, &proc)
when Array then options[:as] || singularizer.call(record_or_name_or_array.last.class) # [@post, @comment] # => "comment"
else options[:as] || singularizer.call(record_or_name_or_array.class) # @post => "post"
end
options[:html][:class] = class_names.join(" ")
options[:html][:class] = class_names.compact.join(" ")

with_custom_field_error_proc do
self.form_for(record_or_name_or_array, *(args << options), &proc)
Expand All @@ -178,17 +184,9 @@ def semantic_fields_for(record_name, record_object = nil, options = {}, &block)

protected

# Override the default ActiveRecordHelper behaviour of wrapping the input.
# This gets taken care of semantically by adding an error class to the LI tag
# containing the input.
# @private
FIELD_ERROR_PROC = proc do |html_tag, instance_tag|
html_tag
end

def with_custom_field_error_proc(&block)
default_field_error_proc = ::ActionView::Base.field_error_proc
::ActionView::Base.field_error_proc = FIELD_ERROR_PROC
::ActionView::Base.field_error_proc = @@field_error_proc
yield
ensure
::ActionView::Base.field_error_proc = default_field_error_proc
Expand Down
1 change: 0 additions & 1 deletion lib/formtastic/inputs/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@ def removed_option!(old_option_name)
include Html
include Options
include Database
include Database
include Errors
include Hints
include Naming
Expand Down
17 changes: 14 additions & 3 deletions lib/formtastic/inputs/base/collections.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,21 @@ def collection_from_association

scope_conditions = conditions_from_reflection.empty? ? nil : {:conditions => conditions_from_reflection}
if conditions_from_options.any?
reflection.klass.scoped(scope_conditions).where(conditions_from_options)
if Util.rails3?
reflection.klass.scoped(scope_conditions).where(conditions_from_options)
else
reflection.klass.where(scope_conditions[:conditions]).where(conditions_from_options)
end
else
find_options_from_options.merge!(:include => group_by) if self.respond_to?(:group_by) && group_by
reflection.klass.scoped(scope_conditions).where(find_options_from_options)

if Util.rails3?
find_options_from_options.merge!(:include => group_by) if self.respond_to?(:group_by) && group_by
reflection.klass.scoped(scope_conditions).where(find_options_from_options)
else
coll = reflection.klass.where(scope_conditions)
coll = coll.includes(group_by) if self.respond_to?(:group_by) && group_by
coll.where(find_options_from_options)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/formtastic/inputs/base/options.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ def input_options
end

def formtastic_options
[:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :label_html, :value_as_class, :find_options, :class]
[:priority_countries, :priority_zones, :member_label, :member_value, :collection, :required, :label, :as, :hint, :input_html, :value_as_class, :find_options, :class]
end

end
Expand Down
7 changes: 5 additions & 2 deletions lib/formtastic/inputs/base/timeish.rb
Original file line number Diff line number Diff line change
Expand Up @@ -188,8 +188,11 @@ def position(fragment)

def i18n_date_fragments
order = ::I18n.t(:order, :scope => [:date])
order = nil unless order.is_a?(Array)
order
if order.is_a?(Array)
order.map &:to_sym
else
nil
end
end

def fragments_wrapping(&block)
Expand Down
6 changes: 1 addition & 5 deletions lib/formtastic/inputs/boolean_input.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,7 @@ def input_html_options_name
end

def checked?
if defined? ActionView::Helpers::InstanceTag
object && ActionView::Helpers::InstanceTag.check_box_checked?(object.send(method), checked_value)
else
object && boolean_checked?(object.send(method), checked_value)
end
object && boolean_checked?(object.send(method), checked_value)
end

private
Expand Down
Loading

0 comments on commit 116f8b1

Please sign in to comment.