techthumb-formtastic 1.rails3.sha

Sign up to get free protection for your applications and to get access to all the features.
Files changed (58) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.textile +584 -0
  3. data/Rakefile +127 -0
  4. data/generators/form/USAGE +16 -0
  5. data/generators/form/form_generator.rb +120 -0
  6. data/generators/form/templates/view__form.html.erb +5 -0
  7. data/generators/form/templates/view__form.html.haml +4 -0
  8. data/generators/formtastic/formtastic_generator.rb +24 -0
  9. data/generators/formtastic/templates/formtastic.css +131 -0
  10. data/generators/formtastic/templates/formtastic.rb +54 -0
  11. data/generators/formtastic/templates/formtastic_changes.css +14 -0
  12. data/generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb +16 -0
  13. data/init.rb +5 -0
  14. data/lib/formtastic/i18n.rb +35 -0
  15. data/lib/formtastic/layout_helper.rb +10 -0
  16. data/lib/formtastic/railtie.rb +12 -0
  17. data/lib/formtastic/util.rb +36 -0
  18. data/lib/formtastic.rb +1870 -0
  19. data/lib/generators/formtastic/form/form_generator.rb +86 -0
  20. data/lib/generators/formtastic/install/install_generator.rb +24 -0
  21. data/lib/locale/en.yml +8 -0
  22. data/rails/init.rb +2 -0
  23. data/spec/buttons_spec.rb +166 -0
  24. data/spec/commit_button_spec.rb +401 -0
  25. data/spec/custom_builder_spec.rb +98 -0
  26. data/spec/defaults_spec.rb +20 -0
  27. data/spec/error_proc_spec.rb +27 -0
  28. data/spec/errors_spec.rb +105 -0
  29. data/spec/form_helper_spec.rb +142 -0
  30. data/spec/helpers/layout_helper_spec.rb +21 -0
  31. data/spec/i18n_spec.rb +152 -0
  32. data/spec/include_blank_spec.rb +74 -0
  33. data/spec/input_spec.rb +786 -0
  34. data/spec/inputs/boolean_input_spec.rb +104 -0
  35. data/spec/inputs/check_boxes_input_spec.rb +426 -0
  36. data/spec/inputs/country_input_spec.rb +118 -0
  37. data/spec/inputs/date_input_spec.rb +168 -0
  38. data/spec/inputs/datetime_input_spec.rb +310 -0
  39. data/spec/inputs/file_input_spec.rb +34 -0
  40. data/spec/inputs/hidden_input_spec.rb +78 -0
  41. data/spec/inputs/numeric_input_spec.rb +44 -0
  42. data/spec/inputs/password_input_spec.rb +46 -0
  43. data/spec/inputs/radio_input_spec.rb +243 -0
  44. data/spec/inputs/select_input_spec.rb +546 -0
  45. data/spec/inputs/string_input_spec.rb +64 -0
  46. data/spec/inputs/text_input_spec.rb +34 -0
  47. data/spec/inputs/time_input_spec.rb +206 -0
  48. data/spec/inputs/time_zone_input_spec.rb +110 -0
  49. data/spec/inputs_spec.rb +476 -0
  50. data/spec/label_spec.rb +89 -0
  51. data/spec/semantic_errors_spec.rb +98 -0
  52. data/spec/semantic_fields_for_spec.rb +45 -0
  53. data/spec/spec.opts +2 -0
  54. data/spec/spec_helper.rb +289 -0
  55. data/spec/support/custom_macros.rb +494 -0
  56. data/spec/support/output_buffer.rb +4 -0
  57. data/spec/support/test_environment.rb +45 -0
  58. metadata +235 -0
data/Rakefile ADDED
@@ -0,0 +1,127 @@
1
+ # coding: utf-8
2
+ require 'rubygems'
3
+ require 'rake'
4
+ require 'rake/rdoctask'
5
+
6
+ begin
7
+ gem 'rspec', '>= 1.2.6'
8
+ gem 'rspec-rails', '>= 1.2.6'
9
+ require 'spec'
10
+ require 'spec/rake/spectask'
11
+ rescue LoadError
12
+ begin
13
+ require 'rspec/core/rake_task.rb'
14
+ require 'rspec/core/version'
15
+ rescue LoadError
16
+ puts "[formtastic:] RSpec - or one of it's dependencies - is not available. Install it with: sudo gem install rspec-rails"
17
+ end
18
+ end
19
+
20
+ begin
21
+ GEM = "formtastic"
22
+ AUTHOR = "Justin French"
23
+ EMAIL = "justin@indent.com.au"
24
+ SUMMARY = "A Rails form builder plugin/gem with semantically rich and accessible markup"
25
+ HOMEPAGE = "http://github.com/justinfrench/formtastic/tree/master"
26
+ INSTALL_MESSAGE = %q{
27
+ ========================================================================
28
+ Thanks for installing Formtastic!
29
+ ------------------------------------------------------------------------
30
+ You can now (optionally) run the generator to copy some stylesheets and
31
+ a config initializer into your application:
32
+ rails generator formastic:install # Rails 3
33
+ ./script/generate formtastic # Rails 2
34
+
35
+ To generate some semantic form markup for your existing models, just run:
36
+ rails generate formtastic:form MODEL_NAME # Rails 3
37
+ ./script/generate form MODEL_NAME # Rails 2
38
+
39
+ Find out more and get involved:
40
+ http://github.com/justinfrench/formtastic
41
+ http://groups.google.com.au/group/formtastic
42
+ ========================================================================
43
+ }
44
+
45
+ gem 'jeweler', '>= 1.0.0'
46
+ require 'jeweler'
47
+
48
+ Jeweler::Tasks.new do |s|
49
+ s.name = GEM
50
+ s.summary = SUMMARY
51
+ s.email = EMAIL
52
+ s.homepage = HOMEPAGE
53
+ s.description = SUMMARY
54
+ s.author = AUTHOR
55
+ s.post_install_message = INSTALL_MESSAGE
56
+
57
+ s.require_path = 'lib'
58
+ s.files = %w(MIT-LICENSE README.textile Rakefile init.rb) + Dir.glob("{rails,lib,generators,spec}/**/*")
59
+
60
+ # Runtime dependencies: When installing Formtastic these will be checked if they are installed.
61
+ # Will be offered to install these if they are not already installed.
62
+ s.add_dependency 'activesupport', '>= 2.3.0'
63
+ s.add_dependency 'actionpack', '>= 2.3.0'
64
+ s.add_dependency 'i18n', '>= 0.4.0'
65
+
66
+ # Development dependencies. Not installed by default.
67
+ # Install with: sudo gem install formtastic --development
68
+ s.add_development_dependency 'rspec-rails', '>= 1.2.6'
69
+ s.add_development_dependency 'rspec_tag_matchers', '>= 1.0.0'
70
+ end
71
+
72
+ Jeweler::GemcutterTasks.new
73
+ rescue LoadError
74
+ puts "[formtastic:] Jeweler - or one of its dependencies - is not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
75
+ end
76
+
77
+ desc 'Default: run unit specs.'
78
+ task :default => :spec
79
+
80
+ desc 'Generate documentation for the formtastic plugin.'
81
+ Rake::RDocTask.new(:rdoc) do |rdoc|
82
+ rdoc.rdoc_dir = 'rdoc'
83
+ rdoc.title = 'Formtastic'
84
+ rdoc.options << '--line-numbers' << '--inline-source'
85
+ rdoc.rdoc_files.include('README.textile')
86
+ rdoc.rdoc_files.include('lib/**/*.rb')
87
+ end
88
+
89
+ if defined?(Spec)
90
+ desc 'Test the formtastic plugin.'
91
+ Spec::Rake::SpecTask.new('spec') do |t|
92
+ t.spec_files = FileList['spec/**/*_spec.rb']
93
+ t.spec_opts = ["-c"]
94
+ end
95
+
96
+ desc 'Test the formtastic plugin with specdoc formatting and colors'
97
+ Spec::Rake::SpecTask.new('specdoc') do |t|
98
+ t.spec_files = FileList['spec/**/*_spec.rb']
99
+ t.spec_opts = ["--format specdoc", "-c"]
100
+ end
101
+
102
+ desc "Run all examples with RCov"
103
+ Spec::Rake::SpecTask.new('examples_with_rcov') do |t|
104
+ t.spec_files = FileList['spec/**/*_spec.rb']
105
+ t.rcov = true
106
+ t.rcov_opts = ['--exclude', 'spec,Library']
107
+ end
108
+ end
109
+
110
+ if defined?(RSpec)
111
+ desc 'Test the formtastic plugin.'
112
+ RSpec::Core::RakeTask.new('spec') do |t|
113
+ t.pattern = FileList['spec/**/*_spec.rb']
114
+ end
115
+
116
+ desc 'Test the formtastic plugin with specdoc formatting and colors'
117
+ RSpec::Core::RakeTask.new('specdoc') do |t|
118
+ t.pattern = FileList['spec/**/*_spec.rb']
119
+ end
120
+
121
+ desc "Run all examples with RCov"
122
+ RSpec::Core::RakeTask.new('examples_with_rcov') do |t|
123
+ t.pattern = FileList['spec/**/*_spec.rb']
124
+ t.rcov = true
125
+ t.rcov_opts = ['--exclude', 'spec,Library']
126
+ end
127
+ end
@@ -0,0 +1,16 @@
1
+ NAME
2
+ form - Formtastic form generator.
3
+
4
+ DESCRIPTION
5
+ 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.
6
+
7
+ Required:
8
+ ExistingModelName - The name of an existing model for which the generator should generate form code.
9
+
10
+ Options:
11
+ --haml Generate HAML instead of ERB.
12
+ --partial Generate a form partial in the model views path, i.e. "_form.html.erb" or _form.html.haml".
13
+ --controller PATH Generate for custom controller/view path - in case model and controller namespace is different, i.e. "admin/posts".
14
+
15
+ EXAMPLE
16
+ ./script/generate form ExistingModelName [--haml] [--partial]
@@ -0,0 +1,120 @@
1
+ # coding: utf-8
2
+ # Get current OS - needed for clipboard functionality
3
+ case RUBY_PLATFORM
4
+ when /darwin/ then
5
+ CURRENT_OS = :osx
6
+ when /win32/
7
+ CURRENT_OS = :win
8
+ begin
9
+ require 'win32/clipboard'
10
+ rescue LoadError
11
+ # Do nothing
12
+ end
13
+ else
14
+ CURRENT_OS = :x
15
+ end
16
+
17
+ class FormGenerator < Rails::Generator::NamedBase
18
+
19
+ default_options :haml => false,
20
+ :partial => false
21
+
22
+ VIEWS_PATH = File.join('app', 'views').freeze
23
+ IGNORED_COLUMNS = [:updated_at, :created_at].freeze
24
+
25
+ attr_reader :controller_file_name,
26
+ :controller_class_path,
27
+ :controller_class_nesting,
28
+ :controller_class_nesting_depth,
29
+ :controller_class_name,
30
+ :template_type
31
+
32
+ def initialize(runtime_args, runtime_options = {})
33
+ super
34
+ base_name, @controller_class_path = extract_modules(@name.pluralize)
35
+ controller_class_name_without_nesting, @controller_file_name = inflect_names(base_name)
36
+ @template_type = options[:haml] ? :haml : :erb
37
+ end
38
+
39
+ def manifest
40
+ record do |m|
41
+ if options[:partial]
42
+ controller_and_view_path = options[:controller] || File.join(controller_class_path, controller_file_name)
43
+ # Ensure directory exists.
44
+ m.directory File.join(VIEWS_PATH, controller_and_view_path)
45
+ # Create a form partial for the model as "_form" in it's views path.
46
+ m.template "view__form.html.#{template_type}", File.join(VIEWS_PATH, controller_and_view_path, "_form.html.#{template_type}")
47
+ else
48
+ # Load template file, and render without saving to file
49
+ template = File.read(File.join(source_root, "view__form.html.#{template_type}"))
50
+ erb = ERB.new(template, nil, '-')
51
+ generated_code = erb.result(binding).strip rescue nil
52
+
53
+ # Print the result, and copy to clipboard
54
+ puts "# ---------------------------------------------------------"
55
+ puts "# GENERATED FORMTASTIC CODE"
56
+ puts "# ---------------------------------------------------------"
57
+ puts
58
+ puts generated_code || " Nothing could be generated - model exists?"
59
+ puts
60
+ puts "# ---------------------------------------------------------"
61
+ puts " Copied to clipboard - just paste it!" if save_to_clipboard(generated_code)
62
+ end
63
+ end
64
+ end
65
+
66
+ protected
67
+
68
+ # Save to lipboard with multiple OS support.
69
+ def save_to_clipboard(data)
70
+ return unless data
71
+ begin
72
+ case CURRENT_OS
73
+ when :osx
74
+ `echo "#{data}" | pbcopy`
75
+ when :win
76
+ ::Win32::Clipboard.data = data
77
+ else # :linux/:unix
78
+ `echo "#{data}" | xsel --clipboard` || `echo "#{data}" | xclip`
79
+ end
80
+ rescue
81
+ false
82
+ else
83
+ true
84
+ end
85
+ end
86
+
87
+ # Add additional model attributes if specified in args - probably not that common scenario.
88
+ def attributes
89
+ # Get columns for the requested model.
90
+ existing_attributes = @class_name.constantize.content_columns.reject { |column| IGNORED_COLUMNS.include?(column.name.to_sym) }
91
+ @args = super + existing_attributes
92
+ end
93
+
94
+ def add_options!(opt)
95
+ opt.separator ''
96
+ opt.separator 'Options:'
97
+
98
+ # Allow option to generate HAML views instead of ERB.
99
+ opt.on('--haml',
100
+ "Generate HAML output instead of the default ERB.") do |v|
101
+ options[:haml] = v
102
+ end
103
+
104
+ # Allow option to generate to partial in model's views path, instead of printing out in terminal.
105
+ opt.on('--partial',
106
+ "Save generated output directly to a form partial (app/views/{resource}/_form.html.*).") do |v|
107
+ options[:partial] = v
108
+ end
109
+
110
+ opt.on('--controller CONTROLLER_PATH',
111
+ "Specify a non-standard controller for the specified model (e.g. admin/posts).") do |v|
112
+ options[:controller] = v if v.present?
113
+ end
114
+ end
115
+
116
+ def banner
117
+ "Usage: #{$0} form ExistingModelName [--haml] [--partial]"
118
+ end
119
+
120
+ end
@@ -0,0 +1,5 @@
1
+ <%% f.inputs do %>
2
+ <% attributes.each do |attribute| -%>
3
+ <%%= f.input :<%= attribute.name %>, :label => '<%= attribute.name.humanize %>' %>
4
+ <% end -%>
5
+ <%% end %>
@@ -0,0 +1,4 @@
1
+ - f.inputs do
2
+ <% attributes.each do |attribute| -%>
3
+ = f.input :<%= attribute.name %>, :label => '<%= attribute.name.humanize %>'
4
+ <% end -%>
@@ -0,0 +1,24 @@
1
+ class FormtasticGenerator < Rails::Generator::Base
2
+
3
+ def initialize(*runtime_args)
4
+ super
5
+ end
6
+
7
+ def manifest
8
+ record do |m|
9
+ m.directory File.join('config', 'initializers')
10
+ m.template 'formtastic.rb', File.join('config', 'initializers', 'formtastic.rb')
11
+
12
+ m.directory File.join('public', 'stylesheets')
13
+ m.template 'formtastic.css', File.join('public', 'stylesheets', 'formtastic.css')
14
+ m.template 'formtastic_changes.css', File.join('public', 'stylesheets', 'formtastic_changes.css')
15
+ end
16
+ end
17
+
18
+ protected
19
+
20
+ def banner
21
+ %{Usage: #{$0} #{spec.name}\nCopies formtastic.css and formtastic_changes.css to public/stylesheets/ and a config initializer to config/initializers/formtastic.rb}
22
+ end
23
+
24
+ end
@@ -0,0 +1,131 @@
1
+ /* -------------------------------------------------------------------------------------------------
2
+
3
+ It's *strongly* suggested that you don't modify this file. Instead, load a new stylesheet after
4
+ this one in your layouts (eg formtastic_changes.css) and override the styles to suit your needs.
5
+ This will allow you to update formtastic.css with new releases without clobbering your own changes.
6
+
7
+ This stylesheet forms part of the Formtastic Rails Plugin
8
+ (c) 2008 Justin French
9
+
10
+ --------------------------------------------------------------------------------------------------*/
11
+
12
+
13
+ /* NORMALIZE AND RESET - obviously inspired by Yahoo's reset.css, but scoped to just form.formtastic
14
+ --------------------------------------------------------------------------------------------------*/
15
+ 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; }
16
+ form.formtastic fieldset { border:0; }
17
+ form.formtastic em, form.formtastic strong { font-style:normal; font-weight:normal; }
18
+ form.formtastic ol, form.formtastic ul { list-style:none; }
19
+ form.formtastic abbr, form.formtastic acronym { border:0; font-variant:normal; }
20
+ form.formtastic input, form.formtastic textarea, form.formtastic select { font-family:inherit; font-size:inherit; font-weight:inherit; }
21
+ form.formtastic input, form.formtastic textarea, form.formtastic select { font-size:100%; }
22
+ form.formtastic legend { white-space:normal; color:#000; }
23
+
24
+
25
+ /* SEMANTIC ERRORS
26
+ --------------------------------------------------------------------------------------------------*/
27
+ form.formtastic ul.errors { color:#cc0000; margin:0.5em 0 1.5em 25%; list-style:square; }
28
+ form.formtastic ul.errors li { padding:0; border:none; display:list-item; }
29
+
30
+
31
+ /* FIELDSETS & LISTS
32
+ --------------------------------------------------------------------------------------------------*/
33
+ form.formtastic fieldset { overflow:auto; } /* clearing contained floats */
34
+ form.formtastic fieldset.inputs { }
35
+ form.formtastic fieldset.buttons { padding-left:25%; }
36
+ form.formtastic fieldset ol { }
37
+ form.formtastic fieldset.buttons li { float:left; padding-right:0.5em; }
38
+
39
+ /* INPUT LIs
40
+ --------------------------------------------------------------------------------------------------*/
41
+ form.formtastic fieldset > ol > li { margin-bottom:1.5em; }
42
+ form.formtastic fieldset > ol > li { overflow:auto; } /* clearing contained floats */
43
+
44
+ form.formtastic fieldset > ol > li.required { }
45
+ form.formtastic fieldset > ol > li.optional { }
46
+ form.formtastic fieldset > ol > li.error { }
47
+
48
+
49
+ /* LABELS
50
+ --------------------------------------------------------------------------------------------------*/
51
+ form.formtastic fieldset > ol > li label { display:block; width:25%; float:left; padding-top:.2em; }
52
+ form.formtastic fieldset > ol > li > li label { line-height:100%; padding-top:0; }
53
+ form.formtastic fieldset > ol > li > li label input { line-height:100%; vertical-align:middle; margin-top:-0.1em;}
54
+
55
+
56
+ /* NESTED FIELDSETS AND LEGENDS (radio, check boxes and date/time inputs use nested fieldsets)
57
+ --------------------------------------------------------------------------------------------------*/
58
+ form.formtastic fieldset > ol > li fieldset { position:relative; }
59
+ form.formtastic fieldset > ol > li fieldset legend { position:absolute; width:95%; padding-top:0.1em; left: 0px; }
60
+ form.formtastic fieldset > ol > li fieldset legend span { position:absolute; }
61
+ form.formtastic fieldset > ol > li fieldset legend.label label { position:absolute; }
62
+ form.formtastic fieldset > ol > li fieldset ol { float:left; width:74%; margin:0; padding:0 0 0 25%; }
63
+ form.formtastic fieldset > ol > li fieldset ol li { padding:0; border:0; }
64
+
65
+
66
+ /* INLINE HINTS
67
+ --------------------------------------------------------------------------------------------------*/
68
+ form.formtastic fieldset > ol > li p.inline-hints { color:#666; margin:0.5em 0 0 25%; }
69
+
70
+
71
+ /* INLINE ERRORS
72
+ --------------------------------------------------------------------------------------------------*/
73
+ form.formtastic fieldset > ol > li p.inline-errors { color:#cc0000; margin:0.5em 0 0 25%; }
74
+ form.formtastic fieldset > ol > li ul.errors { color:#cc0000; margin:0.5em 0 0 25%; list-style:square; }
75
+ form.formtastic fieldset > ol > li ul.errors li { padding:0; border:none; display:list-item; }
76
+
77
+
78
+ /* STRING & NUMERIC OVERRIDES
79
+ --------------------------------------------------------------------------------------------------*/
80
+ form.formtastic fieldset > ol > li.string input { max-width:74%; }
81
+ form.formtastic fieldset > ol > li.password input { max-width: 13em; }
82
+ form.formtastic fieldset > ol > li.numeric input { max-width:74%; }
83
+
84
+
85
+ /* TEXTAREA OVERRIDES
86
+ --------------------------------------------------------------------------------------------------*/
87
+ form.formtastic fieldset > ol > li.text textarea { width:74%; }
88
+
89
+
90
+ /* HIDDEN OVERRIDES
91
+ --------------------------------------------------------------------------------------------------*/
92
+ form.formtastic fieldset ol li.hidden { display:none; }
93
+
94
+ /* BOOLEAN OVERRIDES
95
+ --------------------------------------------------------------------------------------------------*/
96
+ form.formtastic fieldset > ol > li.boolean label { padding-left:25%; width:auto; }
97
+ form.formtastic fieldset > ol > li.boolean label input { margin:0 0.5em 0 0.2em; }
98
+
99
+
100
+ /* RADIO OVERRIDES
101
+ --------------------------------------------------------------------------------------------------*/
102
+ form.formtastic fieldset > ol > li.radio { }
103
+ form.formtastic fieldset > ol > li.radio fieldset ol { margin-bottom:-0.6em; }
104
+ form.formtastic fieldset > ol > li.radio fieldset ol li { margin:0.1em 0 0.5em 0; }
105
+ form.formtastic fieldset > ol > li.radio fieldset ol li label { float:none; width:100%; }
106
+ form.formtastic fieldset > ol > li.radio fieldset ol li label input { margin-right:0.2em; }
107
+
108
+
109
+ /* CHECK BOXES (COLLECTION) OVERRIDES
110
+ --------------------------------------------------------------------------------------------------*/
111
+ form.formtastic fieldset > ol > li.check_boxes { }
112
+ form.formtastic fieldset > ol > li.check_boxes fieldset ol { margin-bottom:-0.6em; }
113
+ form.formtastic fieldset > ol > li.check_boxes fieldset ol li { margin:0.1em 0 0.5em 0; }
114
+ form.formtastic fieldset > ol > li.check_boxes fieldset ol li label { float:none; width:100%; }
115
+ form.formtastic fieldset > ol > li.check_boxes fieldset ol li label input { margin-right:0.2em; }
116
+
117
+
118
+
119
+ /* DATE & TIME OVERRIDES
120
+ --------------------------------------------------------------------------------------------------*/
121
+ form.formtastic fieldset > ol > li.date fieldset ol li,
122
+ form.formtastic fieldset > ol > li.time fieldset ol li,
123
+ form.formtastic fieldset > ol > li.datetime fieldset ol li { float:left; width:auto; margin:0 .3em 0 0; }
124
+
125
+ form.formtastic fieldset > ol > li.date fieldset ol li label,
126
+ form.formtastic fieldset > ol > li.time fieldset ol li label,
127
+ form.formtastic fieldset > ol > li.datetime fieldset ol li label { display:none; }
128
+
129
+ form.formtastic fieldset > ol > li.date fieldset ol li label input,
130
+ form.formtastic fieldset > ol > li.time fieldset ol li label input,
131
+ form.formtastic fieldset > ol > li.datetime fieldset ol li label input { display:inline; margin:0; padding:0; }
@@ -0,0 +1,54 @@
1
+ # Set the default text field size when input is a string. Default is 50.
2
+ # Formtastic::SemanticFormBuilder.default_text_field_size = 50
3
+
4
+ # Set the default text area height when input is a text. Default is 20.
5
+ # Formtastic::SemanticFormBuilder.default_text_area_height = 5
6
+
7
+ # Should all fields be considered "required" by default?
8
+ # Defaults to true, see ValidationReflection notes below.
9
+ # Formtastic::SemanticFormBuilder.all_fields_required_by_default = true
10
+
11
+ # Should select fields have a blank option/prompt by default?
12
+ # Defaults to true.
13
+ # Formtastic::SemanticFormBuilder.include_blank_for_select_by_default = true
14
+
15
+ # Set the string that will be appended to the labels/fieldsets which are required
16
+ # It accepts string or procs and the default is a localized version of
17
+ # '<abbr title="required">*</abbr>'. In other words, if you configure formtastic.required
18
+ # in your locale, it will replace the abbr title properly. But if you don't want to use
19
+ # abbr tag, you can simply give a string as below
20
+ # Formtastic::SemanticFormBuilder.required_string = "(required)"
21
+
22
+ # Set the string that will be appended to the labels/fieldsets which are optional
23
+ # Defaults to an empty string ("") and also accepts procs (see required_string above)
24
+ # Formtastic::SemanticFormBuilder.optional_string = "(optional)"
25
+
26
+ # Set the way inline errors will be displayed.
27
+ # Defaults to :sentence, valid options are :sentence, :list and :none
28
+ # Formtastic::SemanticFormBuilder.inline_errors = :sentence
29
+
30
+ # Set the method to call on label text to transform or format it for human-friendly
31
+ # reading when formtastic is used without object. Defaults to :humanize.
32
+ # Formtastic::SemanticFormBuilder.label_str_method = :humanize
33
+
34
+ # Set the array of methods to try calling on parent objects in :select and :radio inputs
35
+ # for the text inside each @<option>@ tag or alongside each radio @<input>@. The first method
36
+ # that is found on the object will be used.
37
+ # Defaults to ["to_label", "display_name", "full_name", "name", "title", "username", "login", "value", "to_s"]
38
+ # Formtastic::SemanticFormBuilder.collection_label_methods = [
39
+ # "to_label", "display_name", "full_name", "name", "title", "username", "login", "value", "to_s"]
40
+
41
+ # Formtastic by default renders inside li tags the input, hints and then
42
+ # errors messages. Sometimes you want the hints to be rendered first than
43
+ # the input, in the following order: hints, input and errors. You can
44
+ # customize it doing just as below:
45
+ # Formtastic::SemanticFormBuilder.inline_order = [:input, :hints, :errors]
46
+
47
+ # Specifies if labels/hints for input fields automatically be looked up using I18n.
48
+ # Default value: false. Overridden for specific fields by setting value to true,
49
+ # i.e. :label => true, or :hint => true (or opposite depending on initialized value)
50
+ # Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
51
+
52
+ # You can add custom inputs or override parts of Formtastic by subclassing SemanticFormBuilder and
53
+ # specifying that class here. Defaults to SemanticFormBuilder.
54
+ # Formtastic::SemanticFormHelper.builder = MyCustomBuilder
@@ -0,0 +1,14 @@
1
+ /* -------------------------------------------------------------------------------------------------
2
+
3
+ Load this stylesheet after formtastic.css in your layouts to override the CSS to suit your needs.
4
+ This will allow you to update formtastic.css with new releases without clobbering your own changes.
5
+
6
+ For example, to make the inline hint paragraphs a little darker in color than the standard #666:
7
+
8
+ form.formtastic fieldset > ol > li p.inline-hints { color:#333; }
9
+
10
+ HINT:
11
+ The following style may be *conditionally* included for improved support on older versions of IE(<8)
12
+ form.formtastic fieldset ol li fieldset legend { margin-left: -6px;}
13
+
14
+ --------------------------------------------------------------------------------------------------*/
@@ -0,0 +1,16 @@
1
+ class FormtasticStylesheetsGenerator < Rails::Generator::Base
2
+
3
+ def initialize(*runtime_args)
4
+ puts %q{
5
+ ===================================================
6
+ Please run `./script/generate formtastic` instead.
7
+ ===================================================
8
+ }
9
+ end
10
+
11
+ def manifest
12
+ record do |m|
13
+ end
14
+ end
15
+
16
+ end
data/init.rb ADDED
@@ -0,0 +1,5 @@
1
+ # coding: utf-8
2
+ require 'formtastic'
3
+ require 'formtastic/layout_helper'
4
+ ActionView::Base.send :include, Formtastic::SemanticFormHelper
5
+ ActionView::Base.send :include, Formtastic::LayoutHelper
@@ -0,0 +1,35 @@
1
+ module Formtastic
2
+ module I18n
3
+
4
+ DEFAULT_SCOPE = [:formtastic].freeze
5
+ DEFAULT_VALUES = {
6
+ :required => 'required',
7
+ :yes => 'Yes',
8
+ :no => 'No',
9
+ :create => 'Create %{model}',
10
+ :update => 'Update %{model}'
11
+ }.freeze
12
+ SCOPES = [
13
+ '%{model}.%{nested_model}.%{action}.%{attribute}',
14
+ '%{model}.%{action}.%{attribute}',
15
+ '%{model}.%{nested_model}.%{attribute}',
16
+ '%{model}.%{attribute}',
17
+ '%{nested_model}.%{attribute}',
18
+ '%{attribute}'
19
+ ]
20
+
21
+ class << self
22
+
23
+ def translate(*args)
24
+ key = args.shift.to_sym
25
+ options = args.extract_options!
26
+ options.reverse_merge!(:default => DEFAULT_VALUES[key])
27
+ options[:scope] = [DEFAULT_SCOPE, options[:scope]].flatten.compact
28
+ ::I18n.translate(key, *(args << options))
29
+ end
30
+ alias :t :translate
31
+
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,10 @@
1
+ module Formtastic
2
+ module LayoutHelper
3
+
4
+ def formtastic_stylesheet_link_tag
5
+ stylesheet_link_tag("formtastic") +
6
+ stylesheet_link_tag("formtastic_changes")
7
+ end
8
+
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ require 'formtastic'
2
+ require 'formtastic/layout_helper'
3
+ require 'rails'
4
+
5
+ module Formtastic
6
+ class Railtie < Rails::Railtie
7
+ initializer 'formtastic.initialize', :after => :after_initialize do
8
+ ActionView::Base.send :include, Formtastic::SemanticFormHelper
9
+ ActionView::Base.send(:include, Formtastic::LayoutHelper)
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,36 @@
1
+ # Adapted from the rails3 compatibility shim in Haml 2.2
2
+ module Formtastic
3
+ module Util
4
+ extend self
5
+ ## Rails XSS Safety
6
+
7
+ # Returns the given text, marked as being HTML-safe.
8
+ # With older versions of the Rails XSS-safety mechanism,
9
+ # this destructively modifies the HTML-safety of `text`.
10
+ #
11
+ # @param text [String]
12
+ # @return [String] `text`, marked as HTML-safe
13
+ def html_safe(text)
14
+ return text if text.nil?
15
+ return text.html_safe if defined?(ActiveSupport::SafeBuffer)
16
+ return text.html_safe! if text.respond_to?(:html_safe!)
17
+ text
18
+ end
19
+
20
+ def rails_safe_buffer_class
21
+ # It's important that we check ActiveSupport first,
22
+ # because in Rails 2.3.6 ActionView::SafeBuffer exists
23
+ # but is a deprecated proxy object.
24
+ return ActiveSupport::SafeBuffer if defined?(ActiveSupport::SafeBuffer)
25
+ return ActionView::SafeBuffer
26
+ end
27
+
28
+ def rails3?
29
+ version=
30
+ if defined?(ActionPack::VERSION::MAJOR)
31
+ ActionPack::VERSION::MAJOR
32
+ end
33
+ !version.blank? && version >= 3
34
+ end
35
+ end
36
+ end