shakes 0.7.0 → 0.8.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 +6 -9
- data/app/views/shakes/_form.html.erb +5 -12
- data/app/views/shakes/edit.html.erb +2 -2
- data/app/views/shakes/form/_boolean.html.erb +2 -2
- data/app/views/shakes/form/_date.html.erb +2 -2
- data/app/views/shakes/form/_datetime.html.erb +2 -2
- data/app/views/shakes/form/_field.html.erb +2 -2
- data/app/views/shakes/form/_text.html.erb +2 -2
- data/app/views/shakes/form/_time.html.erb +2 -2
- data/app/views/shakes/index.html.erb +8 -8
- data/app/views/shakes/index/_field.html.erb +1 -1
- data/app/views/shakes/index/_text.html.erb +1 -1
- data/app/views/shakes/new.html.erb +2 -2
- data/app/views/shakes/show.html.erb +5 -5
- data/app/views/shakes/show/_field.html.erb +2 -2
- data/app/views/shakes/show/_text.html.erb +2 -2
- data/lib/shakes/actions/create.rb +1 -1
- data/lib/shakes/actions/destroy.rb +1 -1
- data/lib/shakes/actions/update.rb +1 -1
- data/lib/shakes/has_the_shakes.rb +4 -0
- data/lib/shakes/helpers/views_helper.rb +66 -38
- metadata +3 -3
data/README.md
CHANGED
|
@@ -173,18 +173,14 @@ following command will create a new Shakes aware layout at `app/views/layouts/ar
|
|
|
173
173
|
|
|
174
174
|
Configuring The Views
|
|
175
175
|
---------------------
|
|
176
|
-
There
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
You can do that by running the following command (this will also generate a Shakes aware layout):
|
|
176
|
+
There is only one configuration options available at the moment when rendering Shakes views. It tells Shakes to use
|
|
177
|
+
Markdown to render text fields. It defaults to `false`. To change it to `true` you need to install the Shakes
|
|
178
|
+
initializer. You can do that by running the following command (this will also generate a Shakes aware layout):
|
|
180
179
|
|
|
181
180
|
script/generate shakes
|
|
182
181
|
|
|
183
182
|
Than you can modify `config/initializers/shakes.rb` like so:
|
|
184
183
|
|
|
185
|
-
# Should Shakes attempt to use formtastic to render forms. Default is false
|
|
186
|
-
Shakes::Helpers::ViewsHelper::Configuration.use_formtastic = true
|
|
187
|
-
|
|
188
184
|
# Should Shakes attempt to use markdown to display text fields. Default is false
|
|
189
185
|
Shakes::Helpers::ViewsHelper::Configuration.use_markdown = true
|
|
190
186
|
|
|
@@ -246,11 +242,11 @@ Now, if I wanted the show view to render like the original scaffold markup, I co
|
|
|
246
242
|
|
|
247
243
|
<%- show_attributes.each do |field| -%>
|
|
248
244
|
<% content_tag :p do %>
|
|
249
|
-
<%= content_tag :b,
|
|
245
|
+
<%= content_tag :b, attribute_human_name(field) %>
|
|
250
246
|
<%= h @resource[field] %>
|
|
251
247
|
<% end %>
|
|
252
248
|
<%- end -%>
|
|
253
|
-
<%=
|
|
249
|
+
<%= links_to_actions([:edit, :index], @resource) %>
|
|
254
250
|
|
|
255
251
|
Alternatively, I could have just created `app/views/shakes/show.html.erb` without running the generator if that's all I
|
|
256
252
|
wanted to change.
|
|
@@ -260,6 +256,7 @@ TODO
|
|
|
260
256
|
* Add validation error messages to forms
|
|
261
257
|
* Style flash messages
|
|
262
258
|
* Support custom actions and views
|
|
259
|
+
* Support nested resources
|
|
263
260
|
* Support Rails 3
|
|
264
261
|
|
|
265
262
|
Copyright
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
|
|
2
|
-
<% form_for(@resource, :url => controller_action_path(controller, ((action.eql? :new) ? :create : :update ), @resource)) do |form| %>
|
|
1
|
+
<% form_for(@resource, :url => action_path(((action.eql? :new) ? :create : :update ), @resource)) do |form| %>
|
|
3
2
|
<fieldset class="fields">
|
|
4
3
|
<ol>
|
|
5
|
-
<%- form_attributes(action).each do |
|
|
6
|
-
<% content_tag :li, :class => ['
|
|
7
|
-
<%=
|
|
4
|
+
<%- form_attributes(action).each do |attribute| -%>
|
|
5
|
+
<% content_tag :li, :class => ['attribute', attribute_type(attribute).to_s].join(' ') do -%>
|
|
6
|
+
<%= render_attribute action, attribute, @resource, form %>
|
|
8
7
|
<%- end %>
|
|
9
8
|
<%- end -%>
|
|
10
9
|
</ol>
|
|
@@ -12,14 +11,8 @@
|
|
|
12
11
|
<fieldset class="buttons">
|
|
13
12
|
<ol>
|
|
14
13
|
<% content_tag :li, :class => 'commit' do -%>
|
|
15
|
-
<%= form.submit "#{((action.eql? :new) ? 'Create' : 'Update')} #{
|
|
14
|
+
<%= form.submit "#{((action.eql? :new) ? 'Create' : 'Update')} #{controller_human_name}" %>
|
|
16
15
|
<%- end %>
|
|
17
16
|
</ol>
|
|
18
17
|
</fieldset>
|
|
19
18
|
<% end %>
|
|
20
|
-
<%- else -%>
|
|
21
|
-
<% semantic_form_for(@resource, :url => controller_action_path(controller, action, @resource)) do |form| %>
|
|
22
|
-
<%= form.inputs %>
|
|
23
|
-
<%= form.buttons %>
|
|
24
|
-
<% end %>
|
|
25
|
-
<%- end -%>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div class="article">
|
|
2
2
|
<div class="section">
|
|
3
|
-
<%= title "Edit #{
|
|
3
|
+
<%= title "Edit #{controller_human_name}", :h1 %>
|
|
4
4
|
<%= render :partial => 'shakes/form', :locals => { :action => :edit } %>
|
|
5
5
|
</div>
|
|
6
6
|
</div>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<div class="section">
|
|
9
9
|
<h1>Related Links</h1>
|
|
10
10
|
<ul class="links">
|
|
11
|
-
<%-
|
|
11
|
+
<%- links_to_actions([:show, :destroy, :index], @resource).each do |link| -%>
|
|
12
12
|
<%= content_tag :li, link%>
|
|
13
13
|
<%- end -%>
|
|
14
14
|
</ul>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<%= form.label
|
|
2
|
-
<%= form.check_box
|
|
1
|
+
<%= form.label attribute, attribute_human_name(attribute).titleize %>
|
|
2
|
+
<%= form.check_box attribute %>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<%= form.label
|
|
2
|
-
<%= form.date_select
|
|
1
|
+
<%= form.label attribute, attribute_human_name(attribute).titleize %>
|
|
2
|
+
<%= form.date_select attribute %>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<%= form.label
|
|
2
|
-
<%= form.datetime_select
|
|
1
|
+
<%= form.label attribute, attribute_human_name(attribute).titleize %>
|
|
2
|
+
<%= form.datetime_select attribute %>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<%= form.label
|
|
2
|
-
<%= form.text_field
|
|
1
|
+
<%= form.label attribute, attribute_human_name(attribute).titleize %>
|
|
2
|
+
<%= form.text_field attribute %>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<%= form.label
|
|
2
|
-
<%= form.text_area
|
|
1
|
+
<%= form.label attribute, attribute_human_name(attribute).titleize %>
|
|
2
|
+
<%= form.text_area attribute, :rows => 10 %>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<%= form.label
|
|
2
|
-
<%= form.time_select
|
|
1
|
+
<%= form.label attribute, attribute_human_name(attribute).titleize %>
|
|
2
|
+
<%= form.time_select attribute %>
|
|
@@ -1,22 +1,22 @@
|
|
|
1
1
|
<div class="article">
|
|
2
2
|
<div class="section">
|
|
3
|
-
<%= title "List #{
|
|
3
|
+
<%= title "List #{controller_human_name.pluralize}", :h1 %>
|
|
4
4
|
<table class="collection">
|
|
5
5
|
<tr class="headers">
|
|
6
|
-
<%- index_attributes.each do |
|
|
7
|
-
<%= content_tag :th,
|
|
6
|
+
<%- index_attributes.each do |attribute| -%>
|
|
7
|
+
<%= content_tag :th, attribute_human_name(attribute).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
|
-
<%- index_attributes.each do |
|
|
14
|
-
<%= content_tag :td,
|
|
15
|
-
:class => ['field',
|
|
13
|
+
<%- index_attributes.each do |attribute| -%>
|
|
14
|
+
<%= content_tag :td, render_attribute(:index, attribute, resource),
|
|
15
|
+
:class => ['field', attribute_type(attribute).to_s].join(' ') %>
|
|
16
16
|
<%- end -%>
|
|
17
17
|
<% content_tag :td, :class => 'actions' do %>
|
|
18
18
|
<ul class="links">
|
|
19
|
-
<%
|
|
19
|
+
<% links_to_actions([:show, :edit, :destroy], resource, :short => true).each do |link| %>
|
|
20
20
|
<%= content_tag :li, link %>
|
|
21
21
|
<% end %>
|
|
22
22
|
</ul>
|
|
@@ -30,7 +30,7 @@
|
|
|
30
30
|
<div class="section">
|
|
31
31
|
<h1>Related Links</h1>
|
|
32
32
|
<ul class="links">
|
|
33
|
-
<%-
|
|
33
|
+
<%- links_to_actions([:new], @resource).each do |link| -%>
|
|
34
34
|
<%= content_tag :li, link%>
|
|
35
35
|
<%- end -%>
|
|
36
36
|
</ul>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<%= h(resource[
|
|
1
|
+
<%= h(resource[attribute]) %>
|
|
@@ -1 +1 @@
|
|
|
1
|
-
<%= resource[
|
|
1
|
+
<%= resource[attribute].length > 255 ? shakedown("#{resource[attribute][0,252]}...") : shakedown(resource[attribute]) %>
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<div class="article">
|
|
2
2
|
<div class="section">
|
|
3
|
-
<%= title "New #{
|
|
3
|
+
<%= title "New #{controller_human_name}", :h1 %>
|
|
4
4
|
<%= render :partial => 'shakes/form', :locals => { :action => :new } %>
|
|
5
5
|
</div>
|
|
6
6
|
</div>
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
<div class="section">
|
|
9
9
|
<h1>Related Links</h1>
|
|
10
10
|
<ul class="links">
|
|
11
|
-
<%-
|
|
11
|
+
<%- links_to_actions([:index], @resource).each do |link| -%>
|
|
12
12
|
<%= content_tag :li, link%>
|
|
13
13
|
<%- end -%>
|
|
14
14
|
</ul>
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
<div class="article">
|
|
2
2
|
<div class="section">
|
|
3
|
-
<%= title "Show #{
|
|
3
|
+
<%= title "Show #{controller_human_name}", :h1 %>
|
|
4
4
|
<ol class="fields">
|
|
5
|
-
<%- show_attributes.each do |
|
|
6
|
-
<% content_tag :li, :class => ['
|
|
7
|
-
<%=
|
|
5
|
+
<%- show_attributes.each do |attribute| -%>
|
|
6
|
+
<% content_tag :li, :class => ['attribute', attribute_type(attribute).to_s].join(' ') do -%>
|
|
7
|
+
<%= render_attribute :show, attribute, @resource %>
|
|
8
8
|
<%- end %>
|
|
9
9
|
<%- end -%>
|
|
10
10
|
</ol>
|
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
<div class="section">
|
|
15
15
|
<h1>Related Links</h1>
|
|
16
16
|
<ul class="links">
|
|
17
|
-
<%-
|
|
17
|
+
<%- links_to_actions([:edit, :destroy, :index], @resource).each do |link| -%>
|
|
18
18
|
<%= content_tag :li, link%>
|
|
19
19
|
<%- end -%>
|
|
20
20
|
</ul>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<%= content_tag :label,
|
|
2
|
-
<%= content_tag :span, h(resource[
|
|
1
|
+
<%= content_tag :label, attribute_human_name(attribute).titleize %>
|
|
2
|
+
<%= content_tag :span, h(resource[attribute]) %>
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
<%= content_tag :label,
|
|
2
|
-
<%= content_tag :div, shakedown(resource[
|
|
1
|
+
<%= content_tag :label, attribute_human_name(attribute).titleize %>
|
|
2
|
+
<%= content_tag :div, shakedown(resource[attribute]) %>
|
|
@@ -6,7 +6,7 @@ module Shakes
|
|
|
6
6
|
|
|
7
7
|
respond_to do |format|
|
|
8
8
|
if @resource.save
|
|
9
|
-
format.html { redirect_to(
|
|
9
|
+
format.html { redirect_to(action_path(:show, @resource), :notice => "#{self.class.model_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
|
|
@@ -6,7 +6,7 @@ module Shakes
|
|
|
6
6
|
|
|
7
7
|
respond_to do |format|
|
|
8
8
|
if @resource.update_attributes(params[self.class.model_name.to_sym])
|
|
9
|
-
format.html { redirect_to(
|
|
9
|
+
format.html { redirect_to(action_path(:show, @resource), :notice => "#{self.class.model_class.to_s} was successfully updated.") }
|
|
10
10
|
format.xml { head :ok }
|
|
11
11
|
format.json { head :ok }
|
|
12
12
|
else
|
|
@@ -2,8 +2,7 @@ module Shakes
|
|
|
2
2
|
module Helpers
|
|
3
3
|
module ViewsHelper
|
|
4
4
|
class Configuration
|
|
5
|
-
cattr_accessor :
|
|
6
|
-
self.use_formtastic = false
|
|
5
|
+
cattr_accessor :use_markdown
|
|
7
6
|
self.use_markdown = false
|
|
8
7
|
end
|
|
9
8
|
|
|
@@ -23,56 +22,85 @@ module Shakes
|
|
|
23
22
|
def form_attributes(action)
|
|
24
23
|
(action.eql? :new) ? controller.class.new_attributes : controller.class.edit_attributes
|
|
25
24
|
end
|
|
26
|
-
|
|
27
|
-
def shakedown(content, options={})
|
|
28
|
-
Configuration.use_markdown && options[:markdown] ? markdown(h(content)) : h(content)
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
|
|
32
25
|
|
|
33
|
-
def
|
|
26
|
+
def attribute_type(attribute)
|
|
34
27
|
columns_hash = controller.class.model_class.columns_hash
|
|
35
|
-
(columns_hash.has_key?
|
|
28
|
+
(columns_hash.has_key? attribute.to_s) ? columns_hash[attribute.to_s].type : 'string'
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
def controller_human_name
|
|
32
|
+
controller.class.model_class.human_name
|
|
36
33
|
end
|
|
37
34
|
|
|
38
|
-
def
|
|
39
|
-
controller.class.model_class.human_attribute_name
|
|
35
|
+
def attribute_human_name(attribute)
|
|
36
|
+
controller.class.model_class.human_attribute_name attribute
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def shakedown(text, options={})
|
|
40
|
+
Configuration.use_markdown && options[:markdown] ? markdown(h(text)) : h(text)
|
|
40
41
|
end
|
|
41
42
|
|
|
42
|
-
def
|
|
43
|
-
controller.
|
|
43
|
+
def controller_action?(action)
|
|
44
|
+
controller.respond_to? action
|
|
44
45
|
end
|
|
45
46
|
|
|
46
|
-
def
|
|
47
|
+
def action_path(action, resource=nil)
|
|
48
|
+
controller_action_path(controller, action, resource)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def link_to_action(action, *args)
|
|
47
52
|
resource = (args.empty? or args.first.is_a? Hash) ? nil : args.shift
|
|
48
53
|
options = (args.empty?) ? {} : args.shift
|
|
49
54
|
links = []
|
|
50
|
-
options[:
|
|
55
|
+
options[:short] ||= false
|
|
56
|
+
|
|
57
|
+
case action
|
|
58
|
+
when :index
|
|
59
|
+
link_to(action_label(action, options), action_path(:index))
|
|
60
|
+
when :new
|
|
61
|
+
link_to(action_label(action, options), action_path(:new))
|
|
62
|
+
when :show
|
|
63
|
+
link_to(action_label(action, options), action_path(:show, resource))
|
|
64
|
+
when :edit
|
|
65
|
+
link_to(action_label(action, options), action_path(:edit, resource))
|
|
66
|
+
when :destroy
|
|
67
|
+
link_to(action_label(action, options), action_path(:destroy, resource), :confirm => 'Are you sure?', :method => :delete)
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def links_to_actions(actions=[], *args)
|
|
72
|
+
links = []
|
|
51
73
|
(actions.map { |action| action.to_sym }).each do |action|
|
|
52
|
-
|
|
53
|
-
when :index
|
|
54
|
-
links << link_to((options[:short_name] ? 'List' : "List all #{shakes_human_name.pluralize}"), controller_action_path(controller, :index)) if controller.respond_to? :index
|
|
55
|
-
when :new
|
|
56
|
-
links << link_to((options[:short_name] ? 'New' : "Create a new #{shakes_human_name}"), controller_action_path(controller, :new)) if controller.respond_to? :new
|
|
57
|
-
when :show
|
|
58
|
-
links << link_to((options[:short_name] ? 'Show' : "Show this #{shakes_human_name}"), controller_action_path(controller, :show, resource)) if controller.respond_to? :show
|
|
59
|
-
when :edit
|
|
60
|
-
links << link_to((options[:short_name] ? 'Edit' : "Edit this #{shakes_human_name}"), controller_action_path(controller, :edit, resource)) if controller.respond_to? :edit
|
|
61
|
-
when :destroy
|
|
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
|
|
63
|
-
end
|
|
74
|
+
links << link_to_action(action, *args) if controller_action? action
|
|
64
75
|
end
|
|
65
76
|
links
|
|
66
77
|
end
|
|
67
78
|
|
|
68
|
-
def
|
|
69
|
-
render :partial => "shakes/#{
|
|
70
|
-
:locals => { :action => action, :
|
|
79
|
+
def render_attribute(action, attribute, resource=nil, form=nil)
|
|
80
|
+
render :partial => "shakes/#{partial_directory action}/#{partial_name action, attribute}",
|
|
81
|
+
:locals => { :action => action, :attribute => attribute, :resource => resource, :form => form }
|
|
71
82
|
end
|
|
72
83
|
|
|
73
84
|
private
|
|
74
85
|
|
|
75
|
-
def
|
|
86
|
+
def action_label(action, options={})
|
|
87
|
+
(case action
|
|
88
|
+
when :index
|
|
89
|
+
['List', "List all #{controller_human_name.pluralize}"]
|
|
90
|
+
when :new
|
|
91
|
+
['New', "Create a new #{controller_human_name}"]
|
|
92
|
+
when :show
|
|
93
|
+
['Show', "Show this #{controller_human_name}"]
|
|
94
|
+
when :edit
|
|
95
|
+
['Edit', "Edit this #{controller_human_name}"]
|
|
96
|
+
when :destroy
|
|
97
|
+
['Delete', "Delete this #{controller_human_name}"]
|
|
98
|
+
else
|
|
99
|
+
['Unknown', "Do something unknown"]
|
|
100
|
+
end)[options[:short] ? 0 : 1]
|
|
101
|
+
end
|
|
102
|
+
|
|
103
|
+
def partial_directory(action)
|
|
76
104
|
case action.to_sym
|
|
77
105
|
when :new, :edit
|
|
78
106
|
'form'
|
|
@@ -81,20 +109,20 @@ module Shakes
|
|
|
81
109
|
end
|
|
82
110
|
end
|
|
83
111
|
|
|
84
|
-
def
|
|
85
|
-
|
|
112
|
+
def partial_name(action, attribute)
|
|
113
|
+
type = attribute_type(attribute).to_sym
|
|
86
114
|
case action.to_sym
|
|
87
115
|
when :new, :edit
|
|
88
|
-
case
|
|
116
|
+
case type
|
|
89
117
|
when :boolean, :date, :datetime, :text, :time, :timestamp
|
|
90
|
-
|
|
118
|
+
type.to_s
|
|
91
119
|
else
|
|
92
120
|
'field'
|
|
93
121
|
end
|
|
94
122
|
else
|
|
95
|
-
case
|
|
123
|
+
case type
|
|
96
124
|
when :text
|
|
97
|
-
|
|
125
|
+
type.to_s
|
|
98
126
|
else
|
|
99
127
|
'field'
|
|
100
128
|
end
|
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: 63
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
|
-
-
|
|
8
|
+
- 8
|
|
9
9
|
- 0
|
|
10
|
-
version: 0.
|
|
10
|
+
version: 0.8.0
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Jason Stahl
|