ez 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ez/version.rb +1 -1
  3. data/lib/generators/ez/resource/USAGE +35 -0
  4. data/lib/generators/ez/resource/migration.rb +15 -0
  5. data/lib/generators/ez/resource/resource_generator.rb +143 -0
  6. data/lib/generators/ez/resource/templates/bootstrapped/edit.html.erb +26 -0
  7. data/lib/generators/ez/resource/templates/bootstrapped/index.html.erb +42 -0
  8. data/lib/generators/ez/resource/templates/bootstrapped/new.html.erb +26 -0
  9. data/lib/generators/ez/resource/templates/bootstrapped/show.html.erb +11 -0
  10. data/lib/generators/ez/resource/templates/controller.rb +70 -0
  11. data/lib/generators/ez/resource/templates/dried/_form.html.erb +13 -0
  12. data/lib/generators/ez/resource/templates/dried/bootstrapped/_form.html.erb +21 -0
  13. data/lib/generators/ez/resource/templates/dried/bootstrapped/edit.html.erb +5 -0
  14. data/lib/generators/ez/resource/templates/dried/bootstrapped/index.html.erb +42 -0
  15. data/lib/generators/ez/resource/templates/dried/bootstrapped/new.html.erb +5 -0
  16. data/lib/generators/ez/resource/templates/dried/bootstrapped/show.html.erb +11 -0
  17. data/lib/generators/ez/resource/templates/dried/controller.rb +72 -0
  18. data/lib/generators/ez/resource/templates/dried/edit.html.erb +3 -0
  19. data/lib/generators/ez/resource/templates/dried/index.html.erb +40 -0
  20. data/lib/generators/ez/resource/templates/dried/new.html.erb +3 -0
  21. data/lib/generators/ez/resource/templates/dried/show.html.erb +9 -0
  22. data/lib/generators/ez/resource/templates/edit.html.erb +24 -0
  23. data/lib/generators/ez/resource/templates/index.html.erb +40 -0
  24. data/lib/generators/ez/resource/templates/migration.rb +15 -0
  25. data/lib/generators/ez/resource/templates/model.rb +2 -0
  26. data/lib/generators/ez/resource/templates/new.html.erb +22 -0
  27. data/lib/generators/ez/resource/templates/show.html.erb +9 -0
  28. data/lib/generators/ez/style/USAGE +31 -0
  29. data/lib/generators/ez/style/style_generator.rb +34 -0
  30. data/lib/generators/ez/style/templates/layout.html.erb +66 -0
  31. data/lib/generators/ez/user/templates/user_controller.rb +68 -0
  32. data/lib/generators/ez/user/user_generator.rb +91 -0
  33. data/lib/generators/ez/views/USAGE +33 -0
  34. data/lib/tasks/ez_tasks.rake +24 -17
  35. metadata +33 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: dfa9e48c563ed020bc8231c6b28274d849afcc2f
4
- data.tar.gz: cb1569d4994001adcb2efc2fb9f94620ba4be15f
3
+ metadata.gz: c352179b9a780759c9e923d23de75f162cd94af7
4
+ data.tar.gz: b470479273475d5b1d97f5fb392c237faebb54ea
5
5
  SHA512:
6
- metadata.gz: a5016eb92c3a6dec889b2d960ddbeabc63e6d63b01370efb64afc585ae76f0e237fd6bf8eb6879ba668d4eb79e00fd9d0aa2cde7d1bdc7bc79581fd804b36e17
7
- data.tar.gz: 58399bc7f87231a35e9c0993b79b9caa35cc9315944bf2fdd468e68129ddaa3aa4d0995811792ed86bb3da8e6e08a09789ed65af719b2156fa9b2b0194aa588a
6
+ metadata.gz: 67d6a3bbad1b7a2165fbe01f1995117a96c418eb4ac8d74e4016aad8df73df0588ae34554ae961cdc77c5b6ebd603606c202ec16bc7d489512debf9578293dc2
7
+ data.tar.gz: c40c452e34c92c013b90a3c18fecc466334ab2044ef4db1a6cbbc40492763e45249011d129647dcd60978fac0370e6b5c2dbae4c102bfd555fdba2bc725cf5e2
@@ -1,3 +1,3 @@
1
1
  module Ez
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -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
+ with 'rake db:rollback' if you've already run 'rake db:migrate'. Then run
31
+ 'rails destroy starter: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,143 @@
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
+ remove_class_option :force_plural
13
+ remove_class_option :skip_namespace
14
+ class_option :named_routes, :type => :boolean, :default => true
15
+ class_option :skip_model, :type => :boolean, :default => false
16
+ class_option :skip_controller, :type => :boolean, :default => false
17
+ class_option :styled, :type => :boolean, :default => false, desc: 'Generates bootstrap-ready view templates'
18
+ class_option :dry, :type => :boolean, :default => false, desc: 'DRYs up the controller, views, and routes'
19
+
20
+ def generate_controller
21
+ return if options[:skip_controller]
22
+ if dry?
23
+ template 'dried/controller.rb', "app/controllers/#{plural_name.underscore}_controller.rb"
24
+ else
25
+ template 'controller.rb', "app/controllers/#{plural_name.underscore}_controller.rb"
26
+ end
27
+ end
28
+
29
+ def generate_model
30
+ return if options[:skip_model]
31
+ template 'model.rb', "app/models/#{singular_name.underscore}.rb"
32
+ end
33
+
34
+ def generate_migration
35
+ return if options[:skip_model]
36
+ migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
37
+ end
38
+
39
+ # def create_root_view_folder
40
+ # empty_directory File.join("app/views", controller_file_path)
41
+ # end
42
+
43
+ def copy_view_files
44
+ available_views.each do |view|
45
+ filename = view_filename_with_extensions(view)
46
+ template filename, File.join("app/views", controller_file_path, File.basename(filename))
47
+ end
48
+ end
49
+
50
+
51
+ def generate_routes
52
+ return if options[:skip_controller]
53
+ if dry?
54
+ route "resources :#{plural_name}", "Named RESTful routes"
55
+ elsif named_routes?
56
+ route golden_7_named, "Named RESTful routes"
57
+ else
58
+ route golden_7, "RESTful routes"
59
+ end
60
+ end
61
+
62
+ protected
63
+
64
+ def golden_7
65
+ ["# Routes for the #{singular_name.capitalize} resource:",
66
+ " # CREATE",
67
+ " get '/#{plural_name}/new', controller: '#{plural_name}', action: 'new'",
68
+ " post '/#{plural_name}', controller: '#{plural_name}', action: 'create'",
69
+ "",
70
+ " # READ",
71
+ " get '/#{plural_name}', controller: '#{plural_name}', action: 'index'",
72
+ " get '/#{plural_name}/:id', controller: '#{plural_name}', action: 'show'",
73
+ "",
74
+ " # UPDATE",
75
+ " get '/#{plural_name}/:id/edit', controller: '#{plural_name}', action: 'edit'",
76
+ " patch '/#{plural_name}/:id', controller: '#{plural_name}', action: 'update'",
77
+ "",
78
+ " # DELETE",
79
+ " delete '/#{plural_name}/:id', controller: '#{plural_name}', action: 'destroy'",
80
+ " ##{'-' * 30}"
81
+ ].join("\n")
82
+ end
83
+
84
+ def golden_7_named
85
+ ["# Routes for the #{singular_name.capitalize} resource:",
86
+ " # CREATE",
87
+ " get '/#{plural_name}/new', controller: '#{plural_name}', action: 'new', as: 'new_#{singular_name}'",
88
+ " post '/#{plural_name}', controller: '#{plural_name}', action: 'create', as: '#{plural_name}'",
89
+ "",
90
+ " # READ",
91
+ " get '/#{plural_name}', controller: '#{plural_name}', action: 'index'",
92
+ " get '/#{plural_name}/:id', controller: '#{plural_name}', action: 'show', as: '#{singular_name}'",
93
+ "",
94
+ " # UPDATE",
95
+ " get '/#{plural_name}/:id/edit', controller: '#{plural_name}', action: 'edit', as: 'edit_#{singular_name}'",
96
+ " patch '/#{plural_name}/:id', controller: '#{plural_name}', action: 'update'",
97
+ "",
98
+ " # DELETE",
99
+ " delete '/#{plural_name}/:id', controller: '#{plural_name}', action: 'destroy'",
100
+ " ##{'-' * 30}"
101
+ ].join("\n")
102
+ end
103
+
104
+ def dry?
105
+ options[:dry]
106
+ end
107
+
108
+ def named_routes?
109
+ options[:named_routes]
110
+ end
111
+
112
+ def styled?
113
+ options[:styled]
114
+ end
115
+
116
+ # Override of Rails::Generators::Actions
117
+ def route(routing_code, title)
118
+ log :route, title
119
+ sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
120
+
121
+ in_root do
122
+ inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false }
123
+ end
124
+ end
125
+
126
+ def attributes_with_index
127
+ attributes.select { |a| a.has_index? || (a.reference? && options[:indexes]) }
128
+ end
129
+
130
+ def available_views
131
+ dry? ? %w(index new edit show _form) : %w(index new edit show)
132
+ end
133
+
134
+ def view_filename_with_extensions(name)
135
+ filename = [name, :html, :erb].compact.join(".")
136
+ folders = []
137
+ folders << 'dried' if dry?
138
+ folders << 'bootstrapped' if styled?
139
+ filename = File.join(folders, filename) if folders.any?
140
+ return filename
141
+ end
142
+ end
143
+ end
@@ -0,0 +1,26 @@
1
+ <div class="page-header">
2
+ <h1>Editing <%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
3
+ </div>
4
+
5
+ <%%= form_tag(<%= singular_table_name %>_url(@<%= singular_table_name %>), method: 'patch', class: 'form-horizontal') do %>
6
+ <% attributes.each do |attribute| -%>
7
+ <div class="form-group">
8
+ <%%= label_tag :<%= attribute.name %>, nil, class: 'col-md-2 control-label' %>
9
+ <div class="col-md-6">
10
+ <% if attribute.field_type == :date_select || attribute.field_type == :time_select || attribute.field_type == :datetime_select -%>
11
+ <%%= text_field_tag :<%= attribute.name %>, @<%= singular_table_name %>.<%= attribute.name %>, class: 'form-control' %>
12
+ <% elsif attribute.field_type == :check_box -%>
13
+ <%%= check_box_tag :<%= attribute.name %>, 1, @<%= singular_table_name %>.<%= attribute.name %>? %>
14
+ <% else -%>
15
+ <%%= <%= attribute.field_type %>_tag :<%= attribute.name %>, @<%= singular_table_name %>.<%= attribute.name %>, class: 'form-control' %>
16
+ <% end -%>
17
+ </div>
18
+ </div>
19
+
20
+ <% end -%>
21
+ <div class="form-group">
22
+ <div class="col-md-offset-2 col-md-6">
23
+ <%%= submit_tag "Update <%= human_name.titleize %>", class: 'btn btn-primary' %>
24
+ </div>
25
+ </div>
26
+ <%% end %>
@@ -0,0 +1,42 @@
1
+ <div class="page-header">
2
+ <h1><%= plural_table_name.humanize %></h1>
3
+ </div>
4
+
5
+ <% if named_routes? -%>
6
+ <p><%%= link_to 'Add a New <%= human_name.titleize %>', new_<%= singular_table_name %>_url, class: 'btn btn-primary' %></p>
7
+ <% else -%>
8
+ <p><%%= link_to 'Add a New <%= human_name.titleize %>', "/<%= plural_name %>/new", class: 'btn btn-primary' %></p>
9
+ <% end -%>
10
+
11
+ <table class="table table-hover">
12
+ <thead>
13
+ <tr>
14
+ <% attributes.each do |attribute| -%>
15
+ <th><%= attribute.human_name %></th>
16
+ <% end -%>
17
+ <th></th>
18
+ <th></th>
19
+ <th></th>
20
+ </tr>
21
+ </thead>
22
+
23
+ <tbody>
24
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
25
+ <tr>
26
+ <% attributes.each do |attribute| -%>
27
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %><%= "?" if attribute.type == :boolean %> %></td>
28
+ <% end -%>
29
+ <% if named_routes? -%>
30
+ <td><%%= link_to '<i class="fa fa-search-plus"></i>'.html_safe, <%= singular_table_name %>_url(<%= singular_table_name %>), class: 'btn btn-primary' %></td>
31
+ <td><%%= link_to '<i class="fa fa-edit"></i>'.html_safe, edit_<%= singular_table_name %>_url(<%= singular_table_name %>), class: 'btn btn-warning' %></td>
32
+ <td><%%= link_to '<i class="fa fa-trash-o"></i>'.html_safe, <%= 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>
33
+ <% else -%>
34
+ <td><%%= link_to '<i class="fa fa-search-plus"></i>'.html_safe, "/<%= plural_name %>/#{<%= singular_table_name %>.id}", class: 'btn btn-primary' %></td>
35
+ <td><%%= link_to '<i class="fa fa-edit"></i>'.html_safe, "/<%= plural_name %>/#{<%= singular_table_name %>.id}/edit", class: 'btn btn-warning' %></td>
36
+ <td><%%= link_to '<i class="fa fa-trash-o"></i>'.html_safe, "/<%= 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>
37
+ <% end -%>
38
+ </tr>
39
+ <%% end %>
40
+ </tbody>
41
+ </table>
42
+
@@ -0,0 +1,26 @@
1
+ <div class="page-header">
2
+ <h1>New <%= human_name.titleize %></h1>
3
+ </div>
4
+
5
+ <%%= form_tag(<%= plural_name %>_url, method: 'post', class: 'form-horizontal') do %>
6
+ <% attributes.each do |attribute| -%>
7
+ <div class="form-group">
8
+ <%%= label_tag :<%= attribute.name %>, nil, class: 'col-md-2 control-label' %>
9
+ <div class="col-md-6">
10
+ <% if attribute.field_type == :date_select || attribute.field_type == :time_select || attribute.field_type == :datetime_select -%>
11
+ <%%= text_field_tag :<%= attribute.name %>, nil, class: 'form-control' %>
12
+ <% elsif attribute.field_type == :check_box -%>
13
+ <%%= check_box_tag :<%= attribute.name %> %>
14
+ <% else -%>
15
+ <%%= <%= attribute.field_type %>_tag :<%= attribute.name %>, nil, class: 'form-control' %>
16
+ <% end -%>
17
+ </div>
18
+ </div>
19
+
20
+ <% end -%>
21
+ <div class="form-group">
22
+ <div class="col-md-offset-2 col-md-6">
23
+ <%%= submit_tag "Create <%= human_name.titleize %>", class: 'btn btn-primary' %>
24
+ </div>
25
+ </div>
26
+ <%% end %>
@@ -0,0 +1,11 @@
1
+ <div class="page-header">
2
+ <h1><%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
3
+ </div>
4
+
5
+ <dl class="dl-horizontal">
6
+ <% attributes.each do |attribute| -%>
7
+ <dt><%= attribute.human_name %></dt>
8
+ <dd><%%= @<%= singular_table_name %>.<%= attribute.name %><%= "?" if attribute.type == :boolean %> %></dd>
9
+
10
+ <% end -%>
11
+ </dl>
@@ -0,0 +1,70 @@
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
+ end
13
+
14
+ def create
15
+ @<%= singular_name.underscore %> = <%= class_name %>.new
16
+ <% attributes.each do |attribute| -%>
17
+ @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
18
+ <% end -%>
19
+
20
+ <% if named_routes? -%>
21
+ if @<%= singular_name.underscore %>.save
22
+ redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> created successfully."
23
+ else
24
+ render 'new'
25
+ end
26
+ <% else -%>
27
+ if @<%= singular_name.underscore %>.save
28
+ redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> created successfully."
29
+ else
30
+ render 'new'
31
+ end
32
+ <% end -%>
33
+ end
34
+
35
+ def edit
36
+ @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
37
+ end
38
+
39
+ def update
40
+ @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
41
+ <% attributes.each do |attribute| -%>
42
+ @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
43
+ <% end -%>
44
+
45
+ <% if named_routes? -%>
46
+ if @<%= singular_name.underscore %>.save
47
+ redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> updated successfully."
48
+ else
49
+ render 'edit'
50
+ end
51
+ <% else -%>
52
+ if @<%= singular_name.underscore %>.save
53
+ redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> updated successfully."
54
+ else
55
+ render 'edit'
56
+ end
57
+ <% end -%>
58
+ end
59
+
60
+ def destroy
61
+ @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
62
+ @<%= singular_name.underscore %>.destroy
63
+
64
+ <% if named_routes? -%>
65
+ redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> deleted."
66
+ <% else -%>
67
+ redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> deleted."
68
+ <% end -%>
69
+ end
70
+ end
@@ -0,0 +1,13 @@
1
+ <%%= form_for @<%= singular_table_name %> do |f| %>
2
+
3
+ <% attributes.each do |attribute| -%>
4
+ <div>
5
+ <%%= f.label :<%= attribute.name %> %><br>
6
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %><%= "?" if attribute.type == :boolean %> %>
7
+ </div>
8
+
9
+ <% end -%>
10
+ <div>
11
+ <%%= f.submit %>
12
+ </div>
13
+ <%% end %>
@@ -0,0 +1,21 @@
1
+ <%%= form_for(@<%= singular_table_name %>, html: { class: 'form-horizontal'}) do |f| %>
2
+
3
+ <% attributes.each do |attribute| -%>
4
+ <div class="form-group">
5
+ <%%= f.label :<%= attribute.name %>, class: 'col-md-2' %>
6
+ <%
7
+ colsize = 6
8
+ colsize = 2 if attribute.type == :integer
9
+ %>
10
+ <div class="col-md-<%= colsize %>">
11
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %><%= "?" if attribute.type == :boolean %>, class: 'form-control' %>
12
+ </div>
13
+ </div>
14
+
15
+ <% end -%>
16
+ <div class="form-group">
17
+ <div class="col-md-offset-2 col-md-6">
18
+ <%%= f.submit nil, class: 'btn btn-primary' %>
19
+ </div>
20
+ </div>
21
+ <%% end %>
@@ -0,0 +1,5 @@
1
+ <div class="page-header">
2
+ <h1>Editing <%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
3
+ </div>
4
+
5
+ <%%= render 'form' %>
@@ -0,0 +1,42 @@
1
+ <div class="page-header">
2
+ <h1><%= plural_table_name.humanize %></h1>
3
+ </div>
4
+
5
+ <% if named_routes? -%>
6
+ <p><%%= link_to 'Add a New <%= human_name.titleize %>', new_<%= singular_table_name %>_url, class: 'btn btn-primary' %></p>
7
+ <% else -%>
8
+ <p><%%= link_to 'Add a New <%= human_name.titleize %>', "/<%= plural_name %>/new", class: 'btn btn-primary' %></p>
9
+ <% end -%>
10
+
11
+ <table class="table table-hover">
12
+ <thead>
13
+ <tr>
14
+ <% attributes.each do |attribute| -%>
15
+ <th><%= attribute.human_name %></th>
16
+ <% end -%>
17
+ <th></th>
18
+ <th></th>
19
+ <th></th>
20
+ </tr>
21
+ </thead>
22
+
23
+ <tbody>
24
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
25
+ <tr>
26
+ <% attributes.each do |attribute| -%>
27
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
28
+ <% end -%>
29
+ <% if named_routes? %>
30
+ <td><%%= link_to '<i class="fa fa-search-plus"></i>'.html_safe, <%= singular_table_name %>_url(<%= singular_table_name %>), class: 'btn btn-primary' %></td>
31
+ <td><%%= link_to '<i class="fa fa-edit"></i>'.html_safe, edit_<%= singular_table_name %>_url(<%= singular_table_name %>), class: 'btn btn-warning' %></td>
32
+ <td><%%= link_to '<i class="fa fa-trash-o"></i>'.html_safe, <%= 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>
33
+ <% else %>
34
+ <td><%%= link_to '<i class="fa fa-search-plus"></i>'.html_safe, "/<%= plural_name %>/#{<%= singular_table_name %>.id}", class: 'btn btn-primary' %></td>
35
+ <td><%%= link_to '<i class="fa fa-edit"></i>'.html_safe, "/<%= plural_name %>/#{<%= singular_table_name %>.id}/edit", class: 'btn btn-warning' %></td>
36
+ <td><%%= link_to '<i class="fa fa-trash-o"></i>'.html_safe, "/<%= 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>
37
+ <% end %>
38
+ </tr>
39
+ <%% end %>
40
+ </tbody>
41
+ </table>
42
+
@@ -0,0 +1,5 @@
1
+ <div class="page-header">
2
+ <h1>New <%= human_name.titleize %></h1>
3
+ </div>
4
+
5
+ <%%= render 'form' %>
@@ -0,0 +1,11 @@
1
+ <div class="page-header">
2
+ <h1><%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
3
+ </div>
4
+
5
+ <dl class="dl-horizontal">
6
+ <% attributes.each do |attribute| -%>
7
+ <dt><%= attribute.human_name %></dt>
8
+ <dd><%%= @<%= singular_table_name %>.<%= attribute.name %> %></dd>
9
+
10
+ <% end %>
11
+ </dl>
@@ -0,0 +1,72 @@
1
+ class <%= plural_name.camelize %>Controller < ApplicationController
2
+
3
+ before_action :set_<%= singular_name.underscore %>, only: [:show, :edit, :update, :destroy]
4
+
5
+ def index
6
+ @<%= plural_name.underscore %> = <%= class_name %>.all
7
+ end
8
+
9
+ def show
10
+ end
11
+
12
+ def new
13
+ @<%= singular_name.underscore %> = <%= class_name %>.new
14
+ end
15
+
16
+ def create
17
+ @<%= singular_name.underscore %> = <%= class_name %>.new
18
+ <% attributes.each do |attribute| -%>
19
+ @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= singular_name.underscore %>][:<%= attribute.name %>]
20
+ <% end %>
21
+ <% if named_routes? -%>
22
+ if @<%= singular_name.underscore %>.save
23
+ redirect_to <%= plural_name %>_url
24
+ else
25
+ render 'new'
26
+ end
27
+ <% else -%>
28
+ if @<%= singular_name.underscore %>.save
29
+ redirect_to "/<%= plural_name %>"
30
+ else
31
+ render 'new'
32
+ end
33
+ <% end -%>
34
+ end
35
+
36
+ def edit
37
+ end
38
+
39
+ def update
40
+ <% attributes.each do |attribute| -%>
41
+ @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= singular_name.underscore %>][:<%= attribute.name %>]
42
+ <% end %>
43
+ <% if named_routes? -%>
44
+ if @<%= singular_name.underscore %>.save
45
+ redirect_to <%= plural_name %>_url
46
+ else
47
+ render 'new'
48
+ end
49
+ <% else -%>
50
+ if @<%= singular_name.underscore %>.save
51
+ redirect_to "/<%= plural_name %>"
52
+ else
53
+ render 'new'
54
+ end
55
+ <% end -%>
56
+ end
57
+
58
+ def destroy
59
+ @<%= singular_name.underscore %>.destroy
60
+ <% if named_routes? -%>
61
+ redirect_to <%= plural_name %>_url
62
+ <% else -%>
63
+ redirect_to "/<%= plural_name %>"
64
+ <% end -%>
65
+ end
66
+
67
+ private
68
+
69
+ def set_<%= singular_name.underscore %>
70
+ @<%= singular_name.underscore %> = <%= class_name %>.find(params[:id])
71
+ end
72
+ end
@@ -0,0 +1,3 @@
1
+ <h1>Editing <%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
2
+
3
+ <%%= render 'form' %>
@@ -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 %><%= "?" if attribute.type == :boolean %> %></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
+ </tbody>
39
+ </table>
40
+
@@ -0,0 +1,3 @@
1
+ <h1>New <%= human_name.titleize %></h1>
2
+
3
+ <%%= render 'form' %>
@@ -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,24 @@
1
+ <h1>Editing <%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
2
+
3
+ <% if named_routes? -%>
4
+ <%%= form_tag(<%= singular_table_name %>_url(@<%= singular_table_name %>), method: 'patch') do %>
5
+ <% else -%>
6
+ <%%= form_tag("/<%= plural_name %>/#{<%= singular_table_name %>.id}", method: 'patch') do %>
7
+ <% end -%>
8
+ <% attributes.each do |attribute| -%>
9
+ <div>
10
+ <%%= label_tag :<%= attribute.name %> %><br />
11
+ <% if attribute.field_type == :date_select || attribute.field_type == :time_select || attribute.field_type == :datetime_select -%>
12
+ <%%= text_field_tag :<%= attribute.name %>, @<%= singular_table_name %>.<%= attribute.name %> %>
13
+ <% elsif attribute.field_type == :check_box -%>
14
+ <%%= check_box_tag :<%= attribute.name %>, 1, @<%= singular_table_name %>.<%= attribute.name %>? %>
15
+ <% else -%>
16
+ <%%= <%= attribute.field_type %>_tag :<%= attribute.name %>, @<%= singular_table_name %>.<%= attribute.name %><%= "?" if attribute.type == :boolean %> %>
17
+ <% end -%>
18
+ </div>
19
+
20
+ <% end -%>
21
+ <div>
22
+ <%%= submit_tag "Update <%= human_name.titleize %>" %>
23
+ </div>
24
+ <%% 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
+ </tbody>
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,22 @@
1
+ <h1>New <%= human_name.titleize %></h1>
2
+
3
+ <% if named_routes? -%>
4
+ <%%= form_tag(<%= plural_name %>_url, method: 'post') do %>
5
+ <% else -%>
6
+ <%%= form_tag('/<%= plural_name %>', method: 'post') do %>
7
+ <% end -%>
8
+ <% attributes.each do |attribute| -%>
9
+ <div>
10
+ <%%= label_tag :<%= attribute.name %> %><br />
11
+ <% if attribute.field_type == :date_select || attribute.field_type == :time_select || attribute.field_type == :datetime_select -%>
12
+ <%%= text_field_tag :<%= attribute.name %> %>
13
+ <% else -%>
14
+ <%%= <%= attribute.field_type %>_tag :<%= attribute.name %> %>
15
+ <% end -%>
16
+ </div>
17
+
18
+ <% end -%>
19
+ <div>
20
+ <%%= submit_tag "Create <%= human_name.titleize %>" %>
21
+ </div>
22
+ <%% end %>
@@ -0,0 +1,9 @@
1
+ <h1><%= human_name.titleize %> #<%%= @<%= singular_table_name %>.id %></h1>
2
+
3
+ <dl>
4
+ <% attributes.each do |attribute| -%>
5
+ <dt><%= attribute.human_name %></dt>
6
+ <dd><%%= @<%= singular_table_name %>.<%= attribute.name %><%= "?" if attribute.type == :boolean %> %></dd>
7
+
8
+ <% end -%>
9
+ </dl>
@@ -0,0 +1,31 @@
1
+ Description:
2
+ Injects the Bootstrap framework, FontAwesome support, and a standard application layout template into your app.
3
+
4
+ The application layout will provide a standard top navbar based on the models already in your application, with support for flash messages.
5
+
6
+ Specify "default" as the THEME_NAME to use the default bootstrap theme. Or, provide a Bootswatch name instead.
7
+
8
+
9
+ THEME_NAME can be one of:
10
+ amelia, cerulian, cyborg, default, journal, geo, readable, simplex, slate, spacelab, spruce, superhero, united
11
+
12
+ LAYOUT_FILE defaults to "application".
13
+
14
+ WARNING: You will LOSE any modifications you've made to your application layout unless you specify a different filename with the --layout-file option.
15
+
16
+ Examples:
17
+ `rails generate starter:style default`
18
+
19
+ Injects Bootstrap 3.0 into your CSS folder, adjusts your applications' css manifest, and replaces your application layout with a standard Bootstrap template and a navigation bar based on your models.
20
+
21
+ `rails generate starter:style --no-navbar`
22
+
23
+ Injects Bootstrap 3.0 into your CSS folder, adjusts your applications' css manifest, and replaces your application layout with a standard Bootstrap template.
24
+
25
+ `rails generate starter:style united`
26
+
27
+ Injects Bootstrap 3.0 into your CSS folder, adjusts your applications' css manifest, and replaces your application layout with the United bootswatch theme.
28
+
29
+
30
+
31
+
@@ -0,0 +1,34 @@
1
+ module Starter
2
+ class StyleGenerator < Rails::Generators::Base
3
+ source_root File.expand_path('../templates', __FILE__)
4
+
5
+ argument :theme_name, :type => :string#, :default => 'default'
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 generate_layout
12
+ if bootswatch_theme?
13
+ log :insert, "Bootswatch theme '#{theme_name}'"
14
+ else
15
+ log :insert, 'Bootstrap CSS framework'
16
+ end
17
+ log :insert, 'FontAwesome support'
18
+ template "layout.html.erb", "app/views/layouts/#{layout_file}.html.erb" if options[:layout]
19
+ end
20
+
21
+ protected
22
+
23
+ def bootswatch_theme?
24
+ if theme_name.present?
25
+ (theme_name.downcase != 'default') && (theme_name.downcase != 'd')
26
+ end
27
+ end
28
+
29
+ def app_tables
30
+ ActiveRecord::Base.connection.tables - ['schema_migrations']
31
+ end
32
+
33
+ end
34
+ end
@@ -0,0 +1,66 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="utf-8">
5
+ <title><%= Rails.application.class.parent_name %></title>
6
+
7
+ <% if bootswatch_theme? -%>
8
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootswatch/3.0.2/<%= theme_name %>/bootstrap.min.css">
9
+ <% else %>
10
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
11
+ <% end -%>
12
+ <link rel="stylesheet" href="//netdna.bootstrapcdn.com/font-awesome/4.0.2/css/font-awesome.min.css">
13
+
14
+ <style>
15
+ /* Only necessary if you are using navbar-fixed-top */
16
+ body {
17
+ padding-top: 50px;
18
+ }
19
+ </style>
20
+
21
+ <%%= stylesheet_link_tag "application", :media => "all" %>
22
+ <%%= javascript_include_tag "application" %>
23
+ <%%= csrf_meta_tags %>
24
+
25
+ <script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
26
+
27
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
28
+ </head>
29
+ <body>
30
+ <nav class="navbar navbar-default navbar-fixed-top" role="navigation">
31
+ <!-- Brand and toggle get grouped for better mobile display -->
32
+ <div class="navbar-header">
33
+ <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1">
34
+ <span class="sr-only">Toggle navigation</span>
35
+ <span class="icon-bar"></span>
36
+ <span class="icon-bar"></span>
37
+ <span class="icon-bar"></span>
38
+ </button>
39
+ <%%= link_to Rails.application.class.parent_name, root_url, :class => "navbar-brand" %>
40
+ </div>
41
+
42
+ <!-- Collect the nav links, forms, and other content for toggling -->
43
+ <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
44
+ <ul class="nav navbar-nav">
45
+ <% if options[:navbar] -%>
46
+ <% app_tables.each do |table_name| -%>
47
+ <li><%%= link_to "<%= table_name.humanize.titleize %>", <%= table_name.pluralize %>_url %></li>
48
+ <% end -%>
49
+ <li><a href="#">About</a></li>
50
+ <% end -%>
51
+ </ul>
52
+ </div><!-- /.navbar-collapse -->
53
+ </nav>
54
+
55
+ <div class="container">
56
+ <%% if notice.present? %>
57
+ <div class="alert alert-dismissable alert-success">
58
+ <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
59
+ <%%= notice %>
60
+ </div>
61
+ <%% end %>
62
+
63
+ <%%= yield %>
64
+ </div>
65
+ </body>
66
+ </html>
@@ -0,0 +1,68 @@
1
+ class <%= plural_name.camelize %>Controller < ApplicationController
2
+
3
+ before_action :require_login, :only => [:show, :edit, :update, :destroy]
4
+
5
+ def show
6
+ @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
7
+ end
8
+
9
+ def new
10
+ end
11
+
12
+ def create
13
+ @<%= singular_name.underscore %> = <%= class_name %>.new
14
+ <% attributes.each do |attribute| -%>
15
+ @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
16
+ <% end -%>
17
+
18
+ <% if named_routes? -%>
19
+ if @<%= singular_name.underscore %>.save
20
+ redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> created successfully."
21
+ else
22
+ render 'new'
23
+ end
24
+ <% else -%>
25
+ if @<%= singular_name.underscore %>.save
26
+ redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> created successfully."
27
+ else
28
+ render 'new'
29
+ end
30
+ <% end -%>
31
+ end
32
+
33
+ def edit
34
+ @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
35
+ end
36
+
37
+ def update
38
+ @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
39
+ <% attributes.each do |attribute| -%>
40
+ @<%= singular_name.underscore %>.<%= attribute.name %> = params[:<%= attribute.name %>]
41
+ <% end -%>
42
+
43
+ <% if named_routes? -%>
44
+ if @<%= singular_name.underscore %>.save
45
+ redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> updated successfully."
46
+ else
47
+ render 'edit'
48
+ end
49
+ <% else -%>
50
+ if @<%= singular_name.underscore %>.save
51
+ redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> updated successfully."
52
+ else
53
+ render 'edit'
54
+ end
55
+ <% end -%>
56
+ end
57
+
58
+ def destroy
59
+ @<%= singular_name.underscore %> = <%= class_name %>.find_by(id: params[:id])
60
+ @<%= singular_name.underscore %>.destroy
61
+
62
+ <% if named_routes? -%>
63
+ redirect_to <%= plural_name %>_url, notice: "<%= singular_name.humanize %> deleted."
64
+ <% else -%>
65
+ redirect_to "/<%= plural_name %>", notice: "<%= singular_name.humanize %> deleted."
66
+ <% end -%>
67
+ end
68
+ end
@@ -0,0 +1,91 @@
1
+ require 'rails/generators/active_record'
2
+ require_relative './migration'
3
+ module Starter
4
+ class UserGenerator < 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
+ remove_class_option :force_plural
13
+ remove_class_option :skip_namespace
14
+ class_option :styled, :type => :boolean, :default => true, desc: 'Generates bootstrap-ready view templates'
15
+
16
+ def generate_controller
17
+ template 'user_controller.rb', "app/controllers/#{plural_name.underscore}_controller.rb"
18
+ template 'sessions_controller.rb', "app/controllers/sessions_controller.rb"
19
+ end
20
+
21
+ def generate_model
22
+ template 'model.rb', "app/models/#{singular_name.underscore}.rb"
23
+ end
24
+
25
+ def generate_migration
26
+ return if options[:skip_model]
27
+ migration_template "migration.rb", "db/migrate/create_#{table_name}.rb"
28
+ end
29
+
30
+ # def create_root_view_folder
31
+ # empty_directory File.join("app/views", controller_file_path)
32
+ # end
33
+
34
+ def copy_view_files
35
+ available_views.each do |view|
36
+ filename = view_filename_with_extensions(view)
37
+ template filename, File.join("app/views", controller_file_path, File.basename(filename))
38
+ end
39
+ end
40
+
41
+
42
+ def generate_routes
43
+ route user_routes, "Routes"
44
+ end
45
+
46
+ protected
47
+
48
+ def user_routes
49
+ ["# Routes for sign up, user profile management, login, and logout:",
50
+ " get '/#{plural_name}/new' => '#{plural_name}#new'",
51
+ " get '/#{plural_name}/create' => '#{plural_name}#create'",
52
+ " get '/#{plural_name}/:#{singular_name}/show' => '#{plural_name}#show'",
53
+ " get '/#{plural_name}/:#{singular_name}/edit' => '#{plural_name}#edit'",
54
+ " get '/#{plural_name}/:#{singular_name}/update' => '#{plural_name}#update'",
55
+ " get '/#{plural_name}/:#{singular_name}/delete' => '#{plural_name}#destroy'",
56
+ " ",
57
+ " get '/login' => 'sessions#new'",
58
+ " get '/handle_login' => 'sessions#create'",
59
+ " get '/logout' => 'sessions#logout'"
60
+
61
+ ].join("\n")
62
+ end
63
+
64
+ # Override of Rails::Generators::Actions
65
+ def route(routing_code, title)
66
+ log :route, title
67
+ sentinel = /\.routes\.draw do(?:\s*\|map\|)?\s*$/
68
+
69
+ in_root do
70
+ inject_into_file 'config/routes.rb', "\n #{routing_code}\n", { :after => sentinel, :verbose => false }
71
+ end
72
+ end
73
+
74
+ def attributes_with_index
75
+ attributes.select { |a| a.has_index? || (a.reference? && options[:indexes]) }
76
+ end
77
+
78
+ def available_views
79
+ dry? ? %w(index new edit show _form) : %w(index new edit show)
80
+ end
81
+
82
+ def view_filename_with_extensions(name)
83
+ filename = [name, :html, :erb].compact.join(".")
84
+ folders = []
85
+ folders << 'dried' if dry?
86
+ folders << 'bootstrapped' if styled?
87
+ filename = File.join(folders, filename) if folders.any?
88
+ return filename
89
+ end
90
+ end
91
+ end
@@ -0,0 +1,33 @@
1
+ Description:
2
+ Generates "CRUD"-style views
3
+
4
+ Pass the name of the model (in singular form), either CamelCased or
5
+ under_scored, as the first argument, and an optional list of attribute
6
+ pairs.
7
+
8
+ Attributes are field arguments specifying the model's attributes. You can
9
+ optionally pass the type and an index to each field. For instance:
10
+ "title body:text tracking_id:integer:uniq" will generate a title field of
11
+ string type, a body with text type and a tracking_id as an integer with an
12
+ unique index. "index" could also be given instead of "uniq" if one desires
13
+ a non unique index.
14
+
15
+ Timestamps are added by default, so you don't have to specify them by hand
16
+ as 'created_at:datetime updated_at:datetime'.
17
+
18
+ You don't have to think up every attribute up front, but it helps to
19
+ sketch out a few so you can start working with the resource immediately.
20
+
21
+ For example, 'starter:resource post title body:text published:boolean' gives
22
+ you a model with those three attributes, a controller that handles
23
+ the create/show/update/destroy, forms to create and edit your posts, and
24
+ an index that lists them all, as well as the Golden Seven "RESTful" routes
25
+ in config/routes.rb.
26
+
27
+ If you want to remove all the generated files, first rollback your migration
28
+ with 'rake db:rollback' if you've already run 'rake db:migrate'. Then run
29
+ 'rails destroy starter:resource ModelName'.
30
+
31
+ Examples:
32
+ `rails generate starter:resource post title body:text published:boolean`
33
+ `rails generate starter:resource purchase amount:decimal tracking_id:integer:uniq`
@@ -1,22 +1,8 @@
1
1
  namespace :ez do
2
2
 
3
- desc "Reset the database scheme from scratch."
4
- task :reset_tables => ['db:drop', :tables] do
5
- end
6
-
7
- desc "Automatically update the database schema and model files."
8
- task :tables => :environment do
9
- if File.exists?('db/models.yml')
10
- DomainModeler.update_tables
11
- Rake::Task["db:schema:dump"].invoke
12
- else
13
- emit_help_page
14
- end
15
- end
16
-
17
- def emit_help_page
18
- puts "To get started, edit the db/models.yml file to describe your table schema."
19
- File.open("db/models.yml", "w") do |f|
3
+ desc "Generate models.yml if it doesn't exist yet."
4
+ task :generate_yml do
5
+ File.open("db/models.yml", "w") do |f|
20
6
  f.puts <<-EOS
21
7
  # Example table for a typical Book model.
22
8
  #
@@ -33,4 +19,25 @@ namespace :ez do
33
19
  EOS
34
20
  end
35
21
  end
22
+
23
+ desc "Reset the database schema and data from scratch."
24
+ task :reset_tables => ['db:drop', :tables] do
25
+ end
26
+
27
+
28
+ desc "Attempts to update the database schema and model files with minimal data loss."
29
+ task :tables => :environment do
30
+ if File.exists?('db/models.yml')
31
+ DomainModeler.update_tables
32
+ Rake::Task["db:schema:dump"].invoke
33
+ else
34
+ emit_help_page
35
+ Rake::Task["generate_yml"].invoke
36
+ end
37
+ end
38
+
39
+ def emit_help_page
40
+ puts "To get started, edit the db/models.yml file to describe your table schema."
41
+
42
+ end
36
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ez
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Cohen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-03-02 00:00:00.000000000 Z
11
+ date: 2014-03-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -65,6 +65,37 @@ files:
65
65
  - lib/ez/mapper.rb
66
66
  - lib/ez/schema_modifier.rb
67
67
  - lib/ez/version.rb
68
+ - lib/generators/ez/resource/USAGE
69
+ - lib/generators/ez/resource/migration.rb
70
+ - lib/generators/ez/resource/resource_generator.rb
71
+ - lib/generators/ez/resource/templates/bootstrapped/edit.html.erb
72
+ - lib/generators/ez/resource/templates/bootstrapped/index.html.erb
73
+ - lib/generators/ez/resource/templates/bootstrapped/new.html.erb
74
+ - lib/generators/ez/resource/templates/bootstrapped/show.html.erb
75
+ - lib/generators/ez/resource/templates/controller.rb
76
+ - lib/generators/ez/resource/templates/dried/_form.html.erb
77
+ - lib/generators/ez/resource/templates/dried/bootstrapped/_form.html.erb
78
+ - lib/generators/ez/resource/templates/dried/bootstrapped/edit.html.erb
79
+ - lib/generators/ez/resource/templates/dried/bootstrapped/index.html.erb
80
+ - lib/generators/ez/resource/templates/dried/bootstrapped/new.html.erb
81
+ - lib/generators/ez/resource/templates/dried/bootstrapped/show.html.erb
82
+ - lib/generators/ez/resource/templates/dried/controller.rb
83
+ - lib/generators/ez/resource/templates/dried/edit.html.erb
84
+ - lib/generators/ez/resource/templates/dried/index.html.erb
85
+ - lib/generators/ez/resource/templates/dried/new.html.erb
86
+ - lib/generators/ez/resource/templates/dried/show.html.erb
87
+ - lib/generators/ez/resource/templates/edit.html.erb
88
+ - lib/generators/ez/resource/templates/index.html.erb
89
+ - lib/generators/ez/resource/templates/migration.rb
90
+ - lib/generators/ez/resource/templates/model.rb
91
+ - lib/generators/ez/resource/templates/new.html.erb
92
+ - lib/generators/ez/resource/templates/show.html.erb
93
+ - lib/generators/ez/style/USAGE
94
+ - lib/generators/ez/style/style_generator.rb
95
+ - lib/generators/ez/style/templates/layout.html.erb
96
+ - lib/generators/ez/user/templates/user_controller.rb
97
+ - lib/generators/ez/user/user_generator.rb
98
+ - lib/generators/ez/views/USAGE
68
99
  - lib/tasks/ez_tasks.rake
69
100
  homepage: http://www.jeffcohenonline.com/ez
70
101
  licenses: