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,35 @@
1
+ require 'action_dispatch'
2
+ require 'capybara/rails'
3
+ require 'capybara/dsl'
4
+
5
+ module RSpec::Rails
6
+ module IntegrationExampleGroup
7
+ extend ActiveSupport::Concern
8
+
9
+ include ActionDispatch::Integration::Runner
10
+ include RSpec::Rails::TestUnitAssertionAdapter
11
+ include ActionDispatch::Assertions
12
+ include Capybara
13
+ include RSpec::Matchers
14
+
15
+ module InstanceMethods
16
+ def app
17
+ ::Rails.application
18
+ end
19
+
20
+ def last_response
21
+ page
22
+ end
23
+ end
24
+
25
+ included do
26
+ before do
27
+ @router = ::Rails.application.routes
28
+ end
29
+ end
30
+
31
+ RSpec.configure do |c|
32
+ c.include self, :example_group => { :file_path => /\bspec\/integration\// }
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,61 @@
1
+ require 'spec_helper'
2
+
3
+ describe "foos/edit.html.erb" do
4
+ before(:each) do
5
+ @foo = assign(:foo, stub_model(Foo,
6
+ :new_record? => false,
7
+ :name => "MyString",
8
+ :active => false,
9
+ :style => "MyString"
10
+ ))
11
+ end
12
+
13
+ it "renders the edit foo form" do
14
+ render
15
+
16
+ rendered.should have_selector("form", :action => foo_path(@foo), :method => "post") do |form|
17
+ form.should have_selector("input#foo_name", :name => "foo[name]")
18
+ form.should have_selector("input#foo_active", :name => "foo[active]")
19
+ form.should have_selector("select#foo_style", :name => "foo[style]")
20
+ form.should have_xpath("//select[@id='foo_style']/option", :value => 'Select...')
21
+ end
22
+ end
23
+
24
+ it 'renders a text field with a default label' do
25
+ render
26
+ rendered.should have_selector("form", :action => foo_path(@foo), :method => "post") do |form|
27
+ form.should have_xpath("//label[@for='foo_name']", :content => 'Name')
28
+ form.should have_selector("input#foo_name", :name => "foo[name]")
29
+ end
30
+ end
31
+
32
+ it 'renders a field with a custom label' do
33
+ render
34
+ rendered.should have_selector("form", :action => foo_path(@foo), :method => "post") do |form|
35
+ form.should have_xpath("//label[@for='foo_active']", :content => 'Status')
36
+ end
37
+ end
38
+
39
+ it 'renders an inline label for a checkbox' do
40
+ render
41
+ rendered.should have_selector("form", :action => foo_path(@foo), :method => "post") do |form|
42
+ form.should have_xpath("//label[@for='foo_active']", :content => 'Active', :class => 'inline')
43
+ end
44
+ end
45
+
46
+ it 'renders a select control with a default option' do
47
+ render
48
+ rendered.should have_selector("form", :action => foo_path(@foo), :method => "post") do |form|
49
+ form.should have_xpath("//select[@id='foo_style']/option", :value => 'Select...')
50
+ end
51
+ end
52
+
53
+ it 'renders a date select' do
54
+ render
55
+ rendered.should have_selector("form", :action => foo_path(@foo), :method => "post") do |form|
56
+ form.should have_xpath("//select/option", :content => 'January')
57
+ form.should have_xpath("//select/option", :content => '1')
58
+ form.should have_xpath("//select/option", :content => '2010')
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,25 @@
1
+ require 'spec_helper'
2
+
3
+ describe "foos/index.html.erb" do
4
+ before(:each) do
5
+ assign(:foos, [
6
+ stub_model(Foo,
7
+ :name => "Name",
8
+ :active => false,
9
+ :style => "Style"
10
+ ),
11
+ stub_model(Foo,
12
+ :name => "Name",
13
+ :active => false,
14
+ :style => "Style"
15
+ )
16
+ ])
17
+ end
18
+
19
+ it "renders a list of foos" do
20
+ render
21
+ rendered.should have_selector("tr>td", :content => "Name".to_s, :count => 2)
22
+ rendered.should have_selector("tr>td", :content => false.to_s, :count => 2)
23
+ rendered.should have_selector("tr>td", :content => "Style".to_s, :count => 2)
24
+ end
25
+ end
@@ -0,0 +1,22 @@
1
+ require 'spec_helper'
2
+
3
+ describe "foos/new.html.erb" do
4
+ before(:each) do
5
+ assign(:foo, stub_model(Foo,
6
+ :new_record? => true,
7
+ :name => "MyString",
8
+ :active => false,
9
+ :style => "MyString"
10
+ ))
11
+ end
12
+
13
+ it "renders new foo form" do
14
+ render
15
+
16
+ rendered.should have_selector("form", :action => foos_path, :method => "post") do |form|
17
+ form.should have_selector("input#foo_name", :name => "foo[name]")
18
+ form.should have_selector("input#foo_active", :name => "foo[active]")
19
+ form.should have_selector("select#foo_style", :name => "foo[style]")
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,18 @@
1
+ require 'spec_helper'
2
+
3
+ describe "foos/show.html.erb" do
4
+ before(:each) do
5
+ @foo = assign(:foo, stub_model(Foo,
6
+ :name => "Name",
7
+ :active => false,
8
+ :style => "Style"
9
+ ))
10
+ end
11
+
12
+ it "renders attributes in <p>" do
13
+ render
14
+ rendered.should contain("Name".to_s)
15
+ rendered.should contain(false.to_s)
16
+ rendered.should contain("Style".to_s)
17
+ end
18
+ end
metadata CHANGED
@@ -4,10 +4,10 @@ version: !ruby/object:Gem::Version
4
4
  hash: 23
5
5
  prerelease: false
6
6
  segments:
7
+ - 1
7
8
  - 0
8
- - 2
9
9
  - 0
10
- version: 0.2.0
10
+ version: 1.0.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Corey Ehmke
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-08-01 00:00:00 -05:00
19
+ date: 2010-08-02 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -72,9 +72,16 @@ files:
72
72
  - Rakefile
73
73
  - VERSION
74
74
  - app/controllers/application_controller.rb
75
+ - app/controllers/foos_controller.rb
75
76
  - app/helpers/application_helper.rb
77
+ - app/models/foo.rb
76
78
  - app/models/primary.rb
77
79
  - app/models/secondary.rb
80
+ - app/views/foos/_form.html.erb
81
+ - app/views/foos/edit.html.erb
82
+ - app/views/foos/index.html.erb
83
+ - app/views/foos/new.html.erb
84
+ - app/views/foos/show.html.erb
78
85
  - app/views/layouts/application.html.erb
79
86
  - autotest/discover.rb
80
87
  - config.ru
@@ -93,6 +100,7 @@ files:
93
100
  - config/locales/en.yml
94
101
  - config/routes.rb
95
102
  - db/development.sqlite3
103
+ - db/migrate/20100801224509_create_foos.rb
96
104
  - db/mir_ext_development.sqlite3
97
105
  - db/mir_ext_test.sqlite3
98
106
  - db/schema.rb
@@ -101,20 +109,17 @@ files:
101
109
  - doc/README_FOR_APP
102
110
  - lib/core_ext/controller_extensions.rb
103
111
  - lib/core_ext/core_ext.rb
104
- - lib/core_ext/helper_extensions.rb
105
112
  - lib/mir_extensions.rb
113
+ - lib/mir_form_builder.rb
106
114
  - lib/tasks/.gitkeep
107
- - log/development.log
108
115
  - log/production.log
109
116
  - log/server.log
110
- - log/test.log
111
117
  - mir_extensions.gemspec
112
118
  - public/404.html
113
119
  - public/422.html
114
120
  - public/500.html
115
121
  - public/favicon.ico
116
122
  - public/images/rails.png
117
- - public/index.html
118
123
  - public/javascripts/application.js
119
124
  - public/javascripts/controls.js
120
125
  - public/javascripts/dragdrop.js
@@ -123,11 +128,20 @@ files:
123
128
  - public/javascripts/rails.js
124
129
  - public/robots.txt
125
130
  - public/stylesheets/.gitkeep
131
+ - public/stylesheets/scaffold.css
126
132
  - script/rails
127
133
  - spec/controllers/application_controller_spec.rb
134
+ - spec/controllers/foos_controller_spec.rb
128
135
  - spec/helpers/application_helper_spec.rb
129
136
  - spec/mir_extensions_spec.rb
137
+ - spec/routing/foos_routing_spec.rb
130
138
  - spec/spec_helper.rb
139
+ - spec/support/integration_example_group.rb
140
+ - spec/views/foos/edit.html.erb_spec.rb
141
+ - spec/views/foos/index.html.erb_spec.rb
142
+ - spec/views/foos/new.html.erb_spec.rb
143
+ - spec/views/foos/show.html.erb_spec.rb
144
+ - test/integration/foo_test.rb
131
145
  - vendor/plugins/.gitkeep
132
146
  has_rdoc: true
133
147
  homepage: http://github.com/Bantik/mir_extensions
@@ -165,6 +179,14 @@ specification_version: 3
165
179
  summary: Standard extensions and utility methods for SEO Logic's Rails 3 apps.
166
180
  test_files:
167
181
  - spec/controllers/application_controller_spec.rb
182
+ - spec/controllers/foos_controller_spec.rb
168
183
  - spec/helpers/application_helper_spec.rb
169
184
  - spec/mir_extensions_spec.rb
185
+ - spec/routing/foos_routing_spec.rb
170
186
  - spec/spec_helper.rb
187
+ - spec/support/integration_example_group.rb
188
+ - spec/views/foos/edit.html.erb_spec.rb
189
+ - spec/views/foos/index.html.erb_spec.rb
190
+ - spec/views/foos/new.html.erb_spec.rb
191
+ - spec/views/foos/show.html.erb_spec.rb
192
+ - test/integration/foo_test.rb
@@ -1,383 +0,0 @@
1
- module ActionController
2
- module Helpers
3
-
4
- def action?( expression )
5
- !! ( expression.class == Regexp ? controller.action_name =~ expression : controller.action_name == expression )
6
- end
7
-
8
- # Formats an array with HTML line breaks, or the specified delimiter.
9
- def array_to_lines(array, delimiter = '<br />')
10
- array.blank? ? nil : array * delimiter
11
- end
12
-
13
- def checkmark
14
- %{<div class="checkmark"></div>}
15
- end
16
-
17
- def controller?( expression )
18
- !! ( expression.class == Regexp ? controller.controller_name =~ expression : controller.controller_name == expression )
19
- end
20
-
21
- # Display CRUD icons or links, according to setting in use_crud_icons method.
22
- #
23
- # In application_helper.rb:
24
- #
25
- # def use_crud_icons
26
- # true
27
- # end
28
- #
29
- # Then use in index views like this:
30
- #
31
- # <td class="crud_links"><%= crud_links(my_model, 'my_model', [:show, :edit, :delete]) -%></td>
32
- #
33
- def crud_links(model, instance_name, actions, args={})
34
- _html = ""
35
- _options = args.keys.empty? ? '' : ", #{args.map{|k,v| ":#{k} => #{v}"}}"
36
-
37
- if use_crud_icons
38
- if actions.include?(:show)
39
- _html << eval("link_to image_tag('/images/icons/view.png', :class => 'crud_icon'), model, :title => 'View'#{_options}")
40
- end
41
- if actions.include?(:edit)
42
- _html << eval("link_to image_tag('/images/icons/edit.png', :class => 'crud_icon'), edit_#{instance_name}_path(model), :title => 'Edit'#{_options}")
43
- end
44
- if actions.include?(:delete)
45
- _html << eval("link_to image_tag('/images/icons/delete.png', :class => 'crud_icon'), model, :confirm => 'Are you sure? This action cannot be undone.', :method => :delete, :title => 'Delete'#{_options}")
46
- end
47
- else
48
- if actions.include?(:show)
49
- _html << eval("link_to 'View', model, :title => 'View', :class => 'crud_link'#{_options}")
50
- end
51
- if actions.include?(:edit)
52
- _html << eval("link_to 'Edit', edit_#{instance_name}_path(model), :title => 'Edit', :class => 'crud_link'#{_options}")
53
- end
54
- if actions.include?(:delete)
55
- _html << eval("link_to 'Delete', model, :confirm => 'Are you sure? This action cannot be undone.', :method => :delete, :title => 'Delete', :class => 'crud_link'#{_options}")
56
- end
57
- end
58
- _html
59
- end
60
-
61
- # Display CRUD icons or links, according to setting in use_crud_icons method.
62
- # This method works with nested resources.
63
- # Use in index views like this:
64
- #
65
- # <td class="crud_links"><%= crud_links_for_nested_resource(@my_model, my_nested_model, 'my_model', 'my_nested_model', [:show, :edit, :delete]) -%></td>
66
- #
67
- def crud_links_for_nested_resource(model, nested_model, model_instance_name, nested_model_instance_name, actions, args={})
68
- _html = ""
69
- if use_crud_icons
70
- if actions.include?(:show)
71
- _html << eval("link_to image_tag('/images/icons/view.png', :class => 'crud_icon'), #{model_instance_name}_#{nested_model_instance_name}_path(model, nested_model), :title => 'View'")
72
- end
73
-
74
- if actions.include?(:edit)
75
- _html << eval("link_to image_tag('/images/icons/edit.png', :class => 'crud_icon'), edit_#{model_instance_name}_#{nested_model_instance_name}_path(model, nested_model), :title => 'Edit'")
76
- end
77
-
78
- if actions.include?(:delete)
79
- _html << eval("link_to image_tag('/images/icons/delete.png', :class => 'crud_icon'), #{model_instance_name}_#{nested_model_instance_name}_path(model, nested_model), :method => :delete, :confirm => 'Are you sure? This action cannot be undone.', :title => 'Delete'")
80
- end
81
- end
82
- _html
83
- end
84
-
85
- # DRY way to return a legend tag that renders correctly in all browsers. This variation allows
86
- # for more "stuff" inside the legend tag, e.g. expand/collapse controls, without having to worry
87
- # about escape sequences.
88
- #
89
- # Sample usage:
90
- #
91
- # <%- legend_block do -%>
92
- # <span id="hide_or_show_backlinks" class="show_link" style="background-color: #999999;
93
- # border: 1px solid #999999;" onclick="javascript:hide_or_show('backlinks');"></span>Backlinks (<%=
94
- # @google_results.size -%>)
95
- # <%- end -%>
96
- #
97
- def legend_block(&block)
98
- concat content_tag(:div, capture(&block), :class => "faux_legend")
99
- end
100
-
101
- # DRY way to return a legend tag that renders correctly in all browsers
102
- def legend_tag(text, args={})
103
- _html = %{<div id="#{args[:id]}" class="faux_legend">#{text}</div>\r}
104
- _html.gsub!(/ id=""/,'')
105
- _html.gsub!(/ class=""/,'')
106
- _html
107
- end
108
-
109
- def meta_description(content=nil)
110
- content_for(:meta_description) { content } unless content.blank?
111
- end
112
-
113
- def meta_keywords(content=nil)
114
- content_for(:meta_keywords) { content } unless content.blank?
115
- end
116
-
117
- def models_for_select( models, label = 'name' )
118
- models.map{ |m| [m[label], m.id] }.sort_by{ |e| e[0] }
119
- end
120
-
121
- def options_for_array( a, selected = nil, prompt = select_prompt )
122
- "<option value=''>#{prompt}</option>" + a.map{ |_e| _flag = _e[0].to_s == selected ? 'selected="1"' : ''; _e.is_a?(Array) ? "<option value=\"#{_e[0]}\" #{_flag}>#{_e[1]}</option>" : "<option>#{_e}</option>" }.to_s
123
- end
124
-
125
- # Create a link that is opaque to search engine spiders.
126
- def obfuscated_link_to(path, image, label, args={})
127
- _html = %{<form action="#{path}" method="get" class="obfuscated_link">}
128
- _html << %{ <fieldset><input alt="#{label}" src="#{image}" type="image" /></fieldset>}
129
- args.each{ |k,v| _html << %{ <div><input id="#{k.to_s}" name="#{k}" type="hidden" value="#{v}" /></div>} }
130
- _html << %{</form>}
131
- _html
132
- end
133
-
134
- # Wraps the given HTML in Rails' default style to highlight validation errors, if any.
135
- def required_field_helper( model, element, html )
136
- if model && ! model.errors.empty? && element.is_required
137
- return content_tag( :div, html, :class => 'fieldWithErrors' )
138
- else
139
- return html
140
- end
141
- end
142
-
143
- def select_prompt
144
- "Select..."
145
- end
146
-
147
- def select_prompt_option
148
- "<option value=''>#{select_prompt}</option>"
149
- end
150
-
151
- # Use on index pages to create dropdown list of filtering criteria.
152
- # Populate the filter list using a constant in the model corresponding to named scopes.
153
- #
154
- # Usage:
155
- #
156
- # - item.rb:
157
- #
158
- # named_scope :active, :conditions => { :is_active => true }
159
- # named_scope :inactive, :conditions => { :is_active => false }
160
- #
161
- # FILTERS = [
162
- # {:scope => "all", :label => "All"},
163
- # {:scope => "active", :label => "Active Only"},
164
- # {:scope => "inactive", :label => "Inactive Only"}
165
- # ]
166
- #
167
- # - items/index.html.erb:
168
- #
169
- # <%= select_tag_for_filter("items", @filters, params) -%>
170
- #
171
- # - items_controller.rb:
172
- #
173
- # def index
174
- # @filters = Item::FILTERS
175
- # if params[:show] && params[:show] != "all" && @filters.collect{|f| f[:scope]}.include?(params[:show])
176
- # @items = eval("@items.#{params[:show]}.order_by(params[:by], params[:dir])")
177
- # else
178
- # @items = @items.order_by(params[:by], params[:dir])
179
- # end
180
- # ...
181
- # end
182
- #
183
- def select_tag_for_filter(model, nvpairs, params)
184
- return unless model && nvpairs && ! nvpairs.empty?
185
- options = { :query => params[:query] }
186
- _url = url_for(eval("#{model}_url(options)"))
187
- _html = %{<label for="show">Show:</label><br />}
188
- _html << %{<select name="show" id="show" onchange="window.location='#{_url}' + '?show=' + this.value">}
189
- nvpairs.each do |pair|
190
- _html << %{<option value="#{pair[:scope]}"}
191
- if params[:show] == pair[:scope] || ((params[:show].nil? || params[:show].empty?) && pair[:scope] == "all")
192
- _html << %{ selected="selected"}
193
- end
194
- _html << %{>#{pair[:label]}}
195
- _html << %{</option>}
196
- end
197
- _html << %{</select>}
198
- end
199
-
200
- # Returns a link_to tag with sorting parameters that can be used with ActiveRecord.order_by.
201
- #
202
- # To use standard resources, specify the resources as a plural symbol:
203
- # sort_link(:users, 'email', params)
204
- #
205
- # To use resources aliased with :as (in routes.rb), specify the aliased route as a string.
206
- # sort_link('users_admin', 'email', params)
207
- #
208
- # You can override the link's label by adding a labels hash to your params in the controller:
209
- # params[:labels] = {'user_id' => 'User'}
210
- def sort_link(model, field, params, html_options={})
211
- if (field.to_sym == params[:by] || field == params[:by]) && params[:dir] == "ASC"
212
- classname = "arrow-asc"
213
- dir = "DESC"
214
- elsif (field.to_sym == params[:by] || field == params[:by])
215
- classname = "arrow-desc"
216
- dir = "ASC"
217
- else
218
- dir = "ASC"
219
- end
220
-
221
- options = {
222
- :anchor => html_options[:anchor] || nil,
223
- :by => field,
224
- :dir => dir,
225
- :query => params[:query],
226
- :show => params[:show]
227
- }
228
-
229
- options[:show] = params[:show] unless params[:show].blank? || params[:show] == 'all'
230
-
231
- html_options = {
232
- :class => "#{classname} #{html_options[:class]}",
233
- :style => "color: white; font-weight: #{params[:by] == field ? "bold" : "normal"}; #{html_options[:style]}",
234
- :title => "Sort by this field"
235
- }
236
-
237
- field_name = params[:labels] && params[:labels][field] ? params[:labels][field] : field.titleize
238
-
239
- _link = model.is_a?(Symbol) ? eval("#{model}_url(options)") : "/#{model}?#{options.to_params}"
240
- link_to(field_name, _link, html_options)
241
- end
242
-
243
- # Tabbed interface helpers =======================================================================
244
-
245
- # Returns formatted tabs with appropriate JS for activation. Use in conjunction with tab_body.
246
- #
247
- # Usage:
248
- #
249
- # <%- tabset do -%>
250
- # <%= tab_tag :id => 'ppc_ads', :label => 'PPC Ads', :state => 'active' %>
251
- # <%= tab_tag :id => 'budget' %>
252
- # <%= tab_tag :id => 'geotargeting' %>
253
- # <%- end -%>
254
- #
255
- def tabset(&proc)
256
- concat %{
257
- <div class="jump_links">
258
- <ul>
259
- }
260
- yield
261
- concat %{
262
- </ul>
263
- </div>
264
- <br style="clear: both;" /><br />
265
- <input type="hidden" id="show_tab" />
266
- <script type="text/javascript">
267
- function hide_all_tabs() { $$('.tab_block').invoke('hide'); }
268
- function activate_tab(tab) {
269
- $$('.tab_control').each(function(elem){ elem.className = 'tab_control'});
270
- $('show_' + tab).className = 'tab_control active';
271
- hide_all_tabs();
272
- $(tab).toggle();
273
- $('show_tab').value = tab
274
- }
275
- function sticky_tab() { if (location.hash) { activate_tab(location.hash.gsub('#','')); } }
276
- Event.observe(window, 'load', function() { sticky_tab(); });
277
- </script>
278
- }
279
- end
280
-
281
- # Returns a tab body corresponding to tabs in a tabset. Make sure that the id of the tab_body
282
- # matches the id provided to the tab_tag in the tabset block.
283
- #
284
- # Usage:
285
- #
286
- # <%- tab_body :id => 'ppc_ads', :label => 'PPC Ad Details' do -%>
287
- # PPC ads form here.
288
- # <%- end -%>
289
- #
290
- # <%- tab_body :id => 'budget' do -%>
291
- # Budget form here.
292
- # <%- end -%>
293
- #
294
- # <%- tab_body :id => 'geotargeting' do -%>
295
- # Geotargeting form here.
296
- # <%- end -%>
297
- #
298
- def tab_body(args, &proc)
299
- concat %{<div id="#{args[:id]}" class="tab_block form_container" style="display: #{args[:display] || 'none'};">}
300
- concat %{#{legend_tag args[:label] || args[:id].titleize }}
301
- concat %{<a name="#{args[:id]}"></a><br />}
302
- yield
303
- concat %{</div>}
304
- end
305
-
306
- # Returns the necessary HTML for a particular tab. Use inside a tabset block.
307
- # Override the default tab label by specifying a :label parameter.
308
- # Indicate that the tab should be active by setting its :state to 'active'.
309
- # (NOTE: You must define a corresponding CSS style for active tabs.)
310
- #
311
- # Usage:
312
- #
313
- # <%= tab_tag :id => 'ppc_ads', :label => 'PPC Ads', :state => 'active' %>
314
- #
315
- def tab_tag(args, *css_class)
316
- %{<li id="show_#{args[:id]}" class="tab_control #{args[:state]}" onclick="window.location='##{args[:id]}'; activate_tab('#{args[:id]}');">#{args[:label] || args[:id].to_s.titleize}</li>}
317
- end
318
-
319
- # ================================================================================================
320
-
321
- def tag_for_collapsible_row(obj, params)
322
- _html = ""
323
- if obj && obj.respond_to?(:parent) && obj.parent
324
- _html << %{<tr class="#{obj.class.name.downcase}_#{obj.parent.id} #{params[:class]}" style="display: none; #{params[:style]}">}
325
- else
326
- _html << %{<tr class="#{params[:class]}" style="#{params[:style]}">}
327
- end
328
- _html
329
- end
330
-
331
- def tag_for_collapsible_row_control(obj)
332
- _base_id = "#{obj.class.name.downcase}_#{obj.id}"
333
- _html = %{<div id="hide_or_show_#{_base_id}" class="show_link" style="background-color: #999999; border: 1px solid #999999;" onclick="javascript:hide_or_show('#{_base_id}');"></div>}
334
- end
335
-
336
- # Create a set of tags for displaying a field label with inline help.
337
- # Field label text is appended with a ? icon, which responds to a click
338
- # by showing or hiding the provided help text.
339
- #
340
- # Sample usage:
341
- #
342
- # <%= tag_for_label_with_inline_help 'Relative Frequency', 'rel_frequency', 'Relative frequency of search traffic for this keyword across multiple search engines, as measured by WordTracker.' %>
343
- #
344
- # Yields:
345
- #
346
- # <label for="rel_frequency">Relative Frequency: <%= image_tag "/images/help_icon.png", :onclick => "$('rel_frequency_help').toggle();", :class => 'inline_icon' %></label><br />
347
- # <div class="inline_help" id="rel_frequency_help" style="display: none;">
348
- # <p>Relative frequency of search traffic for this keyword across multiple search engines, as measured by WordTracker.</p>
349
- # </div>
350
- def tag_for_label_with_inline_help( label_text, field_id, help_text )
351
- _html = ""
352
- _html << %{<label for="#{field_id}">#{label_text}}
353
- _html << %{<img src="/images/icons/help_icon.png" onclick="$('#{field_id}_help').toggle();" class='inline_icon' />}
354
- _html << %{</label><br />}
355
- _html << %{<div class="inline_help" id="#{field_id}_help" style="display: none;">}
356
- _html << %{<p>#{help_text}</p>}
357
- _html << %{</div>}
358
- _html
359
- end
360
-
361
- # Create a set of tags for displaying a field label followed by instructions.
362
- # The instructions are displayed on a new line following the field label.
363
- #
364
- # Usage:
365
- #
366
- # <%= tag_for_label_with_instructions 'Status', 'is_active', 'Only active widgets will be visible to the public.' %>
367
- #
368
- # Yields:
369
- #
370
- # <label for="is_active">
371
- # Status<br />
372
- # <span class="instructions">Only active widgets will be visible to the public.</span>
373
- # <label><br />
374
- def tag_for_label_with_instructions( label_text, field_id, instructions )
375
- _html = ""
376
- _html << %{<label for="#{field_id}">#{label_text}}
377
- _html << %{<span class="instructions">#{instructions}</span>}
378
- _html << %{</label><br />}
379
- _html
380
- end
381
-
382
- end
383
- end