Skip to content
Browse files

Revert all the changes introduced in commits 8d17ca4..8d8c50

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...
1 parent 8d8c50f commit f9c1a8ad4279dd819235754ac6b53f606eba68dd @yabawock yabawock committed Apr 15, 2010
Showing with 109 additions and 526 deletions.
  1. +0 −6 init.rb
  2. +29 −28 lib/formtastic.rb
  3. +0 −7 lib/formtastic/html_safe.rb
  4. +0 −1 lib/formtastic/i18n.rb
  5. +0 −1 lib/formtastic/layout_helper.rb
  6. +0 −10 lib/formtastic/railtie.rb
  7. +0 −85 lib/generators/formtastic/form/form_generator.rb
  8. +0 −5 lib/generators/formtastic/form/templates/_form.html.erb
  9. +0 −4 lib/generators/formtastic/form/templates/_form.html.haml
  10. +0 −23 lib/generators/formtastic/install/install_generator.rb
  11. +0 −144 lib/generators/formtastic/install/templates/formtastic.css
  12. +0 −58 lib/generators/formtastic/install/templates/formtastic.rb
  13. +0 −10 lib/generators/formtastic/install/templates/formtastic_changes.css
  14. +5 −0 rails/init.rb
  15. +1 −1 spec/buttons_spec.rb
  16. +2 −13 spec/commit_button_spec.rb
  17. +1 −1 spec/custom_builder_spec.rb
  18. +1 −1 spec/error_proc_spec.rb
  19. +1 −1 spec/errors_spec.rb
  20. +17 −1 spec/form_helper_spec.rb
  21. +1 −1 spec/i18n_spec.rb
  22. +1 −1 spec/include_blank_spec.rb
  23. +1 −1 spec/input_spec.rb
  24. +2 −2 spec/inputs/boolean_input_spec.rb
  25. +2 −57 spec/inputs/check_boxes_input_spec.rb
  26. +2 −2 spec/inputs/country_input_spec.rb
  27. +1 −1 spec/inputs/date_input_spec.rb
  28. +1 −1 spec/inputs/datetime_input_spec.rb
  29. +1 −1 spec/inputs/file_input_spec.rb
  30. +1 −1 spec/inputs/hidden_input_spec.rb
  31. +1 −1 spec/inputs/numeric_input_spec.rb
  32. +1 −1 spec/inputs/password_input_spec.rb
  33. +2 −2 spec/inputs/radio_input_spec.rb
  34. +17 −3 spec/inputs/select_input_spec.rb
  35. +1 −1 spec/inputs/string_input_spec.rb
  36. +1 −1 spec/inputs/text_input_spec.rb
  37. +1 −1 spec/inputs/time_input_spec.rb
  38. +2 −2 spec/inputs/time_zone_input_spec.rb
  39. +1 −1 spec/inputs_spec.rb
  40. +1 −1 spec/label_spec.rb
  41. +1 −14 spec/layout_helper_spec.rb
  42. +1 −1 spec/semantic_errors_spec.rb
  43. +1 −1 spec/semantic_fields_for_spec.rb
  44. 0 spec/{.rspec → spec.opts}
  45. +8 −28 spec/spec_helper.rb
View
6 init.rb
@@ -1,6 +0,0 @@
-# coding: utf-8
-require 'formtastic'
-require 'formtastic/layout_helper'
-
-ActionView::Base.send(:include, Formtastic::SemanticFormHelper)
-ActionView::Base.send(:include, Formtastic::LayoutHelper)
View
57 lib/formtastic.rb
@@ -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:
@@ -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
@@ -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
@@ -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,
@@ -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
@@ -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)
@@ -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
@@ -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)
@@ -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,
@@ -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?
@@ -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
@@ -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
@@ -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
@@ -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:
#
@@ -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!
@@ -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
View
7 lib/formtastic/html_safe.rb
@@ -1,7 +0,0 @@
-if !defined?(::Rails::VERSION) || Rails::VERSION::MAJOR == 2
- class String
- def html_safe
- self
- end
- end
-end
View
1 lib/formtastic/i18n.rb
@@ -1,4 +1,3 @@
-# coding: utf-8
module Formtastic
module I18n
View
1 lib/formtastic/layout_helper.rb
@@ -1,4 +1,3 @@
-# coding: utf-8
module Formtastic
module LayoutHelper
View
10 lib/formtastic/railtie.rb
@@ -1,10 +0,0 @@
-require 'formtastic'
-require 'rails'
-
-module Formtastic
- class Railtie < Rails::Railtie
- initializer :after_initialize do
- ActionView::Base.send :include, Formtastic::SemanticFormHelper
- end
- end
-end
View
85 lib/generators/formtastic/form/form_generator.rb
@@ -1,85 +0,0 @@
-# coding: utf-8
-module Formtastic
- class FormGenerator < Rails::Generators::NamedBase
- desc "Generates formtastic form code based on an existing model. By default the " <<
- "generated code will be printed out directly in the terminal, and also copied " <<
- "to clipboard. Can optionally be saved into partial directly."
-
- class_option :haml, :type => :boolean, :default => false, :group => :formtastic,
- :desc => "Generate HAML instead of ERB"
-
- class_option :partial, :type => :boolean, :default => false, :group => :formtastic,
- :desc => 'Generate a form partial in the model views path, i.e. "_form.html.erb" or "_form.html.haml"'
-
- class_option :controller, :type => :string, :default => false, :group => :formtastic,
- :desc => 'Generate for custom controller/view path - in case model and controller namespace is different, i.e. "admin/posts"'
-
- def self.source_root
- @source_root ||= File.expand_path("../templates", __FILE__)
- end
-
- def self.banner
- "rails generate formtastic:form ExistingModelName [options]"
- end
-
- def create_or_show
- if options[:partial]
- empty_directory "app/views/#{controller_path}"
- template "_form.html.#{template_type}", "app/views/#{controller_path}/_form.html.#{template_type}"
- else
- template = File.read("#{self.class.source_root}/_form.html.#{template_type}")
- erb = ERB.new(template, nil, '-')
- generated_code = erb.result(binding).strip rescue nil
-
- puts "# ---------------------------------------------------------"
- puts "# GENERATED FORMTASTIC CODE"
- puts "# ---------------------------------------------------------"
- puts
- puts generated_code || "Nothing could be generated - model exists?"
- puts
- puts "# ---------------------------------------------------------"
- puts "Copied to clipboard - just paste it!" if save_to_clipboard(generated_code)
- end
- end
-
- protected
-
- IGNORED_COLUMNS = [:updated_at, :created_at].freeze
-
- def template_type
- @template_type ||= options[:haml] ? :haml : :erb
- end
-
- def controller_path
- @controller_path ||= if options[:controller]
- options[:controller].underscore
- else
- name.underscore.pluralize
- end
- end
-
- def columns
- @columns ||= self.name.camelize.constantize.content_columns.reject { |column| IGNORED_COLUMNS.include?(column.name.to_sym) }
- end
-
- def save_to_clipboard(data)
- return unless data
-
- begin
- case RUBY_PLATFORM
- when /win32/
- require 'win32/clipboard'
- ::Win32::Clipboard.data = data
- when /darwin/ # mac
- `echo "#{data}" | pbcopy`
- else # linux/unix
- `echo "#{data}" | xsel --clipboard` || `echo "#{data}" | xclip`
- end
- rescue LoadError
- false
- else
- true
- end
- end
- end
-end
View
5 lib/generators/formtastic/form/templates/_form.html.erb
@@ -1,5 +0,0 @@
-<%% f.inputs do %>
-<% columns.each do |column| -%>
- <%%= f.input :<%= column.name %>, :label => '<%= column.name.humanize %>' %>
-<% end -%>
-<%% end %>
View
4 lib/generators/formtastic/form/templates/_form.html.haml
@@ -1,4 +0,0 @@
-- f.inputs do
-<% columns.each do |column| -%>
- = f.input :<%= column.name %>, :label => '<%= column.name.humanize %>'
-<% end -%>
View
23 lib/generators/formtastic/install/install_generator.rb
@@ -1,23 +0,0 @@
-# coding: utf-8
-module Formtastic
- class InstallGenerator < Rails::Generators::Base
- desc "Copies formtastic.css and formtastic_changes.css to public/stylesheets/ and a config initializer to config/initializers/formtastic_config.rb"
-
- def self.source_root
- @source_root ||= File.expand_path("../templates", __FILE__)
- end
-
- def self.banner
- "rails generate formtastic:install [options]"
- end
-
- def copy_files
- empty_directory 'config/initializers'
- template 'formtastic.rb', 'config/initializers/formtastic.rb'
-
- empty_directory 'public/stylesheets'
- template 'formtastic.css', 'public/stylesheets/formtastic.css'
- template 'formtastic_changes.css', 'public/stylesheets/formtastic_changes.css'
- end
- end
-end
View
144 lib/generators/formtastic/install/templates/formtastic.css
@@ -1,144 +0,0 @@
-/* -------------------------------------------------------------------------------------------------
-
-It's *strongly* suggested that you don't modify this file. Instead, load a new stylesheet after
-this one in your layouts (eg formtastic_changes.css) and override the styles to suit your needs.
-This will allow you to update formtastic.css with new releases without clobbering your own changes.
-
-This stylesheet forms part of the Formtastic Rails Plugin
-(c) 2008 Justin French
-
---------------------------------------------------------------------------------------------------*/
-
-
-/* NORMALIZE AND RESET - obviously inspired by Yahoo's reset.css, but scoped to just form.formtastic
---------------------------------------------------------------------------------------------------*/
-form.formtastic, form.formtastic ul, form.formtastic ol, form.formtastic li, form.formtastic fieldset, form.formtastic legend, form.formtastic input, form.formtastic textarea, form.formtastic select, form.formtastic p { margin:0; padding:0; }
-form.formtastic fieldset { border:0; }
-form.formtastic em, form.formtastic strong { font-style:normal; font-weight:normal; }
-form.formtastic ol, form.formtastic ul { list-style:none; }
-form.formtastic abbr, form.formtastic acronym { border:0; font-variant:normal; }
-form.formtastic input, form.formtastic textarea, form.formtastic select { font-family:inherit; font-size:inherit; font-weight:inherit; }
-form.formtastic input, form.formtastic textarea, form.formtastic select { font-size:100%; }
-form.formtastic legend { color:#000; }
-
-
-/* SEMANTIC ERRORS
---------------------------------------------------------------------------------------------------*/
-form.formtastic ul.errors { color:#cc0000; margin:0.5em 0 1.5em 25%; list-style:square; }
-form.formtastic ul.errors li { padding:0; border:none; display:list-item; }
-
-
-/* FIELDSETS & LISTS
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset { }
-form.formtastic fieldset.inputs { }
-form.formtastic fieldset.buttons { padding-left:25%; }
-form.formtastic fieldset ol { }
-form.formtastic fieldset.buttons li { float:left; padding-right:0.5em; }
-
-/* clearfixing the fieldsets */
-form.formtastic fieldset { display: inline-block; }
-form.formtastic fieldset:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
-html[xmlns] form.formtastic fieldset { display: block; }
-* html form.formtastic fieldset { height: 1%; }
-
-
-/* INPUT LIs
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li { margin-bottom:1.5em; }
-
-/* clearfixing the li's */
-form.formtastic fieldset ol li { display: inline-block; }
-form.formtastic fieldset ol li:after { content: "."; display: block; height: 0; clear: both; visibility: hidden; }
-html[xmlns] form.formtastic fieldset ol li { display: block; }
-* html form.formtastic fieldset ol li { height: 1%; }
-
-form.formtastic fieldset ol li.required { }
-form.formtastic fieldset ol li.optional { }
-form.formtastic fieldset ol li.error { }
-
-
-/* LABELS
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li label { display:block; width:25%; float:left; padding-top:.2em; }
-form.formtastic fieldset ol li li label { line-height:100%; padding-top:0; }
-form.formtastic fieldset ol li li label input { line-height:100%; vertical-align:middle; margin-top:-0.1em;}
-
-
-/* NESTED FIELDSETS AND LEGENDS (radio, check boxes and date/time inputs use nested fieldsets)
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li fieldset { position:relative; }
-form.formtastic fieldset ol li fieldset legend { position:absolute; width:25%; padding-top:0.1em; }
-form.formtastic fieldset ol li fieldset legend span { position:absolute; }
-form.formtastic fieldset ol li fieldset legend.label label { position:absolute; }
-form.formtastic fieldset ol li fieldset ol { float:left; width:74%; margin:0; padding:0 0 0 25%; }
-form.formtastic fieldset ol li fieldset ol li { padding:0; border:0; }
-
-
-/* INLINE HINTS
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li p.inline-hints { color:#666; margin:0.5em 0 0 25%; }
-
-
-/* INLINE ERRORS
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li p.inline-errors { color:#cc0000; margin:0.5em 0 0 25%; }
-form.formtastic fieldset ol li ul.errors { color:#cc0000; margin:0.5em 0 0 25%; list-style:square; }
-form.formtastic fieldset ol li ul.errors li { padding:0; border:none; display:list-item; }
-
-
-/* STRING & NUMERIC OVERRIDES
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li.string input { width:74%; }
-form.formtastic fieldset ol li.password input { width:74%; }
-form.formtastic fieldset ol li.numeric input { width:74%; }
-
-
-/* TEXTAREA OVERRIDES
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li.text textarea { width:74%; }
-
-
-/* HIDDEN OVERRIDES
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li.hidden { display:none; }
-
-
-/* BOOLEAN OVERRIDES
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li.boolean label { padding-left:25%; width:auto; }
-form.formtastic fieldset ol li.boolean label input { margin:0 0.5em 0 0.2em; }
-
-
-/* RADIO OVERRIDES
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li.radio { }
-form.formtastic fieldset ol li.radio fieldset ol { margin-bottom:-0.6em; }
-form.formtastic fieldset ol li.radio fieldset ol li { margin:0.1em 0 0.5em 0; }
-form.formtastic fieldset ol li.radio fieldset ol li label { float:none; width:100%; }
-form.formtastic fieldset ol li.radio fieldset ol li label input { margin-right:0.2em; }
-
-
-/* CHECK BOXES (COLLECTION) OVERRIDES
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li.check_boxes { }
-form.formtastic fieldset ol li.check_boxes fieldset ol { margin-bottom:-0.6em; }
-form.formtastic fieldset ol li.check_boxes fieldset ol li { margin:0.1em 0 0.5em 0; }
-form.formtastic fieldset ol li.check_boxes fieldset ol li label { float:none; width:100%; }
-form.formtastic fieldset ol li.check_boxes fieldset ol li label input { margin-right:0.2em; }
-
-
-
-/* DATE & TIME OVERRIDES
---------------------------------------------------------------------------------------------------*/
-form.formtastic fieldset ol li.date fieldset ol li,
-form.formtastic fieldset ol li.time fieldset ol li,
-form.formtastic fieldset ol li.datetime fieldset ol li { float:left; width:auto; margin:0 .3em 0 0; }
-
-form.formtastic fieldset ol li.date fieldset ol li label,
-form.formtastic fieldset ol li.time fieldset ol li label,
-form.formtastic fieldset ol li.datetime fieldset ol li label { display:none; }
-
-form.formtastic fieldset ol li.date fieldset ol li label input,
-form.formtastic fieldset ol li.time fieldset ol li label input,
-form.formtastic fieldset ol li.datetime fieldset ol li label input { display:inline; margin:0; padding:0; }
View
58 lib/generators/formtastic/install/templates/formtastic.rb
@@ -1,58 +0,0 @@
-# Set the default text field size when input is a string. Default is 50.
-# Formtastic::SemanticFormBuilder.default_text_field_size = 50
-
-# Set the default text area height when input is a text. Default is 20.
-# Formtastic::SemanticFormBuilder.default_text_area_height = 5
-
-# Should all fields be considered "required" by default?
-# Defaults to true, see ValidationReflection notes below.
-# Formtastic::SemanticFormBuilder.all_fields_required_by_default = true
-
-# Should select fields have a blank option/prompt by default?
-# Defaults to true.
-# Formtastic::SemanticFormBuilder.include_blank_for_select_by_default = true
-
-# Set the string that will be appended to the labels/fieldsets which are required
-# It accepts string or procs and the default is a localized version of
-# '<abbr title="required">*</abbr>'. In other words, if you configure formtastic.required
-# in your locale, it will replace the abbr title properly. But if you don't want to use
-# abbr tag, you can simply give a string as below
-# Formtastic::SemanticFormBuilder.required_string = "(required)"
-
-# Set the string that will be appended to the labels/fieldsets which are optional
-# Defaults to an empty string ("") and also accepts procs (see required_string above)
-# Formtastic::SemanticFormBuilder.optional_string = "(optional)"
-
-# Set the way inline errors will be displayed.
-# Defaults to :sentence, valid options are :sentence, :list and :none
-# Formtastic::SemanticFormBuilder.inline_errors = :sentence
-
-# Set the method to call on label text to transform or format it for human-friendly
-# reading when formtastic is user without object. Defaults to :humanize.
-# Formtastic::SemanticFormBuilder.label_str_method = :humanize
-
-# Set the array of methods to try calling on parent objects in :select and :radio inputs
-# for the text inside each @<option>@ tag or alongside each radio @<input>@. The first method
-# that is found on the object will be used.
-# Defaults to ["to_label", "display_name", "full_name", "name", "title", "username", "login", "value", "to_s"]
-# Formtastic::SemanticFormBuilder.collection_label_methods = [
-# "to_label", "display_name", "full_name", "name", "title", "username", "login", "value", "to_s"]
-
-# Formtastic by default renders inside li tags the input, hints and then
-# errors messages. Sometimes you want the hints to be rendered first than
-# the input, in the following order: hints, input and errors. You can
-# customize it doing just as below:
-# Formtastic::SemanticFormBuilder.inline_order = [:input, :hints, :errors]
-
-# Formtastic by default renders inside li tags you can customize it to render
-# with div tags if required
-# Formtastic::SemanticFormBuilder.item_separator = :div
-
-# Specifies if labels/hints for input fields automatically be looked up using I18n.
-# Default value: false. Overridden for specific fields by setting value to true,
-# i.e. :label => true, or :hint => true (or opposite depending on initialized value)
-# Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
-
-# You can add custom inputs or override parts of Formtastic by subclassing SemanticFormBuilder and
-# specifying that class here. Defaults to SemanticFormBuilder.
-# Formtastic::SemanticFormHelper.builder = MyCustomBuilder
View
10 lib/generators/formtastic/install/templates/formtastic_changes.css
@@ -1,10 +0,0 @@
-/* -------------------------------------------------------------------------------------------------
-
-Load this stylesheet after formtastic.css in your layouts to override the CSS to suit your needs.
-This will allow you to update formtastic.css with new releases without clobbering your own changes.
-
-For example, to make the inline hint paragraphs a little darker in color than the standard #666:
-
-form.formtastic fieldset ol li p.inline-hints { color:#333; }
-
---------------------------------------------------------------------------------------------------*/
View
5 rails/init.rb
@@ -0,0 +1,5 @@
+# coding: utf-8
+require File.join(File.dirname(__FILE__), *%w[.. lib formtastic])
+require File.join(File.dirname(__FILE__), *%w[.. lib formtastic layout_helper])
+ActionView::Base.send :include, Formtastic::SemanticFormHelper
+ActionView::Base.send :include, Formtastic::LayoutHelper
View
2 spec/buttons_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
View
15 spec/commit_button_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
@@ -348,18 +348,7 @@
describe 'when the model is two words' do
before do
output_buffer = ''
-
- class ::UserPost
- extend ActiveModel::Naming
-
- def id
- end
-
- def self.human_name
- "Userpost" # Rails does crappy human_name
- end
- end
-
+ class ::UserPost; def id; end; def self.human_name; "Userpost"; end; end # Rails does crappy human_name
@new_user_post = ::UserPost.new
@new_user_post.stub!(:new_record?).and_return(true)
View
2 spec/custom_builder_spec.rb
@@ -12,7 +12,7 @@ def awesome_input(method, options)
end
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
View
2 spec/error_proc_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
View
2 spec/errors_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
@title_errors = ['must not be blank', 'must be longer than 10 characters', 'must be awesome']
@errors = mock('errors')
View
18 spec/form_helper_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
@@ -106,5 +106,21 @@ class MyAwesomeCustomBuilder < ::Formtastic::SemanticFormBuilder
end
end
+ describe '#semantic_form_remote_for' do
+ it 'yields an instance of SemanticFormBuilder' do
+ semantic_form_remote_for(:post, ::Post.new, :url => '/hello') do |builder|
+ builder.class.should == ::Formtastic::SemanticFormBuilder
+ end
+ end
+ end
+
+ describe '#semantic_form_for_remote' do
+ it 'yields an instance of SemanticFormBuilder' do
+ semantic_remote_form_for(:post, ::Post.new, :url => '/hello') do |builder|
+ builder.class.should == ::Formtastic::SemanticFormBuilder
+ end
+ end
+ end
+
end
View
2 spec/i18n_spec.rb
@@ -85,7 +85,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
::I18n.backend.store_translations :en, :formtastic => {
View
2 spec/include_blank_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
@new_post.stub!(:author_id).and_return(nil)
View
2 spec/input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
View
4 spec/inputs/boolean_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
semantic_form_for(@new_post) do |builder|
@@ -58,7 +58,7 @@
describe 'when :selected is set' do
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
end
describe "not selected" do
View
59 spec/inputs/check_boxes_input_spec.rb
@@ -7,7 +7,7 @@
describe 'for a has_many association' do
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
semantic_form_for(@fred) do |builder|
@@ -108,7 +108,7 @@
describe 'when :selected is set' do
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
end
describe "no selected items" do
@@ -177,61 +177,6 @@
end
- describe 'when :disabled is set' do
- before do
- @output_buffer = ''
- end
-
- describe "no disabled items" do
- before do
- @new_post.stub!(:author_ids).and_return(nil)
-
- semantic_form_for(@new_post) do |builder|
- concat(builder.input(:authors, :as => :check_boxes, :disabled => nil))
- end
- end
-
- it 'should not have any disabled item(s)' do
- output_buffer.should_not have_tag("form li fieldset ol li label input[@disabled='disabled']")
- end
- end
-
- describe "single disabled item" do
- before do
- @new_post.stub!(:author_ids).and_return(nil)
-
- semantic_form_for(@new_post) do |builder|
- concat(builder.input(:authors, :as => :check_boxes, :disabled => @fred.id))
- end
- end
-
- it "should have one item disabled; the specified one" do
- output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 1)
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
- output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
- end
- end
-
- describe "multiple disabled items" do
- before do
- @new_post.stub!(:author_ids).and_return(nil)
-
- semantic_form_for(@new_post) do |builder|
- concat(builder.input(:authors, :as => :check_boxes, :disabled => [@bob.id, @fred.id]))
- end
- end
-
- it "should have multiple items disabled; the specified ones" do
- output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled']", :count => 2)
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@bob.id}']", /bob/i)
- output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@bob.id}']")
- output_buffer.should have_tag("form li fieldset ol li label[@for='post_author_ids_#{@fred.id}']", /fred/i)
- output_buffer.should have_tag("form li fieldset ol li label input[@disabled='disabled'][@value='#{@fred.id}']")
- end
- end
-
- end
-
end
View
4 spec/inputs/country_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
@@ -26,7 +26,7 @@
before do
semantic_form_for(@new_post) do |builder|
- builder.stub!(:country_select).and_return(ActiveSupport::SafeBuffer.new("<select><option>...</option></select>"))
+ builder.stub!(:country_select).and_return("<select><option>...</option></select>")
concat(builder.input(:country, :as => :country))
end
end
View
2 spec/inputs/date_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
View
2 spec/inputs/datetime_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
@new_post.should_receive(:publish_at=).any_number_of_times
View
2 spec/inputs/file_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
semantic_form_for(@new_post) do |builder|
View
2 spec/inputs/hidden_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
semantic_form_for(@new_post) do |builder|
View
2 spec/inputs/numeric_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
semantic_form_for(@new_post) do |builder|
View
2 spec/inputs/password_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
semantic_form_for(@new_post) do |builder|
View
4 spec/inputs/radio_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
@@ -114,7 +114,7 @@
describe 'when :selected is set' do
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
end
describe "no selected items" do
View
20 spec/inputs/select_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
@@ -149,6 +149,20 @@
output_buffer.should have_tag('form li select#post_author_status_id')
end
+
+ it 'should use the "class_name" option' do
+ @new_post.stub!(:status).and_return(@bob)
+ @new_post.stub!(:author_status_id).and_return(@bob.id)
+
+ ::Post.stub!(:reflect_on_association).with(:status).and_return(
+ mock('reflection', :options => {:class_name => 'AuthorStatus'}, :klass => ::Author, :macro => :belongs_to))
+
+ semantic_form_for(@new_post) do |builder|
+ concat(builder.input(:status, :as => :select))
+ end
+
+ output_buffer.should have_tag('form li select#post_author_status_id')
+ end
end
describe "for a belongs_to association with :group_by => :author" do
@@ -343,7 +357,7 @@
describe 'when :selected is set' do
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
end
describe "no selected items" do
@@ -424,7 +438,7 @@
describe "enum" do
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
@some_meta_descriptions = ["One", "Two", "Three"]
@new_post.stub!(:meta_description).any_number_of_times
end
View
2 spec/inputs/string_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
semantic_form_for(@new_post) do |builder|
View
2 spec/inputs/text_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
semantic_form_for(@new_post) do |builder|
View
2 spec/inputs/time_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
View
4 spec/inputs/time_zone_input_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
semantic_form_for(@new_post) do |builder|
@@ -59,7 +59,7 @@
describe 'when :selected is set' do
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
end
# Note: Not possible to override default selected value for time_zone input
View
2 spec/inputs_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
View
2 spec/label_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
end
View
15 spec/layout_helper_spec.rb
@@ -7,7 +7,7 @@
include Formtastic::LayoutHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
end
describe '#formtastic_stylesheet_link_tag' do
@@ -25,18 +25,5 @@
end
end
-
- # FIXME: Rspec issue?
- def controller
- mock('controller')
- end
-
- # FIXME: Rspec issue?
- def config
- returning mock('config') do |config|
- config.stub!(:assets_dir).and_return('')
- end
- end
-
end
View
2 spec/semantic_errors_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
@title_errors = ['must not be blank', 'must be awesome']
@base_errors = ['base error message', 'nasty error']
View
2 spec/semantic_fields_for_spec.rb
@@ -6,7 +6,7 @@
include FormtasticSpecHelper
before do
- @output_buffer = ActiveSupport::SafeBuffer.new
+ @output_buffer = ''
mock_everything
@new_post.stub!(:author).and_return(::Author.new)
end
View
0 spec/.rspec → spec/spec.opts
File renamed without changes.
View
36 spec/spec_helper.rb
@@ -1,43 +1,38 @@
# coding: utf-8
require 'rubygems'
-gem 'activesupport', '3.0.0.beta2'
-gem 'actionpack', '3.0.0.beta2'
-gem 'activemodel', '3.0.0.beta2'
+gem 'activesupport', '2.3.5'
+gem 'actionpack', '2.3.5'
require 'active_support'
require 'action_pack'
require 'action_view'
require 'action_controller'
-require 'active_model'
-gem 'rspec', '>= 2.0.0.beta.6'
-require 'rspec'
-gem 'rspec-rails', '>= 2.0.0.beta.6'
+gem 'rspec', '>= 1.2.6'
+gem 'rspec-rails', '>= 1.2.6'
gem 'hpricot', '>= 0.6.1'
gem 'rspec_tag_matchers', '>= 1.0.0'
require 'rspec_tag_matchers'
require 'custom_macros'
-Rspec.configure do |config|
- config.include RspecTagMatchers
- config.include CustomMacros
- config.mock_with :rspec
+Spec::Runner.configure do |config|
+ config.include(RspecTagMatchers)
+ config.include(CustomMacros)
end
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic'))
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/formtastic/layout_helper'))
module FormtasticSpecHelper
- include ActionView::Context
include ActionView::Helpers::FormHelper
include ActionView::Helpers::FormTagHelper
include ActionView::Helpers::FormOptionsHelper
include ActionView::Helpers::UrlHelper
include ActionView::Helpers::TagHelper
include ActionView::Helpers::TextHelper
- include ActionView::Helpers::ActiveModelHelper
+ include ActionView::Helpers::ActiveRecordHelper
include ActionView::Helpers::RecordIdentificationHelper
include ActionView::Helpers::DateHelper
include ActionView::Helpers::CaptureHelper
@@ -59,34 +54,20 @@ def default_input_type(column_type, column_name = :generic_column_name)
end
class ::Post
- extend ActiveModel::Naming
- include ActiveModel::Conversion
-
def id
end
end
-
module ::Namespaced
class Post
- extend ActiveModel::Naming
- include ActiveModel::Conversion
-
def id
end
end
end
-
class ::Author
- extend ActiveModel::Naming
- include ActiveModel::Conversion
-
def to_label
end
end
-
class ::Continent
- extend ActiveModel::Naming
- include ActiveModel::Conversion
end
def mock_everything
@@ -147,7 +128,6 @@ def new_author_path; "/authors/new"; end
@new_post.stub!(:author).and_return(nil)
@new_post.stub!(:main_post).and_return(nil)
@new_post.stub!(:sub_posts).and_return([]) #TODO should be a mock with methods for adding sub posts
- @new_post.stub!(:to_model).and_return(@new_post)
@freds_post = mock('post')
@freds_post.stub!(:class).and_return(::Post)

0 comments on commit f9c1a8a

Please sign in to comment.
Something went wrong with that request. Please try again.