shakes 0.1.1 → 0.2.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 CHANGED
@@ -13,22 +13,29 @@ Installing Shakes
13
13
  Add it to your environment.rb configuration as a gem dependency:
14
14
 
15
15
  config.gem 'shakes'
16
-
16
+
17
17
  Tell Rails to install the required gems:
18
18
 
19
19
  rake gems:install
20
20
 
21
21
  Using Shakes
22
22
  ------------
23
- Using shakes is simple. If we were working with a new Article resource, we could add the following code to our
23
+ Using Shakes is simple. If we were working with a new `Article` resource, we could add the following code to our
24
24
  controller and instantly have default actions and views for our new resource:
25
25
 
26
26
  class ArticlesController < ApplicationController
27
27
  by_convention
28
28
  end
29
29
 
30
- Overriding the default implementation is simple. You can just add your custom action implementation to your controller
31
- as usual:
30
+ You can limit the actions that are implemented by default passing the `only` or `except` option to `by_convention`. For
31
+ example, if you just wanted to have default implementations for `index` and `show` you would use the following code:
32
+
33
+ class ArticlesController < ApplicationController
34
+ by_convention :only => [:index, :show]
35
+ end
36
+
37
+ Overriding the default implementation for a specific controller is simple. You can just add your custom action
38
+ implementation to your controller as usual:
32
39
 
33
40
  class ArticlesController < ApplicationController
34
41
  by_convention
@@ -38,26 +45,41 @@ as usual:
38
45
  end
39
46
  end
40
47
 
41
- You can also limit the actions that are implemented by default passing the `only` or `except` option to `by_convention`.
42
- For example, if you just wanted to have default implementations for `index` and `show` you would use the following code:
48
+ Overriding the default views for a specific resource is just as simple. You just have to create your view as usual. If
49
+ I wanted to change the view for `articles#show`, I could just create my custom view at `app/views/article/show.html.erb`
50
+ and that view will be used.
43
51
 
44
- class ArticlesController < ApplicationController
45
- by_convention :only => [:index, :show]
46
- end
52
+ Generators
53
+ ----------
54
+ Shakes provides a collection of generators that are designed to help you better take advantage of Shakes.
55
+
56
+ If you want to change the default views that Shakes uses you can run the following command and editable files will be
57
+ placed in `app/views/shakes`:
58
+
59
+ script/generate shakes_views
60
+
61
+ If you want to install the Formtastic stylesheets and create a version of `app/views/layout/application.html.erb` that
62
+ includes them for you, run the following command:
63
+
64
+ script/generate shakes_layout
65
+
66
+ Additionally, you can create more named layouts by running the command and passing the layout name. For example, the
67
+ following command will create a new layout at `app/views/layouts/article.html.erb`:
68
+
69
+ script/generate shakes_layout article
47
70
 
48
- Override the default views is just as simple. If I wanted to change the view for show, I could just create my custom
49
- view at `app/views/article/show.html.erb` and Shakes use that view. For example, my `app/views/article/show.html.erb`
50
- could be:
71
+ You can create the customizable default views and the application layout in one easy step. Just run the following
72
+ command and both generators will execute for you:
51
73
 
52
- <h1><%=h @article.title %></h1>
53
- <p><%=h @article.content%></p>
74
+ script/generate shakes
54
75
 
55
76
  Formtastic
56
77
  ----------
57
78
  The default `new` and `edit` view implementations use Formtastic to create the form HTML. To get the most out of
58
- Formtastic, I suggest you install and use the stylesheets that are included in the gem.
79
+ Formtastic, I suggest you install and use the stylesheets that are included in the gem. See the section on Generators
80
+ above to see how this can be done automatically for you.
59
81
 
60
- Run the following command to install the stylesheets:
82
+ Run the following command to install the stylesheets (and the Formtastic initializer):
61
83
 
62
84
  script/generate formtastic
63
85
 
@@ -74,5 +96,4 @@ See the [Formtastic](http://github.com/justinfrench/formtastic) project page for
74
96
  TODO
75
97
  ----
76
98
  * Test against Rails 3 (needs GA'ed Formtastic support for Rails 3)
77
- * Allow for application specific overrides of default implementations
78
- * Support Haml
99
+ * Allow for application specific overrides of default action implementations
@@ -0,0 +1,12 @@
1
+ <h1>Editing <%= @resource_class.human_name.downcase %></h1>
2
+ <%= render :partial => 'shakes/form' %>
3
+
4
+ <%- if @controller_class.new.respond_to? :show %>
5
+ <%= link_to 'Show', @resource %>
6
+ <% end -%>
7
+ <%- if @controller_class.new.respond_to? :show and @controller_class.new.respond_to? :index %>
8
+ |
9
+ <% end -%>
10
+ <%- if @controller_class.new.respond_to? :index %>
11
+ <%= link_to "Back", method("#{@resource_collection_name}_path".to_sym).call %>
12
+ <% end -%>
@@ -0,0 +1,39 @@
1
+ <h1>Listing <%= @resource_class.human_name.downcase.pluralize %></h1>
2
+
3
+ <table>
4
+ <tr>
5
+ <%- @resource_class.column_names.each do |column_name| %>
6
+ <%- unless %W{id created_at updated_at}.include? column_name %>
7
+ <th><%= @resource_class.human_attribute_name column_name.to_sym %></th>
8
+ <% end -%>
9
+ <% end -%>
10
+ </tr>
11
+ <% @resources.each do |resource| %>
12
+ <tr>
13
+ <%- @resource_class.column_names.each do |column_name| %>
14
+ <%- unless %W{id created_at updated_at}.include? column_name %>
15
+ <td><%=h resource[column_name.to_sym]%></td>
16
+ <% end -%>
17
+ <% end -%>
18
+ <td>
19
+ <%- if @controller_class.new.respond_to? :show %>
20
+ <%= link_to 'Show', resource %>
21
+ <% end -%>
22
+ </td>
23
+ <td>
24
+ <%- if @controller_class.new.respond_to? :edit %>
25
+ <%= link_to 'Edit', method("edit_#{@resource_instance_name}_path".to_sym).call(resource) %>
26
+ <% end -%>
27
+ </td>
28
+ <td>
29
+ <%- if @controller_class.new.respond_to? :destroy %>
30
+ <%= link_to 'Destroy', resource, :confirm => 'Are you sure?', :method => :delete %>
31
+ <% end -%>
32
+ </td>
33
+ </tr>
34
+ <% end %>
35
+ </table>
36
+
37
+ <%- if @controller_class.new.respond_to? :new %>
38
+ <%= link_to "New #{@resource_class.human_name.downcase}", method("new_#{@resource_instance_name}_path".to_sym).call %>
39
+ <% end -%>
@@ -0,0 +1,6 @@
1
+ <h1>New <%= @resource_class.human_name.downcase %></h1>
2
+ <%= render :partial => 'shakes/form' %>
3
+
4
+ <%- if @controller_class.new.respond_to? :index %>
5
+ <%= link_to "Back", method("#{@resource_collection_name}_path".to_sym).call %>
6
+ <% end -%>
@@ -0,0 +1,18 @@
1
+ <%- @resource_class.column_names.each do |column_name| %>
2
+ <%- unless %W{id created_at updated_at}.include? column_name %>
3
+ <p>
4
+ <b><%= @resource_class.human_attribute_name column_name.to_sym %>:</b>
5
+ <%=h @resource[column_name.to_sym]%>
6
+ </p>
7
+ <% end -%>
8
+ <% end -%>
9
+
10
+ <%- if @controller_class.new.respond_to? :edit %>
11
+ <%= link_to 'Edit', method("edit_#{@resource_instance_name}_path".to_sym).call(@resource) %>
12
+ <% end -%>
13
+ <%- if @controller_class.new.respond_to? :edit and @controller_class.new.respond_to? :index %>
14
+ |
15
+ <% end -%>
16
+ <%- if @controller_class.new.respond_to? :index %>
17
+ <%= link_to "Back", method("#{@resource_collection_name}_path".to_sym).call %>
18
+ <% end -%>
@@ -0,0 +1,22 @@
1
+ class ShakesGenerator < Rails::Generator::Base
2
+ def initialize(runtime_args, runtime_options = {})
3
+ super
4
+ end
5
+
6
+ def manifest
7
+ record do |m|
8
+ m.dependency 'shakes_layout', []
9
+ m.dependency 'shakes_views', []
10
+ end
11
+ end
12
+
13
+ def file_name
14
+ @name.underscore
15
+ end
16
+
17
+ protected
18
+
19
+ def banner
20
+ "Usage: #{$0} #{spec.name}"
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ class ShakesLayoutGenerator < Rails::Generator::Base
2
+ def initialize(runtime_args, runtime_options = {})
3
+ super
4
+ @name = @args.first || 'application'
5
+ end
6
+
7
+ def manifest
8
+ record do |m|
9
+ m.directory 'app/views/layouts'
10
+ m.directory 'public/stylesheets'
11
+
12
+ m.template 'layout.html.erb', "app/views/layouts/#{file_name}.html.erb"
13
+ m.file 'stylesheet.css', "public/stylesheets/#{file_name}.css"
14
+
15
+ m.dependency 'formtastic', []
16
+ end
17
+ end
18
+
19
+ def file_name
20
+ @name.underscore
21
+ end
22
+
23
+ protected
24
+
25
+ def banner
26
+ "Usage: #{$0} #{spec.name} [layout_name]"
27
+ end
28
+ end
@@ -0,0 +1,17 @@
1
+ <!DOCTYPE html>
2
+
3
+ <html xmlns="http://www.w3.org/1999/xhtml">
4
+ <head>
5
+ <meta http-equiv="content-type" content="text/html; charset=utf-8" />
6
+ <title><%%= "#{controller.controller_name}##{controller.action_name}" %></title>
7
+ <%%= formtastic_stylesheet_link_tag %>
8
+ <%%= stylesheet_link_tag '<%= file_name %>' %>
9
+ <%%= yield :head %>
10
+ </head>
11
+ <body>
12
+ <%%- flash.each do |name, message| -%>
13
+ <%%= content_tag :p, message, :id => "flash_#{name}" %>
14
+ <%%- end -%>
15
+ <%%= yield %>
16
+ </body>
17
+ </html>
@@ -0,0 +1,17 @@
1
+ body {
2
+ background-color: #fff;
3
+ color: #666;
4
+ font-family: Tahoma,Arial,Helvetica,sans-serif;
5
+ margin: 1em auto;
6
+ width: 940px;
7
+ }
8
+ a {
9
+ color: #000;
10
+ font-weight: bold;
11
+ }
12
+ h1, h2, h3, h4, h5, h6 {
13
+ color: #696;
14
+ font-family: Georgia,Utopia,Palatino,'Palatino Linotype',serif;
15
+ font-variant: small-caps;
16
+ letter-spacing: 0.1em;
17
+ }
@@ -0,0 +1,27 @@
1
+ class ShakesViewsGenerator < Rails::Generator::Base
2
+ def initialize(runtime_args, runtime_options = {})
3
+ super
4
+ end
5
+
6
+ def manifest
7
+ record do |m|
8
+ m.directory 'app/views/shakes'
9
+
10
+ m.file '../../../app/views/shakes/_form.html.erb', "app/views/shakes/_form.html.erb"
11
+ m.file '../../../app/views/shakes/edit.html.erb', "app/views/shakes/edit.html.erb"
12
+ m.file '../../../app/views/shakes/index.html.erb', "app/views/shakes/index.html.erb"
13
+ m.file '../../../app/views/shakes/new.html.erb', "app/views/shakes/new.html.erb"
14
+ m.file '../../../app/views/shakes/show.html.erb', "app/views/shakes/show.html.erb"
15
+ end
16
+ end
17
+
18
+ def file_name
19
+ @name.underscore
20
+ end
21
+
22
+ protected
23
+
24
+ def banner
25
+ "Usage: #{$0} #{spec.name}"
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ *** DO NOT REMOVE**
2
+
3
+ This file causes the templates directory to be included in the gem...
data/lib/shakes.rb CHANGED
@@ -1,6 +1,4 @@
1
1
  module Shakes
2
2
  autoload :ByConvention, 'shakes/by_convention'
3
- autoload :Helpers, 'shakes/helpers'
4
3
  end
5
4
  ActionController::Base.send :include, Shakes::ByConvention
6
- ActionView::Base.send :include, Shakes::Helpers
@@ -55,18 +55,7 @@ module Shakes
55
55
  resource_collection_name
56
56
  resource_instance_name
57
57
 
58
- case options[:action]
59
- when 'index'
60
- super 'shakes/by_convention/index.html.erb'
61
- when 'new'
62
- super 'shakes/by_convention/new.html.erb'
63
- when 'show'
64
- super 'shakes/by_convention/show.html.erb'
65
- when 'edit'
66
- super 'shakes/by_convention/edit.html.erb'
67
- else
68
- raise
69
- end
58
+ super "shakes/#{options[:action]}.html.erb"
70
59
  end
71
60
  end
72
61
 
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: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason Stahl
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-05-25 00:00:00 -05:00
18
+ date: 2010-05-26 00:00:00 -05:00
19
19
  default_executable:
20
20
  dependencies:
21
21
  - !ruby/object:Gem::Dependency
@@ -43,13 +43,18 @@ extensions: []
43
43
  extra_rdoc_files: []
44
44
 
45
45
  files:
46
- - app/views/shakes/by_convention/_form.html.erb
47
- - app/views/shakes/by_convention/edit.html.erb
48
- - app/views/shakes/by_convention/index.html.erb
49
- - app/views/shakes/by_convention/new.html.erb
50
- - app/views/shakes/by_convention/show.html.erb
46
+ - app/views/shakes/_form.html.erb
47
+ - app/views/shakes/edit.html.erb
48
+ - app/views/shakes/index.html.erb
49
+ - app/views/shakes/new.html.erb
50
+ - app/views/shakes/show.html.erb
51
+ - generators/shakes/shakes_generator.rb
52
+ - generators/shakes_layout/shakes_layout_generator.rb
53
+ - generators/shakes_layout/templates/layout.html.erb
54
+ - generators/shakes_layout/templates/stylesheet.css
55
+ - generators/shakes_views/shakes_views_generator.rb
56
+ - generators/shakes_views/templates/touchfile
51
57
  - lib/shakes/by_convention.rb
52
- - lib/shakes/helpers.rb
53
58
  - lib/shakes.rb
54
59
  - rails/init.rb
55
60
  - README.md
@@ -58,7 +63,7 @@ has_rdoc: true
58
63
  homepage: http://github.com/jfs/shakes
59
64
  licenses: []
60
65
 
61
- post_install_message:
66
+ post_install_message: "\n ========================================================================\n Thanks for installing Shakes!\n ------------------------------------------------------------------------\n You can start using Shakes immedialy by adding Shakes to your\n environment.rb configuration as a gem dependency:\n \n config.gem 'shakes'\n\n Then tell Shakes which controllers to provide default implementations\n for by adding `by_convention` to them:\n \n class ArticlesController < ApplicationController\n by_convention\n end\n\n Find out more and get involved:\n \n http://github.com/jfs/shakes\n ========================================================================\n "
62
67
  rdoc_options: []
63
68
 
64
69
  require_paths:
@@ -1,4 +0,0 @@
1
- <h1>Editing <%= @resource_class.human_name.downcase %></h1>
2
- <%= render :partial => 'shakes/by_convention/form' %>
3
-
4
- <%= link_to_show_resource_path(@resource) %> | <%= link_to_index_resources_path %>
@@ -1,27 +0,0 @@
1
- <h1>Listing <%= @resource_class.human_name.downcase.pluralize %></h1>
2
-
3
- <table>
4
- <tr>
5
- <%- @resource_class.column_names.each do |column_name| %>
6
- <%- unless %W{id created_at updated_at}.include? column_name %>
7
- <th><%= @resource_class.human_attribute_name column_name.to_sym %></th>
8
- <% end -%>
9
- <% end -%>
10
- </tr>
11
- <% @resources.each do |resource| %>
12
- <tr>
13
- <%- @resource_class.column_names.each do |column_name| %>
14
- <%- unless %W{id created_at updated_at}.include? column_name %>
15
- <td><%=h resource[column_name.to_sym]%></td>
16
- <% end -%>
17
- <% end -%>
18
- <td><%= link_to_show_resource_path(resource) %></td>
19
- <td><%= link_to_edit_resource_path(resource) %></td>
20
- <td><%= link_to_destroy_resource_path(resource) %></td>
21
- </tr>
22
- <% end %>
23
- </table>
24
-
25
- <br />
26
-
27
- <%= link_to_new_resource_path %>
@@ -1,4 +0,0 @@
1
- <h1>New <%= @resource_class.human_name.downcase %></h1>
2
- <%= render :partial => 'shakes/by_convention/form' %>
3
-
4
- <%= link_to_index_resources_path %>
@@ -1,11 +0,0 @@
1
- <%- @resource_class.column_names.each do |column_name| %>
2
- <%- unless %W{id created_at updated_at}.include? column_name %>
3
- <p>
4
- <b><%= @resource_class.human_attribute_name column_name.to_sym %>:</b>
5
- <%=h @resource[column_name.to_sym]%>
6
- </p>
7
- <% end -%>
8
- <% end -%>
9
-
10
-
11
- <%= link_to_edit_resource_path(@resource) %> | <%= link_to_index_resources_path %>
@@ -1,33 +0,0 @@
1
- module Shakes
2
- module Helpers
3
- def link_to_index_resources_path
4
- if @controller_class.new.respond_to? :index
5
- link_to "Back", method("#{@resource_collection_name}_path".to_sym).call
6
- end
7
- end
8
-
9
- def link_to_new_resource_path
10
- if @controller_class.new.respond_to? :new
11
- link_to "New #{@resource_class.human_name.downcase}", method("new_#{@resource_instance_name}_path".to_sym).call
12
- end
13
- end
14
-
15
- def link_to_show_resource_path(resource)
16
- if @controller_class.new.respond_to? :show
17
- link_to 'Show', resource
18
- end
19
- end
20
-
21
- def link_to_edit_resource_path(resource)
22
- if @controller_class.new.respond_to? :edit
23
- link_to 'Edit', method("edit_#{@resource_instance_name}_path".to_sym).call(resource)
24
- end
25
- end
26
-
27
- def link_to_destroy_resource_path(resource)
28
- if @controller_class.new.respond_to? :destroy
29
- link_to 'Destroy', resource, :confirm => 'Are you sure?', :method => :delete
30
- end
31
- end
32
- end
33
- end