dm-haml-scaffold-generator 0.0.1
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/LICENSE +20 -0
- data/README.rdoc +20 -0
- data/VERSION.yml +4 -0
- data/generators/USAGE +1 -0
- data/generators/dm_haml_scaffold/dm_haml_scaffold_generator.rb +204 -0
- data/generators/dm_haml_scaffold/templates/INSTALL +15 -0
- data/generators/dm_haml_scaffold/templates/controller.rb +85 -0
- data/generators/dm_haml_scaffold/templates/edit_haml_spec.rb +23 -0
- data/generators/dm_haml_scaffold/templates/helper.rb +3 -0
- data/generators/dm_haml_scaffold/templates/helper_spec.rb +4 -0
- data/generators/dm_haml_scaffold/templates/index_haml_spec.rb +21 -0
- data/generators/dm_haml_scaffold/templates/model.rb +10 -0
- data/generators/dm_haml_scaffold/templates/model_spec.rb +13 -0
- data/generators/dm_haml_scaffold/templates/new_haml_spec.rb +24 -0
- data/generators/dm_haml_scaffold/templates/show_haml_spec.rb +22 -0
- data/generators/dm_haml_scaffold/templates/view__form_haml.erb +8 -0
- data/generators/dm_haml_scaffold/templates/view__singular_haml.erb +8 -0
- data/generators/dm_haml_scaffold/templates/view_edit_haml.erb +11 -0
- data/generators/dm_haml_scaffold/templates/view_index_haml.erb +13 -0
- data/generators/dm_haml_scaffold/templates/view_new_haml.erb +9 -0
- data/generators/dm_haml_scaffold/templates/view_show_haml.erb +9 -0
- metadata +76 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Zach Inglis
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
RSpec Haml Scaffold Generator
|
2
|
+
====
|
3
|
+
|
4
|
+
This is an uber version of the RSpec Scaffold Generator, the following things have been added:
|
5
|
+
|
6
|
+
Support for Haml instead of erb
|
7
|
+
Nested routes (nested tests/migrations)
|
8
|
+
|
9
|
+
Installation:
|
10
|
+
sudo gem install zachinglis-rspec-haml-scaffold
|
11
|
+
|
12
|
+
Examples:
|
13
|
+
|
14
|
+
./script/generate dm_haml_scaffold post # no attributes, view will be anemic
|
15
|
+
./script/generate dm_haml_scaffold post attribute:string attribute:boolean # this is actually broken at the moment, don't do this !!! Feel free to patch it
|
16
|
+
|
17
|
+
Credits
|
18
|
+
|
19
|
+
* Daniel Fischer - http://danielfischer.com
|
20
|
+
* Zach Inglis - http://zachinglis.com
|
data/VERSION.yml
ADDED
data/generators/USAGE
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
./script/generate dm_haml_scaffold
|
@@ -0,0 +1,204 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'activerecord'
|
3
|
+
|
4
|
+
class DmHamlScaffoldGenerator < Rails::Generator::NamedBase
|
5
|
+
attr_reader :controller_name,
|
6
|
+
:controller_class_path,
|
7
|
+
:controller_file_path,
|
8
|
+
:controller_class_nesting,
|
9
|
+
:controller_class_nesting_depth,
|
10
|
+
:controller_class_name,
|
11
|
+
:controller_singular_name,
|
12
|
+
:controller_plural_name,
|
13
|
+
:resource_edit_path,
|
14
|
+
:default_file_extension
|
15
|
+
:model_name
|
16
|
+
|
17
|
+
alias_method :controller_file_name, :controller_singular_name
|
18
|
+
alias_method :controller_table_name, :controller_plural_name
|
19
|
+
|
20
|
+
def initialize runtime_args, runtime_options = {}
|
21
|
+
super
|
22
|
+
@model_name = singular_name.split.map { |e| e.capitalize }.join('')
|
23
|
+
@controller_name = @name.pluralize
|
24
|
+
|
25
|
+
base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(@controller_name)
|
26
|
+
@controller_class_name_without_nesting, @controller_singular_name, @controller_plural_name = inflect_names(base_name)
|
27
|
+
|
28
|
+
if @controller_class_nesting.empty?
|
29
|
+
@controller_class_name = @controller_class_name_without_nesting
|
30
|
+
else
|
31
|
+
@controller_class_name = "#{ @controller_class_nesting }::#{ @controller_class_name_without_nesting }"
|
32
|
+
end
|
33
|
+
|
34
|
+
@resource_generator = 'dm_haml_scaffold'
|
35
|
+
@default_file_extension = 'html.haml'
|
36
|
+
@resource_edit_path = '/edit'
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
def manifest
|
41
|
+
record do |m|
|
42
|
+
#just so you can see what the variables are
|
43
|
+
# => "yoda/bob"
|
44
|
+
#p @name # yoda/bob
|
45
|
+
#p @controller_name # yoda/bobs
|
46
|
+
#p @controller_class_name_without_nesting # Bobs
|
47
|
+
#p @controller_class_nesting # yoda
|
48
|
+
#p @controller_plural_name #bobs
|
49
|
+
#p @controller_singular_name #bobs
|
50
|
+
#p @controller_file_path #yoda/bobs
|
51
|
+
#p @controller_class_path # ["yoda"]
|
52
|
+
|
53
|
+
# Check for class naming collisions.
|
54
|
+
m.class_collisions(controller_class_path, "#{ controller_class_name }Controller", "#{ controller_class_name }Helper")
|
55
|
+
m.class_collisions(class_path, "#{ class_name }")
|
56
|
+
|
57
|
+
# Controller, helper, views, and spec directories.
|
58
|
+
m.directory File.join('app/models')
|
59
|
+
m.directory File.join('app/controllers', controller_class_path)
|
60
|
+
m.directory File.join('app/helpers', controller_class_path)
|
61
|
+
m.directory File.join('app/views', controller_class_path, controller_file_name)
|
62
|
+
m.directory File.join('spec/models')
|
63
|
+
m.directory File.join('spec/helpers', class_path)
|
64
|
+
m.directory File.join('spec/factories')
|
65
|
+
m.directory File.join('spec/integration')
|
66
|
+
m.directory File.join('spec/views', controller_class_path, controller_file_name)
|
67
|
+
|
68
|
+
# Controller spec, class, and helper.
|
69
|
+
m.template 'dm_haml_scaffold:controller.rb',
|
70
|
+
File.join('app/controllers', controller_class_path, "#{ controller_file_name }_controller.rb")
|
71
|
+
|
72
|
+
m.template 'dm_haml_scaffold:helper_spec.rb',
|
73
|
+
File.join('spec/helpers', class_path, "#{ controller_file_name }_helper_spec.rb")
|
74
|
+
|
75
|
+
m.template "#{ @resource_generator }:helper.rb",
|
76
|
+
File.join('app/helpers', controller_class_path, "#{ controller_file_name }_helper.rb")
|
77
|
+
|
78
|
+
# views with form partial
|
79
|
+
for action in scaffold_views
|
80
|
+
m.template "dm_haml_scaffold:view_#{ action }_haml.erb",
|
81
|
+
File.join('app/views', controller_class_path, controller_file_name, "#{ action }.#{ default_file_extension }")
|
82
|
+
end
|
83
|
+
|
84
|
+
# partial for the index
|
85
|
+
m.template "dm_haml_scaffold:view__singular_haml.erb",
|
86
|
+
File.join('app/views', controller_class_path, controller_file_name, "_#{ name.singularize }.#{ default_file_extension }")
|
87
|
+
|
88
|
+
# Model class, unit test
|
89
|
+
m.template 'dm_haml_scaffold:model.rb',
|
90
|
+
File.join('app/models', "#{ @controller_singular_name.singularize }.rb")
|
91
|
+
|
92
|
+
m.template 'dm_haml_scaffold:model_spec.rb',
|
93
|
+
File.join('spec/models', "#{ @controller_singular_name.singularize }_spec.rb")
|
94
|
+
|
95
|
+
# View specs
|
96
|
+
m.template "dm_haml_scaffold:edit_haml_spec.rb",
|
97
|
+
File.join('spec/views', controller_class_path, controller_file_name, "edit.#{ default_file_extension }_spec.rb")
|
98
|
+
|
99
|
+
m.template "dm_haml_scaffold:index_haml_spec.rb",
|
100
|
+
File.join('spec/views', controller_class_path, controller_file_name, "index.#{ default_file_extension }_spec.rb")
|
101
|
+
|
102
|
+
m.template "dm_haml_scaffold:new_haml_spec.rb",
|
103
|
+
File.join('spec/views', controller_class_path, controller_file_name, "new.#{ default_file_extension }_spec.rb")
|
104
|
+
|
105
|
+
m.template "dm_haml_scaffold:show_haml_spec.rb",
|
106
|
+
File.join('spec/views', controller_class_path, controller_file_name, "show.#{ default_file_extension }_spec.rb")
|
107
|
+
|
108
|
+
m.route_resources controller_file_name
|
109
|
+
route_resources name
|
110
|
+
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
protected
|
115
|
+
|
116
|
+
def form_link_for(table_name, singular_name)
|
117
|
+
if !@controller_name.split("/")[1].nil?
|
118
|
+
return "[:#{ @controller_class_nesting.downcase }, @#{ singular_name.singularize }]"
|
119
|
+
else
|
120
|
+
return "@#{ singular_name.singularize }"
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def path_for singular, plural, txt
|
125
|
+
case txt
|
126
|
+
when 'show'
|
127
|
+
return "#{ table_name.singularize }_path(@#{ singular_name.singularize })"
|
128
|
+
when 'edit'
|
129
|
+
return "edit_#{ table_name.singularize }_path(@#{ singular_name.singularize })"
|
130
|
+
when 'destroy'
|
131
|
+
return "#{ table_name.singularize }_path(@#{ singular_name.singularize }), :confirm => 'Are you sure?', :method => :delete"
|
132
|
+
when 'index'
|
133
|
+
return "#{ table_name }_path"
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Override with your own usage banner.
|
138
|
+
def banner
|
139
|
+
"Usage: #{ $0 } dm_haml_scaffold ModelName [field:type field:type]"
|
140
|
+
end
|
141
|
+
|
142
|
+
def scaffold_views
|
143
|
+
%w[ index show new edit _form ]
|
144
|
+
end
|
145
|
+
|
146
|
+
def model_name
|
147
|
+
class_name.demodulize
|
148
|
+
end
|
149
|
+
|
150
|
+
def route_resources resource
|
151
|
+
sentinel = 'ActionController::Routing::Routes.draw do |map|'
|
152
|
+
logger.route "map.resources #{ resource }"
|
153
|
+
unless options[:pretend]
|
154
|
+
gsub_file 'config/routes.rb', /(#{ Regexp.escape(sentinel) })/mi do |match|
|
155
|
+
|
156
|
+
if !resource.split('/')[1].nil?
|
157
|
+
one = resource.split('/')[0]
|
158
|
+
two = resource.split('/')[1]
|
159
|
+
"#{ match }\n map.namespace(:#{ one }) do |#{ one }|\n #{ one }.resources :#{ two.pluralize }\n end"
|
160
|
+
else
|
161
|
+
"#{ match }\n map.resources :#{ resource.pluralize }\n"
|
162
|
+
end
|
163
|
+
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|
167
|
+
|
168
|
+
|
169
|
+
def gsub_file relative_destination, regexp, *args, &block
|
170
|
+
path = destination_path relative_destination
|
171
|
+
content = File.read(path).gsub(regexp, *args, &block)
|
172
|
+
File.open(path, 'wb') { |file| file.write content }
|
173
|
+
end
|
174
|
+
|
175
|
+
end
|
176
|
+
|
177
|
+
module Rails
|
178
|
+
module Generator
|
179
|
+
class GeneratedAttribute
|
180
|
+
def default_value
|
181
|
+
@default_value ||= case type
|
182
|
+
when :int, :integer then "\"1\""
|
183
|
+
when :float then "\"1.5\""
|
184
|
+
when :decimal then "\"9.99\""
|
185
|
+
when :datetime, :timestamp, :time then "Time.now"
|
186
|
+
when :date then "Date.today"
|
187
|
+
when :string then "\"MyString\""
|
188
|
+
when :text then "\"MyText\""
|
189
|
+
when :boolean then "false"
|
190
|
+
else
|
191
|
+
""
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
def input_type
|
196
|
+
@input_type ||= case type
|
197
|
+
when :text then "textarea"
|
198
|
+
else
|
199
|
+
"input"
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
RSpec Haml Scaffold Generator
|
2
|
+
====
|
3
|
+
|
4
|
+
This is an super - uber version of the RSpec Scaffold Generator, the following things have been added:
|
5
|
+
|
6
|
+
Support for Haml instead of erb
|
7
|
+
Nested routes (nested tests/migrations)
|
8
|
+
DataMapper
|
9
|
+
|
10
|
+
Also assumes you're using factory girl and factory girl extensions.
|
11
|
+
|
12
|
+
Examples:
|
13
|
+
|
14
|
+
./script generate dm_haml_scaffold post # no attributes, view will be anemic
|
15
|
+
./script generate dm_haml_scaffold post attribute:string attribute:boolean # this is actually broken at the moment, don't do this !!! Feel free to patch it
|
@@ -0,0 +1,85 @@
|
|
1
|
+
class <%= controller_class_name %>Controller < ApplicationController
|
2
|
+
# GET /<%= name %>
|
3
|
+
# GET /<%= name %>.xml
|
4
|
+
def index
|
5
|
+
@<%= plural_name %> = <%= singular_name.capitalize %>.find(:all)
|
6
|
+
|
7
|
+
respond_to do |format|
|
8
|
+
format.html # index.html.haml
|
9
|
+
format.xml { render :xml => @<%= plural_name %> }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
# GET /<%= name %>/1
|
14
|
+
# GET /<%= name %>/1.xml
|
15
|
+
def show
|
16
|
+
@<%= singular_name %> = <%= singular_name.capitalize %>.find(params[:id])
|
17
|
+
|
18
|
+
respond_to do |format|
|
19
|
+
format.html # show.html.haml
|
20
|
+
format.xml { render :xml => @<%= singular_name %> }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /<%= name %>/new
|
25
|
+
# GET /<%= name %>/new.xml
|
26
|
+
def new
|
27
|
+
@<%= singular_name %> = <%= singular_name.capitalize %>.new
|
28
|
+
|
29
|
+
respond_to do |format|
|
30
|
+
format.html # new.html.haml
|
31
|
+
format.xml { render :xml => @<%= singular_name %> }
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# GET /<%= name %>/1/edit
|
36
|
+
def edit
|
37
|
+
@<%= singular_name %> = <%= singular_name.capitalize %>.find(params[:id])
|
38
|
+
end
|
39
|
+
|
40
|
+
# POST /<%= name %>
|
41
|
+
# POST /<%= name %>.xml
|
42
|
+
def create
|
43
|
+
@<%= file_name %> = <%= singular_name.capitalize %>.new(params[:<%= singular_name %>])
|
44
|
+
|
45
|
+
respond_to do |format|
|
46
|
+
if @<%= file_name %>.save
|
47
|
+
flash[:notice] = '<%= singular_name.capitalize %> was successfully created.'
|
48
|
+
format.html { redirect_to(<%= table_name.singularize %>_path(@<%= file_name %>)) }
|
49
|
+
format.xml { render :xml => @<%= file_name %>, :status => :created, :location => @<%= file_name %> }
|
50
|
+
else
|
51
|
+
format.html { render :action => "new" }
|
52
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
|
57
|
+
# PUT /<%= name %>/1
|
58
|
+
# PUT /<%= name %>/1.xml
|
59
|
+
def update
|
60
|
+
@<%= file_name %> = <%= singular_name.capitalize %>.find(params[:id])
|
61
|
+
|
62
|
+
respond_to do |format|
|
63
|
+
if @<%= file_name %>.update_attributes(params[:<%= file_name %>])
|
64
|
+
flash[:notice] = '<%= singular_name.capitalize %> was successfully updated.'
|
65
|
+
format.html { redirect_to(<%= table_name.singularize %>_path(@<%= file_name %>)) }
|
66
|
+
format.xml { head :ok }
|
67
|
+
else
|
68
|
+
format.html { render :action => "edit" }
|
69
|
+
format.xml { render :xml => @<%= file_name %>.errors, :status => :unprocessable_entity }
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# DELETE /<%= name %>/1
|
75
|
+
# DELETE /<%= name %>/1.xml
|
76
|
+
def destroy
|
77
|
+
@<%= file_name %> = <%= singular_name.capitalize %>.find(params[:id])
|
78
|
+
@<%= file_name %>.destroy
|
79
|
+
|
80
|
+
respond_to do |format|
|
81
|
+
format.html { redirect_to(<%= table_name %>_url) }
|
82
|
+
format.xml { head :ok }
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
|
2
|
+
|
3
|
+
describe "/<%= name %>/edit.<%= default_file_extension %>" do
|
4
|
+
include <%= controller_class_name %>Helper
|
5
|
+
|
6
|
+
before do
|
7
|
+
@<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
|
8
|
+
<% for attribute in attributes -%>
|
9
|
+
@<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
|
10
|
+
<% end -%>
|
11
|
+
assigns[:<%= file_name %>] = @<%= file_name %>
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should render edit form" do
|
15
|
+
render "/<%= name.pluralize %>/edit.<%= default_file_extension %>"
|
16
|
+
|
17
|
+
response.should have_tag("form[action=#{<%= table_name.singularize %>_path(@<%= file_name %>)}][method=post]") do
|
18
|
+
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
|
19
|
+
with_tag('<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]', "<%= file_name %>[<%= attribute.name %>]")
|
20
|
+
<% end -%><% end -%>
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
|
2
|
+
|
3
|
+
describe "/<%= name.pluralize %>/index.<%= default_file_extension %>" do
|
4
|
+
include <%= controller_class_name %>Helper
|
5
|
+
|
6
|
+
before do
|
7
|
+
<% [98,99].each do |id| -%>
|
8
|
+
<%= file_name %>_<%= id %> = mock_model(<%= singular_name.capitalize %>)
|
9
|
+
<% for attribute in attributes -%>
|
10
|
+
<%= file_name %>_<%= id %>.should_receive(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
|
11
|
+
<% end -%><% end %>
|
12
|
+
assigns[:<%= file_name.pluralize %>] = [<%= file_name %>_98, <%= file_name %>_99]
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should render list of <%= table_name %>" do
|
16
|
+
render "/<%= name.pluralize %>/index.<%= default_file_extension %>"
|
17
|
+
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
|
18
|
+
response.should have_tag("tr>td", <%= attribute.default_value %>, 2)
|
19
|
+
<% end -%><% end -%>
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
|
2
|
+
|
3
|
+
describe "/<%= name.pluralize %>/new.<%= default_file_extension %>" do
|
4
|
+
include <%= controller_class_name %>Helper
|
5
|
+
|
6
|
+
before do
|
7
|
+
@<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
|
8
|
+
@<%= file_name %>.stub!(:new_record?).and_return(true)
|
9
|
+
<% for attribute in attributes -%>
|
10
|
+
@<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
|
11
|
+
<% end -%>
|
12
|
+
assigns[:<%= file_name %>] = @<%= file_name %>
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should render new form" do
|
16
|
+
render "/<%= name.pluralize %>/new.<%= default_file_extension %>"
|
17
|
+
|
18
|
+
response.should have_tag("form[action=?][method=post]", <%= table_name %>_path) do
|
19
|
+
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
|
20
|
+
with_tag("<%= attribute.input_type -%>#<%= file_name %>_<%= attribute.name %>[name=?]", "<%= file_name %>[<%= attribute.name %>]")
|
21
|
+
<% end -%><% end -%>
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.dirname(__FILE__) + '<%= '/..' * class_nesting_depth %>/../../spec_helper'
|
2
|
+
|
3
|
+
describe "/<%= name.pluralize %>/show.<%= default_file_extension %>" do
|
4
|
+
include <%= controller_class_name %>Helper
|
5
|
+
|
6
|
+
before do
|
7
|
+
@<%= file_name %> = mock_model(<%= singular_name.capitalize %>)
|
8
|
+
<% for attribute in attributes -%>
|
9
|
+
@<%= file_name %>.stub!(:<%= attribute.name %>).and_return(<%= attribute.default_value %>)
|
10
|
+
<% end -%>
|
11
|
+
|
12
|
+
assigns[:<%= file_name %>] = @<%= file_name %>
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should render attributes in <p>" do
|
16
|
+
render "/<%= name.pluralize %>/show.<%= default_file_extension %>"
|
17
|
+
<% for attribute in attributes -%><% unless attribute.name =~ /_id/ || [:datetime, :timestamp, :time, :date].index(attribute.type) -%>
|
18
|
+
response.should have_text(/<%= Regexp.escape(attribute.default_value)[1..-2]%>/)
|
19
|
+
<% end -%><% end -%>
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
@@ -0,0 +1,8 @@
|
|
1
|
+
%tr
|
2
|
+
<% for attribute in attributes -%>
|
3
|
+
%td=h <%= singular_name %>.<%= attribute.name %>
|
4
|
+
<% end %>
|
5
|
+
%td
|
6
|
+
= link_to 'Show', <%= name.singularize %>
|
7
|
+
= link_to 'Edit', <%= path_for(table_name, singular_name, "edit").gsub(/@/, "") %>
|
8
|
+
= link_to 'Destroy', <%= name.singularize %>, :confirm => "Are you sure?", :method => :delete
|
@@ -0,0 +1,11 @@
|
|
1
|
+
%h1 Editing <%= singular_name %>
|
2
|
+
|
3
|
+
- form_for(<%= form_link_for(table_name, singular_name) %>) do |f|
|
4
|
+
= render :partial => 'form', :locals => { :f => f }
|
5
|
+
|
6
|
+
%p
|
7
|
+
= f.submit "Update"
|
8
|
+
or
|
9
|
+
= link_to 'Show', <%= path_for(table_name, singular_name, "show") %>
|
10
|
+
or
|
11
|
+
= link_to 'Back', <%= path_for(table_name, singular_name, "index") %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
%h1 Listing <%= plural_name %>
|
2
|
+
|
3
|
+
= link_to 'Add <%= singular_name.singularize.titleize %>', new_<%= table_name.singularize %>_path
|
4
|
+
|
5
|
+
%table
|
6
|
+
%thead
|
7
|
+
%tr
|
8
|
+
<% for attribute in attributes -%>
|
9
|
+
%th <%=attribute.column.human_name %>
|
10
|
+
<% end -%>
|
11
|
+
%th
|
12
|
+
|
13
|
+
%tbody= render @<%= plural_name %>
|
@@ -0,0 +1,9 @@
|
|
1
|
+
<% for attribute in attributes -%>
|
2
|
+
%p
|
3
|
+
%strong <%= attribute.column.human_name %>:
|
4
|
+
=h @<%= singular_name %>.<%= attribute.name %>
|
5
|
+
|
6
|
+
<% end -%>
|
7
|
+
|
8
|
+
= link_to 'Edit', <%= path_for(table_name, singular_name, "edit") %>
|
9
|
+
= link_to 'Back', <%= path_for(table_name, singular_name, "index") %>
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: dm-haml-scaffold-generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- BM5k
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2010-01-19 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: gems@bm5k.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- LICENSE
|
24
|
+
- README.rdoc
|
25
|
+
files:
|
26
|
+
- LICENSE
|
27
|
+
- README.rdoc
|
28
|
+
- VERSION.yml
|
29
|
+
- generators/USAGE
|
30
|
+
- generators/dm_haml_scaffold/dm_haml_scaffold_generator.rb
|
31
|
+
- generators/dm_haml_scaffold/templates/INSTALL
|
32
|
+
- generators/dm_haml_scaffold/templates/controller.rb
|
33
|
+
- generators/dm_haml_scaffold/templates/edit_haml_spec.rb
|
34
|
+
- generators/dm_haml_scaffold/templates/helper.rb
|
35
|
+
- generators/dm_haml_scaffold/templates/helper_spec.rb
|
36
|
+
- generators/dm_haml_scaffold/templates/index_haml_spec.rb
|
37
|
+
- generators/dm_haml_scaffold/templates/model.rb
|
38
|
+
- generators/dm_haml_scaffold/templates/model_spec.rb
|
39
|
+
- generators/dm_haml_scaffold/templates/view__form_haml.erb
|
40
|
+
- generators/dm_haml_scaffold/templates/view__singular_haml.erb
|
41
|
+
- generators/dm_haml_scaffold/templates/new_haml_spec.rb
|
42
|
+
- generators/dm_haml_scaffold/templates/show_haml_spec.rb
|
43
|
+
- generators/dm_haml_scaffold/templates/view_edit_haml.erb
|
44
|
+
- generators/dm_haml_scaffold/templates/view_index_haml.erb
|
45
|
+
- generators/dm_haml_scaffold/templates/view_new_haml.erb
|
46
|
+
- generators/dm_haml_scaffold/templates/view_show_haml.erb
|
47
|
+
has_rdoc: true
|
48
|
+
homepage: http://github.com/bm5k/dm-haml-scaffold-generator
|
49
|
+
licenses: []
|
50
|
+
|
51
|
+
post_install_message:
|
52
|
+
rdoc_options:
|
53
|
+
- --charset=UTF-8
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: "0"
|
61
|
+
version:
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: "0"
|
67
|
+
version:
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.3.5
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Generate DataMapper/RSpec/HAML scaffolds with partials. Ported from rspec-haml-scaffold-generator by Zach Inglis & Daniel Fischer
|
75
|
+
test_files: []
|
76
|
+
|