formtastic 3.1.0 → 3.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 3.1.1
2
+
3
+ * Fixed class custom input & action class loading in test environments
4
+ * Added documentation of custom input & action class finders
5
+ * Added a link to documentation & wiki from custom class deprecation warnings
6
+
1
7
  3.1.0
2
8
 
3
9
  * Performance and documentation improvements
@@ -98,7 +98,7 @@ Simply add Formtastic to your Gemfile and bundle it up:
98
98
 
99
99
  Run the installation generator:
100
100
 
101
- <pre>
101
+ <pre lang=shell>
102
102
  $ rails generate formtastic:install
103
103
  </pre>
104
104
 
data/Rakefile CHANGED
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require 'bundler/setup'
3
3
  require 'appraisal'
4
- require 'rdoc/task'
4
+ require 'yard'
5
5
  require 'rspec/core/rake_task'
6
6
 
7
7
  Bundler::GemHelper.install_tasks
@@ -14,13 +14,10 @@ else
14
14
  end
15
15
 
16
16
  desc 'Generate documentation for the formtastic plugin.'
17
- Rake::RDocTask.new(:rdoc) do |rdoc|
18
- rdoc.rdoc_dir = 'rdoc'
19
- rdoc.title = 'Formtastic'
20
- rdoc.options << '--line-numbers' << '--inline-source'
21
- rdoc.rdoc_files.include('README.textile')
22
- rdoc.rdoc_files.include('lib/**/*.rb')
17
+ YARD::Rake::YardocTask.new(:yard) do |t|
18
+
23
19
  end
20
+ task doc: :yard
24
21
 
25
22
  desc 'Test the formtastic plugin.'
26
23
  RSpec::Core::RakeTask.new('spec') do |t|
@@ -27,12 +27,12 @@ Gem::Specification.new do |s|
27
27
 
28
28
  s.add_dependency(%q<actionpack>, [">= 3.2.13"])
29
29
 
30
- s.add_development_dependency(%q<nokogiri>)
30
+ s.add_development_dependency(%q<nokogiri>)
31
31
  s.add_development_dependency(%q<rspec-rails>, ["~> 2.14"])
32
32
  s.add_development_dependency(%q<rspec_tag_matchers>, ["~> 1.0"])
33
33
  s.add_development_dependency(%q<hpricot>, ["~> 0.8.3"])
34
- s.add_development_dependency(%q<BlueCloth>, ["~> 1.0"]) # for YARD
35
- s.add_development_dependency(%q<yard>, ["~> 0.6"])
34
+ s.add_development_dependency(%q<RedCloth>, ["~> 4.2"]) # for YARD Textile formatting
35
+ s.add_development_dependency(%q<yard>, ["~> 0.8"])
36
36
  s.add_development_dependency(%q<colored>, ["~> 1.2"])
37
37
  s.add_development_dependency(%q<tzinfo>)
38
38
  s.add_development_dependency(%q<ammeter>, ["1.1.1"])
@@ -26,7 +26,7 @@ module Formtastic
26
26
  deprecation.warn("Support for Rails < 4.0.4 will be dropped ")
27
27
  end
28
28
 
29
- # @private
29
+ # @public
30
30
  class UnknownInputError < NameError
31
31
  end
32
32
 
@@ -1,16 +1,16 @@
1
1
  module Formtastic
2
2
 
3
- # Uses the +NamespacedClassFinder+ to look up action class names.
3
+ # Uses the {NamespacedClassFinder} to look up action class names.
4
4
  #
5
- # See +Formtastic::Helpers::ActionHelper#namespaced_action_class+ for details.
5
+ # See {Formtastic::Helpers::ActionHelper#namespaced_action_class} for details.
6
6
  #
7
7
  class ActionClassFinder < NamespacedClassFinder
8
+
9
+ # @param builder [FormBuilder]
8
10
  def initialize(builder)
9
11
  super builder.action_namespaces
10
12
  end
11
13
 
12
- private
13
-
14
14
  def class_name(as)
15
15
  "#{super}Action"
16
16
  end
@@ -1,59 +1,61 @@
1
- # Outputs a `<button type="submit">` or `<button type="reset">` wrapped in the standard `<li>`
2
- # wrapper. This is an alternative choice for `:submit` and `:reset` actions, which render with
3
- # `<input type="submit">` and `<input type="reset">` by default.
4
- #
5
- # @example Full form context and output
6
- #
7
- # <%= semantic_form_for(@post) do |f| %>
8
- # <%= f.actions do %>
9
- # <%= f.action :reset, :as => :button %>
10
- # <%= f.action :submit, :as => :button %>
11
- # <% end %>
12
- # <% end %>
13
- #
14
- # <form...>
15
- # <fieldset class="actions">
16
- # <ol>
17
- # <li class="action button_action" id="post_reset_action">
18
- # <button type="reset" value="Reset">
19
- # </li>
20
- # <li class="action button_action" id="post_submit_action">
21
- # <button type="submit" value="Create Post">
22
- # </li>
23
- # </ol>
24
- # </fieldset>
25
- # </form>
26
- #
27
- # @example Specifying a label with a String
28
- # <%= f.action :submit, :as => :button, :label => "Go" %>
29
- #
30
- # @example Pass HTML attributes down to the `<button>`
31
- # <%= f.action :submit, :as => :button, :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
32
- #
33
- # @example Access key can also be set as a top-level option
34
- # <%= f.action :submit, :as => :button, :accesskey => 'g' %>
35
- #
36
- # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
37
- # <%= f.action :submit, :as => :button, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
38
- # <%= f.action :submit, :as => :button, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
39
- #
40
- # @option *args :label [String, Symbol]
41
- # Override the label text with a String or a symbol for an i18n translation key
42
- #
43
- # @option *args :button_html [Hash]
44
- # Override or add to the HTML attributes to be passed down to the `<input>` tag
45
- #
46
- # @option *args :wrapper_html [Hash]
47
- # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
48
- #
49
- # @todo document i18n keys
50
- # @todo document i18n translation with :label (?)
51
1
  module Formtastic
52
2
  module Actions
53
- class ButtonAction
3
+
4
+ # Outputs a `<button type="submit">` or `<button type="reset">` wrapped in the standard `<li>`
5
+ # wrapper. This is an alternative choice for `:submit` and `:reset` actions, which render with
6
+ # `<input type="submit">` and `<input type="reset">` by default.
7
+ #
8
+ # @example Full form context and output
9
+ #
10
+ # <%= semantic_form_for(@post) do |f| %>
11
+ # <%= f.actions do %>
12
+ # <%= f.action :reset, :as => :button %>
13
+ # <%= f.action :submit, :as => :button %>
14
+ # <% end %>
15
+ # <% end %>
16
+ #
17
+ # <form...>
18
+ # <fieldset class="actions">
19
+ # <ol>
20
+ # <li class="action button_action" id="post_reset_action">
21
+ # <button type="reset" value="Reset">
22
+ # </li>
23
+ # <li class="action button_action" id="post_submit_action">
24
+ # <button type="submit" value="Create Post">
25
+ # </li>
26
+ # </ol>
27
+ # </fieldset>
28
+ # </form>
29
+ #
30
+ # @example Specifying a label with a String
31
+ # <%= f.action :submit, :as => :button, :label => "Go" %>
32
+ #
33
+ # @example Pass HTML attributes down to the `<button>`
34
+ # <%= f.action :submit, :as => :button, :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
35
+ #
36
+ # @example Access key can also be set as a top-level option
37
+ # <%= f.action :submit, :as => :button, :accesskey => 'g' %>
38
+ #
39
+ # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
40
+ # <%= f.action :submit, :as => :button, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
41
+ # <%= f.action :submit, :as => :button, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
42
+ #
43
+ # @todo document i18n keys
44
+ # @todo document i18n translation with :label (?)
45
+ class ButtonAction
54
46
  include Base
55
47
  include Buttonish
56
-
48
+
49
+ # @see Formtastic::Helpers::ActionHelper#action
50
+ # @option *args :label [String, Symbol]
51
+ # Override the label text with a String or a symbol for an i18n translation key
52
+ #
53
+ # @option *args :button_html [Hash]
54
+ # Override or add to the HTML attributes to be passed down to the `<input>` tag
55
+ #
56
+ # @option *args :wrapper_html [Hash]
57
+ # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
58
+
57
59
  # TODO reset_action class?
58
60
  def to_html
59
61
  wrapper do
@@ -62,4 +64,4 @@ module Formtastic
62
64
  end
63
65
  end
64
66
  end
65
- end
67
+ end
@@ -1,63 +1,65 @@
1
- # Outputs an `<input type="submit">` or `<input type="reset">` wrapped in the standard `<li>`
2
- # wrapper. This the default for `:submit` and `:reset` actions, but `:as => :button` is also
3
- # available as an alternative.
4
- #
5
- # @example The `:as` can be ommitted, these are functionally equivalent
6
- # <%= f.action :submit, :as => :input %>
7
- # <%= f.action :submit %>
8
- #
9
- # @example Full form context and output
10
- #
11
- # <%= semantic_form_for(@post) do |f| %>
12
- # <%= f.actions do %>
13
- # <%= f.action :reset, :as => :input %>
14
- # <%= f.action :submit, :as => :input %>
15
- # <% end %>
16
- # <% end %>
17
- #
18
- # <form...>
19
- # <fieldset class="actions">
20
- # <ol>
21
- # <li class="action input_action" id="post_reset_action">
22
- # <input type="reset" value="Reset">
23
- # </li>
24
- # <li class="action input_action" id="post_submit_action">
25
- # <input type="submit" value="Create Post">
26
- # </li>
27
- # </ol>
28
- # </fieldset>
29
- # </form>
30
- #
31
- # @example Specifying a label with a String
32
- # <%= f.action :submit, :as => :input, :label => "Go" %>
33
- #
34
- # @example Pass HTML attributes down to the `<input>`
35
- # <%= f.action :submit, :as => :input, :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
36
- #
37
- # @example Access key can also be set as a top-level option
38
- # <%= f.action :submit, :as => :input, :accesskey => 'g' %>
39
- #
40
- # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
41
- # <%= f.action :submit, :as => :input, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
42
- # <%= f.action :submit, :as => :input, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
43
- #
44
- # @option *args :label [String, Symbol]
45
- # Override the label text with a String or a symbol for an i18n translation key
46
- #
47
- # @option *args :button_html [Hash]
48
- # Override or add to the HTML attributes to be passed down to the `<input>` tag
49
- #
50
- # @option *args :wrapper_html [Hash]
51
- # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
52
- #
53
- # @todo document i18n keys
54
- # @todo document i18n translation with :label (?)
55
1
  module Formtastic
56
2
  module Actions
57
- class InputAction
3
+
4
+ # Outputs an `<input type="submit">` or `<input type="reset">` wrapped in the standard `<li>`
5
+ # wrapper. This the default for `:submit` and `:reset` actions, but `:as => :button` is also
6
+ # available as an alternative.
7
+ #
8
+ # @example The `:as` can be ommitted, these are functionally equivalent
9
+ # <%= f.action :submit, :as => :input %>
10
+ # <%= f.action :submit %>
11
+ #
12
+ # @example Full form context and output
13
+ #
14
+ # <%= semantic_form_for(@post) do |f| %>
15
+ # <%= f.actions do %>
16
+ # <%= f.action :reset, :as => :input %>
17
+ # <%= f.action :submit, :as => :input %>
18
+ # <% end %>
19
+ # <% end %>
20
+ #
21
+ # <form...>
22
+ # <fieldset class="actions">
23
+ # <ol>
24
+ # <li class="action input_action" id="post_reset_action">
25
+ # <input type="reset" value="Reset">
26
+ # </li>
27
+ # <li class="action input_action" id="post_submit_action">
28
+ # <input type="submit" value="Create Post">
29
+ # </li>
30
+ # </ol>
31
+ # </fieldset>
32
+ # </form>
33
+ #
34
+ # @example Specifying a label with a String
35
+ # <%= f.action :submit, :as => :input, :label => "Go" %>
36
+ #
37
+ # @example Pass HTML attributes down to the `<input>`
38
+ # <%= f.action :submit, :as => :input, :button_html => { :class => 'pretty', :accesskey => 'g', :disable_with => "Wait..." } %>
39
+ #
40
+ # @example Access key can also be set as a top-level option
41
+ # <%= f.action :submit, :as => :input, :accesskey => 'g' %>
42
+ #
43
+ # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
44
+ # <%= f.action :submit, :as => :input, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
45
+ # <%= f.action :submit, :as => :input, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
46
+ # @todo document i18n keys
47
+ # @todo document i18n translation with :label (?)
48
+ class InputAction
58
49
  include Base
59
50
  include Buttonish
60
-
51
+
52
+ # @see Formtastic::Helpers::ActionHelper#action
53
+ # @option *args :label [String, Symbol]
54
+ # Override the label text with a String or a symbol for an i18n translation key
55
+ #
56
+ # @option *args :button_html [Hash]
57
+ # Override or add to the HTML attributes to be passed down to the `<input>` tag
58
+ #
59
+ # @option *args :wrapper_html [Hash]
60
+ # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
61
+ #
62
+
61
63
  def to_html
62
64
  wrapper do
63
65
  builder.submit(text, button_html)
@@ -65,4 +67,4 @@ module Formtastic
65
67
  end
66
68
  end
67
69
  end
68
- end
70
+ end
@@ -1,82 +1,83 @@
1
- # Outputs a link wrapped in the standard `<li>` wrapper. This the default for `:cancel` actions.
2
- # The link's URL defaults to Rails' built-in `:back` macro (the HTTP referrer, or Javascript for the
3
- # browser's history), but can be altered with the `:url` option.
4
- #
5
- # @example The `:as` can be ommitted, these are functionally equivalent
6
- # <%= f.action :cancel, :as => :link %>
7
- # <%= f.action :cancel %>
8
- #
9
- # @example Full form context and output
10
- #
11
- # <%= semantic_form_for(@post) do |f| %>
12
- # <%= f.actions do %>
13
- # <%= f.action :submit, :as => :input %>
14
- # <%= f.action :cancel, :as => :link %>
15
- # <% end %>
16
- # <% end %>
17
- #
18
- # <form...>
19
- # <fieldset class="actions">
20
- # <ol>
21
- # <li class="action input_action" id="post_submit_action">
22
- # <input type="submit" value="Create Post">
23
- # </li>
24
- # <li class="action link_action" id="post_cancel_action">
25
- # <a href="javascript:history.back()">Cancel</a>
26
- # </li>
27
- # </ol>
28
- # </fieldset>
29
- # </form>
30
- #
31
- # @example Modifying the URL for the link
32
- # <%= f.action :cancel, :as => :link, :url => "http://example.com/path" %>
33
- # <%= f.action :cancel, :as => :link, :url => "/path" %>
34
- # <%= f.action :cancel, :as => :link, :url => posts_path %>
35
- # <%= f.action :cancel, :as => :link, :url => url_for(...) %>
36
- # <%= f.action :cancel, :as => :link, :url => { :controller => "posts", :action => "index" } %>
37
- #
38
- # @example Specifying a label with a String
39
- # <%= f.action :cancel, :as => :link, :label => "Stop" %>
40
- #
41
- # @example Pass HTML attributes down to the `<a>`
42
- # <%= f.action :cancel, :as => :link, :button_html => { :class => 'pretty', :accesskey => 'x' } %>
43
- #
44
- # @example Access key can also be set as a top-level option
45
- # <%= f.action :cancel, :as => :link, :accesskey => 'x' %>
46
- #
47
- # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
48
- # <%= f.action :cancel, :as => :link, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
49
- # <%= f.action :cancel, :as => :link, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
50
- #
51
- # @option *args :label [String, Symbol]
52
- # Override the label text with a String or a symbol for an i18n translation key
53
- #
54
- # @option *args :button_html [Hash]
55
- # Override or add to the HTML attributes to be passed down to the `<a>` tag
56
- #
57
- # @option *args :wrapper_html [Hash]
58
- # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
59
- #
60
- # @todo document i18n keys
61
- # @todo document i18n translation with :label (?)
62
- # @todo :prefix and :suffix options? (can also be done with CSS or subclassing for custom Actions)
63
1
  module Formtastic
64
2
  module Actions
65
- class LinkAction
66
-
3
+ # Outputs a link wrapped in the standard `<li>` wrapper. This the default for `:cancel` actions.
4
+ # The link's URL defaults to Rails' built-in `:back` macro (the HTTP referrer, or Javascript for the
5
+ # browser's history), but can be altered with the `:url` option.
6
+ #
7
+ # @example The `:as` can be ommitted, these are functionally equivalent
8
+ # <%= f.action :cancel, :as => :link %>
9
+ # <%= f.action :cancel %>
10
+ #
11
+ # @example Full form context and output
12
+ #
13
+ # <%= semantic_form_for(@post) do |f| %>
14
+ # <%= f.actions do %>
15
+ # <%= f.action :submit, :as => :input %>
16
+ # <%= f.action :cancel, :as => :link %>
17
+ # <% end %>
18
+ # <% end %>
19
+ #
20
+ # <form...>
21
+ # <fieldset class="actions">
22
+ # <ol>
23
+ # <li class="action input_action" id="post_submit_action">
24
+ # <input type="submit" value="Create Post">
25
+ # </li>
26
+ # <li class="action link_action" id="post_cancel_action">
27
+ # <a href="javascript:history.back()">Cancel</a>
28
+ # </li>
29
+ # </ol>
30
+ # </fieldset>
31
+ # </form>
32
+ #
33
+ # @example Modifying the URL for the link
34
+ # <%= f.action :cancel, :as => :link, :url => "http://example.com/path" %>
35
+ # <%= f.action :cancel, :as => :link, :url => "/path" %>
36
+ # <%= f.action :cancel, :as => :link, :url => posts_path %>
37
+ # <%= f.action :cancel, :as => :link, :url => url_for(...) %>
38
+ # <%= f.action :cancel, :as => :link, :url => { :controller => "posts", :action => "index" } %>
39
+ #
40
+ # @example Specifying a label with a String
41
+ # <%= f.action :cancel, :as => :link, :label => "Stop" %>
42
+ #
43
+ # @example Pass HTML attributes down to the `<a>`
44
+ # <%= f.action :cancel, :as => :link, :button_html => { :class => 'pretty', :accesskey => 'x' } %>
45
+ #
46
+ # @example Access key can also be set as a top-level option
47
+ # <%= f.action :cancel, :as => :link, :accesskey => 'x' %>
48
+ #
49
+ # @example Pass HTML attributes down to the `<li>` wrapper (classes are appended to the existing classes)
50
+ # <%= f.action :cancel, :as => :link, :wrapper_html => { :class => 'special', :id => 'whatever' } %>
51
+ # <%= f.action :cancel, :as => :link, :wrapper_html => { :class => ['extra', 'special'], :id => 'whatever' } %>
52
+ #
53
+ # @todo document i18n keys
54
+ # @todo document i18n translation with :label (?)
55
+ # @todo :prefix and :suffix options? (can also be done with CSS or subclassing for custom Actions)
56
+ class LinkAction
67
57
  include Base
68
-
58
+
59
+ # @see Formtastic::Helpers::ActionHelper#action
60
+ # @option *args :label [String, Symbol]
61
+ # Override the label text with a String or a symbol for an i18n translation key
62
+ #
63
+ # @option *args :button_html [Hash]
64
+ # Override or add to the HTML attributes to be passed down to the `<a>` tag
65
+ #
66
+ # @option *args :wrapper_html [Hash]
67
+ # Override or add to the HTML attributes to be passed down to the wrapping `<li>` tag
68
+ #
69
+
69
70
  def supported_methods
70
71
  [:cancel]
71
72
  end
72
-
73
+
73
74
  # TODO reset_action class?
74
75
  def to_html
75
76
  wrapper do
76
77
  template.link_to(text, url, button_html)
77
78
  end
78
79
  end
79
-
80
+
80
81
  def url
81
82
  return options[:url] if options.key?(:url)
82
83
  :back
@@ -1,13 +1,13 @@
1
1
  require 'active_support/deprecation'
2
2
 
3
- # TODO: remove this branch and file when support for rails 3.2 is dropped
4
-
5
3
  module Formtastic
6
4
  if ActiveSupport::Deprecation.respond_to?(:new)
7
5
  Deprecation = ActiveSupport::Deprecation
8
6
  else
9
7
  require 'forwardable'
10
8
 
9
+ # @private
10
+ # @todo remove this branch and file when support for rails 3.2 is dropped
11
11
  class Deprecation
12
12
  mattr_accessor :deprecation
13
13
  self.deprecation = ActiveSupport::Deprecation.dup
@@ -1,9 +1,18 @@
1
1
  module Formtastic
2
2
  class FormBuilder < ActionView::Helpers::FormBuilder
3
3
 
4
- def self.configure(name, value = nil)
4
+ # Defines a new configurable option
5
+ # @param [Symbol] name the configuration name
6
+ # @param [Object] default the configuration default value
7
+ # @private
8
+ #
9
+ # @!macro [new] configure
10
+ # @!scope class
11
+ # @!attribute [rw] $1
12
+ # @api public
13
+ def self.configure(name, default = nil)
5
14
  class_attribute(name)
6
- self.send(:"#{name}=", value)
15
+ self.send(:"#{name}=", default)
7
16
  end
8
17
 
9
18
  configure :custom_namespace
@@ -31,11 +40,15 @@ module Formtastic
31
40
  configure :default_hint_class, 'inline-hints'
32
41
  configure :use_required_attribute, false
33
42
  configure :perform_browser_validations, false
43
+ # Check {Formtastic::InputClassFinder} to see how are inputs resolved.
34
44
  configure :input_namespaces, [::Object, ::Formtastic::Inputs]
35
- # TODO: enable this as default in 4.0 and remove it from configuration generator template
45
+ # @todo enable this as default in 4.0 and remove it from configuration generator template
46
+ # Will be {Formtastic::InputClassFinder} by default in 4.0.
36
47
  configure :input_class_finder #, Formtastic::InputClassFinder
48
+ # Check {Formtastic::ActionClassFinder} to see how are inputs resolved.
37
49
  configure :action_namespaces, [::Object, ::Formtastic::Actions]
38
- # TODO: enable this as default in 4.0 and remove it from configuration generator template
50
+ # @todo enable this as default in 4.0 and remove it from configuration generator template
51
+ # Will be {Formtastic::ActionClassFinder} by default in 4.0.
39
52
  configure :action_class_finder#, Formtastic::ActionClassFinder
40
53
 
41
54
  attr_reader :template
@@ -2,7 +2,7 @@
2
2
  module Formtastic
3
3
  module Helpers
4
4
  module ActionHelper
5
- ACTION_CLASS_DEPRECATION = 'configure Formtastic::FormBuilder.action_class_finder instead'.freeze
5
+ ACTION_CLASS_DEPRECATION = 'configure Formtastic::FormBuilder.action_class_finder instead (upgrade guide on wiki: http://bit.ly/1F9QtKc )'.freeze
6
6
  private_constant(:ACTION_CLASS_DEPRECATION)
7
7
 
8
8
  # Renders an action for the form (such as a subit/reset button, or a cancel link).
@@ -89,7 +89,7 @@ module Formtastic
89
89
 
90
90
  protected
91
91
 
92
- def default_action_type(method, options = {}) #:nodoc:
92
+ def default_action_type(method, options = {}) # @private
93
93
  case method
94
94
  when :submit then :input
95
95
  when :reset then :input
@@ -104,9 +104,9 @@ module Formtastic
104
104
  # and modify to suit), falling back to `Formtastic::Actions::AwesomeAction`.
105
105
  #
106
106
  # Custom action namespaces to look into can be configured via the
107
- # .action_namespaces +FormBuilder+ configuration setting.
108
- # See +Formtastic::Helpers::InputHelper#namespaced_input_class+ for details.
109
- #
107
+ # {Formtastic::FormBuilder.action_namespaces} configuration setting.
108
+ # @see Helpers::InputHelper#namespaced_input_class
109
+ # @see Formtastic::ActionClassFinder
110
110
  def namespaced_action_class(as)
111
111
  @action_class_finder ||= action_class_finder.new(self)
112
112
  @action_class_finder.find(as)
@@ -21,7 +21,7 @@ module Formtastic
21
21
  # f.inputs "My little legend", :title, :body, :author # Explicit legend string => "My little legend"
22
22
  # f.inputs :my_little_legend, :title, :body, :author # Localized (118n) legend with I18n key => I18n.t(:my_little_legend, ...)
23
23
  # f.inputs :title, :body, :author # First argument is a column => (no legend)
24
- def field_set_and_list_wrapping(*args, &block) #:nodoc:
24
+ def field_set_and_list_wrapping(*args, &block) # @private
25
25
  contents = args.last.is_a?(::Hash) ? '' : args.pop.flatten
26
26
  html_options = args.extract_options!
27
27
 
@@ -54,7 +54,7 @@ module Formtastic
54
54
 
55
55
  # Gets the nested_child_index value from the parent builder. It returns a hash with each
56
56
  # association that the parent builds.
57
- def parent_child_index(parent) #:nodoc:
57
+ def parent_child_index(parent) # @private
58
58
  # Could be {"post[authors_attributes]"=>0} or { :authors => 0 }
59
59
  duck = parent[:builder].instance_variable_get('@nested_child_index')
60
60
 
@@ -36,7 +36,7 @@ module Formtastic
36
36
  # @see Formtastic::Helpers::InputsHelper#inputs
37
37
  # @see Formtastic::Helpers::FormHelper#semantic_form_for
38
38
  module InputHelper
39
- INPUT_CLASS_DEPRECATION = 'configure Formtastic::FormBuilder.input_class_finder instead'.freeze
39
+ INPUT_CLASS_DEPRECATION = 'configure Formtastic::FormBuilder.input_class_finder instead (upgrade guide on wiki: http://bit.ly/1F9QtKc )'.freeze
40
40
  private_constant(:INPUT_CLASS_DEPRECATION)
41
41
 
42
42
  include Formtastic::Helpers::Reflection
@@ -227,6 +227,7 @@ module Formtastic
227
227
  # first_name: "Joe"
228
228
  # last_name: "Smith"
229
229
  #
230
+ # @see #namespaced_input_class
230
231
  # @todo Many many more examples. Some of the detail probably needs to be pushed out to the relevant methods too.
231
232
  # @todo More i18n examples.
232
233
  def input(method, options = {})
@@ -251,7 +252,7 @@ module Formtastic
251
252
  #
252
253
  # If there is no column for the method (eg "virtual columns" with an attr_accessor), the
253
254
  # default is a :string, a similar behaviour to Rails' scaffolding.
254
- def default_input_type(method, options = {}) #:nodoc:
255
+ def default_input_type(method, options = {}) # @private
255
256
  if @object
256
257
  return :select if reflection_for(method)
257
258
 
@@ -295,7 +296,7 @@ module Formtastic
295
296
  end
296
297
 
297
298
  # Get a column object for a specified attribute method - if possible.
298
- def column_for(method) #:nodoc:
299
+ def column_for(method) # @private
299
300
  if @object.respond_to?(:column_for_attribute)
300
301
  # Remove deprecation wrapper & review after Rails 5.0 ships
301
302
  ActiveSupport::Deprecation.silence do
@@ -310,7 +311,7 @@ module Formtastic
310
311
  # and modify to suit), falling back to `Formtastic::Inputs::AwesomeInput`.
311
312
  #
312
313
  # Custom input namespaces to look into can be configured via the
313
- # .input_namespaces +FormBuilder+ configuration setting.
314
+ # {Formtastic::FormBuilder.input_namespaces} configuration setting.
314
315
  #
315
316
  # @param [Symbol] as A symbol representing the type of input to render
316
317
  # @raise [Formtastic::UnknownInputError] An appropriate input class could not be found
@@ -323,7 +324,7 @@ module Formtastic
323
324
  # @example When a top-level class is found
324
325
  # input_class(:string) #=> StringInput
325
326
  # input_class(:awesome) #=> AwesomeInput
326
-
327
+ # @see NamespacedClassFinder#find
327
328
  def namespaced_input_class(as)
328
329
  @input_class_finder ||= input_class_finder.new(self)
329
330
  @input_class_finder.find(as)
@@ -384,7 +385,7 @@ module Formtastic
384
385
 
385
386
  # @api private
386
387
  # @deprecated Use {InputClassFinder#class_name} instead.
387
- # :as => :string # => Formtastic::Inputs::StringInput
388
+ # :as => :string # => {Formtastic::Inputs::StringInput}
388
389
  def standard_input_class_name(as)
389
390
  input_class_deprecation_warning(__method__)
390
391
  "Formtastic::Inputs::#{as.to_s.camelize}Input"
@@ -338,7 +338,7 @@ module Formtastic
338
338
  # Collects association columns (relation columns) for the current form object class. Skips
339
339
  # polymorphic associations because we can't guess which class to use for an automatically
340
340
  # generated input.
341
- def association_columns(*by_associations) #:nodoc:
341
+ def association_columns(*by_associations) # @private
342
342
  if @object.present? && @object.class.respond_to?(:reflections)
343
343
  @object.class.reflections.collect do |name, association_reflection|
344
344
  if by_associations.present?
@@ -355,7 +355,7 @@ module Formtastic
355
355
  end
356
356
 
357
357
  # Collects content columns (non-relation columns) for the current form object class.
358
- def content_columns #:nodoc:
358
+ def content_columns # @private
359
359
  # TODO: NameError is raised by Inflector.constantize. Consider checking if it exists instead.
360
360
  begin klass = model_name.constantize; rescue NameError; return [] end
361
361
  return [] unless klass.respond_to?(:content_columns)
@@ -367,7 +367,7 @@ module Formtastic
367
367
  # key.
368
368
  #
369
369
  # It should raise an error if a block with arity zero is given.
370
- def inputs_for_nested_attributes(*args, &block) #:nodoc:
370
+ def inputs_for_nested_attributes(*args, &block) # @private
371
371
  options = args.extract_options!
372
372
  args << options.merge!(:parent => { :builder => self, :for => options[:for] })
373
373
 
@@ -396,7 +396,7 @@ module Formtastic
396
396
  fields_for(*fields_for_args, &fields_for_block)
397
397
  end
398
398
 
399
- def field_set_title_from_args(*args) #:nodoc:
399
+ def field_set_title_from_args(*args) # @private
400
400
  options = args.extract_options!
401
401
  options[:name] ||= options.delete(:title)
402
402
  title = options[:name]
@@ -4,20 +4,20 @@ module Formtastic
4
4
  module Reflection
5
5
  # If an association method is passed in (f.input :author) try to find the
6
6
  # reflection object.
7
- def reflection_for(method) #:nodoc:
7
+ def reflection_for(method) # @private
8
8
  if @object.class.respond_to?(:reflect_on_association)
9
- @object.class.reflect_on_association(method)
9
+ @object.class.reflect_on_association(method)
10
10
  elsif @object.class.respond_to?(:associations) # MongoMapper uses the 'associations(method)' instead
11
11
  @object.class.associations[method]
12
12
  end
13
13
  end
14
14
 
15
- def association_macro_for_method(method) #:nodoc:
15
+ def association_macro_for_method(method) # @private
16
16
  reflection = reflection_for(method)
17
17
  reflection.macro if reflection
18
18
  end
19
19
 
20
- def association_primary_key_for_method(method) #:nodoc:
20
+ def association_primary_key_for_method(method) # @private
21
21
  reflection = reflection_for(method)
22
22
  if reflection
23
23
  case association_macro_for_method(method)
@@ -1,16 +1,16 @@
1
1
  module Formtastic
2
2
 
3
- # Uses the Formtastic::NamespacedClassFinder to look up input class names.
3
+ # Uses the {Formtastic::NamespacedClassFinder} to look up input class names.
4
4
  #
5
- # See Formtastic::Helpers::InputHelper#namespaced_input_class for details.
5
+ # See {Formtastic::FormBuilder#namespaced_input_class} for details.
6
6
  #
7
7
  class InputClassFinder < NamespacedClassFinder
8
+
9
+ # @param builder [FormBuilder]
8
10
  def initialize(builder)
9
11
  super builder.input_namespaces
10
12
  end
11
13
 
12
- private
13
-
14
14
  def class_name(as)
15
15
  "#{super}Input"
16
16
  end
@@ -7,7 +7,7 @@ module Formtastic
7
7
 
8
8
  protected
9
9
 
10
- def localized_string(key, value, type, options = {}) #:nodoc:
10
+ def localized_string(key, value, type, options = {}) # @private
11
11
  current_builder = respond_to?(:builder) ? builder : self
12
12
  localizer = Formtastic::FormBuilder.i18n_localizer.new(current_builder)
13
13
  localizer.localize(key, value, type, options)
@@ -56,7 +56,7 @@ module Formtastic
56
56
  self.builder = current_builder
57
57
  end
58
58
 
59
- def localize(key, value, type, options = {}) #:nodoc:
59
+ def localize(key, value, type, options = {}) # @private
60
60
  key = value if value.is_a?(::Symbol)
61
61
 
62
62
  if value.is_a?(::String)
@@ -132,7 +132,7 @@ module Formtastic
132
132
  end
133
133
  end
134
134
 
135
- def escape_html_entities(string) #:nodoc:
135
+ def escape_html_entities(string) # @private
136
136
  if (builder.escape_html_entities_in_hints_and_labels) ||
137
137
  (self.respond_to?(:escape_html_entities_in_hints_and_labels) && escape_html_entities_in_hints_and_labels)
138
138
  string = builder.template.escape_once(string) unless string.respond_to?(:html_safe?) && string.html_safe? == true # Accept html_safe flag as indicator to skip escaping
@@ -3,12 +3,11 @@ module Formtastic
3
3
  # is used both by Formtastic::Helpers::InputHelper and
4
4
  # Formtastic::Helpers::ActionHelper to look up action and input classes.
5
5
  #
6
- # ==== Example
7
- # You can implement own class finder that for example prefixes the class name or uses custom module.
8
- #
6
+ # @example Implementing own class finder
7
+ # # You can implement own class finder that for example prefixes the class name or uses custom module.
9
8
  # class MyInputClassFinder < Formtastic::NamespacedClassFinder
10
- # def initialize(builder)
11
- # super [MyNamespace, Object] # first lookup in MyNamespace then the globals
9
+ # def initialize(namespaces)
10
+ # super [MyNamespace] + namespaces # first lookup in MyNamespace then the defaults
12
11
  # end
13
12
  #
14
13
  # private
@@ -18,17 +17,23 @@ module Formtastic
18
17
  # end
19
18
  # end
20
19
  #
21
- # And then set Formtastic::FormBuilder.input_class_finder with that class.
20
+ # # in config/initializers/formtastic.rb
21
+ # Formtastic::FormBuilder.input_class_finder = MyInputClassFinder
22
22
  #
23
23
 
24
24
  class NamespacedClassFinder
25
- attr_reader :namespaces #:nodoc:
25
+ attr_reader :namespaces # @private
26
26
 
27
27
  # @private
28
28
  class NotFoundError < NameError
29
29
  end
30
30
 
31
- def initialize(namespaces) #:nodoc:
31
+ def self.use_const_defined?
32
+ defined?(Rails) && ::Rails.application && ::Rails.application.config.eager_load
33
+ end
34
+
35
+ # @param namespaces [Array<Module>]
36
+ def initialize(namespaces)
32
37
  @namespaces = namespaces.flatten
33
38
  @cache = {}
34
39
  end
@@ -50,18 +55,23 @@ module Formtastic
50
55
  finder(class_name) or raise NotFoundError, "class #{class_name}"
51
56
  end
52
57
 
53
- private
58
+ # Converts symbol to class name
59
+ # Overridden in subclasses to create `StringInput` and `ButtonAction`
60
+ # @example
61
+ # class_name(:string) == "String"
54
62
 
55
63
  def class_name(as)
56
64
  as.to_s.camelize
57
65
  end
58
66
 
59
- if defined?(Rails) && ::Rails.application && ::Rails.application.config.cache_classes
60
- def finder(class_name) # :nodoc:
67
+ private
68
+
69
+ if use_const_defined?
70
+ def finder(class_name) # @private
61
71
  find_with_const_defined(class_name)
62
72
  end
63
73
  else
64
- def finder(class_name) # :nodoc:
74
+ def finder(class_name) # @private
65
75
  find_by_trying(class_name)
66
76
  end
67
77
  end
@@ -1,3 +1,3 @@
1
1
  module Formtastic
2
- VERSION = "3.1.0"
2
+ VERSION = "3.1.1"
3
3
  end
@@ -4,15 +4,20 @@ module Formtastic
4
4
  # files without confirmation.
5
5
  #
6
6
  # @example
7
+ # !!!shell
7
8
  # $ rails generate formtastic:form Post
8
9
  # @example Copy the partial code to the pasteboard rather than generating a partial
10
+ # !!!shell
9
11
  # $ rails generate formtastic:form Post --copy
10
12
  # @example Return HAML or Slim output instead of default ERB
13
+ # !!!shell
11
14
  # $ rails generate formtastic:form Post --template-engine haml
12
15
  # $ rails generate formtastic:form Post --template-engine slim
13
16
  # @example Generate a form for specific model attributes
17
+ # !!!shell
14
18
  # $ rails generate formtastic:form Post title:string body:text
15
19
  # @example Generate a form for a specific controller
20
+ # !!!shell
16
21
  # $ rails generate formtastic:form Post --controller admin/posts
17
22
  class FormGenerator < Rails::Generators::NamedBase
18
23
  desc "Generates a Formtastic form partial based on an existing model."
@@ -103,4 +108,4 @@ module Formtastic
103
108
  end
104
109
 
105
110
  end
106
- end
111
+ end
@@ -4,6 +4,7 @@ module Formtastic
4
4
  # Copies a config initializer to config/initializers/formtastic.rb
5
5
  #
6
6
  # @example
7
+ # !!!shell
7
8
  # $ rails generate formtastic:install
8
9
  class InstallGenerator < Rails::Generators::Base
9
10
  source_root File.expand_path('../../../templates', __FILE__)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.0
4
+ version: 3.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-11-16 00:00:00.000000000 Z
12
+ date: 2014-11-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: actionpack
@@ -92,13 +92,13 @@ dependencies:
92
92
  - !ruby/object:Gem::Version
93
93
  version: 0.8.3
94
94
  - !ruby/object:Gem::Dependency
95
- name: BlueCloth
95
+ name: RedCloth
96
96
  requirement: !ruby/object:Gem::Requirement
97
97
  none: false
98
98
  requirements:
99
99
  - - ~>
100
100
  - !ruby/object:Gem::Version
101
- version: '1.0'
101
+ version: '4.2'
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
@@ -106,7 +106,7 @@ dependencies:
106
106
  requirements:
107
107
  - - ~>
108
108
  - !ruby/object:Gem::Version
109
- version: '1.0'
109
+ version: '4.2'
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: yard
112
112
  requirement: !ruby/object:Gem::Requirement
@@ -114,7 +114,7 @@ dependencies:
114
114
  requirements:
115
115
  - - ~>
116
116
  - !ruby/object:Gem::Version
117
- version: '0.6'
117
+ version: '0.8'
118
118
  type: :development
119
119
  prerelease: false
120
120
  version_requirements: !ruby/object:Gem::Requirement
@@ -122,7 +122,7 @@ dependencies:
122
122
  requirements:
123
123
  - - ~>
124
124
  - !ruby/object:Gem::Version
125
- version: '0.6'
125
+ version: '0.8'
126
126
  - !ruby/object:Gem::Dependency
127
127
  name: colored
128
128
  requirement: !ruby/object:Gem::Requirement