tabletastic 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
data/lib/tabletastic.rb CHANGED
@@ -49,13 +49,13 @@ module Tabletastic
49
49
  options = args.extract_options!
50
50
  if block_given?
51
51
  yield self
52
- action_cells(options[:actions])
52
+ action_cells(options[:actions], options[:action_prefix])
53
53
  @template.concat(head)
54
54
  @template.concat(body)
55
55
  else
56
56
  @fields = args.empty? ? fields : args
57
57
  @field_labels = fields.map { |f| f.to_s.humanize }
58
- action_cells(options[:actions])
58
+ action_cells(options[:actions], options[:action_prefix])
59
59
  [head, body].join("")
60
60
  end
61
61
  end
@@ -164,26 +164,27 @@ module Tabletastic
164
164
  end
165
165
 
166
166
  # Used internally to build up cells for common CRUD actions
167
- def action_cells(actions)
167
+ def action_cells(actions, prefix = nil)
168
168
  return if actions.blank?
169
169
  actions = [actions] if !actions.respond_to?(:each)
170
170
  actions = [:show, :edit, :destroy] if actions == [:all]
171
171
  actions.each do |action|
172
- action_link(action.to_sym)
172
+ action_link(action.to_sym, prefix)
173
173
  end
174
174
  end
175
175
 
176
176
  # Dynamically builds links for the action
177
- def action_link(action)
177
+ def action_link(action, prefix)
178
178
  html_class = "actions #{action.to_s}_link"
179
179
  self.cell(action, :heading => "", :cell_html => {:class => html_class}) do |resource|
180
+ compound_resource = [prefix, resource].compact
180
181
  case action
181
182
  when :show
182
- @template.link_to("Show", resource)
183
+ @template.link_to("Show", compound_resource)
183
184
  when :edit
184
- @template.link_to("Edit", @template.polymorphic_path(resource, :action => :edit))
185
+ @template.link_to("Edit", @template.polymorphic_path(compound_resource, :action => :edit))
185
186
  when :destroy
186
- @template.link_to("Destroy", resource, :method => :delete)
187
+ @template.link_to("Destroy", compound_resource, :method => :delete)
187
188
  end
188
189
  end
189
190
  end
data/spec/spec_helper.rb CHANGED
@@ -64,7 +64,9 @@ module TabletasticSpecHelper
64
64
 
65
65
  def mock_everything
66
66
  def post_path(post); "/posts/#{post.id}"; end
67
+ def admin_post_path(post); "/admin/posts/#{post.id}"; end
67
68
  def edit_post_path(post); "/posts/#{post.id}/edit"; end
69
+ def edit_admin_post_path(post); "/admin/posts/#{post.id}/edit"; end
68
70
 
69
71
  # Sometimes we need a mock @post object and some Authors for belongs_to
70
72
  @post = mock('post')
@@ -178,6 +178,38 @@ describe "Tabletastic#table_for" do
178
178
  output_buffer.should have_tag("td:nth-child(4) a[@href=/posts/#{@post.id}/edit]", "Edit")
179
179
  output_buffer.should have_tag("td:nth-child(5) a[@href=/posts/#{@post.id}]", "Destroy")
180
180
  end
181
+
182
+ context "with options[:actions_prefix]" do
183
+ it "includes path to admin post for :show" do
184
+ table_for(@posts) do |t|
185
+ concat(t.data(:actions => :show, :action_prefix => :admin))
186
+ end
187
+ output_buffer.should have_tag("td:nth-child(3) a[@href=/admin/posts/#{@post.id}]", "Show")
188
+ end
189
+
190
+ it "includes path to admin post for :edit" do
191
+ table_for(@posts) do |t|
192
+ concat(t.data(:actions => :edit, :action_prefix => :admin))
193
+ end
194
+ output_buffer.should have_tag("td:nth-child(3) a[@href=/admin/posts/#{@post.id}/edit]", "Edit")
195
+ end
196
+
197
+ it "includes path to admin post for :destroy" do
198
+ table_for(@posts) do |t|
199
+ concat(t.data(:actions => :destroy, :action_prefix => :admin))
200
+ end
201
+ output_buffer.should have_tag("td:nth-child(3) a[@href=/admin/posts/#{@post.id}]", "Destroy")
202
+ end
203
+
204
+ it "includes path to admin for all actions" do
205
+ table_for(@posts) do |t|
206
+ concat(t.data(:actions => :all, :action_prefix => :admin))
207
+ end
208
+ output_buffer.should have_tag("td:nth-child(3) a[@href=/admin/posts/#{@post.id}]", "Show")
209
+ output_buffer.should have_tag("td:nth-child(4) a[@href=/admin/posts/#{@post.id}/edit]", "Edit")
210
+ output_buffer.should have_tag("td:nth-child(5) a[@href=/admin/posts/#{@post.id}]", "Destroy")
211
+ end
212
+ end
181
213
  end
182
214
 
183
215
  context "with a list of attributes" do
data/tabletastic.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{tabletastic}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Joshua Davey"]
12
- s.date = %q{2009-11-22}
12
+ s.date = %q{2009-11-25}
13
13
  s.description = %q{A table builder for active record collections that produces semantically rich and accessible markup}
14
14
  s.email = %q{josh@joshuadavey.com}
15
15
  s.extra_rdoc_files = [
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tabletastic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Davey
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-11-22 00:00:00 -06:00
12
+ date: 2009-11-25 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency