shakes 0.4.2 → 0.4.3
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/app/views/shakes/_form.html.erb +1 -1
- data/lib/shakes.rb +2 -0
- 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 +9 -32
- data/lib/shakes/helpers.rb +1 -0
- data/lib/shakes/helpers/url_helper.rb +24 -0
- data/lib/shakes/helpers/views_helper.rb +9 -23
- metadata +4 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<%- unless Shakes::Helpers::ViewsHelper::Configuration.use_formtastic -%>
|
|
2
|
-
<% form_for(@resource, :url => shakes_path_for(action, @resource)) do |form| %>
|
|
2
|
+
<% form_for(@resource, :url => shakes_path_for(((action.eql? :new) ? :create : :update ), @resource)) do |form| %>
|
|
3
3
|
<fieldset class="inputs">
|
|
4
4
|
<ol>
|
|
5
5
|
<%- shakes_fields_for(action).each do |field| -%>
|
data/lib/shakes.rb
CHANGED
|
@@ -4,5 +4,7 @@ module Shakes
|
|
|
4
4
|
autoload :Helpers, 'shakes/helpers'
|
|
5
5
|
end
|
|
6
6
|
ActionController::Base.send :include, Shakes::HasTheShakes
|
|
7
|
+
ActionController::Base.send :include, Shakes::Helpers::UrlHelper
|
|
7
8
|
ActionView::Base.send :include, Shakes::Helpers::LayoutHelper
|
|
9
|
+
ActionView::Base.send :include, Shakes::Helpers::UrlHelper
|
|
8
10
|
ActionView::Base.send :include, Shakes::Helpers::ViewsHelper
|
|
@@ -2,11 +2,11 @@ module Shakes
|
|
|
2
2
|
module Actions
|
|
3
3
|
module Create
|
|
4
4
|
def create
|
|
5
|
-
@resource = instance_variable_set("@#{
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.shakes_resource_name}", self.class.shakes_resource.new(params[self.class.shakes_resource_name.to_sym]))
|
|
6
6
|
|
|
7
7
|
respond_to do |format|
|
|
8
8
|
if @resource.save
|
|
9
|
-
format.html { redirect_to(@resource, :notice => "#{
|
|
9
|
+
format.html { redirect_to(shakes_path_for(:show, @resource), :notice => "#{self.class.shakes_resource.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("@#{
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.shakes_resource_name}", self.class.shakes_resource.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(shakes_path_for(: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("@#{
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.shakes_resource_name}", self.class.shakes_resource.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("@#{
|
|
5
|
+
@resources = instance_variable_set("@#{self.class.shakes_resource_collection_name}", self.class.shakes_resource.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("@#{
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.shakes_resource_name}", self.class.shakes_resource.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("@#{
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.shakes_resource_name}", self.class.shakes_resource.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("@#{
|
|
5
|
+
@resource = instance_variable_set("@#{self.class.shakes_resource_name}", self.class.shakes_resource.find(params[:id]))
|
|
6
6
|
|
|
7
7
|
respond_to do |format|
|
|
8
|
-
if @resource.update_attributes(params[
|
|
9
|
-
format.html { redirect_to(@resource, :notice => "#{
|
|
8
|
+
if @resource.update_attributes(params[self.class.shakes_resource_name.to_sym])
|
|
9
|
+
format.html { redirect_to(shakes_path_for(:show, @resource), :notice => "#{self.class.shakes_resource.to_s} was successfully updated.") }
|
|
10
10
|
format.xml { head :ok }
|
|
11
11
|
format.json { head :ok }
|
|
12
12
|
else
|
|
@@ -19,8 +19,14 @@ module Shakes
|
|
|
19
19
|
|
|
20
20
|
module ClassMethods
|
|
21
21
|
def has_the_shakes(options={})
|
|
22
|
+
cattr_accessor :shakes_controller_name
|
|
23
|
+
self.shakes_controller_name ||= self.name.sub!(/Controller$/,'').singularize.underscore
|
|
24
|
+
cattr_accessor :shakes_resource_name
|
|
25
|
+
self.shakes_resource_name ||= options[:resource] ? options[:resource].to_s.singularize : self.shakes_controller_name
|
|
26
|
+
cattr_accessor :shakes_resource_collection_name
|
|
27
|
+
self.shakes_resource_collection_name ||= self.shakes_resource_name.pluralize
|
|
22
28
|
cattr_accessor :shakes_resource
|
|
23
|
-
self.shakes_resource
|
|
29
|
+
self.shakes_resource ||= Object::const_get(self.shakes_resource_name.classify)
|
|
24
30
|
send :include, InstanceMethods
|
|
25
31
|
|
|
26
32
|
cattr_accessor :shakes_actions
|
|
@@ -36,43 +42,14 @@ module Shakes
|
|
|
36
42
|
end
|
|
37
43
|
|
|
38
44
|
module InstanceMethods
|
|
39
|
-
def controller_class
|
|
40
|
-
@controller_class ||= Object::const_get(self.class.name.classify)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
def controller_class_name
|
|
44
|
-
@controller_class_name ||= self.class.name.sub!(/Controller$/,'').singularize.underscore
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
def resource_class
|
|
48
|
-
@resource_class ||= Object::const_get(self.class.shakes_resource.classify)
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
def resource_collection_name
|
|
52
|
-
@resource_collection_name ||= self.class.shakes_resource.tableize.pluralize
|
|
53
|
-
end
|
|
54
|
-
|
|
55
|
-
def resource_instance_name
|
|
56
|
-
@resource_instance_name ||= self.class.shakes_resource.tableize.singularize
|
|
57
|
-
end
|
|
58
|
-
|
|
59
45
|
def render(options = nil, extra_options = {}, &block)
|
|
60
46
|
begin
|
|
61
47
|
super
|
|
62
48
|
rescue ActionView::MissingTemplate
|
|
63
49
|
raise unless locate_resource?
|
|
64
|
-
|
|
65
50
|
options ||= {}
|
|
66
51
|
options[:action] ||= params[:action]
|
|
67
|
-
|
|
68
52
|
raise unless self.shakes_actions.include? options[:action].to_sym
|
|
69
|
-
|
|
70
|
-
controller_class
|
|
71
|
-
controller_class_name
|
|
72
|
-
resource_class
|
|
73
|
-
resource_collection_name
|
|
74
|
-
resource_instance_name
|
|
75
|
-
|
|
76
53
|
super "shakes/#{options[:action]}.html.erb"
|
|
77
54
|
end
|
|
78
55
|
end
|
|
@@ -80,8 +57,8 @@ module Shakes
|
|
|
80
57
|
private
|
|
81
58
|
|
|
82
59
|
def locate_resource?
|
|
83
|
-
@resources ||= instance_variable_get("@#{
|
|
84
|
-
@resource ||= instance_variable_get("@#{
|
|
60
|
+
@resources ||= instance_variable_get("@#{self.class.shakes_resource_collection_name}")
|
|
61
|
+
@resource ||= instance_variable_get("@#{self.class.shakes_resource_name}")
|
|
85
62
|
(@resources || @resource)
|
|
86
63
|
end
|
|
87
64
|
end
|
data/lib/shakes/helpers.rb
CHANGED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module Shakes
|
|
2
|
+
module Helpers
|
|
3
|
+
module UrlHelper
|
|
4
|
+
def shakes_path_for(action, resource=nil)
|
|
5
|
+
case action
|
|
6
|
+
when :index, :create
|
|
7
|
+
method("#{shakes_controller_name.pluralize}_path".to_sym).call
|
|
8
|
+
when :new
|
|
9
|
+
method("new_#{shakes_controller_name}_path".to_sym).call
|
|
10
|
+
when :show, :update, :destroy
|
|
11
|
+
method("#{shakes_controller_name}_path".to_sym).call(resource)
|
|
12
|
+
when :edit
|
|
13
|
+
method("edit_#{shakes_controller_name}_path".to_sym).call(resource)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
private
|
|
18
|
+
|
|
19
|
+
def shakes_controller_name
|
|
20
|
+
(controller || self).class.shakes_controller_name
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -12,33 +12,19 @@ module Shakes
|
|
|
12
12
|
end
|
|
13
13
|
|
|
14
14
|
def shakes_field_type_for(field)
|
|
15
|
-
|
|
15
|
+
controller.class.shakes_resource.columns_hash[field.to_s].type
|
|
16
16
|
end
|
|
17
17
|
|
|
18
18
|
def shakes_fields_for(action)
|
|
19
|
-
(
|
|
19
|
+
(controller.class.shakes_resource.column_names - %w{id created_at updated_at}).map { |f| f.to_sym }
|
|
20
20
|
end
|
|
21
21
|
|
|
22
22
|
def shakes_human_attribute_name_for(field)
|
|
23
|
-
|
|
23
|
+
controller.class.shakes_resource.human_attribute_name field
|
|
24
24
|
end
|
|
25
25
|
|
|
26
26
|
def shakes_human_name
|
|
27
|
-
|
|
28
|
-
@resource_class.human_name
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
def shakes_path_for(action, resource=nil)
|
|
32
|
-
case action
|
|
33
|
-
when :index
|
|
34
|
-
method("#{@controller_class_name.pluralize}_path".to_sym).call
|
|
35
|
-
when :new
|
|
36
|
-
method("new_#{@controller_class_name}_path".to_sym).call
|
|
37
|
-
when :show, :destroy
|
|
38
|
-
method("#{@controller_class_name}_path".to_sym).call(resource)
|
|
39
|
-
when :edit
|
|
40
|
-
method("edit_#{@controller_class_name}_path".to_sym).call(resource)
|
|
41
|
-
end
|
|
27
|
+
controller.class.shakes_resource.human_name
|
|
42
28
|
end
|
|
43
29
|
|
|
44
30
|
def shakes_link_to_for(actions=[], resource=nil)
|
|
@@ -46,15 +32,15 @@ module Shakes
|
|
|
46
32
|
(actions.map { |action| action.to_sym }).each do |action|
|
|
47
33
|
case action
|
|
48
34
|
when :index
|
|
49
|
-
links << link_to("Back", shakes_path_for(:index)) if
|
|
35
|
+
links << link_to("Back", shakes_path_for(:index)) if controller.respond_to? :index
|
|
50
36
|
when :new
|
|
51
|
-
links << link_to("New #{shakes_human_name}", shakes_path_for(:new)) if
|
|
37
|
+
links << link_to("New #{shakes_human_name}", shakes_path_for(:new)) if controller.respond_to? :new
|
|
52
38
|
when :show
|
|
53
|
-
links << link_to('Show', shakes_path_for(:show, resource)) if
|
|
39
|
+
links << link_to('Show', shakes_path_for(:show, resource)) if controller.respond_to? :show
|
|
54
40
|
when :edit
|
|
55
|
-
links << link_to('Edit', shakes_path_for(:edit, resource)) if
|
|
41
|
+
links << link_to('Edit', shakes_path_for(:edit, resource)) if controller.respond_to? :edit
|
|
56
42
|
when :destroy
|
|
57
|
-
links << link_to('Destroy', shakes_path_for(:destroy, resource), :confirm => 'Are you sure?', :method => :delete) if
|
|
43
|
+
links << link_to('Destroy', shakes_path_for(:destroy, resource), :confirm => 'Are you sure?', :method => :delete) if controller.respond_to? :destroy
|
|
58
44
|
end
|
|
59
45
|
end
|
|
60
46
|
links.join(' | ')
|
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: 9
|
|
5
5
|
prerelease: false
|
|
6
6
|
segments:
|
|
7
7
|
- 0
|
|
8
8
|
- 4
|
|
9
|
-
-
|
|
10
|
-
version: 0.4.
|
|
9
|
+
- 3
|
|
10
|
+
version: 0.4.3
|
|
11
11
|
platform: ruby
|
|
12
12
|
authors:
|
|
13
13
|
- Jason Stahl
|
|
@@ -63,6 +63,7 @@ files:
|
|
|
63
63
|
- lib/shakes/actions.rb
|
|
64
64
|
- lib/shakes/has_the_shakes.rb
|
|
65
65
|
- lib/shakes/helpers/layout_helper.rb
|
|
66
|
+
- lib/shakes/helpers/url_helper.rb
|
|
66
67
|
- lib/shakes/helpers/views_helper.rb
|
|
67
68
|
- lib/shakes/helpers.rb
|
|
68
69
|
- lib/shakes.rb
|