bootstrapped 0.0.3 → 0.0.4

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.
Files changed (55) hide show
  1. data/lib/bootstrapped/version.rb +1 -1
  2. data/lib/generators/bootstrapped.rb +28 -0
  3. data/lib/generators/bootstrapped/layout/USAGE +25 -0
  4. data/lib/generators/bootstrapped/layout/layout_generator.rb +22 -0
  5. data/lib/generators/bootstrapped/layout/templates/_flash.html.erb +4 -0
  6. data/lib/generators/bootstrapped/layout/templates/error_messages_helper.rb +31 -0
  7. data/lib/generators/bootstrapped/layout/templates/layout.html.erb +30 -0
  8. data/lib/generators/bootstrapped/layout/templates/layout_helper.rb +22 -0
  9. data/lib/generators/bootstrapped/scaffold/USAGE +51 -0
  10. data/lib/generators/bootstrapped/scaffold/scaffold_generator.rb +313 -0
  11. data/lib/generators/bootstrapped/scaffold/templates/actions/create.rb +8 -0
  12. data/lib/generators/bootstrapped/scaffold/templates/actions/destroy.rb +5 -0
  13. data/lib/generators/bootstrapped/scaffold/templates/actions/edit.rb +3 -0
  14. data/lib/generators/bootstrapped/scaffold/templates/actions/index.rb +3 -0
  15. data/lib/generators/bootstrapped/scaffold/templates/actions/new.rb +3 -0
  16. data/lib/generators/bootstrapped/scaffold/templates/actions/show.rb +3 -0
  17. data/lib/generators/bootstrapped/scaffold/templates/actions/update.rb +8 -0
  18. data/lib/generators/bootstrapped/scaffold/templates/controller.rb +3 -0
  19. data/lib/generators/bootstrapped/scaffold/templates/fixtures.yml +9 -0
  20. data/lib/generators/bootstrapped/scaffold/templates/helper.rb +2 -0
  21. data/lib/generators/bootstrapped/scaffold/templates/migration.rb +16 -0
  22. data/lib/generators/bootstrapped/scaffold/templates/model.rb +4 -0
  23. data/lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/create.rb +11 -0
  24. data/lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/destroy.rb +6 -0
  25. data/lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/edit.rb +4 -0
  26. data/lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/index.rb +4 -0
  27. data/lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/new.rb +4 -0
  28. data/lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/show.rb +4 -0
  29. data/lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/update.rb +11 -0
  30. data/lib/generators/bootstrapped/scaffold/templates/tests/rspec/controller.rb +8 -0
  31. data/lib/generators/bootstrapped/scaffold/templates/tests/rspec/model.rb +7 -0
  32. data/lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/create.rb +13 -0
  33. data/lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/destroy.rb +8 -0
  34. data/lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/edit.rb +6 -0
  35. data/lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/index.rb +6 -0
  36. data/lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/new.rb +6 -0
  37. data/lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/show.rb +6 -0
  38. data/lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/update.rb +13 -0
  39. data/lib/generators/bootstrapped/scaffold/templates/tests/shoulda/controller.rb +5 -0
  40. data/lib/generators/bootstrapped/scaffold/templates/tests/shoulda/model.rb +7 -0
  41. data/lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/create.rb +11 -0
  42. data/lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/destroy.rb +6 -0
  43. data/lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/edit.rb +4 -0
  44. data/lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/index.rb +4 -0
  45. data/lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/new.rb +4 -0
  46. data/lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/show.rb +4 -0
  47. data/lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/update.rb +11 -0
  48. data/lib/generators/bootstrapped/scaffold/templates/tests/testunit/controller.rb +5 -0
  49. data/lib/generators/bootstrapped/scaffold/templates/tests/testunit/model.rb +7 -0
  50. data/lib/generators/bootstrapped/scaffold/templates/views/erb/_form.html.erb +15 -0
  51. data/lib/generators/bootstrapped/scaffold/templates/views/erb/edit.html.erb +14 -0
  52. data/lib/generators/bootstrapped/scaffold/templates/views/erb/index.html.erb +39 -0
  53. data/lib/generators/bootstrapped/scaffold/templates/views/erb/new.html.erb +7 -0
  54. data/lib/generators/bootstrapped/scaffold/templates/views/erb/show.html.erb +23 -0
  55. metadata +62 -9
@@ -1,3 +1,3 @@
1
1
  module Bootstrapped
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -0,0 +1,28 @@
1
+ require 'rails/generators/base'
2
+
3
+ module Bootstrapped
4
+ module Generators
5
+ class Base < ::Rails::Generators::Base
6
+ def self.source_root
7
+ @_bootstrapped_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'bootstrapped', generator_name, 'templates'))
8
+ end
9
+
10
+ def self.banner
11
+ "rails generate bootstrap:#{generator_name} #{self.arguments.map{ |a| a.usage }.join(' ')} [options]"
12
+ end
13
+
14
+ private
15
+
16
+ def add_gem(name, options = {})
17
+ gemfile_content = File.read(destination_path("Gemfile"))
18
+ File.open(destination_path("Gemfile"), 'a') { |f| f.write("\n") } unless gemfile_content =~ /\n\Z/
19
+ gem name, options unless gemfile_content.include? name
20
+ end
21
+
22
+ def print_usage
23
+ self.class.help(Thor::Base.shell.new)
24
+ exit
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,25 @@
1
+ Description:
2
+ The bootstrap_layout generator creates a basic layout, stylesheet and
3
+ helper which will give some structure to a starting Rails app.
4
+
5
+ The generator takes one argument which will be the name of the
6
+ layout and stylesheet files. If no argument is passed then it defaults
7
+ to "application".
8
+
9
+ The helper module includes some methods which can be called in any
10
+ template or partial to set variables to be used in the layout, such as
11
+ page title and javascript/stylesheet includes.
12
+
13
+ Examples:
14
+ rails generate bootstrap:layout
15
+
16
+ Layout: app/views/layouts/application.html.erb
17
+ Stylesheet: public/stylesheets/application.css
18
+ Helper: app/helpers/layout_helper.rb
19
+
20
+
21
+ rails generate bootstrap:layout admin
22
+
23
+ Layout: app/views/layouts/admin.html.erb
24
+ Stylesheet: public/stylesheets/admin.css
25
+ Helper: app/helpers/layout_helper.rb
@@ -0,0 +1,22 @@
1
+ require 'generators/bootstrapped'
2
+
3
+ module Bootstrapped
4
+ module Generators
5
+ class LayoutGenerator < Base
6
+ argument :layout_name, :type => :string, :default => 'application', :banner => 'layout_name'
7
+
8
+ def create_layout
9
+ template 'layout.html.erb', "app/views/layouts/#{file_name}.html.erb"
10
+ copy_file 'layout_helper.rb', 'app/helpers/layout_helper.rb'
11
+ copy_file 'error_messages_helper.rb', 'app/helpers/error_messages_helper.rb'
12
+ copy_file '_flash.html.erb', 'app/views/share/_flash.html.erb'
13
+ end
14
+
15
+ private
16
+
17
+ def file_name
18
+ layout_name.underscore
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,4 @@
1
+ <div class="alert-message <%%= css %>">
2
+ <a class="close" href="#">×</a>
3
+ <p id="error"><%%= message %></p>
4
+ </div>
@@ -0,0 +1,31 @@
1
+ module ErrorMessagesHelper
2
+ # Render error messages for the given objects. The :message and :header_message options are allowed.
3
+ def error_messages_for(*objects)
4
+ options = objects.extract_options!
5
+ options[:header_message] ||= I18n.t(:"activerecord.errors.header", :default => "Invalid Fields")
6
+ options[:message] ||= I18n.t(:"activerecord.errors.message", :default => "Correct the following errors and try again.")
7
+ messages = objects.compact.map { |o| o.errors.full_messages }.flatten
8
+ unless messages.empty?
9
+ content_tag(:div, :class => "error_messages") do
10
+ list_items = messages.map { |msg| content_tag(:li, msg.html_safe) }
11
+ content_tag(:h2, options[:header_message].html_safe) + content_tag(:p, options[:message].html_safe) + content_tag(:ul, list_items.join.html_safe)
12
+ end
13
+ end
14
+ end
15
+
16
+ def display_flash_message
17
+ flash.each do |key, value|
18
+ css_class = key.eql?('notice') ? 'success' : 'error'
19
+ render :partial => 'share/flash', :locals => { :css => css_class, :message => value }
20
+ end
21
+ nil
22
+ end
23
+
24
+ module FormBuilderAdditions
25
+ def error_messages(options = {})
26
+ @template.error_messages_for(@object, options)
27
+ end
28
+ end
29
+ end
30
+
31
+ ActionView::Helpers::FormBuilder.send(:include, ErrorMessagesHelper::FormBuilderAdditions)
@@ -0,0 +1,30 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%%= content_for?(:title) ? yield(:title) : "Untitled" %></title>
5
+ <%%= stylesheet_link_tag "application" %>
6
+ <%%= javascript_include_tag "application" %>
7
+ <%%= csrf_meta_tag %>
8
+ <%%= yield(:head) %>
9
+ </head>
10
+ <body class="with-header">
11
+ <div class="topbar">
12
+ <div class="fill">
13
+ <div class="container">
14
+ <h3><%%= link_to 'Project Name', '#' %></h3>
15
+ </div>
16
+ </div>
17
+ </div>
18
+ <%%= display_flash_message %>
19
+ <div class="container">
20
+ <%% flash.each do |name, msg| %>
21
+ <%%= content_tag :div, msg, :id => "flash_#{name}" %>
22
+ <%% end %>
23
+ <%%= content_tag :h1, yield(:title) if show_title? %>
24
+ <%%= yield %>
25
+ <footer>
26
+ <p>&copy; Company <%%= Time.now.year %></p>
27
+ </footer>
28
+ </div>
29
+ </body>
30
+ </html>
@@ -0,0 +1,22 @@
1
+ # These helper methods can be called in your template to set variables to be used in the layout
2
+ # This module should be included in all views globally,
3
+ # to do so you may need to add this line to your ApplicationController
4
+ # helper :layout
5
+ module LayoutHelper
6
+ def title(page_title, show_title = true)
7
+ content_for(:title) { h(page_title.to_s) }
8
+ @show_title = show_title
9
+ end
10
+
11
+ def show_title?
12
+ @show_title
13
+ end
14
+
15
+ def stylesheet(*args)
16
+ content_for(:head) { stylesheet_link_tag(*args) }
17
+ end
18
+
19
+ def javascript(*args)
20
+ content_for(:head) { javascript_include_tag(*args) }
21
+ end
22
+ end
@@ -0,0 +1,51 @@
1
+ Description:
2
+ Scaffolds an entire resource, from model and migration to controller and
3
+ views. The resource is ready to use as a starting point for your restful,
4
+ resource-oriented application. Tests or specs are also generated depending
5
+ on if you have a "spec" directory or not.
6
+
7
+ IMPORTANT: This generator uses the "title" helper method which is generated
8
+ by the nifty_layout generator. You may want to run that generator first.
9
+
10
+ Usage:
11
+ Pass the name of the model, either CamelCased or under_scored, as the first
12
+ argument along with an optional list of attribute pairs and controller actions.
13
+
14
+ If no controller actions are specified, they will default to index, show,
15
+ new, create, edit, update, and destroy.
16
+
17
+ IMPORTANT: If no attribute pairs are specified, no model will be generated.
18
+ It will try to determine the attributes from an existing model.
19
+
20
+ Attribute pairs are column_name:sql_type arguments specifying the
21
+ model's attributes. Timestamps are added by default, so you don't have to
22
+ specify them by hand as 'created_at:datetime updated_at:datetime'.
23
+
24
+ For example, `nifty:scaffold post name:string content:text hidden:boolean`
25
+ gives you a model with those three attributes, a controller that handles
26
+ the create/show/update/destroy, forms to create and edit your posts, and
27
+ an index that lists them all, as well as a map.resources :posts
28
+ declaration in config/routes.rb.
29
+
30
+ Adding an "!" in the mix of arguments will invert the passed controller
31
+ actions. This will include all 7 controller actitons except the ones
32
+ mentioned. This option doesn't affect model attributes.
33
+
34
+ Examples:
35
+ rails generate nifty:scaffold post
36
+
37
+ Will create a controller called "posts" it will contain all seven
38
+ CRUD actions along with the views. A model will NOT be created,
39
+ instead it will look for an existing model and use those attributes.
40
+
41
+ rails generate nifty:scaffold post name:string content:text index new edit
42
+
43
+ Will create a Post model and migration file with the name and content
44
+ attributes. It will also create a controller with index, new, create,
45
+ edit, and update actions. Notice the create and update actions are
46
+ added automatically with new and edit.
47
+
48
+ rails generate nifty:scaffold post ! show new
49
+
50
+ Creates a posts controller (no model) with index, edit, update, and
51
+ destroy actions.
@@ -0,0 +1,313 @@
1
+ require 'generators/bootstrapped'
2
+ require 'rails/generators/migration'
3
+ require 'rails/generators/generated_attribute'
4
+
5
+ module Bootstrapped
6
+ module Generators
7
+ class ScaffoldGenerator < Base
8
+ include ::Rails::Generators::Migration
9
+ no_tasks { attr_accessor :scaffold_name, :model_attributes, :controller_actions }
10
+
11
+ argument :scaffold_name, :type => :string, :required => true, :banner => 'ModelName'
12
+ argument :args_for_c_m, :type => :array, :default => [], :banner => 'controller_actions and model:attributes'
13
+
14
+ class_option :skip_model, :desc => 'Don\'t generate a model or migration file.', :type => :boolean
15
+ class_option :skip_migration, :desc => 'Don\'t generate migration file for model.', :type => :boolean
16
+ class_option :skip_timestamps, :desc => 'Don\'t add timestamps to migration file.', :type => :boolean
17
+ class_option :skip_controller, :desc => 'Don\'t generate controller, helper, or views.', :type => :boolean
18
+ class_option :invert, :desc => 'Generate all controller actions except these mentioned.', :type => :boolean
19
+ class_option :namespace_model, :desc => 'If the resource is namespaced, include the model in the namespace.', :type => :boolean
20
+
21
+ class_option :testunit, :desc => 'Use test/unit for test files.', :group => 'Test framework', :type => :boolean
22
+ class_option :rspec, :desc => 'Use RSpec for test files.', :group => 'Test framework', :type => :boolean
23
+ class_option :shoulda, :desc => 'Use shoulda for test files.', :group => 'Test framework', :type => :boolean
24
+
25
+ def initialize(*args, &block)
26
+ super
27
+
28
+ print_usage unless scaffold_name.underscore =~ /^[a-z][a-z0-9_\/]+$/
29
+
30
+ @controller_actions = []
31
+ @model_attributes = []
32
+ @skip_model = options.skip_model?
33
+ @namespace_model = options.namespace_model?
34
+ @invert_actions = options.invert?
35
+
36
+ args_for_c_m.each do |arg|
37
+ if arg == '!'
38
+ @invert_actions = true
39
+ elsif arg.include?(':')
40
+ @model_attributes << ::Rails::Generators::GeneratedAttribute.new(*arg.split(':'))
41
+ else
42
+ @controller_actions << arg
43
+ @controller_actions << 'create' if arg == 'new'
44
+ @controller_actions << 'update' if arg == 'edit'
45
+ end
46
+ end
47
+
48
+ @controller_actions.uniq!
49
+ @model_attributes.uniq!
50
+
51
+ if @invert_actions || @controller_actions.empty?
52
+ @controller_actions = all_actions - @controller_actions
53
+ end
54
+
55
+ if @model_attributes.empty?
56
+ @skip_model = true # skip model if no attributes
57
+ if model_exists?
58
+ model_columns_for_attributes.each do |column|
59
+ @model_attributes << ::Rails::Generators::GeneratedAttribute.new(column.name.to_s, column.type.to_s)
60
+ end
61
+ else
62
+ @model_attributes << ::Rails::Generators::GeneratedAttribute.new('name', 'string')
63
+ end
64
+ end
65
+ end
66
+
67
+ def add_gems
68
+ add_gem "mocha", :group => :test
69
+ end
70
+
71
+ def create_model
72
+ unless @skip_model
73
+ template 'model.rb', "app/models/#{model_path}.rb"
74
+ if test_framework == :rspec
75
+ template "tests/rspec/model.rb", "spec/models/#{model_path}_spec.rb"
76
+ template 'fixtures.yml', "spec/fixtures/#{model_path.pluralize}.yml"
77
+ else
78
+ template "tests/#{test_framework}/model.rb", "test/unit/#{model_path}_test.rb"
79
+ template 'fixtures.yml', "test/fixtures/#{model_path.pluralize}.yml"
80
+ end
81
+ end
82
+ end
83
+
84
+ def create_migration
85
+ unless @skip_model || options.skip_migration?
86
+ migration_template 'migration.rb', "db/migrate/create_#{model_path.pluralize.gsub('/', '_')}.rb"
87
+ end
88
+ end
89
+
90
+ def create_controller
91
+ unless options.skip_controller?
92
+ template 'controller.rb', "app/controllers/#{plural_name}_controller.rb"
93
+
94
+ template 'helper.rb', "app/helpers/#{plural_name}_helper.rb"
95
+
96
+ controller_actions.each do |action|
97
+ if %w[index show new edit].include?(action) # Actions with templates
98
+ template "views/#{view_language}/#{action}.html.#{view_language}", "app/views/#{plural_name}/#{action}.html.#{view_language}"
99
+ end
100
+ end
101
+
102
+ if form_partial?
103
+ template "views/#{view_language}/_form.html.#{view_language}", "app/views/#{plural_name}/_form.html.#{view_language}"
104
+ end
105
+
106
+ namespaces = plural_name.split('/')
107
+ resource = namespaces.pop
108
+ route namespaces.reverse.inject("resources :#{resource}") { |acc, namespace|
109
+ "namespace(:#{namespace}){ #{acc} }"
110
+ }
111
+
112
+ if test_framework == :rspec
113
+ template "tests/#{test_framework}/controller.rb", "spec/controllers/#{plural_name}_controller_spec.rb"
114
+ else
115
+ template "tests/#{test_framework}/controller.rb", "test/functional/#{plural_name}_controller_test.rb"
116
+ end
117
+ end
118
+ end
119
+
120
+ private
121
+
122
+ def form_partial?
123
+ actions? :new, :edit
124
+ end
125
+
126
+ def all_actions
127
+ %w[index show new create edit update destroy]
128
+ end
129
+
130
+ def action?(name)
131
+ controller_actions.include? name.to_s
132
+ end
133
+
134
+ def actions?(*names)
135
+ names.all? { |name| action? name }
136
+ end
137
+
138
+ def singular_name
139
+ scaffold_name.underscore
140
+ end
141
+
142
+ def plural_name
143
+ scaffold_name.underscore.pluralize
144
+ end
145
+
146
+ def table_name
147
+ if scaffold_name.include?('::') && @namespace_model
148
+ plural_name.gsub('/', '_')
149
+ end
150
+ end
151
+
152
+ def class_name
153
+ if @namespace_model
154
+ scaffold_name.camelize
155
+ else
156
+ scaffold_name.split('::').last.camelize
157
+ end
158
+ end
159
+
160
+ def model_path
161
+ class_name.underscore
162
+ end
163
+
164
+ def plural_class_name
165
+ plural_name.camelize
166
+ end
167
+
168
+ def instance_name
169
+ if @namespace_model
170
+ singular_name.gsub('/','_')
171
+ else
172
+ singular_name.split('/').last
173
+ end
174
+ end
175
+
176
+ def instances_name
177
+ instance_name.pluralize
178
+ end
179
+
180
+ def controller_methods(dir_name)
181
+ controller_actions.map do |action|
182
+ read_template("#{dir_name}/#{action}.rb")
183
+ end.join("\n").strip
184
+ end
185
+
186
+ def render_form
187
+ if form_partial?
188
+ "<%= render \"form\" %>"
189
+ else
190
+ read_template("views/#{view_language}/_form.html.#{view_language}")
191
+ end
192
+ end
193
+
194
+ def item_resource
195
+ scaffold_name.underscore.gsub('/','_')
196
+ end
197
+
198
+ def items_path
199
+ if action? :index
200
+ "#{item_resource.pluralize}_path"
201
+ else
202
+ "root_path"
203
+ end
204
+ end
205
+
206
+ def item_path(options = {})
207
+ name = options[:instance_variable] ? "@#{instance_name}" : instance_name
208
+ suffix = options[:full_url] ? "url" : "path"
209
+ if options[:action].to_s == "new"
210
+ "new_#{item_resource}_#{suffix}"
211
+ elsif options[:action].to_s == "edit"
212
+ "edit_#{item_resource}_#{suffix}(#{name})"
213
+ else
214
+ if scaffold_name.include?('::') && !@namespace_model
215
+ namespace = singular_name.split('/')[0..-2]
216
+ "[:#{namespace.join(', :')}, #{name}]"
217
+ else
218
+ name
219
+ end
220
+ end
221
+ end
222
+
223
+ def item_url
224
+ if action? :show
225
+ item_path(:full_url => true, :instance_variable => true)
226
+ else
227
+ items_url
228
+ end
229
+ end
230
+
231
+ def items_url
232
+ if action? :index
233
+ item_resource.pluralize + '_url'
234
+ else
235
+ "root_url"
236
+ end
237
+ end
238
+
239
+ def item_path_for_spec(suffix = 'path')
240
+ if action? :show
241
+ "#{item_resource}_#{suffix}(assigns[:#{instance_name}])"
242
+ else
243
+ if suffix == 'path'
244
+ items_path
245
+ else
246
+ items_url
247
+ end
248
+ end
249
+ end
250
+
251
+ def item_path_for_test(suffix = 'path')
252
+ if action? :show
253
+ "#{item_resource}_#{suffix}(assigns(:#{instance_name}))"
254
+ else
255
+ if suffix == 'path'
256
+ items_path
257
+ else
258
+ items_url
259
+ end
260
+ end
261
+ end
262
+
263
+ def model_columns_for_attributes
264
+ class_name.constantize.columns.reject do |column|
265
+ column.name.to_s =~ /^(id|created_at|updated_at)$/
266
+ end
267
+ end
268
+
269
+ def view_language
270
+ 'erb'
271
+ end
272
+
273
+ def test_framework
274
+ return @test_framework if defined?(@test_framework)
275
+ if options.testunit?
276
+ return @test_framework = :testunit
277
+ elsif options.rspec?
278
+ return @test_framework = :rspec
279
+ elsif options.shoulda?
280
+ return @test_framework = :shoulda
281
+ else
282
+ return @test_framework = default_test_framework
283
+ end
284
+ end
285
+
286
+ def default_test_framework
287
+ File.exist?(destination_path("spec")) ? :rspec : :testunit
288
+ end
289
+
290
+ def model_exists?
291
+ File.exist? destination_path("app/models/#{singular_name}.rb")
292
+ end
293
+
294
+ def read_template(relative_path)
295
+ ERB.new(File.read(find_in_source_paths(relative_path)), nil, '-').result(binding)
296
+ end
297
+
298
+ def destination_path(path)
299
+ File.join(destination_root, path)
300
+ end
301
+
302
+ # FIXME: Should be proxied to ActiveRecord::Generators::Base
303
+ # Implement the required interface for Rails::Generators::Migration.
304
+ def self.next_migration_number(dirname) #:nodoc:
305
+ if ActiveRecord::Base.timestamped_migrations
306
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
307
+ else
308
+ "%.3d" % (current_migration_number(dirname) + 1)
309
+ end
310
+ end
311
+ end
312
+ end
313
+ end
@@ -0,0 +1,8 @@
1
+ def create
2
+ @<%= instance_name %> = <%= class_name %>.new(params[:<%= instance_name %>])
3
+ if @<%= instance_name %>.save
4
+ redirect_to <%= item_url %>, :notice => "Successfully created <%= class_name.underscore.humanize.downcase %>."
5
+ else
6
+ render :new
7
+ end
8
+ end
@@ -0,0 +1,5 @@
1
+ def destroy
2
+ @<%= instance_name %> = <%= class_name %>.find(params[:id])
3
+ @<%= instance_name %>.destroy
4
+ redirect_to <%= items_url %>, :notice => "Successfully destroyed <%= class_name.underscore.humanize.downcase %>."
5
+ end
@@ -0,0 +1,3 @@
1
+ def edit
2
+ @<%= instance_name %> = <%= class_name %>.find(params[:id])
3
+ end
@@ -0,0 +1,3 @@
1
+ def index
2
+ @<%= instances_name %> = <%= class_name %>.all
3
+ end
@@ -0,0 +1,3 @@
1
+ def new
2
+ @<%= instance_name %> = <%= class_name %>.new
3
+ end
@@ -0,0 +1,3 @@
1
+ def show
2
+ @<%= instance_name %> = <%= class_name %>.find(params[:id])
3
+ end
@@ -0,0 +1,8 @@
1
+ def update
2
+ @<%= instance_name %> = <%= class_name %>.find(params[:id])
3
+ if @<%= instance_name %>.update_attributes(params[:<%= instance_name %>])
4
+ redirect_to <%= item_url %>, :notice => "Successfully updated <%= class_name.underscore.humanize.downcase %>."
5
+ else
6
+ render :edit
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ class <%= plural_class_name %>Controller < ApplicationController
2
+ <%= controller_methods :actions %>
3
+ end
@@ -0,0 +1,9 @@
1
+ one:
2
+ <%- for attribute in model_attributes -%>
3
+ <%= attribute.name %>: <%= attribute.default %>
4
+ <%- end -%>
5
+
6
+ two:
7
+ <%- for attribute in model_attributes -%>
8
+ <%= attribute.name %>: <%= attribute.default %>
9
+ <%- end -%>
@@ -0,0 +1,2 @@
1
+ module <%= plural_class_name %>Helper
2
+ end
@@ -0,0 +1,16 @@
1
+ class Create<%= class_name.pluralize.delete('::') %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name || plural_name.split('/').last %> do |t|
4
+ <%- for attribute in model_attributes -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %>
6
+ <%- end -%>
7
+ <%- unless options[:skip_timestamps] -%>
8
+ t.timestamps
9
+ <%- end -%>
10
+ end
11
+ end
12
+
13
+ def self.down
14
+ drop_table :<%= table_name || plural_name.split('/').last %>
15
+ end
16
+ end
@@ -0,0 +1,4 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ <%= " set_table_name :#{table_name}\n" if table_name -%>
3
+ attr_accessible <%= model_attributes.map { |a| ":#{a.name}" }.join(", ") %>
4
+ end
@@ -0,0 +1,11 @@
1
+ it "create action should render new template when model is invalid" do
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ post :create
4
+ response.should render_template(:new)
5
+ end
6
+
7
+ it "create action should redirect when model is valid" do
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ post :create
10
+ response.should redirect_to(<%= item_path_for_spec('url') %>)
11
+ end
@@ -0,0 +1,6 @@
1
+ it "destroy action should destroy model and redirect to index action" do
2
+ <%= instance_name %> = <%= class_name %>.first
3
+ delete :destroy, :id => <%= instance_name %>
4
+ response.should redirect_to(<%= items_url %>)
5
+ <%= class_name %>.exists?(<%= instance_name %>.id).should be_false
6
+ end
@@ -0,0 +1,4 @@
1
+ it "edit action should render edit template" do
2
+ get :edit, :id => <%= class_name %>.first
3
+ response.should render_template(:edit)
4
+ end
@@ -0,0 +1,4 @@
1
+ it "index action should render index template" do
2
+ get :index
3
+ response.should render_template(:index)
4
+ end
@@ -0,0 +1,4 @@
1
+ it "new action should render new template" do
2
+ get :new
3
+ response.should render_template(:new)
4
+ end
@@ -0,0 +1,4 @@
1
+ it "show action should render show template" do
2
+ get :show, :id => <%= class_name %>.first
3
+ response.should render_template(:show)
4
+ end
@@ -0,0 +1,11 @@
1
+ it "update action should render edit template when model is invalid" do
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ put :update, :id => <%= class_name %>.first
4
+ response.should render_template(:edit)
5
+ end
6
+
7
+ it "update action should redirect when model is valid" do
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ put :update, :id => <%= class_name %>.first
10
+ response.should redirect_to(<%= item_path_for_spec('url') %>)
11
+ end
@@ -0,0 +1,8 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= plural_class_name %>Controller do
4
+ fixtures :all
5
+ render_views
6
+
7
+ <%= controller_methods 'tests/rspec/actions' %>
8
+ end
@@ -0,0 +1,7 @@
1
+ require File.dirname(__FILE__) + '/../spec_helper'
2
+
3
+ describe <%= class_name %> do
4
+ it "should be valid" do
5
+ <%= class_name %>.new.should be_valid
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ context "create action" do
2
+ should "render new template when model is invalid" do
3
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
4
+ post :create
5
+ assert_template 'new'
6
+ end
7
+
8
+ should "redirect when model is valid" do
9
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
10
+ post :create
11
+ assert_redirected_to <%= item_path_for_test('url') %>
12
+ end
13
+ end
@@ -0,0 +1,8 @@
1
+ context "destroy action" do
2
+ should "destroy model and redirect to index action" do
3
+ <%= instance_name %> = <%= class_name %>.first
4
+ delete :destroy, :id => <%= instance_name %>
5
+ assert_redirected_to <%= items_url %>
6
+ assert !<%= class_name %>.exists?(<%= instance_name %>.id)
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ context "edit action" do
2
+ should "render edit template" do
3
+ get :edit, :id => <%= class_name %>.first
4
+ assert_template 'edit'
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ context "index action" do
2
+ should "render index template" do
3
+ get :index
4
+ assert_template 'index'
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ context "new action" do
2
+ should "render new template" do
3
+ get :new
4
+ assert_template 'new'
5
+ end
6
+ end
@@ -0,0 +1,6 @@
1
+ context "show action" do
2
+ should "render show template" do
3
+ get :show, :id => <%= class_name %>.first
4
+ assert_template 'show'
5
+ end
6
+ end
@@ -0,0 +1,13 @@
1
+ context "update action" do
2
+ should "render edit template when model is invalid" do
3
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
4
+ put :update, :id => <%= class_name %>.first
5
+ assert_template 'edit'
6
+ end
7
+
8
+ should "redirect when model is valid" do
9
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
10
+ put :update, :id => <%= class_name %>.first
11
+ assert_redirected_to <%= item_path_for_test('url') %>
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ require 'test_helper'
2
+
3
+ class <%= plural_class_name %>ControllerTest < ActionController::TestCase
4
+ <%= controller_methods 'tests/shoulda/actions' %>
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
+ should "be valid" do
5
+ assert <%= class_name %>.new.valid?
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ def test_create_invalid
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ post :create
4
+ assert_template 'new'
5
+ end
6
+
7
+ def test_create_valid
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ post :create
10
+ assert_redirected_to <%= item_path_for_test('url') %>
11
+ end
@@ -0,0 +1,6 @@
1
+ def test_destroy
2
+ <%= instance_name %> = <%= class_name %>.first
3
+ delete :destroy, :id => <%= instance_name %>
4
+ assert_redirected_to <%= items_url %>
5
+ assert !<%= class_name %>.exists?(<%= instance_name %>.id)
6
+ end
@@ -0,0 +1,4 @@
1
+ def test_edit
2
+ get :edit, :id => <%= class_name %>.first
3
+ assert_template 'edit'
4
+ end
@@ -0,0 +1,4 @@
1
+ def test_index
2
+ get :index
3
+ assert_template 'index'
4
+ end
@@ -0,0 +1,4 @@
1
+ def test_new
2
+ get :new
3
+ assert_template 'new'
4
+ end
@@ -0,0 +1,4 @@
1
+ def test_show
2
+ get :show, :id => <%= class_name %>.first
3
+ assert_template 'show'
4
+ end
@@ -0,0 +1,11 @@
1
+ def test_update_invalid
2
+ <%= class_name %>.any_instance.stubs(:valid?).returns(false)
3
+ put :update, :id => <%= class_name %>.first
4
+ assert_template 'edit'
5
+ end
6
+
7
+ def test_update_valid
8
+ <%= class_name %>.any_instance.stubs(:valid?).returns(true)
9
+ put :update, :id => <%= class_name %>.first
10
+ assert_redirected_to <%= item_path_for_test('url') %>
11
+ end
@@ -0,0 +1,5 @@
1
+ require 'test_helper'
2
+
3
+ class <%= plural_class_name %>ControllerTest < ActionController::TestCase
4
+ <%= controller_methods 'tests/testunit/actions' %>
5
+ end
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
+ def test_should_be_valid
5
+ assert <%= class_name %>.new.valid?
6
+ end
7
+ end
@@ -0,0 +1,15 @@
1
+ <%%= form_for <%= item_path :instance_variable => true %> do |f| %>
2
+ <fieldset>
3
+ <%- model_attributes.each do |attribute| -%>
4
+ <div class="clearfix">
5
+ <%%= f.label :<%= attribute.name %> %>
6
+ <div class="input">
7
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %>, :class => "xxlarge" %>
8
+ </div>
9
+ </div>
10
+ <%- end -%>
11
+ <div class="actions">
12
+ <%%= f.submit :class => "btn primary float-right"%>
13
+ </div>
14
+ <fieldset>
15
+ <%% end %>
@@ -0,0 +1,14 @@
1
+ <%% title "Edit <%= singular_name.titleize %>" %>
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if actions? :show, :index -%>
6
+ <p>
7
+ <%- if action? :show -%>
8
+ <%%= link_to "Show", <%= item_path :instance_variable => true %> %> |
9
+ <%- end -%>
10
+ <%- if action? :index -%>
11
+ <%%= link_to "View All", <%= items_path %> %>
12
+ <%- end -%>
13
+ </p>
14
+ <%- end -%>
@@ -0,0 +1,39 @@
1
+ <%% title "<%= plural_name.titleize %>" %>
2
+
3
+ <div class="well">
4
+ <table class="zebra-striped">
5
+ <tr>
6
+ <%- model_attributes.each do |attribute| %>
7
+ <th><%= attribute.human_name.titleize %></th>
8
+ <%- end -%>
9
+ <%- if action? :show -%>
10
+ <th></th>
11
+ <%- end -%>
12
+ <%- if action? :edit -%>
13
+ <th></th>
14
+ <%- end -%>
15
+ <%- if action? :destroy -%>
16
+ <th></th>
17
+ <%- end -%>
18
+ </tr>
19
+ <%% @<%= instances_name %>.each do |<%= instance_name %>| %>
20
+ <tr>
21
+ <%- model_attributes.each do |attribute| %>
22
+ <td><%%= <%= instance_name %>.<%= attribute.name %> %></td>
23
+ <%- end -%>
24
+ <%- if action? :show -%>
25
+ <td><%%= link_to "Show", <%= item_path %> %></td>
26
+ <%- end -%>
27
+ <%- if action? :edit -%>
28
+ <td><%%= link_to "Edit", <%= item_path :action => :edit %> %></td>
29
+ <%- end -%>
30
+ <%- if action? :destroy -%>
31
+ <td><%%= link_to "Destroy", <%= item_path %>, :confirm => 'Are you sure?', :method => :delete %></td>
32
+ <%- end -%>
33
+ </tr>
34
+ <%% end %>
35
+ </table>
36
+ </div>
37
+ <%- if action? :new -%>
38
+ <p><%%= link_to "New <%= singular_name.titleize %>", <%= item_path :action => :new %>, :class => 'btn primary float-right' %></p>
39
+ <%- end -%>
@@ -0,0 +1,7 @@
1
+ <%% title "New <%= singular_name.titleize %>" %>
2
+
3
+ <%= render_form %>
4
+
5
+ <%- if action? :index -%>
6
+ <p><%%= link_to "Back to List", <%= items_path %> %></p>
7
+ <%- end -%>
@@ -0,0 +1,23 @@
1
+ <%% title "<%= singular_name.titleize %> Details" %>
2
+
3
+ <div class="well">
4
+
5
+ <%- model_attributes.each do |attribute| %>
6
+ <p>
7
+ <strong><%= attribute.human_name.titleize %>:</strong>
8
+ <%%= @<%= instance_name %>.<%= attribute.name %> %>
9
+ </p>
10
+ <% end -%>
11
+ </div>
12
+
13
+ <p>
14
+ <%- if action? :edit -%>
15
+ <%%= link_to "Edit", <%= item_path :action => :edit, :instance_variable => true %>, :class => 'btn float-right' %> |
16
+ <%- end -%>
17
+ <%- if action? :destroy -%>
18
+ <%%= link_to "Destroy", <%= item_path :instance_variable => true %>, :confirm => 'Are you sure?', :method => :delete, :class => 'btn float-right' %> |
19
+ <%- end -%>
20
+ <%- if action? :index -%>
21
+ <%%= link_to "View All", <%= items_path %>, :class => 'btn float-right' %>
22
+ <%- end -%>
23
+ </p>
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrapped
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -14,7 +14,7 @@ default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: railties
17
- requirement: &70330114966080 !ruby/object:Gem::Requirement
17
+ requirement: &70115773758520 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ~>
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '3.1'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70330114966080
25
+ version_requirements: *70115773758520
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: thor
28
- requirement: &70330114965540 !ruby/object:Gem::Requirement
28
+ requirement: &70115773758020 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ~>
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0.14'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70330114965540
36
+ version_requirements: *70115773758020
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: bundler
39
- requirement: &70330114965060 !ruby/object:Gem::Requirement
39
+ requirement: &70115773757560 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ~>
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: 1.0.0
45
45
  type: :development
46
46
  prerelease: false
47
- version_requirements: *70330114965060
47
+ version_requirements: *70115773757560
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rails
50
- requirement: &70330114964540 !ruby/object:Gem::Requirement
50
+ requirement: &70115773757100 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ~>
@@ -55,7 +55,7 @@ dependencies:
55
55
  version: '3.1'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70330114964540
58
+ version_requirements: *70115773757100
59
59
  description: Twitters Bootstrap CSS and JS files all in one nice little gem
60
60
  email:
61
61
  - nwwatson@gmail.com
@@ -70,6 +70,59 @@ files:
70
70
  - lib/bootstrapped.rb
71
71
  - lib/bootstrapped/engine.rb
72
72
  - lib/bootstrapped/version.rb
73
+ - lib/generators/bootstrapped.rb
74
+ - lib/generators/bootstrapped/layout/USAGE
75
+ - lib/generators/bootstrapped/layout/layout_generator.rb
76
+ - lib/generators/bootstrapped/layout/templates/_flash.html.erb
77
+ - lib/generators/bootstrapped/layout/templates/error_messages_helper.rb
78
+ - lib/generators/bootstrapped/layout/templates/layout.html.erb
79
+ - lib/generators/bootstrapped/layout/templates/layout_helper.rb
80
+ - lib/generators/bootstrapped/scaffold/USAGE
81
+ - lib/generators/bootstrapped/scaffold/scaffold_generator.rb
82
+ - lib/generators/bootstrapped/scaffold/templates/actions/create.rb
83
+ - lib/generators/bootstrapped/scaffold/templates/actions/destroy.rb
84
+ - lib/generators/bootstrapped/scaffold/templates/actions/edit.rb
85
+ - lib/generators/bootstrapped/scaffold/templates/actions/index.rb
86
+ - lib/generators/bootstrapped/scaffold/templates/actions/new.rb
87
+ - lib/generators/bootstrapped/scaffold/templates/actions/show.rb
88
+ - lib/generators/bootstrapped/scaffold/templates/actions/update.rb
89
+ - lib/generators/bootstrapped/scaffold/templates/controller.rb
90
+ - lib/generators/bootstrapped/scaffold/templates/fixtures.yml
91
+ - lib/generators/bootstrapped/scaffold/templates/helper.rb
92
+ - lib/generators/bootstrapped/scaffold/templates/migration.rb
93
+ - lib/generators/bootstrapped/scaffold/templates/model.rb
94
+ - lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/create.rb
95
+ - lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/destroy.rb
96
+ - lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/edit.rb
97
+ - lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/index.rb
98
+ - lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/new.rb
99
+ - lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/show.rb
100
+ - lib/generators/bootstrapped/scaffold/templates/tests/rspec/actions/update.rb
101
+ - lib/generators/bootstrapped/scaffold/templates/tests/rspec/controller.rb
102
+ - lib/generators/bootstrapped/scaffold/templates/tests/rspec/model.rb
103
+ - lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/create.rb
104
+ - lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/destroy.rb
105
+ - lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/edit.rb
106
+ - lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/index.rb
107
+ - lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/new.rb
108
+ - lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/show.rb
109
+ - lib/generators/bootstrapped/scaffold/templates/tests/shoulda/actions/update.rb
110
+ - lib/generators/bootstrapped/scaffold/templates/tests/shoulda/controller.rb
111
+ - lib/generators/bootstrapped/scaffold/templates/tests/shoulda/model.rb
112
+ - lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/create.rb
113
+ - lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/destroy.rb
114
+ - lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/edit.rb
115
+ - lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/index.rb
116
+ - lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/new.rb
117
+ - lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/show.rb
118
+ - lib/generators/bootstrapped/scaffold/templates/tests/testunit/actions/update.rb
119
+ - lib/generators/bootstrapped/scaffold/templates/tests/testunit/controller.rb
120
+ - lib/generators/bootstrapped/scaffold/templates/tests/testunit/model.rb
121
+ - lib/generators/bootstrapped/scaffold/templates/views/erb/_form.html.erb
122
+ - lib/generators/bootstrapped/scaffold/templates/views/erb/edit.html.erb
123
+ - lib/generators/bootstrapped/scaffold/templates/views/erb/index.html.erb
124
+ - lib/generators/bootstrapped/scaffold/templates/views/erb/new.html.erb
125
+ - lib/generators/bootstrapped/scaffold/templates/views/erb/show.html.erb
73
126
  - vendor/.DS_Store
74
127
  - vendor/assets/.DS_Store
75
128
  - vendor/assets/javascripts/.DS_Store