From 2655d6bfa23a005eba255ccc045073161eb139e7 Mon Sep 17 00:00:00 2001 From: Gabriel Sobrinho Date: Mon, 22 Mar 2010 03:34:31 +0800 Subject: [PATCH 001/992] Fix a coding issue with HAML + Rails 3 + Ruby 1.9.1 --- lib/formtastic/layout_helper.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/formtastic/layout_helper.rb b/lib/formtastic/layout_helper.rb index daea784bc..2da334176 100644 --- a/lib/formtastic/layout_helper.rb +++ b/lib/formtastic/layout_helper.rb @@ -1,3 +1,4 @@ +# coding: utf-8 module Formtastic module LayoutHelper From 6de8bf7489f8a1210a42afd7ce84394a02b5e8a5 Mon Sep 17 00:00:00 2001 From: Gabriel Sobrinho Date: Mon, 22 Mar 2010 03:35:25 +0800 Subject: [PATCH 002/992] Fix another coding issue with HAML + Rails 3 + Ruby 1.9.1 --- lib/formtastic/i18n.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/formtastic/i18n.rb b/lib/formtastic/i18n.rb index 97b05e4c2..c3536f2fa 100644 --- a/lib/formtastic/i18n.rb +++ b/lib/formtastic/i18n.rb @@ -1,3 +1,4 @@ +# coding: utf-8 module Formtastic module I18n From 62443aa2b44b5f87b30be0d1a2ea980eccfe9d9f Mon Sep 17 00:00:00 2001 From: Dallas Reedy Date: Sat, 27 Feb 2010 07:26:56 +0800 Subject: [PATCH 003/992] added the :disabled option to #check_boxes_input --- lib/formtastic.rb | 6 ++- spec/inputs/check_boxes_input_spec.rb | 55 +++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) diff --git a/lib/formtastic.rb b/lib/formtastic.rb index ee0b0c81f..367a27551 100644 --- a/lib/formtastic.rb +++ b/lib/formtastic.rb @@ -1110,7 +1110,10 @@ 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 @@ -1118,6 +1121,7 @@ def check_boxes_input(method, options) 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, diff --git a/spec/inputs/check_boxes_input_spec.rb b/spec/inputs/check_boxes_input_spec.rb index b0aaffd54..f0017bdf9 100644 --- a/spec/inputs/check_boxes_input_spec.rb +++ b/spec/inputs/check_boxes_input_spec.rb @@ -177,6 +177,61 @@ 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 From 8d17ca431c8a60a14399834623ab798dcf0f1b98 Mon Sep 17 00:00:00 2001 From: Morton Jonuschat Date: Sun, 11 Apr 2010 11:04:36 +0200 Subject: [PATCH 004/992] Add railtie to perform initialization when running under rails3 --- lib/formtastic.rb | 1 + lib/formtastic/railtie.rb | 10 ++++++++++ 2 files changed, 11 insertions(+) create mode 100644 lib/formtastic/railtie.rb diff --git a/lib/formtastic.rb b/lib/formtastic.rb index 367a27551..0b8b7c9c1 100644 --- a/lib/formtastic.rb +++ b/lib/formtastic.rb @@ -1,5 +1,6 @@ # coding: utf-8 require File.join(File.dirname(__FILE__), *%w[formtastic i18n]) +require File.join(File.dirname(__FILE__), *%w[formtastic railtie]) if defined?(::Rails::Railtie) module Formtastic #:nodoc: diff --git a/lib/formtastic/railtie.rb b/lib/formtastic/railtie.rb new file mode 100644 index 000000000..799e6c4b2 --- /dev/null +++ b/lib/formtastic/railtie.rb @@ -0,0 +1,10 @@ +require 'formtastic' +require 'rails' + +module Formtastic + class Railtie < Rails::Railtie + initializer :after_initialize do + ActionView::Base.send :include, Formtastic::SemanticFormHelper + end + end +end \ No newline at end of file From 23fb5ce3f71e77ecce2d7b144cb7b1748cc30ea6 Mon Sep 17 00:00:00 2001 From: Morton Jonuschat Date: Sun, 11 Apr 2010 12:49:24 +0200 Subject: [PATCH 005/992] html_safe for rails2 --- lib/formtastic.rb | 1 + lib/formtastic/html_safe.rb | 7 +++++++ 2 files changed, 8 insertions(+) create mode 100644 lib/formtastic/html_safe.rb diff --git a/lib/formtastic.rb b/lib/formtastic.rb index 0b8b7c9c1..a0c55cb2c 100644 --- a/lib/formtastic.rb +++ b/lib/formtastic.rb @@ -1,5 +1,6 @@ # 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: diff --git a/lib/formtastic/html_safe.rb b/lib/formtastic/html_safe.rb new file mode 100644 index 000000000..c0ce300c8 --- /dev/null +++ b/lib/formtastic/html_safe.rb @@ -0,0 +1,7 @@ +if !defined?(::Rails::VERSION) || Rails::VERSION::MAJOR == 2 + class String + def html_safe + self + end + end +end From 4cce32776805f2b05a07749f831e1d4db46f8f27 Mon Sep 17 00:00:00 2001 From: Morton Jonuschat Date: Sun, 11 Apr 2010 12:49:52 +0200 Subject: [PATCH 006/992] html safe outputs --- lib/formtastic.rb | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/lib/formtastic.rb b/lib/formtastic.rb index a0c55cb2c..8a4a3026b 100644 --- a/lib/formtastic.rb +++ b/lib/formtastic.rb @@ -107,7 +107,7 @@ def input(method, options = {}) send(:"inline_#{type}_for", method, options) end.compact.join("\n") - return template.content_tag(:li, list_item_content, wrapper_html) + return template.content_tag(:li, list_item_content.to_s.html_safe, wrapper_html) end # Creates an input fieldset and ol tag wrapping for use around a set of inputs. It can be @@ -344,7 +344,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), :class => element_class) + template.content_tag(:li, self.submit(text, button_html).to_s.html_safe, :class => element_class) end # A thin wrapper around #fields_for to set :builder => Formtastic::SemanticFormBuilder @@ -408,7 +408,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, options) + super(input_name, text.to_s.html_safe, options) end # Generates error messages for the given method. Errors can be shown as list, @@ -454,7 +454,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) }.join + full_errors.map { |error| template.content_tag(:li, error.to_s.html_safe) }.join.to_s.html_safe end end @@ -861,12 +861,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}", + "#{self.radio_button(input_name, value, html_options)} #{label}".to_s.html_safe, :for => input_id ) li_options = value_as_class ? { :class => [method.to_s.singularize, value.to_s.downcase].join('_') } : {} - template.content_tag(:li, li_content, li_options) + template.content_tag(:li, li_content.to_s.html_safe, li_options) end field_set_and_list_wrapping_for_method(method, options, list_item_content) @@ -1016,9 +1016,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, :for => input_id) : "", + !item_label_text.blank? ? template.content_tag(:label, item_label_text.to_s.html_safe, :for => input_id) : "", template.send(:"select_#{input}", datetime, opts, html_options.merge(:id => input_id)) - ].join("") + ].join("").to_s.html_safe ) end end @@ -1127,12 +1127,12 @@ def check_boxes_input(method, options) html_options[:id] = input_id li_content = template.content_tag(:label, - "#{self.check_box(input_name, html_options, value, unchecked_value)} #{label}", + "#{self.check_box(input_name, html_options, value, unchecked_value)} #{label}".to_s.html_safe, :for => input_id ) li_options = value_as_class ? { :class => [method.to_s.singularize, value.to_s.downcase].join('_') } : {} - template.content_tag(:li, li_content, li_options) + template.content_tag(:li, li_content.to_s.html_safe, li_options) end field_set_and_list_wrapping_for_method(method, options, list_item_content) @@ -1197,13 +1197,13 @@ 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], :class => 'inline-hints') + template.content_tag(:p, options[:hint].to_s.html_safe, :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, :class => 'inline-errors') + template.content_tag(:p, errors.to_sentence.untaint.to_s.html_safe, :class => 'inline-errors') end # Creates an error li list. @@ -1211,15 +1211,15 @@ def error_sentence(errors) #:nodoc: def error_list(errors) #:nodoc: list_elements = [] errors.each do |error| - list_elements << template.content_tag(:li, error.untaint) + list_elements << template.content_tag(:li, error.untaint.to_s.html_safe) end - template.content_tag(:ul, list_elements.join("\n"), :class => 'errors') + template.content_tag(:ul, list_elements.join("\n").to_s.html_safe, :class => 'errors') end # Creates an error sentence containing only the first error # def error_first(errors) #:nodoc: - template.content_tag(:p, errors.first.untaint, :class => 'inline-errors') + template.content_tag(:p, errors.first.untaint.to_s.html_safe, :class => 'inline-errors') end # Generates the required or optional string. If the value set is a proc, @@ -1266,7 +1266,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)) unless legend.blank? + legend = template.content_tag(:legend, template.content_tag(:span, legend.to_s.html_safe)) unless legend.blank? if block_given? contents = if template.respond_to?(:is_haml?) && template.is_haml? @@ -1279,7 +1279,7 @@ 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 << template.content_tag(:ol, contents), + legend.to_s.html_safe << template.content_tag(:ol, contents.to_s.html_safe), html_options.except(:builder, :parent) ) @@ -1311,7 +1311,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) + template.content_tag(:ol, contents.to_s.html_safe) ) end From fcc5bae7a0efa853427722338576bb000a2c9ff2 Mon Sep 17 00:00:00 2001 From: Morton Jonuschat Date: Sun, 11 Apr 2010 14:59:19 +0200 Subject: [PATCH 007/992] Helpers like form_for are expected to return a String with rails3 --- lib/formtastic.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/formtastic.rb b/lib/formtastic.rb index 8a4a3026b..7a8b0cd90 100644 --- a/lib/formtastic.rb +++ b/lib/formtastic.rb @@ -1283,7 +1283,7 @@ def field_set_and_list_wrapping(*args, &block) #:nodoc: html_options.except(:builder, :parent) ) - template.concat(fieldset) if block_given? + template.concat(fieldset) if block_given? && (!defined?(Rails::VERSION) || Rails::VERSION::MAJOR == 2) fieldset end From 4053e09e7ede79fe3e273e4db117e84aee5ef66c Mon Sep 17 00:00:00 2001 From: Gabriel Sobrinho Date: Sun, 7 Mar 2010 11:20:52 -0300 Subject: [PATCH 008/992] Move deprecated rails/init.rb to init.rb --- init.rb | 6 ++++++ rails/init.rb | 5 ----- 2 files changed, 6 insertions(+), 5 deletions(-) create mode 100644 init.rb delete mode 100644 rails/init.rb diff --git a/init.rb b/init.rb new file mode 100644 index 000000000..cc5fbb21a --- /dev/null +++ b/init.rb @@ -0,0 +1,6 @@ +# coding: utf-8 +require 'formtastic' +require 'formtastic/layout_helper' + +ActionView::Base.send(:include, Formtastic::SemanticFormHelper) +ActionView::Base.send(:include, Formtastic::LayoutHelper) diff --git a/rails/init.rb b/rails/init.rb deleted file mode 100644 index 1db466496..000000000 --- a/rails/init.rb +++ /dev/null @@ -1,5 +0,0 @@ -# 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 From ab85b8deaaa710e135e2c74b2a19418eb94090b7 Mon Sep 17 00:00:00 2001 From: Gabriel Sobrinho Date: Sun, 7 Mar 2010 11:21:53 -0300 Subject: [PATCH 009/992] Create formtastic:form generator --- .../formtastic/form/form_generator.rb | 85 +++++++++++++++++++ .../formtastic/form/templates/_form.html.erb | 5 ++ .../formtastic/form/templates/_form.html.haml | 4 + 3 files changed, 94 insertions(+) create mode 100644 lib/generators/formtastic/form/form_generator.rb create mode 100644 lib/generators/formtastic/form/templates/_form.html.erb create mode 100644 lib/generators/formtastic/form/templates/_form.html.haml diff --git a/lib/generators/formtastic/form/form_generator.rb b/lib/generators/formtastic/form/form_generator.rb new file mode 100644 index 000000000..3dc74719c --- /dev/null +++ b/lib/generators/formtastic/form/form_generator.rb @@ -0,0 +1,85 @@ +# 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 diff --git a/lib/generators/formtastic/form/templates/_form.html.erb b/lib/generators/formtastic/form/templates/_form.html.erb new file mode 100644 index 000000000..5eb30bdc3 --- /dev/null +++ b/lib/generators/formtastic/form/templates/_form.html.erb @@ -0,0 +1,5 @@ +<%% f.inputs do %> +<% columns.each do |column| -%> + <%%= f.input :<%= column.name %>, :label => '<%= column.name.humanize %>' %> +<% end -%> +<%% end %> \ No newline at end of file diff --git a/lib/generators/formtastic/form/templates/_form.html.haml b/lib/generators/formtastic/form/templates/_form.html.haml new file mode 100644 index 000000000..85566ef97 --- /dev/null +++ b/lib/generators/formtastic/form/templates/_form.html.haml @@ -0,0 +1,4 @@ +- f.inputs do +<% columns.each do |column| -%> + = f.input :<%= column.name %>, :label => '<%= column.name.humanize %>' +<% end -%> \ No newline at end of file From b99169fabf571d1deaeda48ef8dd742c5d64aa1c Mon Sep 17 00:00:00 2001 From: Gabriel Sobrinho Date: Sun, 7 Mar 2010 11:30:56 -0300 Subject: [PATCH 010/992] Create formtastic:install generator --- .../formtastic/install/install_generator.rb | 23 +++ .../install/templates/formtastic.css | 144 ++++++++++++++++++ .../install/templates/formtastic.rb | 58 +++++++ .../install/templates/formtastic_changes.css | 10 ++ 4 files changed, 235 insertions(+) create mode 100644 lib/generators/formtastic/install/install_generator.rb create mode 100644 lib/generators/formtastic/install/templates/formtastic.css create mode 100644 lib/generators/formtastic/install/templates/formtastic.rb create mode 100644 lib/generators/formtastic/install/templates/formtastic_changes.css diff --git a/lib/generators/formtastic/install/install_generator.rb b/lib/generators/formtastic/install/install_generator.rb new file mode 100644 index 000000000..c199753e8 --- /dev/null +++ b/lib/generators/formtastic/install/install_generator.rb @@ -0,0 +1,23 @@ +# 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 diff --git a/lib/generators/formtastic/install/templates/formtastic.css b/lib/generators/formtastic/install/templates/formtastic.css new file mode 100644 index 000000000..a33cb022d --- /dev/null +++ b/lib/generators/formtastic/install/templates/formtastic.css @@ -0,0 +1,144 @@ +/* ------------------------------------------------------------------------------------------------- + +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; } diff --git a/lib/generators/formtastic/install/templates/formtastic.rb b/lib/generators/formtastic/install/templates/formtastic.rb new file mode 100644 index 000000000..5136db263 --- /dev/null +++ b/lib/generators/formtastic/install/templates/formtastic.rb @@ -0,0 +1,58 @@ +# 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 +# '*'. 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 @