shakes 0.3.1 → 0.4.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
@@ -81,6 +81,29 @@ placed in `app/views/shakes`:
81
81
 
82
82
  script/generate shakes_views
83
83
 
84
+ Now, if I wanted to add a header to the show view, I could by modifying `app/views/shakes/show.html.erb` to the following:
85
+
86
+ <h1>Showing <%= @resource_class.human_name.downcase %></h1>
87
+
88
+ <%- @resource_class.column_names.each do |column_name| %>
89
+ <%- unless %w{id created_at updated_at}.include? column_name %>
90
+ <p>
91
+ <b><%= @resource_class.human_attribute_name column_name.to_sym %>:</b>
92
+ <%=h @resource[column_name.to_sym]%>
93
+ </p>
94
+ <% end -%>
95
+ <% end -%>
96
+
97
+ <%- if @controller_class.new.respond_to? :edit %>
98
+ <%= link_to 'Edit', method("edit_#{@resource_instance_name}_path".to_sym).call(@resource) %>
99
+ <% end -%>
100
+ <%- if @controller_class.new.respond_to? :edit and @controller_class.new.respond_to? :index %>
101
+ |
102
+ <% end -%>
103
+ <%- if @controller_class.new.respond_to? :index %>
104
+ <%= link_to "Back", method("#{@resource_collection_name}_path".to_sym).call %>
105
+ <% end -%>
106
+
84
107
  Formtastic Aware Layouts
85
108
  ------------------------
86
109
  The default `new` and `edit` view implementations use Formtastic to create the form HTML. To get the most out of
@@ -1,4 +1,25 @@
1
+ <%- unless Shakes::Helpers::ViewsHelper::Configuration.use_formtastic -%>
2
+ <% form_for @resource do |form| %>
3
+ <fieldset class="inputs">
4
+ <ol>
5
+ <%- shakes_fields_for(action).each do |field| -%>
6
+ <% content_tag :li, :class => shakes_field_type_for(field).to_s do -%>
7
+ <%= shakes_render_field field, action, @resource, form %>
8
+ <%- end %>
9
+ <%- end -%>
10
+ </ol>
11
+ </fieldset>
12
+ <fieldset class="buttons">
13
+ <ol>
14
+ <% content_tag :li, :class => 'commit' do -%>
15
+ <%= form.submit "#{((action.eql? :new) ? 'Create' : 'Update')} #{shakes_human_name}" %>
16
+ <%- end %>
17
+ </ol>
18
+ </fieldset>
19
+ <% end %>
20
+ <%- else -%>
1
21
  <% semantic_form_for @resource do |form| %>
2
22
  <%= form.inputs %>
3
23
  <%= form.buttons %>
4
24
  <% end %>
25
+ <%- end -%>
@@ -1,12 +1,3 @@
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 -%>
1
+ <h1>Editing <%= shakes_human_name %></h1>
2
+ <%= render :partial => 'shakes/form', :locals => { :action => :edit } %>
3
+ <%= content_tag :p, shakes_link_to_for([:show, :index], @resource), :class => 'actions' %>
@@ -0,0 +1 @@
1
+ <%= form.label field %> <%= form.check_box field %>
@@ -0,0 +1 @@
1
+ <%= form.label field %> <%= form.date_select field %>
@@ -0,0 +1 @@
1
+ <%= form.label field %> <%= form.datetime_select field %>
@@ -0,0 +1 @@
1
+ <%= form.label field %> <%= form.text_field field %>
@@ -0,0 +1 @@
1
+ <%= form.label field %> <%= form.text_area field %>
@@ -0,0 +1 @@
1
+ <%= form.label field %> <%= form.time_select field %>
@@ -0,0 +1 @@
1
+ <%= form.label field %> <%= form.datetime_select field %>
@@ -0,0 +1 @@
1
+ <%= h(resource[field]) %>
@@ -0,0 +1 @@
1
+ <%= resource[field].length > 255 ? content_tag(:span, "#{resource[field][0,252]}...", :title => resource[field]) : shakedown(resource[field]) %>
@@ -1,39 +1,18 @@
1
- <h1>Listing <%= @resource_class.human_name.downcase.pluralize %></h1>
2
-
1
+ <h1>Listing <%= shakes_human_name.pluralize %></h1>
3
2
  <table>
4
3
  <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 -%>
4
+ <%- shakes_fields_for(:index).each do |field| -%>
5
+ <%= content_tag :th, shakes_human_attribute_name_for(field).titleize, :class => shakes_field_type_for(field).to_s %>
6
+ <%- end -%>
7
+ <%= content_tag :th, 'Actions', :class => 'actions' %>
10
8
  </tr>
11
- <% @resources.each do |resource| %>
9
+ <%- @resources.each do |resource| -%>
12
10
  <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>
11
+ <%- shakes_fields_for(:index).each do |field| -%>
12
+ <%= content_tag :td, shakes_render_field(field, :index, resource), :class => shakes_field_type_for(field).to_s %>
13
+ <%- end -%>
14
+ <%= content_tag :td, shakes_link_to_for([:show, :edit, :destroy], resource), :class => 'actions' %>
33
15
  </tr>
34
- <% end %>
16
+ <%- end -%>
35
17
  </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 -%>
18
+ <%= content_tag :p, shakes_link_to_for([:new]), :class => 'actions' %>
@@ -1,6 +1,3 @@
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 -%>
1
+ <h1>New <%= shakes_human_name %></h1>
2
+ <%= render :partial => 'shakes/form', :locals => { :action => :new } %>
3
+ <%= content_tag :p, shakes_link_to_for([:index], @resource), :class => 'actions' %>
@@ -0,0 +1,2 @@
1
+ <%= content_tag :label, shakes_human_attribute_name_for(field).titleize %>
2
+ <%= content_tag :span, resource[field] %>
@@ -0,0 +1,2 @@
1
+ <%= content_tag :label, shakes_human_attribute_name_for(field).titleize %>
2
+ <%= content_tag :div, shakedown(resource[field]) %>
@@ -1,18 +1,9 @@
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 -%>
1
+ <h1>Showing <%= shakes_human_name %></h1>
2
+ <ol class="fields">
3
+ <%- shakes_fields_for(:show).each do |field| -%>
4
+ <% content_tag :li, :class => shakes_field_type_for(field).to_s do -%>
5
+ <%= shakes_render_field field, :show, @resource %>
6
+ <%- end %>
7
+ <%- end -%>
8
+ </ol>
9
+ <%= content_tag :p, shakes_link_to_for([:edit, :index], @resource), :class => 'actions' %>
@@ -5,9 +5,9 @@ class ShakesGenerator < Rails::Generator::Base
5
5
 
6
6
  def manifest
7
7
  record do |m|
8
+ m.directory 'config/initializers'
9
+ m.file 'initializer.rb', "config/initializers/shakes.rb"
8
10
  m.dependency 'shakes_layout', []
9
- m.dependency 'shakes_views', []
10
- m.dependency 'shakes_actions', []
11
11
  end
12
12
  end
13
13
 
@@ -18,3 +18,9 @@
18
18
 
19
19
  # Set the default destroy action module. Default is Shakes::Actions::Destroy
20
20
  # Shakes::HasTheShakes::Configuration.destroy_action = Shakes::Actions::Destroy
21
+
22
+ # Should Shakes attempt to use formtastic to render forms. Default is false
23
+ # Shakes::Helpers::ViewsHelper::Configuration.use_formtastic = false
24
+
25
+ # Should Shakes attempt to use markdown to display text fields. Default is false
26
+ # Shakes::Helpers::ViewsHelper::Configuration.use_markdown = false
@@ -9,8 +9,9 @@ class ShakesLayoutGenerator < Rails::Generator::Base
9
9
  m.directory 'app/views/layouts'
10
10
  m.directory 'public/stylesheets'
11
11
  m.template 'layout.html.erb', "app/views/layouts/#{file_name}.html.erb"
12
+ m.file 'shakes.css', "public/stylesheets/shakes.css"
13
+ m.file 'shakes_changes.css', "public/stylesheets/shakes_changes.css"
12
14
  m.file 'stylesheet.css', "public/stylesheets/#{file_name}.css"
13
- m.dependency 'formtastic', []
14
15
  end
15
16
  end
16
17
 
@@ -3,8 +3,8 @@
3
3
  <html xmlns="http://www.w3.org/1999/xhtml">
4
4
  <head>
5
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 %>
6
+ <title><%%= "#{controller.controller_name}##{controller.action_name}" %> - <%= file_name.titleize %></title>
7
+ <%%= shakes_stylesheet_link_tag %>
8
8
  <%%= stylesheet_link_tag '<%= file_name %>' %>
9
9
  <%%= yield :head %>
10
10
  </head>
File without changes
@@ -1,17 +1 @@
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
- }
1
+ /* Put your layout specifc styles in this file. */
@@ -0,0 +1,9 @@
1
+ module Shakes
2
+ module Helpers
3
+ module LayoutHelper
4
+ def shakes_stylesheet_link_tag
5
+ stylesheet_link_tag("shakes") + stylesheet_link_tag("shakes_changes")
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,87 @@
1
+ module Shakes
2
+ module Helpers
3
+ module ViewsHelper
4
+ class Configuration
5
+ cattr_accessor :use_formtastic, :use_markdown
6
+ self.use_formtastic = false
7
+ self.use_markdown = false
8
+ end
9
+
10
+ def shakedown(content, options={})
11
+ Configuration.use_markdown && options[:markdown] ? markdown(h(content)) : h(content)
12
+ end
13
+
14
+ def shakes_field_type_for(field)
15
+ @resource_class.columns_hash[field.to_s].type
16
+ end
17
+
18
+ def shakes_fields_for(action)
19
+ (@resource_class.column_names - %w{id created_at updated_at}).map { |f| f.to_sym }
20
+ end
21
+
22
+ def shakes_human_attribute_name_for(field)
23
+ @resource_class.human_attribute_name field
24
+ end
25
+
26
+ def shakes_human_name
27
+ @resource_class.human_name
28
+ end
29
+
30
+ def shakes_link_to_for(actions=[], resource=nil)
31
+ links = []
32
+ (actions.map { |action| action.to_sym }).each do |action|
33
+ case action
34
+ when :index
35
+ links << link_to("Back", method("#{@resource_collection_name}_path".to_sym).call) if @controller_class.new.respond_to? :index
36
+ when :new
37
+ links << link_to("New #{shakes_human_name}", method("new_#{@resource_instance_name}_path".to_sym).call) if @controller_class.new.respond_to? :new
38
+ when :show
39
+ links << link_to('Show', resource) if @controller_class.new.respond_to? :show
40
+ when :edit
41
+ links << link_to('Edit', method("edit_#{@resource_instance_name}_path".to_sym).call(resource)) if @controller_class.new.respond_to? :edit
42
+ when :destroy
43
+ links << link_to('Destroy', resource, :confirm => 'Are you sure?', :method => :delete) if @controller_class.new.respond_to? :destroy
44
+ end
45
+ end
46
+ links.join(' | ')
47
+ end
48
+
49
+ def shakes_render_field(field, action, resource=nil, form=nil)
50
+ render :partial => "shakes/#{partial_directory_for action}/#{partial_name_for field, action}",
51
+ :locals => { :action => action, :field => field, :resource => resource, :form => form }
52
+ end
53
+
54
+ protected
55
+
56
+ def partial_directory_for(action)
57
+ case action.to_sym
58
+ when :new, :edit
59
+ 'form'
60
+ else
61
+ action.to_s
62
+ end
63
+ end
64
+
65
+ def partial_name_for(field, action)
66
+ field_type = (shakes_field_type_for field).to_sym
67
+
68
+ case action.to_sym
69
+ when :new, :edit
70
+ case field_type
71
+ when :boolean, :date, :datetime, :text, :time, :timestamp
72
+ field_type.to_s
73
+ else
74
+ 'field'
75
+ end
76
+ else
77
+ case field_type
78
+ when :text
79
+ field_type.to_s
80
+ else
81
+ 'field'
82
+ end
83
+ end
84
+ end
85
+ end
86
+ end
87
+ end
@@ -0,0 +1,6 @@
1
+ module Shakes
2
+ module Helpers
3
+ autoload :LayoutHelper, 'shakes/helpers/layout_helper'
4
+ autoload :ViewsHelper, 'shakes/helpers/views_helper'
5
+ end
6
+ end
data/lib/shakes.rb CHANGED
@@ -1,5 +1,8 @@
1
1
  module Shakes
2
2
  autoload :Actions, 'shakes/actions'
3
3
  autoload :HasTheShakes, 'shakes/has_the_shakes'
4
+ autoload :Helpers, 'shakes/helpers'
4
5
  end
5
6
  ActionController::Base.send :include, Shakes::HasTheShakes
7
+ ActionView::Base.send :include, Shakes::Helpers::LayoutHelper
8
+ ActionView::Base.send :include, Shakes::Helpers::ViewsHelper
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: 17
4
+ hash: 15
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 3
9
- - 1
10
- version: 0.3.1
8
+ - 4
9
+ - 0
10
+ version: 0.4.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Jason Stahl
@@ -17,23 +17,8 @@ cert_chain: []
17
17
 
18
18
  date: 2010-05-26 00:00:00 -05:00
19
19
  default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
22
- name: formtastic
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
25
- none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 43
30
- segments:
31
- - 0
32
- - 9
33
- - 8
34
- version: 0.9.8
35
- type: :runtime
36
- version_requirements: *id001
20
+ dependencies: []
21
+
37
22
  description: Shakes provides default implementations for Rails controller actions and views.
38
23
  email: jason@jasonstahl.net
39
24
  executables: []
@@ -45,14 +30,26 @@ extra_rdoc_files: []
45
30
  files:
46
31
  - app/views/shakes/_form.html.erb
47
32
  - app/views/shakes/edit.html.erb
33
+ - app/views/shakes/form/_boolean.html.erb
34
+ - app/views/shakes/form/_date.html.erb
35
+ - app/views/shakes/form/_datetime.html.erb
36
+ - app/views/shakes/form/_field.html.erb
37
+ - app/views/shakes/form/_text.html.erb
38
+ - app/views/shakes/form/_time.html.erb
39
+ - app/views/shakes/form/_timestamp.html.erb
40
+ - app/views/shakes/index/_field.html.erb
41
+ - app/views/shakes/index/_text.html.erb
48
42
  - app/views/shakes/index.html.erb
49
43
  - app/views/shakes/new.html.erb
44
+ - app/views/shakes/show/_field.html.erb
45
+ - app/views/shakes/show/_text.html.erb
50
46
  - app/views/shakes/show.html.erb
51
47
  - generators/shakes/shakes_generator.rb
52
- - generators/shakes_actions/shakes_actions_generator.rb
53
- - generators/shakes_actions/templates/initializer.rb
48
+ - generators/shakes/templates/initializer.rb
54
49
  - generators/shakes_layout/shakes_layout_generator.rb
55
50
  - generators/shakes_layout/templates/layout.html.erb
51
+ - generators/shakes_layout/templates/shakes.css
52
+ - generators/shakes_layout/templates/shakes_changes.css
56
53
  - generators/shakes_layout/templates/stylesheet.css
57
54
  - generators/shakes_views/shakes_views_generator.rb
58
55
  - generators/shakes_views/templates/touchfile
@@ -65,6 +62,9 @@ files:
65
62
  - lib/shakes/actions/update.rb
66
63
  - lib/shakes/actions.rb
67
64
  - lib/shakes/has_the_shakes.rb
65
+ - lib/shakes/helpers/layout_helper.rb
66
+ - lib/shakes/helpers/views_helper.rb
67
+ - lib/shakes/helpers.rb
68
68
  - lib/shakes.rb
69
69
  - rails/init.rb
70
70
  - README.md
@@ -1,22 +0,0 @@
1
- class ShakesActionsGenerator < 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 'config/initializers'
9
- m.file 'initializer.rb', "config/initializers/shakes.rb"
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