mir_extensions 0.2.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. data/.gitignore +3 -0
  2. data/Gemfile +2 -1
  3. data/Gemfile.lock +18 -2
  4. data/Rakefile +1 -1
  5. data/VERSION +1 -1
  6. data/app/controllers/foos_controller.rb +83 -0
  7. data/app/helpers/application_helper.rb +1 -0
  8. data/app/models/foo.rb +2 -0
  9. data/app/views/foos/_form.html.erb +20 -0
  10. data/app/views/foos/edit.html.erb +6 -0
  11. data/app/views/foos/index.html.erb +27 -0
  12. data/app/views/foos/new.html.erb +5 -0
  13. data/app/views/foos/show.html.erb +20 -0
  14. data/config.ru +1 -1
  15. data/config/application.rb +5 -1
  16. data/config/environment.rb +1 -1
  17. data/config/environments/development.rb +1 -1
  18. data/config/environments/test.rb +1 -1
  19. data/config/initializers/secret_token.rb +1 -1
  20. data/config/initializers/session_store.rb +1 -1
  21. data/config/routes.rb +5 -2
  22. data/db/migrate/20100801224509_create_foos.rb +16 -0
  23. data/db/mir_ext_development.sqlite3 +0 -0
  24. data/db/mir_ext_test.sqlite3 +0 -0
  25. data/db/schema.rb +11 -1
  26. data/lib/core_ext/core_ext.rb +1 -2
  27. data/lib/mir_extensions.rb +386 -2
  28. data/lib/mir_form_builder.rb +166 -0
  29. data/mir_extensions.gemspec +29 -7
  30. data/public/stylesheets/scaffold.css +56 -0
  31. data/spec/controllers/foos_controller_spec.rb +125 -0
  32. data/spec/routing/foos_routing_spec.rb +35 -0
  33. data/spec/support/integration_example_group.rb +35 -0
  34. data/spec/views/foos/edit.html.erb_spec.rb +61 -0
  35. data/spec/views/foos/index.html.erb_spec.rb +25 -0
  36. data/spec/views/foos/new.html.erb_spec.rb +22 -0
  37. data/spec/views/foos/show.html.erb_spec.rb +18 -0
  38. metadata +29 -7
  39. data/lib/core_ext/helper_extensions.rb +0 -383
  40. data/log/development.log +0 -151
  41. data/log/test.log +0 -27
  42. data/public/index.html +0 -262
@@ -0,0 +1,166 @@
1
+ # == Configuration
2
+ #
3
+ # === Configure your application to default to the custom form builder
4
+ #
5
+ # In app/controllers/application_controller.rb:
6
+ #
7
+ # class ApplicationController < ActionController::Base
8
+ # ActionView::Base.default_form_builder = MirFormBuilder
9
+ #
10
+ # == Usage
11
+ #
12
+ # === Default form field with label:
13
+ #
14
+ # <%= f.text_field :last_name -%>
15
+ #
16
+ # Returns:
17
+ #
18
+ # <fieldset>
19
+ # <label for="user_last_name">Last Name</label><br />
20
+ # <input id="user_last_name" name="user[last_name]" size="30" type="text" />
21
+ # </fieldset>
22
+ #
23
+ # === Form field with custom label:
24
+ #
25
+ # <%= f.text_field :first_name, :label => 'Custom' -%>
26
+ #
27
+ # Returns:
28
+ #
29
+ # <fieldset>
30
+ # <label for="user_first_name">Custom</label><br />
31
+ # <input id="user_first_name" name="user[first_name]" size="30" type="text" />
32
+ # </fieldset>
33
+ #
34
+ # === Form field with no label
35
+ #
36
+ # <%= f.text_field :search, :label => false -%>
37
+ #
38
+ # Returns:
39
+ #
40
+ # <input id="search" name="search" size="30" type="text" />
41
+ #
42
+ # === Form field with inline help (? icon which reveals help content when clicked):
43
+ #
44
+ # <%= f.password_field :password %>
45
+ #
46
+ # Returns:
47
+ #
48
+ # <fieldset>
49
+ # <label for="password">Password: <img src="/images/icons/help_icon.png"
50
+ # onclick="$('password_help').toggle();" class='inline_icon' /></label><br />
51
+ # <div class="inline_help" id="password_help" style="display: none;">
52
+ # <p>Here are some detailed instructions on valid passwords.</p>
53
+ # </div>
54
+ # <input id="user_password" name="user[password]" size="30" type="password" />
55
+ # </fieldset>
56
+ #
57
+ # === Form field with instructions (show immediately below the label):
58
+ #
59
+ # <%= f.password_field :password_confirmation %>
60
+ #
61
+ # Returns:
62
+ #
63
+ # <fieldset>
64
+ # <label for="password_confirmation">
65
+ # Confirm Password:
66
+ # <span class="instructions">Enter your password again to confirm.</span>
67
+ # </label><br />
68
+ # <input id="user_password_confirmation" name="user[password_confirmation]" size="30" type="password" />
69
+ # </fieldset>
70
+ #
71
+ # === Check box with label in addition to checkbox value text
72
+ # (E.g. 'Foo' appears above the checkbox, and 'Something' next to it):
73
+ #
74
+ # <%= f.check_box :foo, :inline_label => 'Something' -%>
75
+ #
76
+ # Returns:
77
+ #
78
+ # <fieldset>
79
+ # <label for="user_foo">Foo</label><br />
80
+ # <input name="user[foo]" type="hidden" value="0" />
81
+ # <input id="user_foo" name="user[foo]" type="checkbox" value="1" />
82
+ # <label class="inline" for="user_foo">Something</label><br style='clear: both;'/><br />
83
+ # </fieldset>
84
+ #
85
+ # === Don't wrap fields in a fieldset
86
+ #
87
+ # <%= f.text_field :query, :label => 'Search terms:', :fieldset => false -%>
88
+ #
89
+ # Returns
90
+ #
91
+ # <label for="search_terms_query"><br />
92
+ # <input id="search_terms_query" name="search_terms_query" size="30" />
93
+ #
94
+ # == Troubleshooting
95
+ #
96
+ # If you're seeing double form labels, it's because you still have <%= label -%> elements in your forms.
97
+ #
98
+ module MirExtensions
99
+
100
+
101
+ class MirFormBuilder < ActionView::Helpers::FormBuilder
102
+
103
+ include ActionView::Helpers::DateHelper
104
+ helpers = field_helpers +
105
+ %w{date_select datetime_select time_select} +
106
+ %w{collection_select select country_select time_zone_select} -
107
+ %w{hidden_field label fields_for}
108
+
109
+ helpers.each do |name|
110
+ define_method(name) do |field, *args|
111
+
112
+ # capture first array as select choices
113
+ choices = args.detect{ |a| a.is_a?(Array) } || []
114
+ args.delete(choices)
115
+
116
+ # capture first hash as options
117
+ options = args.detect{ |a| a.is_a?(Hash) } || {}
118
+ args.delete(options)
119
+ include_label = true
120
+
121
+ if options[:label].nil? # Not specified. Default to humanized version of field id.
122
+ _label_text = field.to_s.humanize.capitalize_words
123
+ elsif options[:label]
124
+ _label_text = options.delete :label
125
+ # options[:label] is false!
126
+ else
127
+ include_label = options.delete(:label)
128
+ end
129
+
130
+ # Create label, if label text was provided or created.
131
+ if _label_text || options[:instructions]
132
+ if options[:instructions]
133
+ _label = tag_for_label_with_instructions(_label_text, field, options.delete(:instructions))
134
+ elsif options[:help]
135
+ _label = tag_for_label_with_inline_help(_label_text, field, options.delete(:help))
136
+ elsif include_label
137
+ _label = label(field, _label_text) + @template.tag('br')
138
+ end
139
+ end
140
+
141
+ if options[:inline_label] # Handle inline labels, e.g. for checkboxes
142
+ _inline_label = label(field, options.delete(:inline_label), :class => 'inline') + @template.tag('br', :style => 'clear: both;')
143
+ end
144
+
145
+ _field = nil
146
+
147
+ if name.include? 'select'
148
+ _field = super(field, choices, options)
149
+ else
150
+ if name == 'radio_button'
151
+ # invert arguments
152
+ _field = super(field, args, options)
153
+ else
154
+ _field = args.blank? ? super(field, options).html_safe : super(field, options, args).html_safe
155
+ end
156
+ end
157
+
158
+ if options[:fieldset] == false
159
+ "#{_label}#{_field}#{_inline_label}"
160
+ else
161
+ @template.content_tag(:fieldset, "#{_label}#{_field}#{_inline_label}".html_safe)
162
+ end
163
+ end
164
+ end
165
+ end
166
+ end
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{mir_extensions}
8
- s.version = "0.2.0"
8
+ s.version = "1.0.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Corey Ehmke", "Rod Monje"]
12
- s.date = %q{2010-08-01}
12
+ s.date = %q{2010-08-02}
13
13
  s.description = %q{Standard extensions and utility methods for SEO Logic's Rails 3 apps.}
14
14
  s.email = %q{corey@seologic.com}
15
15
  s.extra_rdoc_files = [
@@ -30,9 +30,16 @@ Gem::Specification.new do |s|
30
30
  "Rakefile",
31
31
  "VERSION",
32
32
  "app/controllers/application_controller.rb",
33
+ "app/controllers/foos_controller.rb",
33
34
  "app/helpers/application_helper.rb",
35
+ "app/models/foo.rb",
34
36
  "app/models/primary.rb",
35
37
  "app/models/secondary.rb",
38
+ "app/views/foos/_form.html.erb",
39
+ "app/views/foos/edit.html.erb",
40
+ "app/views/foos/index.html.erb",
41
+ "app/views/foos/new.html.erb",
42
+ "app/views/foos/show.html.erb",
36
43
  "app/views/layouts/application.html.erb",
37
44
  "autotest/discover.rb",
38
45
  "config.ru",
@@ -51,6 +58,7 @@ Gem::Specification.new do |s|
51
58
  "config/locales/en.yml",
52
59
  "config/routes.rb",
53
60
  "db/development.sqlite3",
61
+ "db/migrate/20100801224509_create_foos.rb",
54
62
  "db/mir_ext_development.sqlite3",
55
63
  "db/mir_ext_test.sqlite3",
56
64
  "db/schema.rb",
@@ -59,20 +67,17 @@ Gem::Specification.new do |s|
59
67
  "doc/README_FOR_APP",
60
68
  "lib/core_ext/controller_extensions.rb",
61
69
  "lib/core_ext/core_ext.rb",
62
- "lib/core_ext/helper_extensions.rb",
63
70
  "lib/mir_extensions.rb",
71
+ "lib/mir_form_builder.rb",
64
72
  "lib/tasks/.gitkeep",
65
- "log/development.log",
66
73
  "log/production.log",
67
74
  "log/server.log",
68
- "log/test.log",
69
75
  "mir_extensions.gemspec",
70
76
  "public/404.html",
71
77
  "public/422.html",
72
78
  "public/500.html",
73
79
  "public/favicon.ico",
74
80
  "public/images/rails.png",
75
- "public/index.html",
76
81
  "public/javascripts/application.js",
77
82
  "public/javascripts/controls.js",
78
83
  "public/javascripts/dragdrop.js",
@@ -81,11 +86,20 @@ Gem::Specification.new do |s|
81
86
  "public/javascripts/rails.js",
82
87
  "public/robots.txt",
83
88
  "public/stylesheets/.gitkeep",
89
+ "public/stylesheets/scaffold.css",
84
90
  "script/rails",
85
91
  "spec/controllers/application_controller_spec.rb",
92
+ "spec/controllers/foos_controller_spec.rb",
86
93
  "spec/helpers/application_helper_spec.rb",
87
94
  "spec/mir_extensions_spec.rb",
95
+ "spec/routing/foos_routing_spec.rb",
88
96
  "spec/spec_helper.rb",
97
+ "spec/support/integration_example_group.rb",
98
+ "spec/views/foos/edit.html.erb_spec.rb",
99
+ "spec/views/foos/index.html.erb_spec.rb",
100
+ "spec/views/foos/new.html.erb_spec.rb",
101
+ "spec/views/foos/show.html.erb_spec.rb",
102
+ "test/integration/foo_test.rb",
89
103
  "vendor/plugins/.gitkeep"
90
104
  ]
91
105
  s.homepage = %q{http://github.com/Bantik/mir_extensions}
@@ -95,9 +109,17 @@ Gem::Specification.new do |s|
95
109
  s.summary = %q{Standard extensions and utility methods for SEO Logic's Rails 3 apps.}
96
110
  s.test_files = [
97
111
  "spec/controllers/application_controller_spec.rb",
112
+ "spec/controllers/foos_controller_spec.rb",
98
113
  "spec/helpers/application_helper_spec.rb",
99
114
  "spec/mir_extensions_spec.rb",
100
- "spec/spec_helper.rb"
115
+ "spec/routing/foos_routing_spec.rb",
116
+ "spec/spec_helper.rb",
117
+ "spec/support/integration_example_group.rb",
118
+ "spec/views/foos/edit.html.erb_spec.rb",
119
+ "spec/views/foos/index.html.erb_spec.rb",
120
+ "spec/views/foos/new.html.erb_spec.rb",
121
+ "spec/views/foos/show.html.erb_spec.rb",
122
+ "test/integration/foo_test.rb"
101
123
  ]
102
124
 
103
125
  if s.respond_to? :specification_version then
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,125 @@
1
+ require 'spec_helper'
2
+
3
+ describe FoosController do
4
+
5
+ def mock_foo(stubs={})
6
+ @mock_foo ||= mock_model(Foo, stubs).as_null_object
7
+ end
8
+
9
+ describe "GET index" do
10
+ it "assigns all foos as @foos" do
11
+ Foo.stub(:all) { [mock_foo] }
12
+ get :index
13
+ assigns(:foos).should eq([mock_foo])
14
+ end
15
+ end
16
+
17
+ describe "GET show" do
18
+ it "assigns the requested foo as @foo" do
19
+ Foo.stub(:find).with("37") { mock_foo }
20
+ get :show, :id => "37"
21
+ assigns(:foo).should be(mock_foo)
22
+ end
23
+ end
24
+
25
+ describe "GET new" do
26
+ it "assigns a new foo as @foo" do
27
+ Foo.stub(:new) { mock_foo }
28
+ get :new
29
+ assigns(:foo).should be(mock_foo)
30
+ end
31
+ end
32
+
33
+ describe "GET edit" do
34
+ it "assigns the requested foo as @foo" do
35
+ Foo.stub(:find).with("37") { mock_foo }
36
+ get :edit, :id => "37"
37
+ assigns(:foo).should be(mock_foo)
38
+ end
39
+ end
40
+
41
+ describe "POST create" do
42
+
43
+ describe "with valid params" do
44
+ it "assigns a newly created foo as @foo" do
45
+ Foo.stub(:new).with({'these' => 'params'}) { mock_foo(:save => true) }
46
+ post :create, :foo => {'these' => 'params'}
47
+ assigns(:foo).should be(mock_foo)
48
+ end
49
+
50
+ it "redirects to the created foo" do
51
+ Foo.stub(:new) { mock_foo(:save => true) }
52
+ post :create, :foo => {}
53
+ response.should redirect_to(foo_url(mock_foo))
54
+ end
55
+ end
56
+
57
+ describe "with invalid params" do
58
+ it "assigns a newly created but unsaved foo as @foo" do
59
+ Foo.stub(:new).with({'these' => 'params'}) { mock_foo(:save => false) }
60
+ post :create, :foo => {'these' => 'params'}
61
+ assigns(:foo).should be(mock_foo)
62
+ end
63
+
64
+ it "re-renders the 'new' template" do
65
+ Foo.stub(:new) { mock_foo(:save => false) }
66
+ post :create, :foo => {}
67
+ response.should render_template("new")
68
+ end
69
+ end
70
+
71
+ end
72
+
73
+ describe "PUT update" do
74
+
75
+ describe "with valid params" do
76
+ it "updates the requested foo" do
77
+ Foo.should_receive(:find).with("37") { mock_foo }
78
+ mock_foo.should_receive(:update_attributes).with({'these' => 'params'})
79
+ put :update, :id => "37", :foo => {'these' => 'params'}
80
+ end
81
+
82
+ it "assigns the requested foo as @foo" do
83
+ Foo.stub(:find) { mock_foo(:update_attributes => true) }
84
+ put :update, :id => "1"
85
+ assigns(:foo).should be(mock_foo)
86
+ end
87
+
88
+ it "redirects to the foo" do
89
+ Foo.stub(:find) { mock_foo(:update_attributes => true) }
90
+ put :update, :id => "1"
91
+ response.should redirect_to(foo_url(mock_foo))
92
+ end
93
+ end
94
+
95
+ describe "with invalid params" do
96
+ it "assigns the foo as @foo" do
97
+ Foo.stub(:find) { mock_foo(:update_attributes => false) }
98
+ put :update, :id => "1"
99
+ assigns(:foo).should be(mock_foo)
100
+ end
101
+
102
+ it "re-renders the 'edit' template" do
103
+ Foo.stub(:find) { mock_foo(:update_attributes => false) }
104
+ put :update, :id => "1"
105
+ response.should render_template("edit")
106
+ end
107
+ end
108
+
109
+ end
110
+
111
+ describe "DELETE destroy" do
112
+ it "destroys the requested foo" do
113
+ Foo.should_receive(:find).with("37") { mock_foo }
114
+ mock_foo.should_receive(:destroy)
115
+ delete :destroy, :id => "37"
116
+ end
117
+
118
+ it "redirects to the foos list" do
119
+ Foo.stub(:find) { mock_foo }
120
+ delete :destroy, :id => "1"
121
+ response.should redirect_to(foos_url)
122
+ end
123
+ end
124
+
125
+ end
@@ -0,0 +1,35 @@
1
+ require "spec_helper"
2
+
3
+ describe FoosController do
4
+ describe "routing" do
5
+
6
+ it "recognizes and generates #index" do
7
+ { :get => "/foos" }.should route_to(:controller => "foos", :action => "index")
8
+ end
9
+
10
+ it "recognizes and generates #new" do
11
+ { :get => "/foos/new" }.should route_to(:controller => "foos", :action => "new")
12
+ end
13
+
14
+ it "recognizes and generates #show" do
15
+ { :get => "/foos/1" }.should route_to(:controller => "foos", :action => "show", :id => "1")
16
+ end
17
+
18
+ it "recognizes and generates #edit" do
19
+ { :get => "/foos/1/edit" }.should route_to(:controller => "foos", :action => "edit", :id => "1")
20
+ end
21
+
22
+ it "recognizes and generates #create" do
23
+ { :post => "/foos" }.should route_to(:controller => "foos", :action => "create")
24
+ end
25
+
26
+ it "recognizes and generates #update" do
27
+ { :put => "/foos/1" }.should route_to(:controller => "foos", :action => "update", :id => "1")
28
+ end
29
+
30
+ it "recognizes and generates #destroy" do
31
+ { :delete => "/foos/1" }.should route_to(:controller => "foos", :action => "destroy", :id => "1")
32
+ end
33
+
34
+ end
35
+ end