khalsah-spiffy-generators 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. data/.gitignore +2 -0
  2. data/Rakefile +17 -0
  3. data/VERSION +1 -0
  4. data/generators/spiffy_layout/spiffy_layout_generator.rb +26 -0
  5. data/generators/spiffy_layout/templates/helper.rb +10 -0
  6. data/generators/spiffy_layout/templates/layout.html.haml +18 -0
  7. data/generators/spiffy_layout/templates/layout.html.haml_spec.rb +41 -0
  8. data/generators/spiffy_layout/templates/stylesheet.sass +67 -0
  9. data/generators/spiffy_scaffold/spiffy_scaffold_generator.rb +72 -0
  10. data/generators/spiffy_scaffold/templates/controller.rb +46 -0
  11. data/generators/spiffy_scaffold/templates/controller_spec.rb +145 -0
  12. data/generators/spiffy_scaffold/templates/migration.rb +14 -0
  13. data/generators/spiffy_scaffold/templates/model.rb +2 -0
  14. data/generators/spiffy_scaffold/templates/model_spec.rb +9 -0
  15. data/generators/spiffy_scaffold/templates/routing_spec.rb +11 -0
  16. data/generators/spiffy_scaffold/templates/views/_form.html.haml +11 -0
  17. data/generators/spiffy_scaffold/templates/views/_form.html.haml_spec.rb +31 -0
  18. data/generators/spiffy_scaffold/templates/views/edit.html.haml +8 -0
  19. data/generators/spiffy_scaffold/templates/views/edit.html.haml_spec.rb +14 -0
  20. data/generators/spiffy_scaffold/templates/views/index.html.haml +22 -0
  21. data/generators/spiffy_scaffold/templates/views/index.html.haml_spec.rb +42 -0
  22. data/generators/spiffy_scaffold/templates/views/new.html.haml +7 -0
  23. data/generators/spiffy_scaffold/templates/views/new.html.haml_spec.rb +14 -0
  24. data/generators/spiffy_scaffold/templates/views/show.html.haml +13 -0
  25. data/generators/spiffy_scaffold/templates/views/show.html.haml_spec.rb +42 -0
  26. data/spiffy-generators.gemspec +54 -0
  27. metadata +78 -0
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ pkg
data/Rakefile ADDED
@@ -0,0 +1,17 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "spiffy-generators"
8
+ gem.summary = %Q{My personal Rails generators.}
9
+ gem.email = "khalsah@gmail.com"
10
+ gem.homepage = "http://github.com/khalsah/spiffy-generators"
11
+ gem.authors = ["Hargobind Khalsa"]
12
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
13
+ end
14
+
15
+ rescue LoadError
16
+ puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
17
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.2.0
@@ -0,0 +1,26 @@
1
+ class SpiffyLayoutGenerator < 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 "spec/views/layouts"
10
+ m.template "layout.html.haml_spec.rb", "spec/views/layouts/#{filename}.html.haml_spec.rb"
11
+
12
+ m.directory "app/views/layouts"
13
+ m.template "layout.html.haml", "app/views/layouts/#{filename}.html.haml"
14
+
15
+ m.directory "app/helpers"
16
+ m.file "helper.rb", "app/helpers/layout_helper.rb"
17
+
18
+ m.directory "public/stylesheets/sass"
19
+ m.file "stylesheet.sass", "public/stylesheets/sass/#{filename}.sass"
20
+ end
21
+ end
22
+
23
+ def filename
24
+ @name.underscore
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ module LayoutHelper
2
+ def title(page_title, show_title = true)
3
+ content_for(:title) { page_title }
4
+ @show_title = show_title
5
+ end
6
+
7
+ def show_title?
8
+ @show_title
9
+ end
10
+ end
@@ -0,0 +1,18 @@
1
+ !!! XML
2
+ !!! 1.1
3
+ %html{html_attrs}
4
+
5
+ %head
6
+ %title= h( yield(:title) || "Untitled" )
7
+ = stylesheet_link_tag '<%= filename %>'
8
+ = yield(:head)
9
+
10
+ %body
11
+ #container
12
+ - if show_title?
13
+ %h1= h yield(:title)
14
+
15
+ - flash.each do |name, msg|
16
+ = content_tag :div, msg, :id => "flash_#{name}"
17
+
18
+ = yield
@@ -0,0 +1,41 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe 'layouts/<%= filename %>.html.haml' do
4
+ it "should render the content" do
5
+ render :inline => 'THIS-IS-THE-CONTENT', :layout => '<%= filename %>'
6
+ response.should include_text('THIS-IS-THE-CONTENT')
7
+ end
8
+
9
+ it "should render the title 'Untitled' if not title is set" do
10
+ render
11
+ response.should have_tag('title', 'Untitled')
12
+ end
13
+
14
+ it "should render the title when it is given" do
15
+ render :inline => "<%%= title('THIS-IS-THE-TITLE') %>", :layout => '<%= filename %>'
16
+ response.should have_tag('title', 'THIS-IS-THE-TITLE')
17
+ end
18
+
19
+ it "should display the title as a header" do
20
+ render :inline => "<%%= title('THIS-IS-THE-TITLE') %>", :layout => '<%= filename %>'
21
+ response.should have_tag('h1', 'THIS-IS-THE-TITLE')
22
+ end
23
+
24
+ it "should not display the title as a header if asked not to" do
25
+ render :inline => "<%%= title('THIS-IS-THE-TITLE', false) %>", :layout => '<%= filename %>'
26
+ response.should_not have_tag('h1', 'THIS-IS-THE-TITLE')
27
+ end
28
+
29
+ it "should render all flashes" do
30
+ flash[:notice] = 'THE-NOTICE-FLASH'
31
+ flash[:weird] = 'THE-WEIRD-FLASH'
32
+ render
33
+ response.should have_tag('div#flash_weird', 'THE-WEIRD-FLASH')
34
+ response.should have_tag('div#flash_notice', 'THE-NOTICE-FLASH')
35
+ end
36
+
37
+ it "should render head content" do
38
+ render :inline => "<%%= @content_for_head = '<meta/>' %>", :layout => '<%= filename %>'
39
+ response.should have_tag('head>meta')
40
+ end
41
+ end
@@ -0,0 +1,67 @@
1
+ !primary_color = #4B7399
2
+
3
+ body
4
+ :background-color = !primary_color
5
+ :font
6
+ :family Verdana, Helvetica, Arial
7
+ :size 14px
8
+
9
+ a
10
+ :color #0000FF
11
+ img
12
+ :border none
13
+
14
+ .clear
15
+ :clear both
16
+ :height 0
17
+ :overflow hidden
18
+
19
+ #container
20
+ :width 75%
21
+ :margin 0 auto
22
+ :background #fff
23
+ :padding 20px 40px
24
+ :border solid 1px black
25
+ :margin-top 20px
26
+
27
+ #flash_notice,
28
+ #flash_error
29
+ :padding 5px 8px
30
+ :margin 10px 0
31
+
32
+ #flash_notice
33
+ :background-color #CFC
34
+ :border solid 1px #6C6
35
+
36
+ #flash_error
37
+ :background-color #FCC
38
+ :border solid 1px #C66
39
+
40
+ .fieldWithErrors
41
+ :display inline
42
+
43
+ #errorExplanation
44
+ :width 400px
45
+ :border 2px solid #CF0000
46
+ :padding 0
47
+ :padding-bottom 12px
48
+ :margin-bottom 20px
49
+ :background-color #f0f0f0
50
+ h2
51
+ :text-align left
52
+ :padding 5px 5px 5px 15px
53
+ :margin 0
54
+ :font
55
+ :weight bold
56
+ :size 12px
57
+ :background-color #c00
58
+ :color #fff
59
+ p
60
+ :color #333
61
+ :margin-bottom 0
62
+ :padding 8px
63
+ ul
64
+ :margin 2px 24px
65
+ li
66
+ :font-size 12px
67
+ :list-style disc
@@ -0,0 +1,72 @@
1
+ class SpiffyScaffoldGenerator < Rails::Generator::Base
2
+ attr_reader :name, :attributes
3
+
4
+ def initialize(runtime_args, runtime_options = {})
5
+ super
6
+ usage if @args.empty?
7
+
8
+ @name = @args.first.singularize
9
+ @attributes = []
10
+
11
+ @args[1..-1].each do |arg|
12
+ @attributes << Rails::Generator::GeneratedAttribute.new(*arg.split(':'))
13
+ end
14
+
15
+ @attributes.uniq!
16
+ end
17
+
18
+ def manifest
19
+ record do |m|
20
+ # Generate Model Spec
21
+ m.directory "spec/models"
22
+ m.template "model_spec.rb", "spec/models/#{singular_name}_spec.rb"
23
+
24
+ # Generate Migration
25
+ m.directory "db/migrate"
26
+ m.migration_template 'migration.rb', 'db/migrate', :migration_file_name => "create_#{plural_name}"
27
+
28
+ # Generate Model
29
+ m.directory "app/models"
30
+ m.template "model.rb", "app/models/#{singular_name}.rb"
31
+
32
+ # Generate Routing Spec
33
+ m.directory 'spec/routing'
34
+ m.template 'routing_spec.rb', "spec/routing/#{plural_name}_routing_spec.rb"
35
+
36
+ # Generate Routing
37
+ m.route_resources plural_name
38
+
39
+ # Generate Controller Spec
40
+ m.directory 'spec/controllers'
41
+ m.template 'controller_spec.rb', "spec/controllers/#{plural_name}_controller_spec.rb"
42
+
43
+ # Generate Controller
44
+ m.directory 'app/controllers'
45
+ m.template 'controller.rb', "app/controllers/#{plural_name}_controller.rb"
46
+
47
+ # Generate Views w/ Specs
48
+ m.directory "spec/views/#{plural_name}"
49
+ m.directory "app/views/#{plural_name}"
50
+ %w[index show new edit _form].each do |action|
51
+ m.template "views/#{action}.html.haml_spec.rb", "spec/views/#{plural_name}/#{action}.html.haml_spec.rb"
52
+ m.template "views/#{action}.html.haml", "app/views/#{plural_name}/#{action}.html.haml"
53
+ end
54
+ end
55
+ end
56
+
57
+ def singular_name
58
+ name.underscore
59
+ end
60
+
61
+ def plural_name
62
+ singular_name.pluralize
63
+ end
64
+
65
+ def class_name
66
+ name.camelize
67
+ end
68
+
69
+ def plural_class_name
70
+ class_name.pluralize
71
+ end
72
+ end
@@ -0,0 +1,46 @@
1
+ class <%= plural_class_name %>Controller < ApplicationController
2
+ before_filter :find_<%= singular_name %>, :only => [:show, :edit, :update, :destroy]
3
+
4
+ def index
5
+ @<%= plural_name %> = <%= class_name %>.all
6
+ end
7
+
8
+ def show
9
+ end
10
+
11
+ def new
12
+ @<%= singular_name %> = <%= class_name %>.new
13
+ end
14
+
15
+ def edit
16
+ end
17
+
18
+ def create
19
+ @<%= singular_name %> = <%= class_name %>.new(params[:<%= singular_name %>])
20
+ if @<%= singular_name %>.save
21
+ flash[:notice] = '<%= name.humanize.capitalize %> successfully created.'
22
+ redirect_to(@<%= singular_name %>)
23
+ else
24
+ render :new
25
+ end
26
+ end
27
+
28
+ def update
29
+ if @<%= singular_name %>.update_attributes(params[:<%= singular_name %>])
30
+ flash[:notice] = '<%= name.humanize.capitalize %> successfully updated.'
31
+ redirect_to(@<%= singular_name %>)
32
+ else
33
+ render :edit
34
+ end
35
+ end
36
+
37
+ def destroy
38
+ @<%= singular_name %>.destroy
39
+ flash[:notice] = '<%= name.humanize.capitalize %> successfully deleted.'
40
+ redirect_to(<%= plural_name %>_url)
41
+ end
42
+
43
+ def find_<%= singular_name %>
44
+ @<%= singular_name %> = <%= class_name %>.find(params[:id])
45
+ end
46
+ end
@@ -0,0 +1,145 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe <%= plural_class_name %>Controller do
4
+
5
+ def mock_<%= singular_name %>(stubs = {})
6
+ @mock_<%= singular_name %> ||= <%= class_name %>.stub_instance(stubs)
7
+ end
8
+
9
+ describe 'GET index' do
10
+ before(:each) do
11
+ <%= class_name %>.stub_method(:find => [mock_<%= singular_name %>])
12
+ get :index
13
+ end
14
+
15
+ it "should find all <%= plural_name.humanize %>" do
16
+ <%= class_name %>.should have_received(:find).with(:all)
17
+ end
18
+ it { should assign_to(:<%= plural_name %>).with([mock_<%= singular_name %>]) }
19
+ it { should respond_with(:success) }
20
+ it { should render_template(:index) }
21
+ it { should_not set_the_flash }
22
+ end
23
+
24
+ describe 'GET show' do
25
+ before(:each) do
26
+ <%= class_name %>.stub_method(:find => mock_<%= singular_name %>)
27
+ get :show, :id => '42'
28
+ end
29
+
30
+ it "should find the <%= singular_name.humanize %>" do
31
+ <%= class_name %>.should have_received(:find).with('42')
32
+ end
33
+ it { should assign_to(:<%= singular_name %>).with(mock_<%= singular_name %>) }
34
+ it { should respond_with(:success) }
35
+ it { should render_template(:show) }
36
+ it { should_not set_the_flash }
37
+ end
38
+
39
+ describe 'GET new' do
40
+ before(:each) do
41
+ <%= class_name %>.stub_method(:new => mock_<%= singular_name %>)
42
+ get :new
43
+ end
44
+
45
+ it "should create a blank <%= singular_name.humanize %>" do
46
+ <%= class_name %>.should have_received(:new).with()
47
+ end
48
+ it { should assign_to(:<%= singular_name %>).with(mock_<%= singular_name %>) }
49
+ it { should respond_with(:success) }
50
+ it { should render_template(:new) }
51
+ it { should_not set_the_flash }
52
+ end
53
+
54
+ describe 'GET edit' do
55
+ before(:each) do
56
+ <%= class_name %>.stub_method(:find => mock_<%= singular_name %>)
57
+ get :edit, :id => 42
58
+ end
59
+
60
+ it "should find the <%= singular_name.humanize %>" do
61
+ <%= class_name %>.should have_received(:find).with('42')
62
+ end
63
+ it { should assign_to(:<%= singular_name %>).with(mock_<%= singular_name %>) }
64
+ it { should respond_with(:success) }
65
+ it { should render_template(:edit) }
66
+ it { should_not set_the_flash }
67
+ end
68
+
69
+ describe 'POST create' do
70
+ describe 'with valid params' do
71
+ before(:each) do
72
+ <%= class_name %>.stub_method(:new => mock_<%= singular_name %>(:save => true))
73
+ post :create, :<%= singular_name %> => {'these' => 'params'}
74
+ end
75
+
76
+ it "should create the <%= singular_name.humanize.downcase %> with the correct params" do
77
+ <%= class_name %>.should have_received(:new).with({'these' => 'params'})
78
+ end
79
+ it "should save the <%= singular_name.humanize.downcase %>" do
80
+ mock_<%= singular_name %>.should have_received(:save).with()
81
+ end
82
+ it { should respond_with(:redirect) }
83
+ it { should redirect_to(<%= singular_name %>_url(mock_<%= singular_name %>)) }
84
+ it { should set_the_flash.to(/created/i) }
85
+ end
86
+
87
+ describe 'with invalid params' do
88
+ before(:each) do
89
+ <%= class_name %>.stub_method(:new => mock_<%= singular_name %>(:save => false))
90
+ post :create, :<%= singular_name %> => {'these' => 'params'}
91
+ end
92
+
93
+ it { should assign_to(:<%= singular_name %>).with(mock_<%= singular_name %>) }
94
+ it { should respond_with(:success) }
95
+ it { should render_template(:new) }
96
+ end
97
+ end
98
+
99
+ describe 'PUT update' do
100
+ describe 'with valid params' do
101
+ before(:each) do
102
+ <%= class_name %>.stub_method(:find => mock_<%= singular_name %>(:update_attributes => true))
103
+ put :update, :id => 42, :<%= singular_name %> => {'these' => 'params'}
104
+ end
105
+
106
+ it "should find the <%= singular_name.humanize.downcase %>" do
107
+ <%= class_name %>.should have_received(:find).with('42')
108
+ end
109
+ it "should update the <%= singular_name.humanize.downcase %> with the correct params" do
110
+ mock_<%= singular_name %>.should have_received(:update_attributes).with({'these' => 'params'})
111
+ end
112
+ it { should respond_with(:redirect) }
113
+ it { should redirect_to(<%= singular_name %>_url(mock_<%= singular_name %>)) }
114
+ it { should set_the_flash.to(/updated/i) }
115
+ end
116
+
117
+ describe 'with invalid params' do
118
+ before(:each) do
119
+ <%= class_name %>.stub_method(:find => mock_<%= singular_name %>(:update_attributes => false))
120
+ put :update, :id => 42, :<%= singular_name %> => {'these' => 'params'}
121
+ end
122
+
123
+ it { should assign_to(:<%= singular_name %>) }
124
+ it { should respond_with(:success) }
125
+ it { should render_template(:edit) }
126
+ end
127
+ end
128
+
129
+ describe 'DELETE destory' do
130
+ before(:each) do
131
+ <%= class_name %>.stub_method(:find => mock_<%= singular_name %>(:destroy => true))
132
+ delete :destroy, :id => 42
133
+ end
134
+
135
+ it "should find the <%= singular_name.humanize.downcase %>" do
136
+ <%= class_name %>.should have_received(:find).with('42')
137
+ end
138
+ it "should delete the <%= singular_name.humanize.downcase %>" do
139
+ mock_<%= singular_name %>.should have_received(:destroy).with()
140
+ end
141
+ it { should respond_with(:redirect) }
142
+ it { should redirect_to(<%= plural_name %>_url) }
143
+ it { should set_the_flash.to(/deleted/i) }
144
+ end
145
+ end
@@ -0,0 +1,14 @@
1
+ class Create<%= plural_class_name %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= plural_name %>, :force => true do |t|
4
+ <%- attributes.each do |attribute| -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <%- end -%>
7
+ t.timestamps
8
+ end
9
+ end
10
+
11
+ def self.down
12
+ drop_table :<%= plural_name %>
13
+ end
14
+ end
@@ -0,0 +1,2 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ end
@@ -0,0 +1,9 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe <%= class_name %> do
4
+ <%- attributes.each do |attribute| -%>
5
+ it { should have_db_column(:<%= attribute.name %>).of_type(:<%= attribute.type %>) }
6
+ <%- end -%>
7
+ it { should have_db_column(:created_at).of_type(:datetime) }
8
+ it { should have_db_column(:updated_at).of_type(:datetime) }
9
+ end
@@ -0,0 +1,11 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2
+
3
+ describe <%= plural_class_name %>Controller do
4
+ it { should route(:get, '/<%= plural_name %>'). to(:action => :index) }
5
+ it { should route(:get, '/<%= plural_name %>/42'). to(:action => :show, :id => 42) }
6
+ it { should route(:get, '/<%= plural_name %>/new'). to(:action => :new) }
7
+ it { should route(:get, '/<%= plural_name %>/42/edit'). to(:action => :edit, :id => 42) }
8
+ it { should route(:post, '/<%= plural_name %>'). to(:action => :create) }
9
+ it { should route(:put, '/<%= plural_name %>/42'). to(:action => :update, :id => 42) }
10
+ it { should route(:delete, '/<%= plural_name %>/42'). to(:action => :destroy, :id => 42) }
11
+ end
@@ -0,0 +1,11 @@
1
+ - submit_label ||= 'Submit'
2
+ - form_for @<%= singular_name %> do |form|
3
+ = form.error_messages
4
+ <%- attributes.each do |attribute| -%>
5
+ %p
6
+ = form.label :<%= attribute.name %>
7
+ %br/
8
+ = form.<%= attribute.field_type %> :<%= attribute.name %>
9
+ <%- end -%>
10
+ %p
11
+ = form.submit submit_label
@@ -0,0 +1,31 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe '/<%= plural_name %>/_form.html.haml' do
4
+ before(:each) do
5
+ <%= singular_name %> = <%= class_name %>.new
6
+ <%= singular_name %>.stub_method(:new_record? => true)
7
+ assigns[:<%= singular_name %>] = <%= singular_name %>
8
+ render
9
+ end
10
+
11
+ it "should render the <%= singular_name %> form" do
12
+ response.should have_tag("form[action=?]", <%= plural_name %>_path) do
13
+ <%- attributes.each do |attribute| -%>
14
+ <%- case attribute.field_type -%>
15
+ <%- when :text_field, :check_box -%>
16
+ with_tag("input#?[name=?]", "<%= singular_name %>_<%= attribute.name %>", "<%= singular_name %>[<%= attribute.name %>]")
17
+ <%- when :text_area -%>
18
+ with_tag("textarea#?[name=?]", "<%= singular_name %>_<%= attribute.name %>", "<%= singular_name %>[<%= attribute.name %>]")
19
+ <%- when :datetime_select -%>
20
+ %w[1i 2i 3i 4i 5i].each do |i|
21
+ with_tag("select#?[name=?]", "<%= singular_name %>_<%= attribute.name %>_#{i}", "<%= singular_name %>[<%= attribute.name %>(#{i})]")
22
+ end
23
+ <%- when :date_select -%>
24
+ %w[1i 2i 3i].each do |i|
25
+ with_tag("select#?[name=?]", "<%= singular_name %>_<%= attribute.name %>_#{i}", "<%= singular_name %>[<%= attribute.name %>(#{i})]")
26
+ end
27
+ <%- end -%>
28
+ <%- end -%>
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,8 @@
1
+ - title "Edit <%= singular_name.titleize %>"
2
+
3
+ = render 'form', :submit_label => 'Update'
4
+
5
+ %table.actions
6
+ %tr
7
+ %td= link_to 'Show', @<%= singular_name %>
8
+ %td= link_to 'View All', <%= plural_name %>_path
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe '/<%= plural_name %>/edit.html.haml' do
4
+ before(:each) do
5
+ <%= singular_name %> = <%= class_name %>.new
6
+ template.track_methods(:render)
7
+ assigns[:<%= singular_name %>] = <%= singular_name %>
8
+ render
9
+ end
10
+
11
+ it "should render the form partial" do
12
+ template.should have_received(:render).with('form', :submit_label => 'Update', :object => nil, :form => nil)
13
+ end
14
+ end
@@ -0,0 +1,22 @@
1
+ - title "<%= plural_name.titleize %>"
2
+
3
+ %table
4
+ %tr
5
+ <%- attributes.each do |attribute| -%>
6
+ %th <%= attribute.column.human_name %>
7
+ <%- end -%>
8
+ - for <%= singular_name %> in @<%= plural_name %>
9
+ %tr
10
+ <%- attributes.each do |attribute| -%>
11
+ %td= h(<%= singular_name %>.<%= attribute.name %>)
12
+ <%- end -%>
13
+ %td
14
+ %table
15
+ %tr
16
+ %td= link_to 'Show', <%= singular_name %>
17
+ %td= link_to 'Edit', edit_<%= singular_name %>_path(<%= singular_name %>)
18
+ %td= button_to 'Delete', <%= singular_name %>, :confirm => 'Are you sure?', :method => :delete
19
+
20
+ %table
21
+ %tr
22
+ %td= link_to 'New <%= singular_name.titleize %>', new_<%= singular_name %>_path
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe '/<%= plural_name %>/index.html.haml' do
4
+ before(:each) do
5
+ <%= singular_name %> = <%= class_name %>.new
6
+ <%= singular_name %>.stub_method(:id => 42, :to_param => '42')
7
+ <%- attributes.each do |attribute| -%>
8
+ <%- case attribute.type -%>
9
+ <%- when :string, :text -%>
10
+ <%= singular_name %>.<%= attribute.name %> = '<%= attribute.column.human_name.upcase %>-VALUE'
11
+ <%- when :integer -%>
12
+ <%= singular_name %>.<%= attribute.name %> = '42'
13
+ <%- when :float, :decimal -%>
14
+ <%= singular_name %>.<%= attribute.name %> = '3.14'
15
+ <%- when :datetime, :timestamp, :time -%>
16
+ <%= singular_name %>.<%= attribute.name %> = DateTime.strptime('2042-01-01T00:00:00+000')
17
+ <%- when :date -%>
18
+ <%= singular_name %>.<%= attribute.name %> = Date.strptime('2042-01-01')
19
+ <%- end -%>
20
+ <%- end -%>
21
+
22
+ assigns[:<%= plural_name %>] = [<%= singular_name %>]
23
+ render
24
+ end
25
+ <%- attributes.each do |attribute| -%>
26
+
27
+ it "should render the <%= attribute.column.human_name.downcase %>" do
28
+ <%- case attribute.type -%>
29
+ <%- when :string, :text -%>
30
+ response.should have_tag('td', '<%= attribute.column.human_name.upcase %>-VALUE')
31
+ <%- when :integer -%>
32
+ response.should have_tag('td', '42')
33
+ <%- when :float, :decimal -%>
34
+ response.should have_tag('td', '3.14')
35
+ <%- when :datetime, :timestamp, :time -%>
36
+ response.should have_tag('td', '2042-01-01 00:00:00 UTC')
37
+ <%- when :date -%>
38
+ response.should have_tag('td', '2042-01-01')
39
+ <%- end -%>
40
+ end
41
+ <%- end -%>
42
+ end
@@ -0,0 +1,7 @@
1
+ - title "New <%= singular_name.titleize %>"
2
+
3
+ = render 'form', :submit_label => 'Create'
4
+
5
+ %table.actions
6
+ %tr
7
+ %td= link_to 'Back to List', <%= plural_name %>_path
@@ -0,0 +1,14 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe '/<%= plural_name %>/new.html.haml' do
4
+ before(:each) do
5
+ <%= singular_name %> = <%= class_name %>.new
6
+ template.track_methods(:render)
7
+ assigns[:<%= singular_name %>] = <%= singular_name %>
8
+ render
9
+ end
10
+
11
+ it "should render the form partial" do
12
+ template.should have_received(:render).with('form', :submit_label => 'Create', :object => nil, :form => nil)
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ - title "<%= singular_name.titleize %>"
2
+
3
+ <%- attributes.each do |attribute| -%>
4
+ %p
5
+ %strong <%= attribute.column.human_name.titleize %>
6
+ = h(@<%= singular_name %>.<%= attribute.name %>)
7
+ <%- end -%>
8
+
9
+ %table.actions
10
+ %tr
11
+ %td= link_to 'Edit', edit_<%= singular_name %>_path(@<%= singular_name %>)
12
+ %td= button_to 'Delete', @<%= singular_name %>, :confirm => 'Are you sure?', :method => :delete
13
+ %td= link_to 'View All', <%= plural_name %>_path
@@ -0,0 +1,42 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/../../spec_helper')
2
+
3
+ describe '/<%= plural_name %>/show.html.haml' do
4
+ before(:each) do
5
+ <%= singular_name %> = <%= class_name %>.new
6
+ <%= singular_name %>.stub_method(:id => 42, :to_param => '42')
7
+ <%- attributes.each do |attribute| -%>
8
+ <%- case attribute.type -%>
9
+ <%- when :string, :text -%>
10
+ <%= singular_name %>.<%= attribute.name %> = '<%= attribute.column.human_name.upcase %>-VALUE'
11
+ <%- when :integer -%>
12
+ <%= singular_name %>.<%= attribute.name %> = '42'
13
+ <%- when :float, :decimal -%>
14
+ <%= singular_name %>.<%= attribute.name %> = '3.14'
15
+ <%- when :datetime, :timestamp, :time -%>
16
+ <%= singular_name %>.<%= attribute.name %> = DateTime.strptime('2042-01-01T00:00:00+000')
17
+ <%- when :date -%>
18
+ <%= singular_name %>.<%= attribute.name %> = Date.strptime('2042-01-01')
19
+ <%- end -%>
20
+ <%- end -%>
21
+
22
+ assigns[:<%= singular_name %>] = <%= singular_name %>
23
+ render
24
+ end
25
+ <%- attributes.each do |attribute| -%>
26
+
27
+ it "should render the <%= attribute.column.human_name.downcase %>" do
28
+ <%- case attribute.type -%>
29
+ <%- when :string, :text -%>
30
+ response.should include_text('<%= attribute.column.human_name.upcase %>-VALUE')
31
+ <%- when :integer -%>
32
+ response.should include_text('42')
33
+ <%- when :float, :decimal -%>
34
+ response.should include_text('3.14')
35
+ <%- when :datetime, :timestamp, :time -%>
36
+ response.should include_text('2042-01-01 00:00:00 UTC')
37
+ <%- when :date -%>
38
+ response.should include_text('2042-01-01')
39
+ <%- end -%>
40
+ end
41
+ <%- end -%>
42
+ end
@@ -0,0 +1,54 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{spiffy-generators}
5
+ s.version = "0.2.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Hargobind Khalsa"]
9
+ s.date = %q{2009-05-22}
10
+ s.email = %q{khalsah@gmail.com}
11
+ s.files = [
12
+ ".gitignore",
13
+ "Rakefile",
14
+ "VERSION",
15
+ "generators/spiffy_layout/spiffy_layout_generator.rb",
16
+ "generators/spiffy_layout/templates/helper.rb",
17
+ "generators/spiffy_layout/templates/layout.html.haml",
18
+ "generators/spiffy_layout/templates/layout.html.haml_spec.rb",
19
+ "generators/spiffy_layout/templates/stylesheet.sass",
20
+ "generators/spiffy_scaffold/spiffy_scaffold_generator.rb",
21
+ "generators/spiffy_scaffold/templates/controller.rb",
22
+ "generators/spiffy_scaffold/templates/controller_spec.rb",
23
+ "generators/spiffy_scaffold/templates/migration.rb",
24
+ "generators/spiffy_scaffold/templates/model.rb",
25
+ "generators/spiffy_scaffold/templates/model_spec.rb",
26
+ "generators/spiffy_scaffold/templates/routing_spec.rb",
27
+ "generators/spiffy_scaffold/templates/views/_form.html.haml",
28
+ "generators/spiffy_scaffold/templates/views/_form.html.haml_spec.rb",
29
+ "generators/spiffy_scaffold/templates/views/edit.html.haml",
30
+ "generators/spiffy_scaffold/templates/views/edit.html.haml_spec.rb",
31
+ "generators/spiffy_scaffold/templates/views/index.html.haml",
32
+ "generators/spiffy_scaffold/templates/views/index.html.haml_spec.rb",
33
+ "generators/spiffy_scaffold/templates/views/new.html.haml",
34
+ "generators/spiffy_scaffold/templates/views/new.html.haml_spec.rb",
35
+ "generators/spiffy_scaffold/templates/views/show.html.haml",
36
+ "generators/spiffy_scaffold/templates/views/show.html.haml_spec.rb",
37
+ "spiffy-generators.gemspec"
38
+ ]
39
+ s.homepage = %q{http://github.com/khalsah/spiffy-generators}
40
+ s.rdoc_options = ["--charset=UTF-8"]
41
+ s.require_paths = ["lib"]
42
+ s.rubygems_version = %q{1.3.1}
43
+ s.summary = %q{My personal Rails generators.}
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 2
48
+
49
+ if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
50
+ else
51
+ end
52
+ else
53
+ end
54
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: khalsah-spiffy-generators
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Hargobind Khalsa
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-05-22 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: khalsah@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - .gitignore
26
+ - Rakefile
27
+ - VERSION
28
+ - generators/spiffy_layout/spiffy_layout_generator.rb
29
+ - generators/spiffy_layout/templates/helper.rb
30
+ - generators/spiffy_layout/templates/layout.html.haml
31
+ - generators/spiffy_layout/templates/layout.html.haml_spec.rb
32
+ - generators/spiffy_layout/templates/stylesheet.sass
33
+ - generators/spiffy_scaffold/spiffy_scaffold_generator.rb
34
+ - generators/spiffy_scaffold/templates/controller.rb
35
+ - generators/spiffy_scaffold/templates/controller_spec.rb
36
+ - generators/spiffy_scaffold/templates/migration.rb
37
+ - generators/spiffy_scaffold/templates/model.rb
38
+ - generators/spiffy_scaffold/templates/model_spec.rb
39
+ - generators/spiffy_scaffold/templates/routing_spec.rb
40
+ - generators/spiffy_scaffold/templates/views/_form.html.haml
41
+ - generators/spiffy_scaffold/templates/views/_form.html.haml_spec.rb
42
+ - generators/spiffy_scaffold/templates/views/edit.html.haml
43
+ - generators/spiffy_scaffold/templates/views/edit.html.haml_spec.rb
44
+ - generators/spiffy_scaffold/templates/views/index.html.haml
45
+ - generators/spiffy_scaffold/templates/views/index.html.haml_spec.rb
46
+ - generators/spiffy_scaffold/templates/views/new.html.haml
47
+ - generators/spiffy_scaffold/templates/views/new.html.haml_spec.rb
48
+ - generators/spiffy_scaffold/templates/views/show.html.haml
49
+ - generators/spiffy_scaffold/templates/views/show.html.haml_spec.rb
50
+ - spiffy-generators.gemspec
51
+ has_rdoc: false
52
+ homepage: http://github.com/khalsah/spiffy-generators
53
+ post_install_message:
54
+ rdoc_options:
55
+ - --charset=UTF-8
56
+ require_paths:
57
+ - lib
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project:
73
+ rubygems_version: 1.2.0
74
+ signing_key:
75
+ specification_version: 2
76
+ summary: My personal Rails generators.
77
+ test_files: []
78
+