formtastic 0.9.2 → 0.9.3
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +35 -4
- data/Rakefile +47 -22
- data/generators/formtastic/templates/formtastic.css +1 -0
- data/lib/formtastic/i18n.rb +27 -0
- data/lib/formtastic.rb +151 -81
- data/lib/locale/en.yml +2 -2
- data/spec/commit_button_spec.rb +5 -5
- data/spec/custom_builder_spec.rb +8 -8
- data/spec/custom_macros.rb +3 -3
- data/spec/errors_spec.rb +6 -6
- data/spec/form_helper_spec.rb +4 -4
- data/spec/i18n_spec.rb +83 -0
- data/spec/input_spec.rb +22 -21
- data/spec/inputs/check_boxes_input_spec.rb +3 -3
- data/spec/inputs/country_input_spec.rb +1 -1
- data/spec/inputs/date_input_spec.rb +2 -2
- data/spec/inputs/datetime_input_spec.rb +5 -5
- data/spec/inputs/hidden_input_spec.rb +13 -2
- data/spec/inputs/radio_input_spec.rb +3 -3
- data/spec/inputs/select_input_spec.rb +83 -4
- data/spec/inputs/time_input_spec.rb +2 -2
- data/spec/inputs_spec.rb +28 -16
- data/spec/label_spec.rb +0 -6
- data/spec/semantic_fields_for_spec.rb +1 -1
- data/spec/spec_helper.rb +4 -2
- metadata +58 -6
data/README.textile
CHANGED
@@ -148,7 +148,7 @@ If you want to customize the label text, or render some hint text below the fiel
|
|
148
148
|
|
149
149
|
<pre>
|
150
150
|
<% semantic_form_for @post do |form| %>
|
151
|
-
<% form.inputs
|
151
|
+
<% form.inputs "Basic", :id => "basic" do %>
|
152
152
|
<%= form.input :title %>
|
153
153
|
<%= form.input :body %>
|
154
154
|
<% end %>
|
@@ -324,11 +324,11 @@ Formtastic supports localized *labels*, *hints*, *legends*, *actions* using the
|
|
324
324
|
|
325
325
|
*4. Localized titles (a.k.a. legends):*
|
326
326
|
|
327
|
-
_Note: Slightly different because Formtastic can't guess how you group fields in a form._
|
327
|
+
_Note: Slightly different because Formtastic can't guess how you group fields in a form. Legend text can be set with first (as in the sample below) specified value, or :name/:title options - depending on what flavor is preferred._
|
328
328
|
|
329
329
|
<pre>
|
330
330
|
<% semantic_form_for @post do |form| %>
|
331
|
-
<% form.inputs :
|
331
|
+
<% form.inputs :post_details do %> # => :title => "Post details"
|
332
332
|
# ...
|
333
333
|
<% end %>
|
334
334
|
# ...
|
@@ -416,6 +416,38 @@ h2. Configuration
|
|
416
416
|
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
|
417
417
|
|
418
418
|
|
419
|
+
h2. Form Generator
|
420
|
+
|
421
|
+
There's a Formtastic form code generator to make your transition to Formtastic easier. All you have to do is to *specify an existing model name*, and optionally specify view template framework (ERB/HAML), and you are good to go. *Note:* This won't overwrite any of you stuff. This is how you use it:
|
422
|
+
|
423
|
+
*Alt. 1: Generate in terminal:*
|
424
|
+
|
425
|
+
<pre>
|
426
|
+
$ ./script/generate form Post
|
427
|
+
# ---------------------------------------------------------
|
428
|
+
# GENERATED FORMTASTIC CODE
|
429
|
+
# ---------------------------------------------------------
|
430
|
+
|
431
|
+
<% form.inputs do %>
|
432
|
+
<%= form.input :title, :label => 'Title' %>
|
433
|
+
<%= form.input :body, :label => 'Body' %>
|
434
|
+
<%= form.input :published, :label => 'Published' %>
|
435
|
+
<% end %>
|
436
|
+
|
437
|
+
# ---------------------------------------------------------
|
438
|
+
Copied to clipboard - just paste it!
|
439
|
+
</pre>
|
440
|
+
|
441
|
+
*Alt. 2: Generate partial:*
|
442
|
+
|
443
|
+
<pre>
|
444
|
+
$ ./script/generate form Post --partial
|
445
|
+
exists app/views/posts
|
446
|
+
create app/views/posts/_form.html.erb
|
447
|
+
</pre>
|
448
|
+
|
449
|
+
To generate *HAML* markup, just add the @--haml@ as argument: @./script/generate form Post --haml@
|
450
|
+
|
419
451
|
h2. Custom Inputs
|
420
452
|
|
421
453
|
If you want to add your own input types to encapsulate your own logic or interface patterns, you can do so by subclassing SemanticFormBuilder and configuring Formtastic to use your custom builder class.
|
@@ -441,7 +473,6 @@ h2. Compatibility
|
|
441
473
|
|
442
474
|
I'm only testing Formtastic with the latest Rails 2.4.x stable release, and it should be fine under Rails 2.3.x as well (including nested forms). Patches are welcome to allow backwards compatibility, but I don't have the energy!
|
443
475
|
|
444
|
-
|
445
476
|
h2. Got TextMate?
|
446
477
|
|
447
478
|
Well...there's a TextMate-bundle in town, dedicated to make usage of Formtastic in the "TextMate":http://macromates.com/ editor even more of a breeze:
|
data/Rakefile
CHANGED
@@ -2,8 +2,16 @@
|
|
2
2
|
require 'rake'
|
3
3
|
require 'rake/rdoctask'
|
4
4
|
|
5
|
-
|
6
|
-
require 'spec/rake/spectask'
|
5
|
+
begin
|
6
|
+
require 'spec/rake/spectask'
|
7
|
+
rescue LoadError
|
8
|
+
begin
|
9
|
+
gem 'rspec-rails', '>= 1.0.0'
|
10
|
+
require 'spec/rake/spectask'
|
11
|
+
rescue LoadError
|
12
|
+
puts "[formtastic:] RSpec - or one of it's dependencies - is not available. Install it with: sudo gem install rspec-rails"
|
13
|
+
end
|
14
|
+
end
|
7
15
|
|
8
16
|
begin
|
9
17
|
GEM = "formtastic"
|
@@ -14,11 +22,14 @@ begin
|
|
14
22
|
INSTALL_MESSAGE = %q{
|
15
23
|
========================================================================
|
16
24
|
Thanks for installing Formtastic!
|
17
|
-
------------------------------------------------------------------------
|
25
|
+
------------------------------------------------------------------------
|
18
26
|
You can now (optionally) run the generater to copy some stylesheets and
|
19
27
|
a config initializer into your application:
|
20
28
|
./script/generate formtastic
|
21
29
|
|
30
|
+
To generate some semantic form markup for your exisiting models, just run:
|
31
|
+
./script/generate form MODEL_NAME
|
32
|
+
|
22
33
|
Find out more and get involved:
|
23
34
|
http://github.com/justinfrench/formtastic
|
24
35
|
http://groups.google.com.au/group/formtastic
|
@@ -38,28 +49,28 @@ begin
|
|
38
49
|
s.post_install_message = INSTALL_MESSAGE
|
39
50
|
|
40
51
|
s.require_path = 'lib'
|
41
|
-
s.autorequire = GEM
|
42
52
|
s.files = %w(MIT-LICENSE README.textile Rakefile) + Dir.glob("{rails,lib,generators,spec}/**/*")
|
53
|
+
|
54
|
+
# Runtime dependencies: When installing Formtastic these will be checked if they are installed.
|
55
|
+
# Will be offered to install these if they are not already installed.
|
56
|
+
s.add_dependency 'activesupport', '>= 2.3.0'
|
57
|
+
s.add_dependency 'actionpack', '>= 2.3.0'
|
58
|
+
|
59
|
+
# Development dependencies. Not installed by default.
|
60
|
+
# Install with: sudo gem install formtastic --development
|
61
|
+
s.add_development_dependency 'rspec-rails', '>= 1.2.6'
|
62
|
+
s.add_development_dependency 'hpricot', '>= 0.6.1' # for: rspec_hpricot_matchers
|
63
|
+
s.add_development_dependency 'rspec_hpricot_matchers', '>= 1.0.0'
|
43
64
|
end
|
65
|
+
|
66
|
+
Jeweler::GemcutterTasks.new
|
44
67
|
rescue LoadError
|
45
|
-
puts "Jeweler
|
68
|
+
puts "[formtastic:] Jeweler - or one of it's dependencies - is not available. Install it with: sudo gem install jeweler -s http://gemcutter.org"
|
46
69
|
end
|
47
70
|
|
48
71
|
desc 'Default: run unit specs.'
|
49
72
|
task :default => :spec
|
50
73
|
|
51
|
-
desc 'Test the formtastic plugin.'
|
52
|
-
Spec::Rake::SpecTask.new('spec') do |t|
|
53
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
54
|
-
t.spec_opts = ["-c"]
|
55
|
-
end
|
56
|
-
|
57
|
-
desc 'Test the formtastic plugin with specdoc formatting and colors'
|
58
|
-
Spec::Rake::SpecTask.new('specdoc') do |t|
|
59
|
-
t.spec_files = FileList['spec/**/*_spec.rb']
|
60
|
-
t.spec_opts = ["--format specdoc", "-c"]
|
61
|
-
end
|
62
|
-
|
63
74
|
desc 'Generate documentation for the formtastic plugin.'
|
64
75
|
Rake::RDocTask.new(:rdoc) do |rdoc|
|
65
76
|
rdoc.rdoc_dir = 'rdoc'
|
@@ -69,9 +80,23 @@ Rake::RDocTask.new(:rdoc) do |rdoc|
|
|
69
80
|
rdoc.rdoc_files.include('lib/**/*.rb')
|
70
81
|
end
|
71
82
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
83
|
+
if defined?(Spec)
|
84
|
+
desc 'Test the formtastic plugin.'
|
85
|
+
Spec::Rake::SpecTask.new('spec') do |t|
|
86
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
87
|
+
t.spec_opts = ["-c"]
|
88
|
+
end
|
89
|
+
|
90
|
+
desc 'Test the formtastic plugin with specdoc formatting and colors'
|
91
|
+
Spec::Rake::SpecTask.new('specdoc') do |t|
|
92
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
93
|
+
t.spec_opts = ["--format specdoc", "-c"]
|
94
|
+
end
|
95
|
+
|
96
|
+
desc "Run all examples with RCov"
|
97
|
+
Spec::Rake::SpecTask.new('examples_with_rcov') do |t|
|
98
|
+
t.spec_files = FileList['spec/**/*_spec.rb']
|
99
|
+
t.rcov = true
|
100
|
+
t.rcov_opts = ['--exclude', 'spec,Library']
|
101
|
+
end
|
77
102
|
end
|
@@ -64,6 +64,7 @@ form.formtastic fieldset ol li li label input { line-height:100%; vertical-align
|
|
64
64
|
form.formtastic fieldset ol li fieldset { position:relative; }
|
65
65
|
form.formtastic fieldset ol li fieldset legend { position:absolute; width:25%; padding-top:0.1em; }
|
66
66
|
form.formtastic fieldset ol li fieldset legend span { position:absolute; }
|
67
|
+
form.formtastic fieldset ol li fieldset legend.label label { position:absolute; }
|
67
68
|
form.formtastic fieldset ol li fieldset ol { float:left; width:74%; margin:0; padding:0 0 0 25%; }
|
68
69
|
form.formtastic fieldset ol li fieldset ol li { padding:0; border:0; }
|
69
70
|
|
@@ -0,0 +1,27 @@
|
|
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
|
+
|
13
|
+
class << self
|
14
|
+
|
15
|
+
def translate(*args)
|
16
|
+
key = args.shift.to_sym
|
17
|
+
options = args.extract_options!
|
18
|
+
options.reverse_merge!(:default => DEFAULT_VALUES[key])
|
19
|
+
options[:scope] = [DEFAULT_SCOPE, options[:scope]].flatten.compact
|
20
|
+
::I18n.translate(key, *(args << options))
|
21
|
+
end
|
22
|
+
alias :t :translate
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
27
|
+
end
|