Commit 60f50df74f43ce91202200e9f3a4fd00993f3853
1 parent
391a7b8b
Exists in
master
and in
1 other branch
added SemiFormal
Showing
9 changed files
with
166 additions
and
0 deletions
Show diff stats
... | ... | @@ -0,0 +1,20 @@ |
1 | +Copyright (c) 2009 [name of plugin creator] | |
2 | + | |
3 | +Permission is hereby granted, free of charge, to any person obtaining | |
4 | +a copy of this software and associated documentation files (the | |
5 | +"Software"), to deal in the Software without restriction, including | |
6 | +without limitation the rights to use, copy, modify, merge, publish, | |
7 | +distribute, sublicense, and/or sell copies of the Software, and to | |
8 | +permit persons to whom the Software is furnished to do so, subject to | |
9 | +the following conditions: | |
10 | + | |
11 | +The above copyright notice and this permission notice shall be | |
12 | +included in all copies or substantial portions of the Software. | |
13 | + | |
14 | +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | |
15 | +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | |
16 | +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | |
17 | +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | |
18 | +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | |
19 | +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | |
20 | +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ... | ... |
... | ... | @@ -0,0 +1,57 @@ |
1 | +SemiFormal | |
2 | +========== | |
3 | + | |
4 | +A FormBuilder meant to play well with [Coulda](http://github.com/dancroak/coulda) and [Evergreen](http://github.com/dancroak/evergreen). | |
5 | + | |
6 | +Examples | |
7 | +-------- | |
8 | + | |
9 | +I had been writing this: | |
10 | + | |
11 | + <% form_for :session, :url => session_path do |form| %> | |
12 | + <fieldset class="inputs"> | |
13 | + <div class="string"> | |
14 | + <%= form.label :email %> | |
15 | + <%= form.text_field :email %> | |
16 | + </div> | |
17 | + <div class="password"> | |
18 | + <%= form.label :password %> | |
19 | + <%= form.password_field :password %> | |
20 | + </div> | |
21 | + <div class="boolean"> | |
22 | + <%= form.check_box :remember_me %> | |
23 | + <%= form.label :remember_me %> | |
24 | + </div> | |
25 | + </fieldset> | |
26 | + <fieldset class="buttons"> | |
27 | + <%= form.submit "Sign in", :disable_with => "Please wait..." %> | |
28 | + </fieldset> | |
29 | + <% end %> | |
30 | + | |
31 | +With SemiFormal, I write this: | |
32 | + | |
33 | + <% form_for :session, :url => session_path do |form| %> | |
34 | + <fieldset class="inputs"> | |
35 | + <%= form.string :email %> | |
36 | + <%= form.password :password %> | |
37 | + <%= form.boolean :remember_me %> | |
38 | + </fieldset> | |
39 | + <fieldset class="buttons"> | |
40 | + <%= form.submit "Sign in", :disable_with => "Please wait..." %> | |
41 | + </fieldset> | |
42 | + <% end %> | |
43 | + | |
44 | +Hey, slightly better. | |
45 | + | |
46 | +Also available: | |
47 | + | |
48 | + form.text | |
49 | + form.numeric | |
50 | + | |
51 | +numeric is also aliased as integer, decimal, and float to feel migration-like. | |
52 | + | |
53 | +Installation | |
54 | +------------ | |
55 | + | |
56 | + script/plugin install git://github.com/dancroak/semi_formal.git | |
57 | + | ... | ... |
... | ... | @@ -0,0 +1,23 @@ |
1 | +require 'rake' | |
2 | +require 'rake/testtask' | |
3 | +require 'rake/rdoctask' | |
4 | + | |
5 | +desc 'Default: run unit tests.' | |
6 | +task :default => :test | |
7 | + | |
8 | +desc 'Test the semi_formal plugin.' | |
9 | +Rake::TestTask.new(:test) do |t| | |
10 | + t.libs << 'lib' | |
11 | + t.libs << 'test' | |
12 | + t.pattern = 'test/**/*_test.rb' | |
13 | + t.verbose = true | |
14 | +end | |
15 | + | |
16 | +desc 'Generate documentation for the semi_formal plugin.' | |
17 | +Rake::RDocTask.new(:rdoc) do |rdoc| | |
18 | + rdoc.rdoc_dir = 'rdoc' | |
19 | + rdoc.title = 'SemiFormal' | |
20 | + rdoc.options << '--line-numbers' << '--inline-source' | |
21 | + rdoc.rdoc_files.include('README') | |
22 | + rdoc.rdoc_files.include('lib/**/*.rb') | |
23 | +end | ... | ... |
... | ... | @@ -0,0 +1,47 @@ |
1 | +class SemiFormal < ActionView::Helpers::FormBuilder | |
2 | + def string(field, *args) | |
3 | + options = args.extract_options! | |
4 | + "<div class=\"string\">" + | |
5 | + label(field, options[:label] || {}) + | |
6 | + text_field(field, options[:text_field] || {}) + | |
7 | + "<div>" | |
8 | + end | |
9 | + | |
10 | + def password(field, *args) | |
11 | + options = args.extract_options! | |
12 | + "<div class=\"password\">" + | |
13 | + label(field, options[:label] || {}) + | |
14 | + password_field(field, options[:password_field] || {}) + | |
15 | + "<div>" | |
16 | + end | |
17 | + | |
18 | + def boolean(field, *args) | |
19 | + options = args.extract_options! | |
20 | + "<div class=\"boolean\">" + | |
21 | + check_box(field, options[:check_box] || {}) + | |
22 | + label(field, options[:label] || {}) + | |
23 | + "<div>" | |
24 | + end | |
25 | + | |
26 | + def numeric(field, *args) | |
27 | + options = args.extract_options! | |
28 | + "<div class=\"numeric\">" + | |
29 | + label(field, options[:label] || {}) + | |
30 | + text_field(field, options[:text_field] || {}) + | |
31 | + "<div>" | |
32 | + end | |
33 | + alias :integer :numeric | |
34 | + alias :float :numeric | |
35 | + alias :decimal :numeric | |
36 | + | |
37 | + def text(field, *args) | |
38 | + options = args.extract_options! | |
39 | + "<div class=\"text\">" + | |
40 | + label(field, options[:label] || {}) + | |
41 | + text_area(field, options[:text_area] || {}) + | |
42 | + "<div>" | |
43 | + end | |
44 | +end | |
45 | + | |
46 | +ActionView::Base.default_form_builder = SemiFormal | |
47 | + | ... | ... |