formtastic 0.2.5 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.textile CHANGED
@@ -79,32 +79,31 @@ RDoc documentation _should_ be automatically generated after each commit and mad
79
79
 
80
80
  h2. Installation
81
81
 
82
- You can and should get it as a gem:
82
+ The gem is hosted on gemcutter, so if you haven't already, add it as a gem source:
83
83
 
84
84
  <pre>
85
- gem install justinfrench-formtastic
85
+ sudo gem sources -a http://gemcutter.org/
86
86
  </pre>
87
87
 
88
- And then add it as a dependency in your environment.rb file:
88
+ Then install the Formtastic gem:q
89
89
 
90
90
  <pre>
91
- config.gem "justinfrench-formtastic",
92
- :lib => 'formtastic',
93
- :source => 'http://gems.github.com'
91
+ sudo gem install formtastic
94
92
  </pre>
95
93
 
96
- If you want, run the generator to copy the following files into your app:
94
+ Optionally, run @./script/generate formtastic@ to copy the following files into your app:
97
95
 
98
96
  * config/initializers/formtastic.rb (a commented out Formtastic config initializer)
99
97
  * public/stylesheets/formtastic.css
100
98
  * public/stylesheets/formtastic_changes.css
101
99
 
100
+ A proof-of-concept stylesheet is provided which you can include in your layout. Customization is best achieved by overriding these styles in an additional stylesheet so that the Formtastic styles can be updated without clobbering your changes. If you want to use these stylesheets, add both to your layout:
101
+
102
102
  <pre>
103
- ./script/generate formtastic
103
+ <%= stylesheet_link_tag "formtastic" %>
104
+ <%= stylesheet_link_tag "formtastic_changes" %>
104
105
  </pre>
105
106
 
106
- See also "What about Stylesheets?"
107
-
108
107
 
109
108
  h2. Usage
110
109
 
@@ -260,6 +259,7 @@ h2. Internationalization (I18n)
260
259
 
261
260
  Formtastic got some neat I18n-features. ActiveRecord object names and attributes are, by default, taken from calling @object.human_name and @object.human_attribute_name(attr) respectively. There are a few words specific to Formtastic that can be translated. See lib/locale/en.yml for more information.
262
261
 
262
+
263
263
  h3. Label/Hint-localization
264
264
 
265
265
  Formtastic supports localized *labels* and *hints* using the I18n API for more advanced usage. Your forms can now be DRYer and more flexible than ever, and still fully localized. This is how:
@@ -397,75 +397,20 @@ For more flexible forms; Formtastic find translations using a bottom-up approach
397
397
 
398
398
  *Note:* For @title@: ATTRIBUTE is a KEY chosen by you, e.g. in step 4 example above: @:post_details@.
399
399
 
400
+
400
401
  h2. ValidationReflection plugin
401
402
 
402
403
  If you have the "ValidationReflection":http://github.com/redinger/validation_reflection plugin installed, you won't have to specify the :required option (it checks the validations on the model instead).
403
404
 
404
- h2. Configuration
405
405
 
406
- If you wish, put something like this in config/initializers/formtastic_config.rb:
406
+ h2. Configuration
407
407
 
408
- <pre>
409
- # Set the default text field size when input is a string. Default is 50
410
- Formtastic::SemanticFormBuilder.default_text_field_size = 30
408
+ Run @./script/generate formtastic@ to copy a commented out config file into @config/initializers/formtastic.rb@. You can "view the configuration file on GitHub":http://github.com/justinfrench/formtastic/blob/master/generators/formtastic/templates/formtastic.rb
411
409
 
412
- # Should all fields be considered "required" by default
413
- # Defaults to true, see ValidationReflection notes below
414
- Formtastic::SemanticFormBuilder.all_fields_required_by_default = false
415
-
416
- # Set the string that will be appended to the labels/fieldsets which are required
417
- # It accepts string or procs and the default is a localized version of
418
- # '<abbr title="required">*</abbr>'. In other words, if you configure formtastic.required
419
- # in your locale, it will replace the abbr title properly. But if you don't want to use
420
- # abbr tag, you can simply give a string as below
421
- Formtastic::SemanticFormBuilder.required_string = "(required)"
422
-
423
- # Set the string that will be appended to the labels/fieldsets which are optional
424
- # Defaults to an empty string ("") and also accepts procs (see required_string above)
425
- Formtastic::SemanticFormBuilder.optional_string = "(optional)"
426
-
427
- # Set the way inline errors will be displayed.
428
- # Defaults to :sentence, valid options are :sentence, :list and :none
429
- Formtastic::SemanticFormBuilder.inline_errors = :list
430
-
431
- # Set the method to call on label text to transform or format it for human-friendly
432
- # reading when formtastic is user without object. Defaults to :humanize.
433
- Formtastic::SemanticFormBuilder.label_str_method = :titleize
434
-
435
- # Set the array of methods to try calling on parent objects in :select and :radio inputs
436
- # for the text inside each @<option>@ tag or alongside each radio @<input>@. The first method
437
- # that is found on the object will be used.
438
- # Defaults to ["to_label", "display_name", "full_name", "name", "title", "username", "login", "value", "to_s"]
439
- Formtastic::SemanticFormBuilder.collection_label_methods = ["title_and_author", "display_name", "login", "to_s"]
440
-
441
- # Formtastic by default renders inside li tags the input, hints and then
442
- # errors messages. Sometimes you want the hints to be rendered first than
443
- # the input, in the following order: hints, input and errors. You can
444
- # customize it doing just as below:
445
- Formtastic::SemanticFormBuilder.inline_order = [:hints, :input, :errors]
446
-
447
- # Set the default "priority countries" to suit your user base when using :as => :country
448
- Formtastic::SemanticFormBuilder.priority_countries = ["Australia", "New Zealand"]
449
-
450
- # Specifies if labels/hints for input fields automatically be looked up using I18n.
451
- # Default value: false. Overridden for specific fields by setting value to true,
452
- # i.e. :label => true, or :hint => true (or opposite depending on initialized value)
453
- # Formtastic::SemanticFormBuilder.i18n_lookups_by_default = false
454
-
455
- # If you want to subclass SemanticFormBuilder to add/change the behavior to suit your needs, you
456
- # can specify the builder class.
457
- # Formtastic::SemanticFormHelper.builder = MyCustomBuilder
458
- </pre>
459
410
 
460
411
  h2. Status
461
412
 
462
- *THINGS ARE GOING TO CHANGE A BIT BEFORE WE HIT 1.0.*
463
-
464
- It's a work in progress and a bit rough around the edges still, but I hope you try it and offer some suggestions and improvements anyway.
465
-
466
- On the plus side, it has a comprehensive spec suite and contributions from at least ten independent developers.
467
-
468
- "Wishlist":http://wiki.github.com/justinfrench/formtastic/wishlist on the wiki is serving as pretty good documentation for the roadmap to 1.0 and beyond right now, but I'll work on getting a real tracking system or something happening soon.
413
+ Formtastic has been in active development for about a year. We've just recently jumped to an 0.9 version number, signalling that we consider this a 1.0 release candidate, and that the API won't change significantly for the 1.x series.
469
414
 
470
415
 
471
416
  h2. Dependencies
@@ -482,30 +427,13 @@ h2. Compatibility
482
427
  I'm only testing Formtastic with the latest Rails 2.2.x stable release, and it should be fine under Rails 2.3 as well (including nested forms). Patches are welcome to allow backwards compatibility, but I don't have the energy!
483
428
 
484
429
 
485
-
486
- h2. What about Stylesheets?
487
-
488
- A proof-of-concept (very much a work-in-progress) stylesheet is provided which you can include in your layout. Customization is best achieved by overriding these styles in an additional stylesheet so that the Formtastic styles can be updated without clobbering your changes.
489
-
490
- 1. Use the generator to copy the formtastic.css and formtastic_changes.css into your public directory
491
-
492
- <pre>
493
- ./script/generate formtastic_stylesheets
494
- </pre>
495
-
496
- 2. Add both formtastic.css and formtastic_changes.css to your layout:
497
-
498
- <pre>
499
- <%= stylesheet_link_tag "formtastic" %>
500
- <%= stylesheet_link_tag "formtastic_changes" %>
501
- </pre>
502
-
503
430
  h2. Got TextMate?
504
431
 
505
432
  Well...there's a TextMate-bundle in town, dedicated to make usage of Formtastic in the TextMate editor even more of a breeze:
506
433
 
507
434
  "Formtastic.tmbundle":http://github.com/grimen/formtastic_tmbundle
508
435
 
436
+
509
437
  h2. Contributors
510
438
 
511
439
  Formtastic is maintained by "Justin French":http://justinfrench.com and "José Valim":http://github.com/josevalim, but it wouldn't be as awesome as it is today if it weren't for the wonderful contributions of these fine, fine coders.
data/Rakefile CHANGED
@@ -11,8 +11,31 @@ begin
11
11
  EMAIL = "justin@indent.com.au"
12
12
  SUMMARY = "A Rails form builder plugin/gem with semantically rich and accessible markup"
13
13
  HOMEPAGE = "http://github.com/justinfrench/formtastic/tree/master"
14
+ INSTALL_MESSAGE = %q{
15
+ ========================================================================
16
+
17
+ Thanks for installing Formtastic!
18
+
19
+ You can now (optionally) run the generater to copy some stylesheets and
20
+ a config initializer into your application:
21
+
22
+ ./script/generate formtastic
23
+
24
+ The following files will be added:
25
+
26
+ RAILS_ROOT/public/stylesheets/formtastic.css
27
+ RAILS_ROOT/public/stylesheets/formtastic_changes.css
28
+ RAILS_ROOT/config/initializers/formtastic.rb
29
+
30
+ Find out more and get involved:
31
+
32
+ http://github.com/justinfrench/formtastic
33
+ http://groups.google.com.au/group/formtastic
34
+
35
+ ========================================================================
36
+ }
14
37
 
15
- gem 'technicalpickles-jeweler', '>= 1.0.0'
38
+ gem 'jeweler', '>= 1.0.0'
16
39
  require 'jeweler'
17
40
 
18
41
  Jeweler::Tasks.new do |s|
@@ -22,6 +45,7 @@ begin
22
45
  s.homepage = HOMEPAGE
23
46
  s.description = SUMMARY
24
47
  s.author = AUTHOR
48
+ s.post_install_message = INSTALL_MESSAGE
25
49
 
26
50
  s.require_path = 'lib'
27
51
  s.autorequire = GEM
@@ -1,4 +1,4 @@
1
- class FormtasticConfigGenerator < Rails::Generator::Base
1
+ class FormtasticGenerator < Rails::Generator::Base
2
2
 
3
3
  def initialize(*runtime_args)
4
4
  super
@@ -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/lib/formtastic.rb CHANGED
@@ -87,6 +87,7 @@ module Formtastic #:nodoc:
87
87
 
88
88
  html_class = [ options[:as], (options[:required] ? :required : :optional) ]
89
89
  html_class << 'error' if @object && @object.respond_to?(:errors) && !@object.errors[method.to_sym].blank?
90
+ html_class << method.to_s
90
91
 
91
92
  wrapper_html = options.delete(:wrapper_html) || {}
92
93
  wrapper_html[:id] ||= generate_html_id(method)
@@ -986,6 +986,7 @@ describe 'Formtastic' do
986
986
  output_buffer.should have_tag("form li.string")
987
987
  output_buffer.should have_tag("form li.required")
988
988
  output_buffer.should have_tag("form li.another_class")
989
+ output_buffer.should have_tag("form li.title")
989
990
  end
990
991
 
991
992
  it 'should allow classes to be an array' do
@@ -995,6 +996,7 @@ describe 'Formtastic' do
995
996
  output_buffer.should have_tag("form li.string")
996
997
  output_buffer.should have_tag("form li.my_class")
997
998
  output_buffer.should have_tag("form li.another_class")
999
+ output_buffer.should have_tag("form li.title")
998
1000
  end
999
1001
  end
1000
1002
 
@@ -1005,6 +1007,7 @@ describe 'Formtastic' do
1005
1007
  end
1006
1008
  output_buffer.should have_tag("form li#post_title_input")
1007
1009
  output_buffer.should have_tag("form li.string")
1010
+ output_buffer.should have_tag("form li.title")
1008
1011
  end
1009
1012
  end
1010
1013
 
@@ -2697,6 +2700,12 @@ describe 'Formtastic' do
2697
2700
  end
2698
2701
 
2699
2702
  describe 'when a :for option is provided' do
2703
+
2704
+ before do
2705
+ @new_post.stub!(:respond_to?).and_return(true, true)
2706
+ @new_post.stub!(:author).and_return(@bob)
2707
+ end
2708
+
2700
2709
  it 'should render nested inputs' do
2701
2710
  @bob.stub!(:column_for_attribute).and_return(mock('column', :type => :string, :limit => 255))
2702
2711
 
@@ -2706,9 +2715,49 @@ describe 'Formtastic' do
2706
2715
  end
2707
2716
  end
2708
2717
 
2709
- output_buffer.should have_tag("form fieldset.inputs #post_author_login")
2718
+ output_buffer.should have_tag("form fieldset.inputs #post_author_attributes_login")
2710
2719
  output_buffer.should_not have_tag("form fieldset.inputs #author_login")
2720
+
2711
2721
  end
2722
+
2723
+ describe "as a symbol representing the association name" do
2724
+
2725
+ it 'should nest the inputs with an _attributes suffix on the association name' do
2726
+ semantic_form_for(@new_post) do |post|
2727
+ post.inputs :for => :author do |author|
2728
+ concat(author.input(:login))
2729
+ end
2730
+ end
2731
+ output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
2732
+ end
2733
+
2734
+ end
2735
+
2736
+ describe 'as an array containing the a symbole for the association name and the associated object' do
2737
+
2738
+ it 'should nest the inputs with an _attributes suffix on the association name' do
2739
+ semantic_form_for(@new_post) do |post|
2740
+ post.inputs :for => [:author, @new_post.author] do |author|
2741
+ concat(author.input(:login))
2742
+ end
2743
+ end
2744
+ output_buffer.should have_tag("form input[@name='post[author_attributes][login]']")
2745
+ end
2746
+
2747
+ end
2748
+
2749
+ describe 'as an associated object' do
2750
+
2751
+ it 'should not nest the inputs with an _attributes suffix' do
2752
+ semantic_form_for(@new_post) do |post|
2753
+ post.inputs :for => @new_post.author do |author|
2754
+ concat(author.input(:login))
2755
+ end
2756
+ end
2757
+ output_buffer.should have_tag("form input[@name='post[author][login]']")
2758
+ end
2759
+
2760
+ end
2712
2761
 
2713
2762
  it 'should raise an error if :for and block with no argument is given' do
2714
2763
  semantic_form_for(@new_post) do |builder|
@@ -2730,7 +2779,7 @@ describe 'Formtastic' do
2730
2779
  end
2731
2780
  end
2732
2781
 
2733
- output_buffer.should have_tag('form fieldset ol li #post_author_10_login')
2782
+ output_buffer.should have_tag('form fieldset ol li #post_author_attributes_10_login')
2734
2783
  end
2735
2784
 
2736
2785
  it 'should not add builder as a fieldset attribute tag' do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: formtastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin French
@@ -9,7 +9,7 @@ autorequire: formtastic
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-10-16 00:00:00 +11:00
12
+ date: 2009-10-21 00:00:00 +11:00
13
13
  default_executable:
14
14
  dependencies: []
15
15
 
@@ -33,6 +33,7 @@ files:
33
33
  - generators/formtastic/templates/formtastic.css
34
34
  - generators/formtastic/templates/formtastic.rb
35
35
  - generators/formtastic/templates/formtastic_changes.css
36
+ - generators/formtastic_stylesheets/formtastic_stylesheets_generator.rb
36
37
  - lib/formtastic.rb
37
38
  - lib/justin_french/formtastic.rb
38
39
  - lib/locale/en.yml
@@ -43,7 +44,7 @@ has_rdoc: true
43
44
  homepage: http://github.com/justinfrench/formtastic/tree/master
44
45
  licenses: []
45
46
 
46
- post_install_message:
47
+ post_install_message: "\n ========================================================================\n\n Thanks for installing Formtastic!\n \n You can now (optionally) run the generater to copy some stylesheets and\n a config initializer into your application:\n \n ./script/generate formtastic\n \n The following files will be added:\n \n RAILS_ROOT/public/stylesheets/formtastic.css\n RAILS_ROOT/public/stylesheets/formtastic_changes.css\n RAILS_ROOT/config/initializers/formtastic.rb\n \n Find out more and get involved:\n\n http://github.com/justinfrench/formtastic\n http://groups.google.com.au/group/formtastic\n \n ========================================================================\n "
47
48
  rdoc_options:
48
49
  - --charset=UTF-8
49
50
  require_paths: