rails-cancan-bootstrap-scaffold 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (34) hide show
  1. data/.gitignore +17 -0
  2. data/Gemfile +4 -0
  3. data/LICENSE.txt +22 -0
  4. data/README.md +48 -0
  5. data/Rakefile +1 -0
  6. data/lib/generators/cancan_bootstrap/controller/USAGE +20 -0
  7. data/lib/generators/cancan_bootstrap/controller/controller_generator.rb +22 -0
  8. data/lib/generators/cancan_bootstrap/controller/templates/controller.rb +75 -0
  9. data/lib/generators/cancan_bootstrap/routes/USAGE +5 -0
  10. data/lib/generators/cancan_bootstrap/routes/routes_generator.rb +11 -0
  11. data/lib/generators/cancan_bootstrap/scaffold/scaffold_generator.rb +19 -0
  12. data/lib/generators/cancan_bootstrap/views/templates/_form.html.erb +16 -0
  13. data/lib/generators/cancan_bootstrap/views/templates/_form.html.haml +10 -0
  14. data/lib/generators/cancan_bootstrap/views/templates/_form.html.slim +11 -0
  15. data/lib/generators/cancan_bootstrap/views/templates/edit.html.erb +4 -0
  16. data/lib/generators/cancan_bootstrap/views/templates/edit.html.haml +3 -0
  17. data/lib/generators/cancan_bootstrap/views/templates/edit.html.slim +3 -0
  18. data/lib/generators/cancan_bootstrap/views/templates/index.html.erb +38 -0
  19. data/lib/generators/cancan_bootstrap/views/templates/index.html.haml +24 -0
  20. data/lib/generators/cancan_bootstrap/views/templates/index.html.slim +26 -0
  21. data/lib/generators/cancan_bootstrap/views/templates/new.html.erb +4 -0
  22. data/lib/generators/cancan_bootstrap/views/templates/new.html.haml +3 -0
  23. data/lib/generators/cancan_bootstrap/views/templates/new.html.slim +3 -0
  24. data/lib/generators/cancan_bootstrap/views/templates/show.html.erb +21 -0
  25. data/lib/generators/cancan_bootstrap/views/templates/show.html.haml +14 -0
  26. data/lib/generators/cancan_bootstrap/views/templates/show.html.slim +16 -0
  27. data/lib/generators/cancan_bootstrap/views/templates/simple_form/_form.html.erb +14 -0
  28. data/lib/generators/cancan_bootstrap/views/templates/simple_form/_form.html.haml +11 -0
  29. data/lib/generators/cancan_bootstrap/views/templates/simple_form/_form.html.slim +12 -0
  30. data/lib/generators/cancan_bootstrap/views/views_generator.rb +99 -0
  31. data/lib/rails-cancan-bootstrap-scaffold.rb +11 -0
  32. data/lib/rails-cancan-bootstrap-scaffold/version.rb +9 -0
  33. data/rails-cancan-bootstrap-scaffold.gemspec +19 -0
  34. metadata +78 -0
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in rails-cancan-bootstrap-scaffold.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Michael Witrant
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.
@@ -0,0 +1,48 @@
1
+ # Rails::Cancan::Bootstrap::Scaffold
2
+
3
+ Rails generators that produce standard code for Bootstrap and Cancan.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'rails-cancan-bootstrap-scaffold'
10
+
11
+ And then execute:
12
+
13
+ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ gem install rails-cancan-bootstrap-scaffold
18
+
19
+ ## Usage
20
+
21
+ First generate your model with Rails and migrate:
22
+
23
+ rails g model Post title:string body:text
24
+ rake db:migrate
25
+
26
+ Then generate the scaffold with:
27
+
28
+ rails g cancan_bootstrap:scaffold Post
29
+
30
+ You can also run the generators individually:
31
+
32
+ rails g cancan_bootstrap:controller Post
33
+ rails g cancan_bootstrap:routes Post
34
+ rails g cancan_bootstrap:views Post
35
+
36
+ If you want to change the model and regenerate the scaffold, you must update the database and call the generator again (you only need to update the views):
37
+
38
+ rails g migration AddActiveToPost active:boolean
39
+ rake db:migrate
40
+ rails g cancan_bootstrap:views Post
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,20 @@
1
+ Description:
2
+ Stubs out a scaffolded controller and its views. Pass the model name,
3
+ either CamelCased or under_scored, and a list of views as arguments.
4
+ The controller name is retrieved as a pluralized version of the model
5
+ name.
6
+
7
+ To create a controller within a module, specify the model name as a
8
+ path like 'parent_module/controller_name'.
9
+
10
+ This generates a controller class in app/controllers and invokes helper,
11
+ template engine and test framework generators.
12
+
13
+ Example:
14
+ `rails generate scaffold_controller CreditCard`
15
+
16
+ Credit card controller with URLs like /credit_card/debit.
17
+ Controller: app/controllers/credit_cards_controller.rb
18
+ Functional Test: test/functional/credit_cards_controller_test.rb
19
+ Views: app/views/credit_cards/index.html.erb [...]
20
+ Helper: app/helpers/credit_cards_helper.rb
@@ -0,0 +1,22 @@
1
+ require 'rails/generators/resource_helpers'
2
+
3
+ module CancanBootstrap
4
+ module Generators
5
+ class ControllerGenerator < Rails::Generators::NamedBase
6
+ include Rails::Generators::ResourceHelpers
7
+ source_root File.expand_path('../templates', __FILE__)
8
+
9
+ check_class_collision :suffix => "Controller"
10
+
11
+ class_option :orm, :banner => "NAME", :type => :string, :required => true,
12
+ :desc => "ORM to generate the controller for"
13
+
14
+ class_option :http, :type => :boolean, :default => false,
15
+ :desc => "Generate controller with HTTP actions only"
16
+
17
+ def create_controller_files
18
+ template "controller.rb", File.join('app/controllers', class_path, "#{controller_file_name}_controller.rb")
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,75 @@
1
+ <% module_namespacing do -%>
2
+ class <%= controller_class_name %>Controller < ApplicationController
3
+ load_and_authorize_resource
4
+
5
+ # GET <%= route_url %>
6
+ # GET <%= route_url %>.json
7
+ def index
8
+ respond_to do |format|
9
+ format.html # index.html.erb
10
+ format.json { render json: <%= "@#{plural_table_name}" %> }
11
+ end
12
+ end
13
+
14
+ # GET <%= route_url %>/1
15
+ # GET <%= route_url %>/1.json
16
+ def show
17
+ respond_to do |format|
18
+ format.html # show.html.erb
19
+ format.json { render json: <%= "@#{singular_table_name}" %> }
20
+ end
21
+ end
22
+
23
+ # GET <%= route_url %>/new
24
+ # GET <%= route_url %>/new.json
25
+ def new
26
+ respond_to do |format|
27
+ format.html # new.html.erb
28
+ format.json { render json: <%= "@#{singular_table_name}" %> }
29
+ end
30
+ end
31
+
32
+ # GET <%= route_url %>/1/edit
33
+ def edit
34
+ end
35
+
36
+ # POST <%= route_url %>
37
+ # POST <%= route_url %>.json
38
+ def create
39
+ respond_to do |format|
40
+ if @<%= orm_instance.save %>
41
+ format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully created.'" %> }
42
+ format.json { render json: <%= "@#{singular_table_name}" %>, status: :created, location: <%= "@#{singular_table_name}" %> }
43
+ else
44
+ format.html { render action: "new" }
45
+ format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
46
+ end
47
+ end
48
+ end
49
+
50
+ # PATCH/PUT <%= route_url %>/1
51
+ # PATCH/PUT <%= route_url %>/1.json
52
+ def update
53
+ respond_to do |format|
54
+ if @<%= orm_instance.update_attributes("params[:#{singular_table_name}]") %>
55
+ format.html { redirect_to @<%= singular_table_name %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
56
+ format.json { head :no_content }
57
+ else
58
+ format.html { render action: "edit" }
59
+ format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
60
+ end
61
+ end
62
+ end
63
+
64
+ # DELETE <%= route_url %>/1
65
+ # DELETE <%= route_url %>/1.json
66
+ def destroy
67
+ @<%= orm_instance.destroy %>
68
+
69
+ respond_to do |format|
70
+ format.html { redirect_to <%= index_helper %>_url }
71
+ format.json { head :no_content }
72
+ end
73
+ end
74
+ end
75
+ <% end -%>
@@ -0,0 +1,5 @@
1
+ Description:
2
+ Generate route to the controller
3
+
4
+ Example:
5
+ `rails generate cancan_bootstrap:routes User`
@@ -0,0 +1,11 @@
1
+ require 'rails/generators'
2
+
3
+ module CancanBootstrap
4
+ module Generators
5
+ class RoutesGenerator < ::Rails::Generators::NamedBase
6
+ def add_route
7
+ route "resources :#{plural_table_name}"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,19 @@
1
+ require 'rails/generators'
2
+
3
+ module CancanBootstrap
4
+ module Generators
5
+ class ScaffoldGenerator < ::Rails::Generators::NamedBase
6
+ def generate_controller
7
+ invoke "cancan_bootstrap:controller"
8
+ end
9
+
10
+ def generate_routes
11
+ invoke "cancan_bootstrap:routes"
12
+ end
13
+
14
+ def generate_views
15
+ invoke "cancan_bootstrap:views"
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,16 @@
1
+ <%%= form_for @<%= resource_name %>, :html => { :class => 'form-horizontal' } do |f| %>
2
+ <%- columns.each do |column| -%>
3
+ <div class="control-group">
4
+ <%%= f.label :<%= column.name %>, :class => 'control-label' %>
5
+ <div class="controls">
6
+ <%%= f.<%= column.field_type %> :<%= column.name %>, :class => '<%= column.field_type %>' %>
7
+ </div>
8
+ </div>
9
+ <%- end -%>
10
+
11
+ <div class="form-actions">
12
+ <%%= f.submit nil, :class => 'btn btn-primary' %>
13
+ <%%= link_to t('.cancel', :default => t("helpers.links.cancel")),
14
+ <%= controller_routing_path %>_path, :class => 'btn' %>
15
+ </div>
16
+ <%% end %>
@@ -0,0 +1,10 @@
1
+ = form_for @<%= resource_name %>, :html => { :class => 'form-horizontal' } do |f|
2
+ <%- columns.each do |column| -%>
3
+ .control-group
4
+ = f.label :<%= column.name %>, :class => 'control-label'
5
+ .controls
6
+ = f.<%= column.field_type %> :<%= column.name %>, :class => '<%= column.field_type %>'
7
+ <%- end -%>
8
+ .form-actions
9
+ = f.submit nil, :class => 'btn btn-primary'
10
+ = link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn'
@@ -0,0 +1,11 @@
1
+ = form_for @<%= resource_name %>, :html => { :class => "form-horizontal" } do |f|
2
+ <%- columns.each do |column| -%>
3
+ .control-group
4
+ = f.label :<%= column.name %>, :class => 'control-label'
5
+ .controls
6
+ = f.<%= column.field_type %> :<%= column.name %>, :class => '<%= column.field_type %>'
7
+ <%- end -%>
8
+ .form-actions
9
+ = f.submit nil, :class => 'btn btn-primary'
10
+ '
11
+ = link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn'
@@ -0,0 +1,4 @@
1
+ <%%- model_class = @<%= resource_name %>.class -%>
2
+ <h1><%%=t '.title', :default => t('helpers.titles.edit', :model => model_class.model_name.human,
3
+ :default => "Edit #{model_class.model_name.human}") %></h1>
4
+ <%%= render :partial => 'form' %>
@@ -0,0 +1,3 @@
1
+ - model_class = @<%= resource_name %>.class
2
+ %h1=t '.title', :default => t('helpers.titles.edit', :model => model_class.model_name.human, :default => "Edit #{model_class.model_name.human}")
3
+ = render :partial => "form"
@@ -0,0 +1,3 @@
1
+ - model_class = @<%= resource_name %>.class
2
+ h1=t '.title', :default => t('helpers.titles.edit', :model => model_class.model_name.human, :default => "Edit #{model_class.model_name.human}")
3
+ = render :partial => "form"
@@ -0,0 +1,38 @@
1
+ <%%- model_class = <%= resource_name.classify %>.new.class -%>
2
+ <h1><%%=t '.title', :default => model_class.model_name.human.pluralize %></h1>
3
+ <table class="table table-striped">
4
+ <thead>
5
+ <tr>
6
+ <th><%%= model_class.human_attribute_name(:id) %></th>
7
+ <%- columns.each do |column| -%>
8
+ <th><%%= model_class.human_attribute_name(:<%= column.name %>) %></th>
9
+ <%- end -%>
10
+ <th><%%= model_class.human_attribute_name(:created_at) %></th>
11
+ <th><%%=t '.actions', :default => t("helpers.actions") %></th>
12
+ </tr>
13
+ </thead>
14
+ <tbody>
15
+ <%% @<%= plural_resource_name %>.each do |<%= resource_name %>| %>
16
+ <tr>
17
+ <td><%%= link_to <%= resource_name %>.id, <%= singular_controller_routing_path %>_path(<%= resource_name %>) %></td>
18
+ <%- columns.each do |column| -%>
19
+ <td><%%= <%= resource_name %>.<%= column.name %> %></td>
20
+ <%- end -%>
21
+ <td><%%=l <%= resource_name %>.created_at %></td>
22
+ <td>
23
+ <%%= link_to t('.edit', :default => t("helpers.links.edit")),
24
+ edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-mini' %>
25
+ <%%= link_to t('.destroy', :default => t("helpers.links.destroy")),
26
+ <%= singular_controller_routing_path %>_path(<%= resource_name %>),
27
+ :method => :delete,
28
+ :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
29
+ :class => 'btn btn-mini btn-danger' %>
30
+ </td>
31
+ </tr>
32
+ <%% end %>
33
+ </tbody>
34
+ </table>
35
+
36
+ <%%= link_to t('.new', :default => t("helpers.links.new")),
37
+ new_<%= singular_controller_routing_path %>_path,
38
+ :class => 'btn btn-primary' %>
@@ -0,0 +1,24 @@
1
+ - model_class = <%= resource_name.classify %>.new.class
2
+ %h1=t '.title', :default => model_class.model_name.human.pluralize
3
+ %table.table.table-striped
4
+ %thead
5
+ %tr
6
+ %th= model_class.human_attribute_name(:id)
7
+ <%- columns.each do |column| -%>
8
+ %th= model_class.human_attribute_name(:<%= column.name %>)
9
+ <%- end -%>
10
+ %th= model_class.human_attribute_name(:created_at)
11
+ %th=t '.actions', :default => t("helpers.actions")
12
+ %tbody
13
+ - @<%= plural_resource_name %>.each do |<%= resource_name %>|
14
+ %tr
15
+ %td= link_to <%= resource_name %>.id, <%= singular_controller_routing_path %>_path(<%= resource_name %>)
16
+ <%- columns.each do |column| -%>
17
+ %td= <%= resource_name %>.<%= column.name %>
18
+ <%- end -%>
19
+ %td=l <%= resource_name %>.created_at
20
+ %td
21
+ = link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-mini' if can? :update, <%= resource_name %>
22
+ = link_to t('.destroy', :default => t("helpers.links.destroy")), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :method => :delete, :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')), :class => 'btn btn-mini btn-danger' if can? :destroy, <%= resource_name %>
23
+
24
+ = link_to t('.new', :default => t("helpers.links.new")), new_<%= singular_controller_routing_path %>_path, :class => 'btn btn-primary' if can? :create, <%= model_name %>
@@ -0,0 +1,26 @@
1
+ - model_class = <%= resource_name.classify %>.new.class
2
+ h1=t '.title', :default => model_class.model_name.human.pluralize
3
+ table class="table table-striped"
4
+ thead
5
+ tr
6
+ th= model_class.human_attribute_name(:id)
7
+ <%- columns.each do |column| -%>
8
+ th= model_class.human_attribute_name(:<%= column.name %>)
9
+ <%- end -%>
10
+ th= model_class.human_attribute_name(:created_at)
11
+ th=t '.actions', :default => t("helpers.actions")
12
+ tbody
13
+ - @<%= plural_resource_name %>.each do |<%= resource_name %>|
14
+ tr
15
+ td= link_to <%= resource_name %>.id, <%= singular_controller_routing_path %>_path(<%= resource_name %>)
16
+ <%- columns.each do |column| -%>
17
+ td= <%= resource_name %>.<%= column.name %>
18
+ <%- end -%>
19
+ td=l <%= resource_name %>.created_at
20
+ td
21
+ = link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(<%= resource_name %>), :class => 'btn btn-mini'
22
+ '
23
+ = link_to t('.destroy', :default => t("helpers.links.destroy")), <%= singular_controller_routing_path %>_path(<%= resource_name %>), :method => :delete, :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')), :class => 'btn btn-mini btn-danger'
24
+
25
+ = link_to t('.new', :default => t("helpers.links.new")), new_<%= singular_controller_routing_path %>_path, :class => 'btn btn-primary'
26
+
@@ -0,0 +1,4 @@
1
+ <%%- model_class = @<%= resource_name %>.class -%>
2
+ <h1><%%=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human,
3
+ :default => "New #{model_class.model_name.human}") %></h1>
4
+ <%%= render :partial => 'form' %>
@@ -0,0 +1,3 @@
1
+ - model_class = @<%= resource_name %>.class
2
+ %h1=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human, :default => "New #{model_class.model_name.human}")
3
+ = render :partial => "form"
@@ -0,0 +1,3 @@
1
+ - model_class = @<%= resource_name %>.class
2
+ h1=t '.title', :default => t('helpers.titles.new', :model => model_class.model_name.human, :default => "New #{model_class.model_name.human}")
3
+ = render :partial => "form"
@@ -0,0 +1,21 @@
1
+ <%%- model_class = @<%= resource_name %>.class -%>
2
+ <h1><%%=t '.title', :default => model_class.model_name.human %></h1>
3
+
4
+ <dl class="dl-horizontal">
5
+ <%- columns.each do |column| -%>
6
+ <dt><strong><%%= model_class.human_attribute_name(:<%= column.name %>) %>:</strong></dt>
7
+ <dd><%%= @<%= resource_name %>.<%= column.name %> %></dd>
8
+ <%- end -%>
9
+ </dl>
10
+
11
+ <div class="form-actions">
12
+ <%%= link_to t('.back', :default => t("helpers.links.back")),
13
+ <%= controller_routing_path %>_path, :class => 'btn' %>
14
+ <%%= link_to t('.edit', :default => t("helpers.links.edit")),
15
+ edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'btn' %>
16
+ <%%= link_to t('.destroy', :default => t("helpers.links.destroy")),
17
+ <%= singular_controller_routing_path %>_path(@<%= resource_name %>),
18
+ :method => 'delete',
19
+ :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')),
20
+ :class => 'btn btn-danger' %>
21
+ </div>
@@ -0,0 +1,14 @@
1
+ - model_class = @<%= resource_name %>.class
2
+ %h1=t '.title', :default => model_class.model_name.human
3
+
4
+ <%- columns.each do |column| -%>
5
+ %p
6
+ %strong= model_class.human_attribute_name(:<%= column.name %>) + ':'
7
+ %br
8
+ = @<%= resource_name %>.<%= column.name %>
9
+ <%- end -%>
10
+
11
+ .form-actions
12
+ = link_to t('.back', :default => t("helpers.links.back")), <%= controller_routing_path %>_path, :class => 'btn'
13
+ = link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'btn' if can? :update, @<%= resource_name %>
14
+ = link_to t('.destroy', :default => t("helpers.links.destroy")), <%= singular_controller_routing_path %>_path(@<%= resource_name %>), :method => "delete", :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')), :class => 'btn btn-danger' if can? :destroy, @<%= resource_name %>
@@ -0,0 +1,16 @@
1
+ - model_class = @<%= resource_name %>.class
2
+ h1=t '.title', :default => model_class.model_name.human
3
+
4
+ <%- columns.each do |column| -%>
5
+ p
6
+ strong= model_class.human_attribute_name(:<%= column.name %>) + ':'
7
+ br
8
+ = @<%= resource_name %>.<%= column.name %>
9
+ <%- end -%>
10
+
11
+ .form-actions
12
+ = link_to t('.back', :default => t("helpers.links.back")), <%= controller_routing_path %>_path, :class => 'btn'
13
+ '
14
+ = link_to t('.edit', :default => t("helpers.links.edit")), edit_<%= singular_controller_routing_path %>_path(@<%= resource_name %>), :class => 'btn'
15
+ '
16
+ = link_to t('.destroy', :default => t("helpers.links.destroy")), <%= singular_controller_routing_path %>_path(@<%= resource_name %>), :method => "delete", :confirm => t('.confirm', :default => t("helpers.links.confirm", :default => 'Are you sure?')), :class => 'btn btn-danger'
@@ -0,0 +1,14 @@
1
+ <%%= simple_form_for @<%= resource_name %>, :html => { :class => 'form-horizontal' } do |f| %>
2
+ <%- columns.each do |column| -%>
3
+ <%%= f.input :<%= column.name %> %>
4
+ <%- end -%>
5
+ <%- if ::SimpleForm::FormBuilder.instance_methods.include?(:wrapped_button) -%>
6
+ <%%= f.button :wrapped, :cancel => <%= controller_routing_path %>_path %>
7
+ <%- else -%>
8
+ <div class="form-actions">
9
+ <%%= f.button :submit, :class => 'btn-primary' %>
10
+ <%%= link_to t('.cancel', :default => t("helpers.links.cancel")),
11
+ <%= controller_routing_path %>_path, :class => 'btn' %>
12
+ </div>
13
+ <%- end -%>
14
+ <%% end %>
@@ -0,0 +1,11 @@
1
+ = simple_form_for @<%= resource_name %>, :html => { :class => 'form-horizontal' } do |f|
2
+ <%- columns.each do |column| -%>
3
+ = f.input :<%= column.name %>
4
+ <%- end -%>
5
+ <%- if ::SimpleForm::FormBuilder.instance_methods.include?(:wrapped_button) -%>
6
+ = f.button :wrapped, :cancel => <%= controller_routing_path %>_path
7
+ <%- else -%>
8
+ .form-actions
9
+ = f.button :submit, :class => 'btn-primary'
10
+ = link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn'
11
+ <%- end -%>
@@ -0,0 +1,12 @@
1
+ = simple_form_for @<%= resource_name %>, :html => { :class => "form-horizontal" } do |f|
2
+ <%- columns.each do |column| -%>
3
+ = f.input :<%= column.name %>
4
+ <%- end -%>
5
+ <%- if ::SimpleForm::FormBuilder.instance_methods.include?(:wrapped_button) -%>
6
+ = f.button :wrapped, :cancel => <%= controller_routing_path %>_path
7
+ <%- else -%>
8
+ .form-actions
9
+ = f.button :submit, :class => 'btn-primary'
10
+ '
11
+ = link_to t('.cancel', :default => t("helpers.links.cancel")), <%= controller_routing_path %>_path, :class => 'btn'
12
+ <%- end -%>
@@ -0,0 +1,99 @@
1
+ require 'rails/generators'
2
+ require 'rails/generators/generated_attribute'
3
+
4
+ module CancanBootstrap
5
+ module Generators
6
+ class ViewsGenerator < ::Rails::Generators::Base
7
+ source_root File.expand_path('../templates', __FILE__)
8
+ argument :controller_path, :type => :string
9
+ argument :model_name, :type => :string, :required => false
10
+ argument :layout, :type => :string, :default => "application",
11
+ :banner => "Specify application layout"
12
+
13
+ def initialize(args, *options)
14
+ super(args, *options)
15
+ initialize_views_variables
16
+ end
17
+
18
+ def copy_views
19
+ generate_views
20
+ end
21
+
22
+ protected
23
+
24
+ def initialize_views_variables
25
+ @base_name, @controller_class_path, @controller_file_path, @controller_class_nesting, @controller_class_nesting_depth = extract_modules(controller_path)
26
+ @controller_routing_path = @controller_file_path.gsub(/\//, '_')
27
+ @model_name = @controller_class_nesting + "::#{@base_name.singularize.camelize}" unless @model_name
28
+ @model_name = @model_name.camelize
29
+ end
30
+
31
+ def controller_routing_path
32
+ @controller_routing_path
33
+ end
34
+
35
+ def singular_controller_routing_path
36
+ @controller_routing_path.singularize
37
+ end
38
+
39
+ def model_name
40
+ @model_name
41
+ end
42
+
43
+ def plural_model_name
44
+ @model_name.pluralize
45
+ end
46
+
47
+ def resource_name
48
+ @model_name.demodulize.underscore
49
+ end
50
+
51
+ def plural_resource_name
52
+ resource_name.pluralize
53
+ end
54
+
55
+ def columns
56
+ begin
57
+ excluded_column_names = %w[id created_at updated_at]
58
+ @model_name.constantize.columns.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type)}
59
+ rescue NoMethodError
60
+ @model_name.constantize.fields.collect{|c| c[1]}.reject{|c| excluded_column_names.include?(c.name) }.collect{|c| ::Rails::Generators::GeneratedAttribute.new(c.name, c.type.to_s)}
61
+ end
62
+ end
63
+
64
+ def extract_modules(name)
65
+ modules = name.include?('/') ? name.split('/') : name.split('::')
66
+ name = modules.pop
67
+ path = modules.map { |m| m.underscore }
68
+ file_path = (path + [name.pluralize.underscore]).join('/')
69
+ nesting = modules.map { |m| m.camelize }.join('::')
70
+ [name, path, file_path, nesting, modules.size]
71
+ end
72
+
73
+ def generate_views
74
+ views = {
75
+ "index.html.#{ext}" => File.join('app/views', @controller_file_path, "index.html.#{ext}"),
76
+ "new.html.#{ext}" => File.join('app/views', @controller_file_path, "new.html.#{ext}"),
77
+ "edit.html.#{ext}" => File.join('app/views', @controller_file_path, "edit.html.#{ext}"),
78
+ "#{form_builder}_form.html.#{ext}" => File.join('app/views', @controller_file_path, "_form.html.#{ext}"),
79
+ "show.html.#{ext}" => File.join('app/views', @controller_file_path, "show.html.#{ext}")}
80
+ selected_views = views
81
+ options.engine == generate_erb(selected_views)
82
+ end
83
+
84
+ def generate_erb(views)
85
+ views.each do |template_name, output_path|
86
+ template template_name, output_path
87
+ end
88
+ end
89
+
90
+ def ext
91
+ ::Rails.application.config.generators.options[:rails][:template_engine] || :erb
92
+ end
93
+
94
+ def form_builder
95
+ defined?(::SimpleForm) ? 'simple_form/' : ''
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,11 @@
1
+ require "rails-cancan-bootstrap-scaffold/version"
2
+
3
+ module Rails
4
+ module Cancan
5
+ module Bootstrap
6
+ module Scaffold
7
+ # Your code goes here...
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ module Rails
2
+ module Cancan
3
+ module Bootstrap
4
+ module Scaffold
5
+ VERSION = "0.0.1"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'rails-cancan-bootstrap-scaffold/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rails-cancan-bootstrap-scaffold"
8
+ gem.version = Rails::Cancan::Bootstrap::Scaffold::VERSION
9
+ gem.authors = ["Ouvrages"]
10
+ gem.email = ["contact@ouvrages-web.fr"]
11
+ gem.description = %q{Bootstrap & cancan generators for Rails}
12
+ gem.summary = %q{Rails generators that produce standard code for Bootstrap and Cancan.}
13
+ gem.homepage = "https://github.com/ouvrages/rails-cancan-bootstrap-scaffold"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-cancan-bootstrap-scaffold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ouvrages
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-01-30 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Bootstrap & cancan generators for Rails
15
+ email:
16
+ - contact@ouvrages-web.fr
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - .gitignore
22
+ - Gemfile
23
+ - LICENSE.txt
24
+ - README.md
25
+ - Rakefile
26
+ - lib/generators/cancan_bootstrap/controller/USAGE
27
+ - lib/generators/cancan_bootstrap/controller/controller_generator.rb
28
+ - lib/generators/cancan_bootstrap/controller/templates/controller.rb
29
+ - lib/generators/cancan_bootstrap/routes/USAGE
30
+ - lib/generators/cancan_bootstrap/routes/routes_generator.rb
31
+ - lib/generators/cancan_bootstrap/scaffold/scaffold_generator.rb
32
+ - lib/generators/cancan_bootstrap/views/templates/_form.html.erb
33
+ - lib/generators/cancan_bootstrap/views/templates/_form.html.haml
34
+ - lib/generators/cancan_bootstrap/views/templates/_form.html.slim
35
+ - lib/generators/cancan_bootstrap/views/templates/edit.html.erb
36
+ - lib/generators/cancan_bootstrap/views/templates/edit.html.haml
37
+ - lib/generators/cancan_bootstrap/views/templates/edit.html.slim
38
+ - lib/generators/cancan_bootstrap/views/templates/index.html.erb
39
+ - lib/generators/cancan_bootstrap/views/templates/index.html.haml
40
+ - lib/generators/cancan_bootstrap/views/templates/index.html.slim
41
+ - lib/generators/cancan_bootstrap/views/templates/new.html.erb
42
+ - lib/generators/cancan_bootstrap/views/templates/new.html.haml
43
+ - lib/generators/cancan_bootstrap/views/templates/new.html.slim
44
+ - lib/generators/cancan_bootstrap/views/templates/show.html.erb
45
+ - lib/generators/cancan_bootstrap/views/templates/show.html.haml
46
+ - lib/generators/cancan_bootstrap/views/templates/show.html.slim
47
+ - lib/generators/cancan_bootstrap/views/templates/simple_form/_form.html.erb
48
+ - lib/generators/cancan_bootstrap/views/templates/simple_form/_form.html.haml
49
+ - lib/generators/cancan_bootstrap/views/templates/simple_form/_form.html.slim
50
+ - lib/generators/cancan_bootstrap/views/views_generator.rb
51
+ - lib/rails-cancan-bootstrap-scaffold.rb
52
+ - lib/rails-cancan-bootstrap-scaffold/version.rb
53
+ - rails-cancan-bootstrap-scaffold.gemspec
54
+ homepage: https://github.com/ouvrages/rails-cancan-bootstrap-scaffold
55
+ licenses: []
56
+ post_install_message:
57
+ rdoc_options: []
58
+ require_paths:
59
+ - lib
60
+ required_ruby_version: !ruby/object:Gem::Requirement
61
+ none: false
62
+ requirements:
63
+ - - ! '>='
64
+ - !ruby/object:Gem::Version
65
+ version: '0'
66
+ required_rubygems_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ! '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 1.8.23
75
+ signing_key:
76
+ specification_version: 3
77
+ summary: Rails generators that produce standard code for Bootstrap and Cancan.
78
+ test_files: []