starter_generators 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +18 -0
  3. data/CHANGELOG.md +21 -0
  4. data/Gemfile +2 -0
  5. data/LICENSE.txt +22 -0
  6. data/README.md +23 -0
  7. data/Rakefile +1 -0
  8. data/lib/generators/starter/resource/USAGE +35 -0
  9. data/lib/generators/starter/resource/migration.rb +15 -0
  10. data/lib/generators/starter/resource/resource_generator.rb +124 -0
  11. data/lib/generators/starter/resource/templates/bootstrapped/edit.html.erb +16 -0
  12. data/lib/generators/starter/resource/templates/bootstrapped/index.html.erb +40 -0
  13. data/lib/generators/starter/resource/templates/bootstrapped/new.html.erb +15 -0
  14. data/lib/generators/starter/resource/templates/bootstrapped/show.html.erb +9 -0
  15. data/lib/generators/starter/resource/templates/controller.rb +48 -0
  16. data/lib/generators/starter/resource/templates/edit.html.erb +16 -0
  17. data/lib/generators/starter/resource/templates/index.html.erb +40 -0
  18. data/lib/generators/starter/resource/templates/migration.rb +15 -0
  19. data/lib/generators/starter/resource/templates/model.rb +2 -0
  20. data/lib/generators/starter/resource/templates/new.html.erb +15 -0
  21. data/lib/generators/starter/resource/templates/show.html.erb +9 -0
  22. data/lib/generators/starter/style/USAGE +11 -0
  23. data/lib/generators/starter/style/style_generator.rb +45 -0
  24. data/lib/generators/starter/style/templates/bootstrap-css/amelia.min.css +9 -0
  25. data/lib/generators/starter/style/templates/bootstrap-css/cerulian.min.css +9 -0
  26. data/lib/generators/starter/style/templates/bootstrap-css/cosmo.min.css +9 -0
  27. data/lib/generators/starter/style/templates/bootstrap-css/cyborg.min.css +9 -0
  28. data/lib/generators/starter/style/templates/bootstrap-css/journal.min.css +9 -0
  29. data/lib/generators/starter/style/templates/bootstrap-css/readable.min.css +9 -0
  30. data/lib/generators/starter/style/templates/bootstrap-css/simplex.min.css +9 -0
  31. data/lib/generators/starter/style/templates/bootstrap-css/slate.min.css +9 -0
  32. data/lib/generators/starter/style/templates/bootstrap-css/spacelab.min.css +9 -0
  33. data/lib/generators/starter/style/templates/bootstrap-css/spruce.min.css +9 -0
  34. data/lib/generators/starter/style/templates/bootstrap-css/superhero.min.css +9 -0
  35. data/lib/generators/starter/style/templates/bootstrap-css/united.min.css +9 -0
  36. data/lib/generators/starter/style/templates/bootstrap_overrides.css +2 -0
  37. data/lib/generators/starter/style/templates/font/FontAwesome.otf +0 -0
  38. data/lib/generators/starter/style/templates/font/fontawesome-webfont.eot +0 -0
  39. data/lib/generators/starter/style/templates/font/fontawesome-webfont.svg +284 -0
  40. data/lib/generators/starter/style/templates/font/fontawesome-webfont.ttf +0 -0
  41. data/lib/generators/starter/style/templates/font/fontawesome-webfont.woff +0 -0
  42. data/lib/generators/starter/style/templates/font-awesome-css/font-awesome.min.css +33 -0
  43. data/lib/generators/starter/style/templates/layout.html.erb +57 -0
  44. data/lib/starter_generators/version.rb +3 -0
  45. data/lib/starter_generators.rb +5 -0
  46. data/starter_generators.gemspec +23 -0
  47. metadata +117 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cee8a6570c3e44af9bf5881f999f767638f1a590
4
+ data.tar.gz: 16eedfc1d066c213eb49b40de2c0c380a36fbc2e
5
+ SHA512:
6
+ metadata.gz: 6f213c9162741d3182898b05c2826d92862858799469840839dececa13629401fdd7f0903aea116cbe09cdb125f1782c4af989a85f27fa6a7d61cbc27477334a
7
+ data.tar.gz: 1b41a751355e0dc9bea5a8abccaacc56322f7ae0009bd6a93bb431a752d913fc7283f52d9edece3406a79bf8199c6ef528e415b5cde7f4237e4ecece0f369e3f
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .DS_Store
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/CHANGELOG.md ADDED
@@ -0,0 +1,21 @@
1
+ ## Version 0.3.1 (March 30, 2013) ##
2
+
3
+ * Fix edit templates to use @ivar in the form_tag call.
4
+
5
+ ## Version 0.3 ##
6
+
7
+ * Add --named-routes option to starter:resource
8
+ * Add --styled option to starter:resource
9
+
10
+ ## Version 0.2 (March 24, 2013) ##
11
+
12
+ * Add starter:style generator to make it easy to apply a bootswatch. Not complete but mostly there.
13
+
14
+ ## Version 0.1 (March 24, 2013) ##
15
+
16
+ * Properly close the erb tag for the link to the show action in the index template. Also add a leading slash in the url.
17
+ * Added a destroy a link to the index template.
18
+
19
+ ## Version 0.0.1 (March 22, 2013) ##
20
+
21
+ * First attempt.
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jeff Cohen
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,23 @@
1
+ # StarterGenerators
2
+
3
+ Rails generators that are helpful in class.
4
+
5
+ Currently there are two generators, **starter:resource** and **starter::style**.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ gem 'starter_generators', git: 'git@github.com:starterleague/starter_generators.git'
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ ## Usage
18
+
19
+ For full usage instructions, run:
20
+
21
+ $ rails g starter:resource
22
+ $ rails g starter:style
23
+
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,35 @@
1
+ Description:
2
+ Generates an example of one entire database-backed resource, from model
3
+ and migration to controller and views. The resource is ready to use as a
4
+ starting point for your RESTful, resource-oriented application.
5
+
6
+ Pass the name of the model (in singular form), either CamelCased or
7
+ under_scored, as the first argument, and an optional list of attribute
8
+ pairs.
9
+
10
+ Attributes are field arguments specifying the model's attributes. You can
11
+ optionally pass the type and an index to each field. For instance:
12
+ "title body:text tracking_id:integer:uniq" will generate a title field of
13
+ string type, a body with text type and a tracking_id as an integer with an
14
+ unique index. "index" could also be given instead of "uniq" if one desires
15
+ a non unique index.
16
+
17
+ Timestamps are added by default, so you don't have to specify them by hand
18
+ as 'created_at:datetime updated_at:datetime'.
19
+
20
+ You don't have to think up every attribute up front, but it helps to
21
+ sketch out a few so you can start working with the resource immediately.
22
+
23
+ For example, 'starter:resource post title body:text published:boolean' gives
24
+ you a model with those three attributes, a controller that handles
25
+ the create/show/update/destroy, forms to create and edit your posts, and
26
+ an index that lists them all, as well as the Golden Seven "RESTful" routes
27
+ in config/routes.rb.
28
+
29
+ If you want to remove all the generated files, first rollback your migration
30
+ if you've already run 'rake db:migrate'. Then run
31
+ 'rails destroy resource ModelName'.
32
+
33
+ Examples:
34
+ `rails generate starter:resource post title body:text published:boolean`
35
+ `rails generate starter:resource purchase amount:decimal tracking_id:integer:uniq`
@@ -0,0 +1,15 @@
1
+ module ActiveRecord
2
+ module Generators
3
+ module Migration
4
+ # Implement the required interface for Rails::Generators::Migration.
5
+ def next_migration_number(dirname) #:nodoc:
6
+ next_migration_number = current_migration_number(dirname) + 1
7
+ if ActiveRecord::Base.timestamped_migrations
8
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
9
+ else
10
+ "%.3d" % next_migration_number
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,124 @@
1
+ require 'rails/generators/active_record'
2
+ require_relative './migration'
3
+ module Starter
4
+ class ResourceGenerator < Rails::Generators::NamedBase
5
+ source_root File.expand_path('../templates', __FILE__)
6
+ include Rails::Generators::ResourceHelpers
7
+ include Rails::Generators::Migration
8
+ extend ActiveRecord::Generators::Migration
9
+
10
+ argument :attributes, :type => :array, :default => [], :banner => "field:type field:type"
11
+ remove_class_option :old_style_hash
12
+ class_option :named_routes, :type => :boolean, :default => false
13
+ class_option :styled, :type => :boolean, :default => false, desc: 'Generates bootstrap-ready view templates'
14
+
15
+ def generate_controller
16
+ template 'controller.rb', "app/controllers/#{plural_name.underscore}_controller.rb"
17
+ end
18
+
19
+ def generate_model
20
+ template 'model.rb', "app/models/#{singular_name.underscore}.rb"
21
+ end
22
+
23
+ def generate_migration
24
+ migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
25
+ end
26
+
27
+ # def create_root_view_folder
28
+ # empty_directory File.join("app/views", controller_file_path)
29
+ # end
30
+
31
+ def copy_view_files
32
+ available_views.each do |view|
33
+ filename = view_filename_with_extensions(view)
34
+ template filename, File.join("app/views", controller_file_path, File.basename(filename))
35
+ end
36
+ end
37
+
38
+
39
+ def generate_routes
40
+ if named_routes?
41
+ route golden_7_named, "Named RESTful routes"
42
+ else
43
+ route golden_7, "RESTful routes"
44
+ end
45
+ end
46
+
47
+ protected
48
+
49
+ def golden_7
50
+ ["# Routes for the #{singular_name.capitalize} resource:",
51
+ " # CREATE",
52
+ " get '/#{plural_name}/new', controller: '#{plural_name}', action: 'new'",
53
+ " post '/#{plural_name}', controller: '#{plural_name}', action: 'create'",
54
+ "",
55
+ " # READ",
56
+ " get '/#{plural_name}', controller: '#{plural_name}', action: 'index'",
57
+ " get '/#{plural_name}/:id', controller: '#{plural_name}', action: 'show'",
58
+ "",
59
+ " # UPDATE",
60
+ " get '/#{plural_name}/:id/edit', controller: '#{plural_name}', action: 'edit'",
61
+ " put '/#{plural_name}/:id', controller: '#{plural_name}', action: 'update'",
62
+ "",
63
+ " # DELETE",
64
+ " delete '/#{plural_name}/:id', controller: '#{plural_name}', action: 'destroy'",
65
+ " ##{'-' * 30}"
66
+ ].join("\n")
67
+ end
68
+
69
+ def golden_7_named
70
+ ["# Routes for the #{singular_name.capitalize} resource:",
71
+ " # CREATE",
72
+ " get '/#{plural_name}/new', controller: '#{plural_name}', action: 'new', as: 'new_#{singular_name}'",
73
+ " post '/#{plural_name}', controller: '#{plural_name}', action: 'create'",
74
+ "",
75
+ " # READ",
76
+ " get '/#{plural_name}', controller: '#{plural_name}', action: 'index', as: '#{plural_name}'",
77
+ " get '/#{plural_name}/:id', controller: '#{plural_name}', action: 'show', as: '#{singular_name}'",
78
+ "",
79
+ " # UPDATE",
80
+ " get '/#{plural_name}/:id/edit', controller: '#{plural_name}', action: 'edit', as: 'edit_#{singular_name}'",
81
+ " put '/#{plural_name}/:id', controller: '#{plural_name}', action: 'update'",
82
+ "",
83
+ " # DELETE",
84
+ " delete '/#{plural_name}/:id', controller: '#{plural_name}', action: 'destroy'",
85
+ " ##{'-' * 30}"
86
+ ].join("\n")
87
+ end
88
+
89
+ def named_routes?
90
+ options[:named_routes]
91
+ end
92
+
93
+ def styled?
94
+ options[:styled]
95
+ end
96
+
97
+ # Override of Rails::Generators::Actions
98
+ def route(routing_code, title)
99
+ log :route, title
100
+ sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
101
+
102
+ in_root do
103
+ inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false }
104
+ end
105
+ end
106
+
107
+ def attributes_with_index
108
+ attributes.select { |a| a.has_index? || (a.reference? && options[:indexes]) }
109
+ end
110
+
111
+ def available_views
112
+ %w(index new edit show)
113
+ end
114
+
115
+ def view_filename_with_extensions(name)
116
+ filename = [name, :html, :erb].compact.join(".")
117
+ if styled?
118
+ filename = File.join("bootstrapped", filename)
119
+ end
120
+ filename
121
+ end
122
+
123
+ end
124
+ end
@@ -0,0 +1,16 @@
1
+ <h1>Editing <%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
2
+
3
+ <%%= form_tag(<%= singular_table_name %>_url(@<%= singular_table_name %>), method: 'put') do %>
4
+
5
+ <% attributes.each do |attribute| -%>
6
+ <div>
7
+ <%%= label_tag :<%= attribute.name %> %><br />
8
+ <%%= <%= attribute.field_type %>_tag :<%= attribute.name %>, @<%= singular_table_name %>.<%= attribute.name %><%= "?" if attribute.type == :boolean %> %>
9
+ </div>
10
+
11
+ <% end %>
12
+ <div>
13
+ <%%= submit_tag "Update <%= human_name.titleize %>", class: 'btn' %>
14
+ </div>
15
+
16
+ <%% end %>
@@ -0,0 +1,40 @@
1
+ <h1><%= plural_table_name.humanize %></h1>
2
+
3
+ <% if named_routes? -%>
4
+ <p><%%= link_to 'Add a New <%= human_name.titleize %>', new_<%= singular_table_name %>_url, class: 'btn' %></p>
5
+ <% else -%>
6
+ <p><%%= link_to 'Add a New <%= human_name.titleize %>', "/<%= plural_name %>/new", class: 'btn' %></p>
7
+ <% end -%>
8
+
9
+ <table class="table table-hover">
10
+ <thead>
11
+ <tr>
12
+ <% attributes.each do |attribute| -%>
13
+ <th><%= attribute.human_name %></th>
14
+ <% end -%>
15
+ <th></th>
16
+ <th></th>
17
+ <th></th>
18
+ </tr>
19
+ </thead>
20
+
21
+ <tbody>
22
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
23
+ <tr>
24
+ <% attributes.each do |attribute| -%>
25
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
26
+ <% end -%>
27
+ <% if named_routes? %>
28
+ <td><%%= link_to 'Show', <%= singular_table_name %>_url(<%= singular_table_name %>), class: 'btn' %></td>
29
+ <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_url(<%= singular_table_name %>), class: 'btn' %></td>
30
+ <td><%%= link_to 'Destroy', <%= singular_table_name %>_url(<%= singular_table_name %>), method: 'delete', data: { confirm: "Do you really want to delete this <%= singular_table_name %>?" }, class: 'btn btn-danger' %></td>
31
+ <% else %>
32
+ <td><%%= link_to 'Show', "/<%= plural_name %>/#{<%= singular_table_name %>.id}", class: 'btn' %></td>
33
+ <td><%%= link_to 'Edit', "/<%= plural_name %>/#{<%= singular_table_name %>.id}/edit", class: 'btn' %></td>
34
+ <td><%%= link_to 'Destroy', "/<%= plural_name %>/#{<%= singular_table_name %>.id}", method: 'delete', data: { confirm: "Do you really want to delete this <%= singular_table_name %>?" }, class: 'btn btn-danger' %></td>
35
+ <% end %>
36
+ </tr>
37
+ <%% end %>
38
+ </body>
39
+ </table>
40
+
@@ -0,0 +1,15 @@
1
+ <h1>New <%= human_name.titleize %></h1>
2
+
3
+ <%%= form_tag(<%= plural_name %>_url, method: 'post') do %>
4
+
5
+ <% attributes.each do |attribute| -%>
6
+ <div>
7
+ <%%= label_tag :<%= attribute.name %> %><br />
8
+ <%%= <%= attribute.field_type %>_tag :<%= attribute.name %><%= "?" if attribute.type == :boolean %> %>
9
+ </div>
10
+
11
+ <% end %>
12
+ <div>
13
+ <%%= submit_tag "Create <%= human_name.titleize %>", class: 'btn' %>
14
+ </div>
15
+ <%% end %>
@@ -0,0 +1,9 @@
1
+ <h1><%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
2
+
3
+ <% attributes.each do |attribute| -%>
4
+ <p>
5
+ <b><%= attribute.human_name %>:</b>
6
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
7
+ </p>
8
+
9
+ <% end %>
@@ -0,0 +1,48 @@
1
+ class <%= plural_name.camelize %>Controller < ApplicationController
2
+
3
+ def index
4
+ @<%= plural_name.underscore %> = <%= class_name %>.all
5
+ end
6
+
7
+ def show
8
+ @<%= singular_name.underscore %> = <%= class_name %>.find_by_id(params[:id])
9
+ end
10
+
11
+ def new
12
+ @<%= singular_name.underscore %> = <%= class_name %>.new
13
+ end
14
+
15
+ def create
16
+ @<%= singular_name.underscore %> = <%= class_name %>.new
17
+ <% attributes.each do |attribute| -%>
18
+ @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
19
+ <% end %>
20
+ if @<%= singular_name.underscore %>.save
21
+ redirect_to "/<%= plural_name %>"
22
+ else
23
+ render 'new'
24
+ end
25
+ end
26
+
27
+ def edit
28
+ @<%= singular_name.underscore %> = <%= class_name %>.find_by_id(params[:id])
29
+ end
30
+
31
+ def update
32
+ @<%= singular_name.underscore %> = <%= class_name %>.find_by_id(params[:id])
33
+ <% attributes.each do |attribute| -%>
34
+ @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
35
+ <% end %>
36
+ if @<%= singular_name.underscore %>.save
37
+ redirect_to "/<%= plural_name %>"
38
+ else
39
+ render 'edit'
40
+ end
41
+ end
42
+
43
+ def destroy
44
+ @<%= singular_name.underscore %> = <%= class_name %>.find_by_id(params[:id])
45
+ @<%= singular_name.underscore %>.destroy
46
+ redirect_to "/<%= plural_name %>"
47
+ end
48
+ end
@@ -0,0 +1,16 @@
1
+ <h1>Editing <%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
2
+
3
+ <%%= form_tag(<%= singular_table_name %>_url(@<%= singular_table_name %>), method: 'put') do %>
4
+
5
+ <% attributes.each do |attribute| -%>
6
+ <div>
7
+ <%%= label_tag :<%= attribute.name %> %><br />
8
+ <%%= <%= attribute.field_type %>_tag :<%= attribute.name %>, @<%= singular_table_name %>.<%= attribute.name %><%= "?" if attribute.type == :boolean %> %>
9
+ </div>
10
+
11
+ <% end %>
12
+ <div>
13
+ <%%= submit_tag "Update <%= human_name.titleize %>" %>
14
+ </div>
15
+
16
+ <%% end %>
@@ -0,0 +1,40 @@
1
+ <h1><%= plural_table_name.humanize %></h1>
2
+
3
+ <% if named_routes? -%>
4
+ <p><%%= link_to 'Add a New <%= human_name.titleize %>', new_<%= singular_table_name %>_url %></p>
5
+ <% else -%>
6
+ <p><%%= link_to 'Add a New <%= human_name.titleize %>', "/<%= plural_name %>/new" %></p>
7
+ <% end -%>
8
+
9
+ <table>
10
+ <thead>
11
+ <tr>
12
+ <% attributes.each do |attribute| -%>
13
+ <th><%= attribute.human_name %></th>
14
+ <% end -%>
15
+ <th></th>
16
+ <th></th>
17
+ <th></th>
18
+ </tr>
19
+ </thead>
20
+
21
+ <tbody>
22
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
23
+ <tr>
24
+ <% attributes.each do |attribute| -%>
25
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
26
+ <% end -%>
27
+ <% if named_routes? %>
28
+ <td><%%= link_to 'Show', <%= singular_table_name %>_url(<%= singular_table_name %>) %></td>
29
+ <td><%%= link_to 'Edit', edit_<%= singular_table_name %>_url(<%= singular_table_name %>) %></td>
30
+ <td><%%= link_to 'Destroy', <%= singular_table_name %>_url(<%= singular_table_name %>), method: 'delete', data: { confirm: "Do you really want to delete this <%= singular_table_name %>?" } %></td>
31
+ <% else %>
32
+ <td><%%= link_to 'Show', "/<%= plural_name %>/#{<%= singular_table_name %>.id}" %></td>
33
+ <td><%%= link_to 'Edit', "/<%= plural_name %>/#{<%= singular_table_name %>.id}/edit" %></td>
34
+ <td><%%= link_to 'Destroy', "/<%= plural_name %>/#{<%= singular_table_name %>.id}", method: 'delete', data: { confirm: "Do you really want to delete this <%= singular_table_name %>?" } %></td>
35
+ <% end %>
36
+ </tr>
37
+ <%% end %>
38
+ </body>
39
+ </table>
40
+
@@ -0,0 +1,15 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration
2
+ def change
3
+ create_table :<%= table_name %> do |t|
4
+ <% attributes.each do |attribute| -%>
5
+ t.<%= attribute.type %> :<%= attribute.name %><%= attribute.inject_options %>
6
+ <% end -%>
7
+ <% if options[:timestamps] %>
8
+ t.timestamps
9
+ <% end -%>
10
+ end
11
+ <% attributes_with_index.each do |attribute| -%>
12
+ add_index :<%= table_name %>, :<%= attribute.index_name %><%= attribute.inject_index_options %>
13
+ <% end -%>
14
+ end
15
+ end
@@ -0,0 +1,2 @@
1
+ class <%= singular_name.camelize %> < ActiveRecord::Base
2
+ end
@@ -0,0 +1,15 @@
1
+ <h1>New <%= human_name.titleize %></h1>
2
+
3
+ <%%= form_tag(<%= plural_name %>_url, method: 'post') do %>
4
+
5
+ <% attributes.each do |attribute| -%>
6
+ <div>
7
+ <%%= label_tag :<%= attribute.name %> %><br />
8
+ <%%= <%= attribute.field_type %>_tag :<%= attribute.name %><%= "?" if attribute.type == :boolean %> %>
9
+ </div>
10
+
11
+ <% end %>
12
+ <div>
13
+ <%%= submit_tag "Create <%= human_name.titleize %>" %>
14
+ </div>
15
+ <%% end %>
@@ -0,0 +1,9 @@
1
+ <h1><%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
2
+
3
+ <% attributes.each do |attribute| -%>
4
+ <p>
5
+ <b><%= attribute.human_name %>:</b>
6
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
7
+ </p>
8
+
9
+ <% end %>
@@ -0,0 +1,11 @@
1
+ Description:
2
+ Injects a bootswatch with FontAwesome support into your app.
3
+
4
+ BOOTSTRAP_NAME must be one of:
5
+ amelia, cerulian, cyborg, journal, readable, simplex, slate, spacelab, spruce, superhero, united
6
+
7
+ LAYOUT_FILE defaults to "application".
8
+
9
+ Examples:
10
+ `rails generate starter:style united`
11
+
@@ -0,0 +1,45 @@
1
+ module Starter
2
+ class StyleGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ argument :bootswatch_name, :type => :string#, :default => 'spacelab'
6
+
7
+ class_option :layout, :type => :boolean, :default => true, :desc => "Generate a new application layout."
8
+ class_option :navbar, :type => :boolean, :default => true, :desc => "Generate a model-based navbar."
9
+ argument :layout_file, :type => :string, :default => 'application', :desc => "Layout filename"
10
+
11
+ def inject_styles
12
+ template "bootstrap-css/#{bootswatch_name}.min.css", "app/assets/stylesheets/#{bootswatch_name}.css"
13
+ directory "font", "app/assets/stylesheets/font", verbose: false
14
+ template "font-awesome-css/font-awesome.min.css", "app/assets/stylesheets/font-awesome.css", verbose: false
15
+ log :insert, 'FontAwesome stylesheet and fonts'
16
+ copy_file 'bootstrap_overrides.css', 'app/assets/stylesheets/bootstrap_overrides.css'
17
+ inject_into_file "app/assets/stylesheets/application.css",
18
+ "\n\n/*= require #{bootswatch_name} */\n/*= require bootstrap_overrides */",
19
+ after: %r{\*\/}
20
+ log :insert, 'Stylesheet manifest directives'
21
+ end
22
+
23
+ def generate_layout
24
+ template "layout.html.erb", "app/views/layouts/#{layout_file}.html.erb" if options[:layout]
25
+ end
26
+
27
+ protected
28
+
29
+ def app_tables
30
+ ActiveRecord::Base.connection.tables - ['schema_migrations']
31
+ end
32
+
33
+ def application_name
34
+ if defined?(Rails) && Rails.application
35
+ Rails.application.class.name.split('::').first.humanize.titleize
36
+ else
37
+ "application"
38
+ end
39
+ end
40
+
41
+ def available_styles
42
+ Dir["bootstrap-css/*"].entries
43
+ end
44
+ end
45
+ end