Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into configurable-name…
Browse files Browse the repository at this point in the history
…spaced-inputs
  • Loading branch information
Michal Cichra committed Aug 19, 2014
2 parents 12bdbdf + 02ffb9a commit a77b386
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG
Expand Up @@ -2,7 +2,7 @@

* Removed support for Ruby version < 1.9.3
* Removed support for Rails version < 3.2.13
* Removed deprecated option :input_html => { :value => '...'} (#1025)
* Removed deprecated option :value (#1025)
* Removed deprecated option :hint_class (#1025)
* Removed deprecated option :error_class (#1025)
* Removed deprecated option :group_by (#1025)
Expand Down
43 changes: 43 additions & 0 deletions DEPRECATIONS
@@ -0,0 +1,43 @@
This document is for tracking deprecations and removals of
Formtastic features and compatibilities.

v4.0

* Remove support for Rails < 4.0.4
* Remove support for country_select 1.x syntax (they want to remove it in 3.0)

v3.0

* Remove support for Ruby version < 1.9.3
* Remove support for Rails version < 3.2.13
* Remove deprecated option :value (#1025)
* Remove deprecated option :hint_class (#1025)
* Remove deprecated option :error_class (#1025)
* Remove deprecated option :group_by (#1025)
* Remove deprecated option :group_label (#1025)
* Remove deprecated option :find_options (#1025)
* Deprecate support for Rails < 4.0.4

v2.3

* Remove deprecated date, time and datetime inputs
* Deprecate :error_class option
* Deprecate support for Rails < 3.2.13

v2.2

* Remove deprecated buttons DSL, ButtonHelper and commit_button helper
* Deprecate :value option
* Deprecate :hint_class option
* Deprecate :error_class option
* Deprecate :group_by and :group_label options
* Deprecate :find_options option

v2.1

* Remove the previously deprecated :label_method, :value_method & :group_label_method options
* Remove the previously deprecated :as => :numeric
* Remove the previously deprecated inline_errors_for and related methods
* Remove the previously deprecated SemanticFormHelper and SemanticFormBuilder
* Deprecate the Buttons DSL (f.buttons, f.commit_button) in favor of the new Actions DSL — see above

15 changes: 0 additions & 15 deletions README.textile
Expand Up @@ -107,21 +107,6 @@ h2. Stylesheets

A proof-of-concept set of stylesheets are provided which you can include in your layout. Customization is best achieved by overriding these styles in an additional stylesheet.

h3. Stylesheet usage in Rails < 3.1:

<pre>
$ rails generate formtastic:install
</pre>

<pre>
# app/views/layouts/application.html.erb
<%= stylesheet_link_tag 'formtastic', 'my_formtastic_changes' %>
<!--[if IE 6]><%= stylesheet_link_tag 'formtastic_ie6' %><![endif]-->
<!--[if IE 7]><%= stylesheet_link_tag 'formtastic_ie7' %><![endif]-->
</pre>

h3. Stylesheet usage in Rails >= 3.1:

Rails 3.1 introduces an asset pipeline that allows plugins like Formtastic to serve their own Stylesheets, Javascripts, etc without having to run generators that copy them across to the host application. Formtastic makes three stylesheets available as an Engine, you just need to require them in your global stylesheets.

<pre>
Expand Down
4 changes: 2 additions & 2 deletions lib/formtastic/helpers/form_helper.rb
Expand Up @@ -155,7 +155,7 @@ def semantic_form_for(record_or_name_or_array, *args, &proc)
options[:builder] ||= @@builder
options[:html] ||= {}
options[:html][:novalidate] = !@@builder.perform_browser_validations unless options[:html].key?(:novalidate)
@@builder.custom_namespace = options.delete(:namespace).to_s
options[:custom_namespace] = options.delete(:namespace)

singularizer = defined?(ActiveModel::Naming.singular) ? ActiveModel::Naming.method(:singular) : ActionController::RecordIdentifier.method(:singular_class_name)

Expand All @@ -182,7 +182,7 @@ def semantic_form_for(record_or_name_or_array, *args, &proc)
def semantic_fields_for(record_name, record_object = nil, options = {}, &block)
options, record_object = record_object, nil if record_object.is_a?(Hash) && record_object.extractable_options?
options[:builder] ||= @@builder
@@builder.custom_namespace = options.delete(:namespace).to_s # TODO needed?
options[:custom_namespace] = options.delete(:namespace)

with_custom_field_error_proc do
self.fields_for(record_name, record_object, options, &block)
Expand Down
11 changes: 11 additions & 0 deletions lib/formtastic/html_attributes.rb
@@ -1,6 +1,17 @@
module Formtastic
# @private
module HtmlAttributes
# Returns a namespace passed by option or inherited from parent builders / class configuration
def dom_id_namespace
namespace = options[:custom_namespace]
parent = options[:parent_builder]

case
when namespace then namespace
when parent && parent != self then parent.dom_id_namespace
else custom_namespace
end
end

protected

Expand Down
2 changes: 1 addition & 1 deletion lib/formtastic/inputs/base/choices.rb
Expand Up @@ -73,7 +73,7 @@ def choice_html_safe_value(choice)

def choice_input_dom_id(choice)
[
builder.custom_namespace,
builder.dom_id_namespace,
sanitized_object_name,
builder.options[:index],
association_primary_key || method,
Expand Down
6 changes: 3 additions & 3 deletions lib/formtastic/inputs/base/html.rb
Expand Up @@ -28,9 +28,9 @@ def input_html_options

def dom_id
[
builder.custom_namespace,
sanitized_object_name,
dom_index,
builder.dom_id_namespace,
sanitized_object_name,
dom_index,
association_primary_key || sanitized_method_name
].reject { |x| x.blank? }.join('_')
end
Expand Down
12 changes: 11 additions & 1 deletion spec/helpers/form_helper_spec.rb
Expand Up @@ -189,7 +189,17 @@ class MyAwesomeCustomBuilder < Formtastic::FormBuilder
describe 'with :namespace option' do
it "should set the custom_namespace" do
semantic_form_for(@new_post, :namespace => 'context2') do |builder|
builder.custom_namespace == 'context2'
expect(builder.dom_id_namespace).to eq('context2')
end
end
end

describe 'without :namespace option' do
it 'defaults to class settings' do
expect(Formtastic::FormBuilder).to receive(:custom_namespace).and_return('context2')

semantic_form_for(@new_post) do |builder|
expect(builder.dom_id_namespace).to eq('context2')
end
end
end
Expand Down

0 comments on commit a77b386

Please sign in to comment.