shakes 0.4.4 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +86 -19
- data/app/views/shakes/_form.html.erb +3 -3
- data/app/views/shakes/index.html.erb +9 -3
- data/app/views/shakes/show.html.erb +1 -1
- data/lib/shakes/actions/create.rb +2 -2
- data/lib/shakes/actions/destroy.rb +2 -2
- data/lib/shakes/actions/edit.rb +1 -1
- data/lib/shakes/actions/index.rb +1 -1
- data/lib/shakes/actions/new.rb +1 -1
- data/lib/shakes/actions/show.rb +1 -1
- data/lib/shakes/actions/update.rb +3 -3
- data/lib/shakes/has_the_shakes.rb +47 -10
- data/lib/shakes/helpers/url_helper.rb +5 -11
- data/lib/shakes/helpers/views_helper.rb +25 -15
- metadata +4 -4
data/README.md
CHANGED
|
@@ -22,37 +22,102 @@ Tell Rails to install the required gems:
|
|
|
22
22
|
|
|
23
23
|
Using Shakes
|
|
24
24
|
------------
|
|
25
|
-
Using Shakes is simple. If we were working with a new `
|
|
26
|
-
controller and instantly have default actions and views for our new
|
|
25
|
+
Using Shakes is simple. If we were working with a new `ArticlesController`, we could add the following code to our
|
|
26
|
+
controller and instantly have default actions and views for our new controller:
|
|
27
27
|
|
|
28
28
|
class ArticlesController < ApplicationController
|
|
29
29
|
has_the_shakes
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
This will create default implementations of `index`, `new`, `create`, `show`, `edit`, `update` and `destroy` that expect
|
|
33
|
+
to work with an `Article` model. Shakes determined the model by looking at the name of the controller, in this case
|
|
34
|
+
`ArticlesController` because `Article`.
|
|
35
|
+
|
|
36
|
+
If you want to change it you can pass a `resource` option to `has_the_shakes`. If we had a model named `Post`, but we
|
|
37
|
+
want the resources to be served up by an `ArticlesController`, we could do the following:
|
|
38
|
+
|
|
39
|
+
class ArticlesController < ApplicationController
|
|
40
|
+
has_the_shakes :resource => :post
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
If you want to limit the actions that are included by default, you can control this by passing the `only` or `except`
|
|
44
|
+
options to `has_the_shakes`. For example, if you just wanted to use the defaults for `index` and `show` you would use
|
|
45
|
+
the following code:
|
|
34
46
|
|
|
35
47
|
class ArticlesController < ApplicationController
|
|
36
48
|
has_the_shakes :only => [:index, :show]
|
|
37
49
|
end
|
|
38
50
|
|
|
39
|
-
Overriding the default implementation for a specific controller is simple. You
|
|
40
|
-
|
|
51
|
+
Overriding the default implementation for a specific controller is simple. You add your custom action implementation to
|
|
52
|
+
your controller as usual. If I wanted to change my create action to create my new `Article` within the scope of the
|
|
53
|
+
current user, I could use the following code:
|
|
41
54
|
|
|
42
55
|
class ArticlesController < ApplicationController
|
|
43
56
|
has_the_shakes
|
|
44
57
|
|
|
45
58
|
def create
|
|
46
|
-
|
|
59
|
+
@article = @current_user.articles.build(params[:article])
|
|
60
|
+
|
|
61
|
+
respond_to do |format|
|
|
62
|
+
if @article.save
|
|
63
|
+
format.html { redirect_to(@article, :notice => "Article was successfully created.") }
|
|
64
|
+
format.xml { render :xml => @article, :status => :created, :location => @article }
|
|
65
|
+
format.json { render :json => @article, :status => :created, :location => @article }
|
|
66
|
+
else
|
|
67
|
+
format.html { render :action => "new" }
|
|
68
|
+
format.xml { render :xml => @article.errors, :status => :unprocessable_entity }
|
|
69
|
+
format.json { render :json => @article.errors, :status => :unprocessable_entity }
|
|
70
|
+
end
|
|
71
|
+
end
|
|
47
72
|
end
|
|
48
73
|
end
|
|
49
74
|
|
|
50
|
-
Overriding the default views for a specific resource is
|
|
51
|
-
I wanted to
|
|
52
|
-
|
|
75
|
+
Overriding the default views for a specific resource is also simple. Like an action, you just create your view as usual.
|
|
76
|
+
If I wanted my `ArticlesController` to use a custom view for the `show` action, I would just create my custom view at
|
|
77
|
+
`app/views/article/show.html.erb`:
|
|
78
|
+
|
|
79
|
+
<div class="article">
|
|
80
|
+
<div class="section">
|
|
81
|
+
<%= content_tag :h1, h(@article.title) %>
|
|
82
|
+
<%= content_tag :p, h(@article.content) %>
|
|
83
|
+
</div>
|
|
84
|
+
</div>
|
|
85
|
+
<div class="aside">
|
|
86
|
+
<div class="section">
|
|
87
|
+
<h1>Related Links</h1>
|
|
88
|
+
<ul class="links">
|
|
89
|
+
<%= content_tag :li, link_to('Edit', edit_article_path(@article)) %>
|
|
90
|
+
<%= content_tag :li, link_to('Back', articles_path(@article)) %>
|
|
91
|
+
</ul>
|
|
92
|
+
</div>
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
Managing Attributes
|
|
96
|
+
-------------------
|
|
97
|
+
Shakes does its best to automatically determine the attributes on your models. If left to its own devices, Shakes will
|
|
98
|
+
use all of the attributes defined in your migrations with the exception of `id`, `created_at` and `updated_at`, but
|
|
99
|
+
sometimes this just isn't enough.
|
|
100
|
+
|
|
101
|
+
You can use the `resource_attributes` hint to help Shakes determine which attributes are available your model. You can
|
|
102
|
+
pass the options `only`, `except` or `with`. The `only` and `except` options work as you would expect. The `with` option
|
|
103
|
+
allows you to specify any additional attributes that are available. If you've defined a virtual attribute on your
|
|
104
|
+
`Article` model named `tag_list`, you would tell Shakes about it like so:
|
|
53
105
|
|
|
54
|
-
|
|
55
|
-
|
|
106
|
+
class ArticlesController < ApplicationController
|
|
107
|
+
has_the_shakes
|
|
108
|
+
resource_attributes :with => [:tag_list]
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
If you need to control which attributes should be used for a specific view, you can do this as well. The
|
|
112
|
+
`index_attributes`, `show_attributes`, `new_attributes` and `edit_attributes` hints are all available. If you want to
|
|
113
|
+
manage your `new` and `edit` views at the same time, there is a combined `form_attributes` hint as well. All of these
|
|
114
|
+
additional hints take the options `only`, `except` and `with`.
|
|
115
|
+
|
|
116
|
+
For all attribute hints, I recommend using `except` or `with` over `only`. This allows Shakes to pick up changes to your
|
|
117
|
+
models at the migration level.
|
|
118
|
+
|
|
119
|
+
Changing The Default Actions
|
|
120
|
+
----------------------------
|
|
56
121
|
You can change the default actions that Shakes uses. First you need to install the Shakes initializer at
|
|
57
122
|
`config/initializers/shakes.rb`. Run the following command to install the initialization file (this will also generate a
|
|
58
123
|
Shakes aware layout):
|
|
@@ -64,7 +129,7 @@ action I would create a module like so:
|
|
|
64
129
|
|
|
65
130
|
module ShakesIndexOverride
|
|
66
131
|
def index
|
|
67
|
-
# default index implementation goes here
|
|
132
|
+
# new default index implementation goes here
|
|
68
133
|
end
|
|
69
134
|
end
|
|
70
135
|
|
|
@@ -75,8 +140,8 @@ configuration to the following:
|
|
|
75
140
|
# Set the default index action module. Default is Shakes::Actions::Index
|
|
76
141
|
Shakes::HasTheShakes::Configuration.index_action = ShakesIndexOverride
|
|
77
142
|
|
|
78
|
-
|
|
79
|
-
|
|
143
|
+
Changing The Default Views
|
|
144
|
+
--------------------------
|
|
80
145
|
If you want to change the default views that Shakes uses, you can run the following command and editable files will be
|
|
81
146
|
placed in `app/views/shakes`:
|
|
82
147
|
|
|
@@ -85,7 +150,7 @@ placed in `app/views/shakes`:
|
|
|
85
150
|
Now, if I wanted the show view to render like the original scaffold markup, I could do that by modifying
|
|
86
151
|
`app/views/shakes/show.html.erb` to the following:
|
|
87
152
|
|
|
88
|
-
<%-
|
|
153
|
+
<%- show_attributes.each do |field| -%>
|
|
89
154
|
<% content_tag :p do %>
|
|
90
155
|
<%= content_tag :b, shakes_human_attribute_name_for(field) %>
|
|
91
156
|
<%= h @resource[field] %>
|
|
@@ -112,8 +177,8 @@ Than you can modify `config/initializers/shakes.rb` like so:
|
|
|
112
177
|
Shakes::Helpers::ViewsHelper::Configuration.use_markdown = true
|
|
113
178
|
|
|
114
179
|
|
|
115
|
-
Shakes Aware Layouts
|
|
116
|
-
|
|
180
|
+
Creating Shakes Aware Layouts
|
|
181
|
+
-----------------------------
|
|
117
182
|
To get the most out of Shakes, I suggest you install and use the stylesheets that are included in the gem. Run the
|
|
118
183
|
following command to install the stylesheets and create a version of `app/views/layouts/application.html.erb` that
|
|
119
184
|
includes them for you:
|
|
@@ -127,4 +192,6 @@ following command will create a new Shakes aware layout at `app/views/layouts/ar
|
|
|
127
192
|
|
|
128
193
|
TODO
|
|
129
194
|
----
|
|
130
|
-
*
|
|
195
|
+
* Add validation error messages to forms
|
|
196
|
+
* Style flash messages
|
|
197
|
+
* Support Rails 3
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
<%- unless Shakes::Helpers::ViewsHelper::Configuration.use_formtastic -%>
|
|
2
|
-
<% form_for(@resource, :url =>
|
|
2
|
+
<% form_for(@resource, :url => controller_action_path(controller, ((action.eql? :new) ? :create : :update ), @resource)) do |form| %>
|
|
3
3
|
<fieldset class="fields">
|
|
4
4
|
<ol>
|
|
5
|
-
<%-
|
|
5
|
+
<%- form_attributes(action).each do |field| -%>
|
|
6
6
|
<% content_tag :li, :class => ['field', shakes_field_type_for(field).to_s].join(' ') do -%>
|
|
7
7
|
<%= shakes_render_field field, action, @resource, form %>
|
|
8
8
|
<%- end %>
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
</fieldset>
|
|
19
19
|
<% end %>
|
|
20
20
|
<%- else -%>
|
|
21
|
-
<% semantic_form_for(@resource, :url =>
|
|
21
|
+
<% semantic_form_for(@resource, :url => controller_action_path(controller, action, @resource)) do |form| %>
|
|
22
22
|
<%= form.inputs %>
|
|
23
23
|
<%= form.buttons %>
|
|
24
24
|
<% end %>
|
|
@@ -3,18 +3,24 @@
|
|
|
3
3
|
<%= title "List #{shakes_human_name.pluralize}", :h1 %>
|
|
4
4
|
<table class="collection">
|
|
5
5
|
<tr class="headers">
|
|
6
|
-
<%-
|
|
6
|
+
<%- index_attributes.each do |field| -%>
|
|
7
7
|
<%= content_tag :th, shakes_human_attribute_name_for(field).titleize %>
|
|
8
8
|
<%- end -%>
|
|
9
9
|
<%= content_tag :th, 'Actions', :class => 'actions' %>
|
|
10
10
|
</tr>
|
|
11
11
|
<%- @resources.each do |resource| -%>
|
|
12
12
|
<tr class="fields">
|
|
13
|
-
<%-
|
|
13
|
+
<%- index_attributes.each do |field| -%>
|
|
14
14
|
<%= content_tag :td, shakes_render_field(field, :index, resource),
|
|
15
15
|
:class => ['field', shakes_field_type_for(field).to_s].join(' ') %>
|
|
16
16
|
<%- end -%>
|
|
17
|
-
|
|
17
|
+
<% content_tag :td, :class => 'actions' do %>
|
|
18
|
+
<ul class="links">
|
|
19
|
+
<% shakes_link_to_for([:show, :edit, :destroy], resource, :short_name => true).each do |link| %>
|
|
20
|
+
<%= content_tag :li, link %>
|
|
21
|
+
<% end %>
|
|
22
|
+
</ul>
|
|
23
|
+
<% end %>
|
|
18
24
|
</tr>
|
|
19
25
|
<%- end -%>
|
|
20
26
|
</table>
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
<div class="section">
|
|
3
3
|
<%= title "Show #{shakes_human_name}", :h1 %>
|
|
4
4
|
<ol class="fields">
|
|
5
|
-
<%-
|
|
5
|
+
<%- show_attributes.each do |field| -%>
|
|
6
6
|
<% content_tag :li, :class => ['field', shakes_field_type_for(field).to_s].join(' ') do -%>
|
|
7
7
|
<%= shakes_render_field field, :show, @resource %>
|
|
8
8
|
<%- end %>
|
|
@@ -2,11 +2,11 @@ module Shakes
|
|
|
2
2
|
module Actions
|
|
3
3
|
module Create
|
|
4
4
|
def create
|
|
5
|
-
@resource = instance_variable_set("@#{self.class.
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.resource_name}", self.class.resource_class.new(params[self.class.resource_name.to_sym]))
|
|
6
6
|
|
|
7
7
|
respond_to do |format|
|
|
8
8
|
if @resource.save
|
|
9
|
-
format.html { redirect_to(
|
|
9
|
+
format.html { redirect_to(controller_action_path(self, :show, @resource), :notice => "#{self.class.resource_class.to_s} was successfully created.") }
|
|
10
10
|
format.xml { render :xml => @resource, :status => :created, :location => @resource }
|
|
11
11
|
format.json { render :json => @resource, :status => :created, :location => @resource }
|
|
12
12
|
else
|
|
@@ -2,11 +2,11 @@ module Shakes
|
|
|
2
2
|
module Actions
|
|
3
3
|
module Destroy
|
|
4
4
|
def destroy
|
|
5
|
-
@resource = instance_variable_set("@#{self.class.
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.resource_name}", self.class.resource_class.find(params[:id]))
|
|
6
6
|
@resource.destroy
|
|
7
7
|
|
|
8
8
|
respond_to do |format|
|
|
9
|
-
format.html { redirect_to(
|
|
9
|
+
format.html { redirect_to(controller_action_path(self, :index)) }
|
|
10
10
|
format.xml { head :ok }
|
|
11
11
|
format.json { head :ok }
|
|
12
12
|
end
|
data/lib/shakes/actions/edit.rb
CHANGED
|
@@ -2,7 +2,7 @@ module Shakes
|
|
|
2
2
|
module Actions
|
|
3
3
|
module Edit
|
|
4
4
|
def edit
|
|
5
|
-
@resource = instance_variable_set("@#{self.class.
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.resource_name}", self.class.resource_class.find(params[:id]))
|
|
6
6
|
end
|
|
7
7
|
end
|
|
8
8
|
end
|
data/lib/shakes/actions/index.rb
CHANGED
|
@@ -2,7 +2,7 @@ module Shakes
|
|
|
2
2
|
module Actions
|
|
3
3
|
module Index
|
|
4
4
|
def index
|
|
5
|
-
@resources = instance_variable_set("@#{self.class.
|
|
5
|
+
@resources = instance_variable_set("@#{self.class.resource_collection_name}", self.class.resource_class.all)
|
|
6
6
|
|
|
7
7
|
respond_to do |format|
|
|
8
8
|
format.html # index.html.erb
|
data/lib/shakes/actions/new.rb
CHANGED
|
@@ -2,7 +2,7 @@ module Shakes
|
|
|
2
2
|
module Actions
|
|
3
3
|
module New
|
|
4
4
|
def new
|
|
5
|
-
@resource = instance_variable_set("@#{self.class.
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.resource_name}", self.class.resource_class.new)
|
|
6
6
|
|
|
7
7
|
respond_to do |format|
|
|
8
8
|
format.html # new.html.erb
|
data/lib/shakes/actions/show.rb
CHANGED
|
@@ -2,7 +2,7 @@ module Shakes
|
|
|
2
2
|
module Actions
|
|
3
3
|
module Show
|
|
4
4
|
def show
|
|
5
|
-
@resource = instance_variable_set("@#{self.class.
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.resource_name}", self.class.resource_class.find(params[:id]))
|
|
6
6
|
|
|
7
7
|
respond_to do |format|
|
|
8
8
|
format.html # show.html.erb
|
|
@@ -2,11 +2,11 @@ module Shakes
|
|
|
2
2
|
module Actions
|
|
3
3
|
module Update
|
|
4
4
|
def update
|
|
5
|
-
@resource = instance_variable_set("@#{self.class.
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.resource_name}", self.class.resource_class.find(params[:id]))
|
|
6
6
|
|
|
7
7
|
respond_to do |format|
|
|
8
|
-
if @resource.update_attributes(params[self.class.
|
|
9
|
-
format.html { redirect_to(
|
|
8
|
+
if @resource.update_attributes(params[self.class.resource_name.to_sym])
|
|
9
|
+
format.html { redirect_to(controller_action_path(self, :show, @resource), :notice => "#{self.class.resource_class.to_s} was successfully updated.") }
|
|
10
10
|
format.xml { head :ok }
|
|
11
11
|
format.json { head :ok }
|
|
12
12
|
else
|
|
@@ -19,16 +19,17 @@ module Shakes
|
|
|
19
19
|
|
|
20
20
|
module ClassMethods
|
|
21
21
|
def has_the_shakes(options={})
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
self.shakes_resource ||= Object::const_get(self.shakes_resource_name.classify)
|
|
22
|
+
|
|
23
|
+
cattr_accessor :resource_name
|
|
24
|
+
self.resource_name ||= options[:resource] ? options[:resource].to_s.singularize : self.controller_name.singularize
|
|
25
|
+
cattr_accessor :resource_collection_name
|
|
26
|
+
self.resource_collection_name ||= self.resource_name.pluralize
|
|
27
|
+
cattr_accessor :resource_class
|
|
28
|
+
self.resource_class ||= Object::const_get(self.resource_name.classify)
|
|
30
29
|
send :include, InstanceMethods
|
|
31
30
|
|
|
31
|
+
# puts "resource: #{self.method(:resource)}"
|
|
32
|
+
|
|
32
33
|
cattr_accessor :shakes_actions
|
|
33
34
|
self.shakes_actions = (options[:only] || SHAKES_ACTIONS) - (options[:except] || [])
|
|
34
35
|
send :include, Configuration.index_action if self.shakes_actions.include? :index
|
|
@@ -39,6 +40,42 @@ module Shakes
|
|
|
39
40
|
send :include, Configuration.update_action if self.shakes_actions.include? :update
|
|
40
41
|
send :include, Configuration.destroy_action if self.shakes_actions.include? :destroy
|
|
41
42
|
end
|
|
43
|
+
|
|
44
|
+
def resource_attributes(options={})
|
|
45
|
+
@resource_attributes = (options[:only] || default_resource_attributes) + (options[:with] || []) - (options[:except] || []) unless options.empty?
|
|
46
|
+
@resource_attributes || default_resource_attributes
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def index_attributes(options={})
|
|
50
|
+
@index_attributes = (options[:only] || resource_attributes) + (options[:with] || []) - (options[:except] || []) unless options.empty?
|
|
51
|
+
@index_attributes || resource_attributes
|
|
52
|
+
end
|
|
53
|
+
|
|
54
|
+
def show_attributes(options={})
|
|
55
|
+
@show_attributes = (options[:only] || resource_attributes) + (options[:with] || []) - (options[:except] || []) unless options.empty?
|
|
56
|
+
@show_attributes || resource_attributes
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def form_attributes(options={})
|
|
60
|
+
@form_attributes = (options[:only] || resource_attributes) + (options[:with] || []) - (options[:except] || []) unless options.empty?
|
|
61
|
+
@form_attributes || resource_attributes
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def new_attributes(options={})
|
|
65
|
+
@new_attributes = (options[:only] || resource_attributes) + (options[:with] || []) - (options[:except] || []) unless options.empty?
|
|
66
|
+
@new_attributes || form_attributes
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
def edit_attributes(options={})
|
|
70
|
+
@edit_attributes = (options[:only] || resource_attributes) + (options[:with] || []) - (options[:except] || []) unless options.empty?
|
|
71
|
+
@edit_attributes || form_attributes
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
protected
|
|
75
|
+
|
|
76
|
+
def default_resource_attributes
|
|
77
|
+
(self.resource_class.column_names - %w{id created_at updated_at}).map { |f| f.to_sym }
|
|
78
|
+
end
|
|
42
79
|
end
|
|
43
80
|
|
|
44
81
|
module InstanceMethods
|
|
@@ -57,8 +94,8 @@ module Shakes
|
|
|
57
94
|
private
|
|
58
95
|
|
|
59
96
|
def locate_resource?
|
|
60
|
-
@resources ||= instance_variable_get("@#{self.class.
|
|
61
|
-
@resource ||= instance_variable_get("@#{self.class.
|
|
97
|
+
@resources ||= instance_variable_get("@#{self.class.resource_collection_name}")
|
|
98
|
+
@resource ||= instance_variable_get("@#{self.class.resource_name}")
|
|
62
99
|
(@resources || @resource)
|
|
63
100
|
end
|
|
64
101
|
end
|
|
@@ -1,24 +1,18 @@
|
|
|
1
1
|
module Shakes
|
|
2
2
|
module Helpers
|
|
3
3
|
module UrlHelper
|
|
4
|
-
def
|
|
4
|
+
def controller_action_path(controller, action, resource=nil)
|
|
5
5
|
case action
|
|
6
6
|
when :index, :create
|
|
7
|
-
method("#{
|
|
7
|
+
method("#{controller.class.controller_name}_path".to_sym).call
|
|
8
8
|
when :new
|
|
9
|
-
method("new_#{
|
|
9
|
+
method("new_#{controller.class.controller_name.singularize}_path".to_sym).call
|
|
10
10
|
when :show, :update, :destroy
|
|
11
|
-
method("#{
|
|
11
|
+
method("#{controller.class.controller_name.singularize}_path".to_sym).call(resource)
|
|
12
12
|
when :edit
|
|
13
|
-
method("edit_#{
|
|
13
|
+
method("edit_#{controller.class.controller_name.singularize}_path".to_sym).call(resource)
|
|
14
14
|
end
|
|
15
15
|
end
|
|
16
|
-
|
|
17
|
-
private
|
|
18
|
-
|
|
19
|
-
def shakes_controller_name
|
|
20
|
-
(controller || self).class.shakes_controller_name
|
|
21
|
-
end
|
|
22
16
|
end
|
|
23
17
|
end
|
|
24
18
|
end
|
|
@@ -12,24 +12,35 @@ module Shakes
|
|
|
12
12
|
(args.empty?) ? @shakes_title : content_tag(args.shift, @shakes_title, (args.shift || {}))
|
|
13
13
|
end
|
|
14
14
|
|
|
15
|
+
def index_attributes
|
|
16
|
+
controller.class.index_attributes
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def show_attributes
|
|
20
|
+
controller.class.show_attributes
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def form_attributes(action)
|
|
24
|
+
(action.eql? :new) ? controller.class.new_attributes : controller.class.edit_attributes
|
|
25
|
+
end
|
|
26
|
+
|
|
15
27
|
def shakedown(content, options={})
|
|
16
28
|
Configuration.use_markdown && options[:markdown] ? markdown(h(content)) : h(content)
|
|
17
29
|
end
|
|
30
|
+
|
|
31
|
+
|
|
18
32
|
|
|
19
33
|
def shakes_field_type_for(field)
|
|
20
|
-
controller.class.
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
def shakes_fields_for(action)
|
|
24
|
-
(controller.class.shakes_resource.column_names - %w{id created_at updated_at}).map { |f| f.to_sym }
|
|
34
|
+
columns_hash = controller.class.resource_class.columns_hash
|
|
35
|
+
(columns_hash.has_key? field.to_s) ? columns_hash[field.to_s].type : 'string'
|
|
25
36
|
end
|
|
26
37
|
|
|
27
38
|
def shakes_human_attribute_name_for(field)
|
|
28
|
-
controller.class.
|
|
39
|
+
controller.class.resource_class.human_attribute_name field
|
|
29
40
|
end
|
|
30
41
|
|
|
31
42
|
def shakes_human_name
|
|
32
|
-
controller.class.
|
|
43
|
+
controller.class.resource_class.human_name
|
|
33
44
|
end
|
|
34
45
|
|
|
35
46
|
def shakes_link_to_for(actions=[], *args)
|
|
@@ -40,15 +51,15 @@ module Shakes
|
|
|
40
51
|
(actions.map { |action| action.to_sym }).each do |action|
|
|
41
52
|
case action
|
|
42
53
|
when :index
|
|
43
|
-
links << link_to((options[:short_name] ? 'List' : "List all #{shakes_human_name.pluralize}"),
|
|
54
|
+
links << link_to((options[:short_name] ? 'List' : "List all #{shakes_human_name.pluralize}"), controller_action_path(controller, :index)) if controller.respond_to? :index
|
|
44
55
|
when :new
|
|
45
|
-
links << link_to((options[:short_name] ? 'New' : "Create a new #{shakes_human_name}"),
|
|
56
|
+
links << link_to((options[:short_name] ? 'New' : "Create a new #{shakes_human_name}"), controller_action_path(controller, :new)) if controller.respond_to? :new
|
|
46
57
|
when :show
|
|
47
|
-
links << link_to((options[:short_name] ? 'Show' : "Show this #{shakes_human_name}"),
|
|
58
|
+
links << link_to((options[:short_name] ? 'Show' : "Show this #{shakes_human_name}"), controller_action_path(controller, :show, resource)) if controller.respond_to? :show
|
|
48
59
|
when :edit
|
|
49
|
-
links << link_to((options[:short_name] ? 'Edit' : "Edit this #{shakes_human_name}"),
|
|
60
|
+
links << link_to((options[:short_name] ? 'Edit' : "Edit this #{shakes_human_name}"), controller_action_path(controller, :edit, resource)) if controller.respond_to? :edit
|
|
50
61
|
when :destroy
|
|
51
|
-
links << link_to((options[:short_name] ? 'Delete' : "Delete this #{shakes_human_name}"),
|
|
62
|
+
links << link_to((options[:short_name] ? 'Delete' : "Delete this #{shakes_human_name}"), controller_action_path(controller, :destroy, resource), :confirm => 'Are you sure?', :method => :delete) if controller.respond_to? :destroy
|
|
52
63
|
end
|
|
53
64
|
end
|
|
54
65
|
links
|
|
@@ -59,7 +70,7 @@ module Shakes
|
|
|
59
70
|
:locals => { :action => action, :field => field, :resource => resource, :form => form }
|
|
60
71
|
end
|
|
61
72
|
|
|
62
|
-
|
|
73
|
+
private
|
|
63
74
|
|
|
64
75
|
def partial_directory_for(action)
|
|
65
76
|
case action.to_sym
|
|
@@ -71,8 +82,7 @@ module Shakes
|
|
|
71
82
|
end
|
|
72
83
|
|
|
73
84
|
def partial_name_for(field, action)
|
|
74
|
-
field_type = (
|
|
75
|
-
|
|
85
|
+
field_type = shakes_field_type_for(field).to_sym
|
|
76
86
|
case action.to_sym
|
|
77
87
|
when :new, :edit
|
|
78
88
|
case field_type
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: shakes
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
hash:
|
|
4
|
+
hash: 11
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
9
|
-
-
|
|
10
|
-
version: 0.
|
|
8
|
+
- 5
|
|
9
|
+
- 0
|
|
10
|
+
version: 0.5.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Jason Stahl
|