rails-admin-scaffold 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 4e1fac9b29b5562ab5219bf487e07bf173c8ba84
4
+ data.tar.gz: bf8cc2870b83ef67ee11d82d057edf3987b5f7c0
5
+ SHA512:
6
+ metadata.gz: 482201651a09ede8bec6c05f08f3e467220ee4d0b81193e5c5aeec0817e208039e065565b280e9150f5d391541ab3c74e7c333bfda145654ec105b516d48d33a
7
+ data.tar.gz: 6fef87346c1730351ee0712d342c89d43b9bd2731633a9e6edfb4808fabdb40ae0340af7ae64b300b80b6bf180992181c1a8136b187e616f515d48cd69955f11
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 Kirill Kalachev (aka dhampik)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ rails-admin-scaffold
2
+ ====================
3
+
4
+ Rails generator which allows to scaffold admin controllers, views with proper (non-namespaced) models, helpers, tests and routes
5
+
6
+ How to use:
7
+ -----------
8
+ * Add ```gem 'rails-admin-scaffold', 'x.x.x'``` to your Gemfile
9
+ * Run ```bundle install```
10
+ * Create admin scaffold with e. g. ```bin/rails g admin:scaffold_controller Post title:string content:text published:boolean```
11
+
12
+ Plans:
13
+ ------
14
+ * add haml suppurt
15
+ * add jbuilder support
16
+ * improve tests
17
+ * use travis for ci
@@ -0,0 +1,12 @@
1
+ Description:
2
+ Stubs out a scaffolded controller, its seven RESTful actions and related
3
+ views. Pass the model name, either CamelCased or under_scored. The
4
+ controller name is retrieved as a pluralized version of the model name
5
+ namespaces within Admin namespaced.
6
+
7
+ This generates a controller class in app/controllers/admin and invokes helper,
8
+ template engine and test framework generators.
9
+ It uses non-namespaced model in app/models
10
+
11
+ Example:
12
+ `rails generate admin:scaffold_controller Post`
@@ -0,0 +1,141 @@
1
+ require 'rails/generators/named_base'
2
+ require 'rails/generators/resource_helpers'
3
+
4
+ module Admin
5
+ module Generators
6
+ class ScaffoldControllerGenerator < Rails::Generators::NamedBase
7
+ include Rails::Generators::ResourceHelpers
8
+
9
+ source_root File.expand_path('../templates', __FILE__)
10
+
11
+ check_class_collision suffix: "Controller"
12
+
13
+ check_class_collision suffix: "ControllerTest"
14
+
15
+ check_class_collision suffix: "Helper"
16
+
17
+ class_option :orm, banner: "NAME", type: :string, required: true,
18
+ desc: "ORM to generate the controller for"
19
+
20
+ class_option :html, type: :boolean, default: true,
21
+ desc: "Generate a scaffold with HTML output"
22
+
23
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
24
+
25
+ def initialize(args, *options) #:nodoc:
26
+ super
27
+ end
28
+
29
+ hook_for :resource_route, in: :rails do |resource_route|
30
+ invoke resource_route, [prefixed_class_name]
31
+ end
32
+
33
+ def create_controller_files
34
+ template "controllers/controller.erb", File.join('app/controllers', prefix, class_path, "#{controller_file_name}_controller.rb")
35
+ end
36
+
37
+ def create_test_files
38
+ template "tests/test_unit/functional_test.erb",
39
+ File.join("test/controllers", prefix, controller_class_path, "#{controller_file_name}_controller_test.rb")
40
+ end
41
+
42
+ hook_for :helper, in: :rails do |helper|
43
+ invoke helper, [prefixed_controller_class_name]
44
+ end
45
+
46
+ def create_root_folder
47
+ empty_directory File.join("app/views", prefix, controller_file_path)
48
+ end
49
+
50
+ def copy_view_files
51
+ available_views.each do |view|
52
+ filename = filename_with_extensions(view)
53
+ template "views/#{handler}/#{filename}", File.join("app/views", prefix, controller_file_path, filename)
54
+ end
55
+ end
56
+
57
+ hook_for :assets, in: :rails do |assets|
58
+ invoke assets, [prefixed_class_name]
59
+ end
60
+
61
+ protected
62
+
63
+ def prefix
64
+ 'admin'
65
+ end
66
+
67
+ def prefixed_class_name
68
+ "#{prefix.capitalize}::#{class_name}"
69
+ end
70
+
71
+ def prefixed_controller_class_name
72
+ "#{prefix.capitalize}::#{controller_class_name}"
73
+ end
74
+
75
+ def prefixed_route_url
76
+ "/#{prefix}#{route_url}"
77
+ end
78
+
79
+ def prefixed_plain_model_url
80
+ "#{prefix}_#{singular_table_name}"
81
+ end
82
+
83
+ def prefixed_index_helper
84
+ "#{prefix}_#{index_helper}"
85
+ end
86
+
87
+ def available_views
88
+ %w(index edit show new _form)
89
+ end
90
+
91
+ def format
92
+ :html
93
+ end
94
+
95
+ def handler
96
+ :erb
97
+ end
98
+
99
+ def filename_with_extensions(name)
100
+ [name, format, handler].compact.join(".")
101
+ end
102
+
103
+ # Add a class collisions name to be checked on class initialization. You
104
+ # can supply a hash with a :prefix or :suffix to be tested.
105
+ #
106
+ # ==== Examples
107
+ #
108
+ # check_class_collision suffix: "Decorator"
109
+ #
110
+ # If the generator is invoked with class name Admin, it will check for
111
+ # the presence of "AdminDecorator".
112
+ #
113
+ def self.check_class_collision(options={})
114
+ define_method :check_class_collision do
115
+ name = if self.respond_to?(:prefixed_controller_class_name) # for ScaffoldBase
116
+ prefixed_controller_class_name
117
+ elsif self.respond_to?(:prefixed_controller_class_name) # for ScaffoldBase
118
+ controller_class_name
119
+ else
120
+ class_name
121
+ end
122
+
123
+ class_collisions "#{options[:prefix]}#{name}#{options[:suffix]}"
124
+ end
125
+ end
126
+
127
+ def attributes_hash
128
+ return if attributes_names.empty?
129
+
130
+ attributes_names.map do |name|
131
+ if %w(password password_confirmation).include?(name) && attributes.any?(&:password_digest?)
132
+ "#{name}: 'secret'"
133
+ else
134
+ "#{name}: @#{singular_table_name}.#{name}"
135
+ end
136
+ end.sort.join(', ')
137
+ end
138
+
139
+ end
140
+ end
141
+ end
@@ -0,0 +1,68 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= prefixed_controller_class_name %>Controller < ApplicationController
7
+ before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
8
+
9
+ # GET <%= prefixed_route_url %>
10
+ def index
11
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
12
+ end
13
+
14
+ # GET <%= prefixed_route_url %>/1
15
+ def show
16
+ end
17
+
18
+ # GET <%= prefixed_route_url %>/new
19
+ def new
20
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
21
+ end
22
+
23
+ # GET <%= prefixed_route_url %>/1/edit
24
+ def edit
25
+ end
26
+
27
+ # POST <%= prefixed_route_url %>
28
+ def create
29
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
30
+
31
+ if @<%= orm_instance.save %>
32
+ redirect_to <%= "[:#{prefix}, @#{singular_table_name}]" %>, notice: <%= "'#{human_name} was successfully created.'" %>
33
+ else
34
+ render action: 'new'
35
+ end
36
+ end
37
+
38
+ # PATCH/PUT <%= prefixed_route_url %>/1
39
+ def update
40
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
41
+ redirect_to <%= "[:#{prefix}, @#{singular_table_name}]" %>, notice: <%= "'#{human_name} was successfully updated.'" %>
42
+ else
43
+ render action: 'edit'
44
+ end
45
+ end
46
+
47
+ # DELETE <%= prefixed_route_url %>/1
48
+ def destroy
49
+ @<%= orm_instance.destroy %>
50
+ redirect_to <%= prefixed_index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %>
51
+ end
52
+
53
+ private
54
+ # Use callbacks to share common setup or constraints between actions.
55
+ def set_<%= singular_table_name %>
56
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
57
+ end
58
+
59
+ # Only allow a trusted parameter "white list" through.
60
+ def <%= "#{singular_table_name}_params" %>
61
+ <%- if attributes_names.empty? -%>
62
+ params[<%= ":#{singular_table_name}" %>]
63
+ <%- else -%>
64
+ params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
65
+ <%- end -%>
66
+ end
67
+ end
68
+ <% end -%>
@@ -0,0 +1,51 @@
1
+ require 'test_helper'
2
+
3
+ <% module_namespacing do -%>
4
+ class <%= prefixed_controller_class_name %>ControllerTest < ActionController::TestCase
5
+ setup do
6
+ @<%= singular_table_name %> = <%= table_name %>(:one)
7
+ end
8
+
9
+ test "should get index" do
10
+ get :index
11
+ assert_response :success
12
+ assert_not_nil assigns(:<%= table_name %>)
13
+ end
14
+
15
+ test "should get new" do
16
+ get :new
17
+ assert_response :success
18
+ end
19
+
20
+ test "should create <%= singular_table_name %>" do
21
+ assert_difference('<%= class_name %>.count') do
22
+ post :create, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
23
+ end
24
+
25
+ assert_redirected_to <%= prefixed_plain_model_url %>_path(assigns(:<%= singular_table_name %>))
26
+ end
27
+
28
+ test "should show <%= singular_table_name %>" do
29
+ get :show, id: <%= "@#{singular_table_name}" %>
30
+ assert_response :success
31
+ end
32
+
33
+ test "should get edit" do
34
+ get :edit, id: <%= "@#{singular_table_name}" %>
35
+ assert_response :success
36
+ end
37
+
38
+ test "should update <%= singular_table_name %>" do
39
+ patch :update, id: <%= "@#{singular_table_name}" %>, <%= "#{singular_table_name}: { #{attributes_hash} }" %>
40
+ assert_redirected_to <%= prefixed_plain_model_url %>_path(assigns(:<%= singular_table_name %>))
41
+ end
42
+
43
+ test "should destroy <%= singular_table_name %>" do
44
+ assert_difference('<%= class_name %>.count', -1) do
45
+ delete :destroy, id: <%= "@#{singular_table_name}" %>
46
+ end
47
+
48
+ assert_redirected_to <%= prefixed_index_helper %>_path
49
+ end
50
+ end
51
+ <% end -%>
@@ -0,0 +1,37 @@
1
+ <%%= form_for(<%= "[:#{prefix}, @#{singular_table_name}]" %>) do |f| %>
2
+ <%% if @<%= singular_table_name %>.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
5
+
6
+ <ul>
7
+ <%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
8
+ <li><%%= msg %></li>
9
+ <%% end %>
10
+ </ul>
11
+ </div>
12
+ <%% end %>
13
+
14
+ <% attributes.each do |attribute| -%>
15
+ <div class="field">
16
+ <% if attribute.password_digest? -%>
17
+ <%%= f.label :password %><br>
18
+ <%%= f.password_field :password %>
19
+ </div>
20
+ <div>
21
+ <%%= f.label :password_confirmation %><br>
22
+ <%%= f.password_field :password_confirmation %>
23
+ <% else -%>
24
+ <% if attribute.reference? -%>
25
+ <%%= f.label :<%= attribute.column_name %> %><br>
26
+ <%%= f.<%= attribute.field_type %> :<%= attribute.column_name %> %>
27
+ <% else -%>
28
+ <%%= f.label :<%= attribute.name %> %><br>
29
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
30
+ <% end -%>
31
+ <% end -%>
32
+ </div>
33
+ <% end -%>
34
+ <div class="actions">
35
+ <%%= f.submit %>
36
+ </div>
37
+ <%% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing <%= singular_table_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Show', <%= "[:#{prefix}, @#{singular_table_name}]" %> %> |
6
+ <%%= link_to 'Back', <%= prefixed_index_helper %>_path %>
@@ -0,0 +1,31 @@
1
+ <h1>Listing <%= plural_table_name %></h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
7
+ <th><%= attribute.human_name %></th>
8
+ <% end -%>
9
+ <th></th>
10
+ <th></th>
11
+ <th></th>
12
+ </tr>
13
+ </thead>
14
+
15
+ <tbody>
16
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
17
+ <tr>
18
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
19
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
20
+ <% end -%>
21
+ <td><%%= link_to 'Show', <%= "[:#{prefix}, #{singular_table_name}]" %> %></td>
22
+ <td><%%= link_to 'Edit', edit_<%= prefixed_plain_model_url %>_path(<%= singular_table_name %>) %></td>
23
+ <td><%%= link_to 'Destroy', <%= "[:#{prefix}, #{singular_table_name}]" %>, method: :delete, data: { confirm: 'Are you sure?' } %></td>
24
+ </tr>
25
+ <%% end %>
26
+ </tbody>
27
+ </table>
28
+
29
+ <br>
30
+
31
+ <%%= link_to 'New <%= human_name %>', new_<%= prefixed_plain_model_url %>_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New <%= singular_table_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Back', <%= prefixed_index_helper %>_path %>
@@ -0,0 +1,11 @@
1
+ <p id="notice"><%%= notice %></p>
2
+
3
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
4
+ <p>
5
+ <strong><%= attribute.human_name %>:</strong>
6
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
7
+ </p>
8
+
9
+ <% end -%>
10
+ <%%= link_to 'Edit', edit_<%= prefixed_plain_model_url %>_path(@<%= singular_table_name %>) %> |
11
+ <%%= link_to 'Back', <%= prefixed_index_helper %>_path %>
@@ -0,0 +1,3 @@
1
+ module RailsAdminScaffold
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1 @@
1
+ require "rails-admin-scaffold/version"
@@ -0,0 +1,58 @@
1
+ TestApp.routes.draw do |map|
2
+ # The priority is based upon order of creation:
3
+ # first created -> highest priority.
4
+
5
+ # Sample of regular route:
6
+ # match 'products/:id' => 'catalog#view'
7
+ # Keep in mind you can assign values other than :controller and :action
8
+
9
+ # Sample of named route:
10
+ # match 'products/:id/purchase' => 'catalog#purchase', :as => :purchase
11
+ # This route can be invoked with purchase_url(:id => product.id)
12
+
13
+ # Sample resource route (maps HTTP verbs to controller actions automatically):
14
+ # resources :products
15
+
16
+ # Sample resource route with options:
17
+ # resources :products do
18
+ # member do
19
+ # get :short
20
+ # post :toggle
21
+ # end
22
+ #
23
+ # collection do
24
+ # get :sold
25
+ # end
26
+ # end
27
+
28
+ # Sample resource route with sub-resources:
29
+ # resources :products do
30
+ # resources :comments, :sales
31
+ # resource :seller
32
+ # end
33
+
34
+ # Sample resource route with more complex sub-resources
35
+ # resources :products do
36
+ # resources :comments
37
+ # resources :sales do
38
+ # get :recent, :on => :collection
39
+ # end
40
+ # end
41
+
42
+ # Sample resource route within a namespace:
43
+ # namespace :admin do
44
+ # # Directs /admin/products/* to Admin::ProductsController
45
+ # # (app/controllers/admin/products_controller.rb)
46
+ # resources :products
47
+ # end
48
+
49
+ # You can have the root of your site routed with "root"
50
+ # just remember to delete public/index.html.
51
+ # root :to => "welcome#index"
52
+
53
+ # See how all your routes lay out with "rake routes"
54
+
55
+ # This is a legacy wild controller route that's not recommended for RESTful applications.
56
+ # Note: This route will make all actions in every controller accessible via GET requests.
57
+ # match ':controller(/:action(/:id(.:format)))'
58
+ end
@@ -0,0 +1,111 @@
1
+ require 'test_helper'
2
+ require 'lib/generators/admin/testing_helper'
3
+
4
+ class Admin::Generators::ScaffoldControllerGeneratorTest < Rails::Generators::TestCase
5
+ destination File.join(Rails.root)
6
+ tests Admin::Generators::ScaffoldControllerGenerator
7
+ arguments %w(User name:string age:integer)
8
+
9
+ setup :prepare_destination
10
+ setup :copy_routes
11
+
12
+ def test_controller_skeleton_is_created
13
+ run_generator
14
+
15
+ assert_file "app/controllers/admin/users_controller.rb" do |content|
16
+ assert_match(/class Admin::UsersController < ApplicationController/, content)
17
+
18
+ assert_instance_method :index, content do |m|
19
+ assert_match(/@users = User\.all/, m)
20
+ end
21
+
22
+ assert_instance_method :show, content
23
+
24
+ assert_instance_method :new, content do |m|
25
+ assert_match(/@user = User\.new/, m)
26
+ end
27
+
28
+ assert_instance_method :edit, content
29
+
30
+ assert_instance_method :create, content do |m|
31
+ assert_match(/@user = User\.new\(user_params\)/, m)
32
+ assert_match(/@user\.save/, m)
33
+ end
34
+
35
+ assert_instance_method :update, content do |m|
36
+ assert_match(/@user\.update\(user_params\)/, m)
37
+ end
38
+
39
+ assert_instance_method :destroy, content do |m|
40
+ assert_match(/@user\.destroy/, m)
41
+ assert_match(/User was successfully destroyed/, m)
42
+ end
43
+
44
+ assert_instance_method :set_user, content do |m|
45
+ assert_match(/@user = User\.find\(params\[:id\]\)/, m)
46
+ end
47
+
48
+ assert_match(/def user_params/, content)
49
+ assert_match(/params\.require\(:user\)\.permit\(:name, :age\)/, content)
50
+ end
51
+ end
52
+
53
+ def test_dont_use_require_or_permit_if_there_are_no_attributes
54
+ run_generator ["User"]
55
+
56
+ assert_file "app/controllers/admin/users_controller.rb" do |content|
57
+ assert_match(/def user_params/, content)
58
+ assert_match(/params\[:user\]/, content)
59
+ end
60
+ end
61
+
62
+ def test_helper_are_invoked_with_a_pluralized_name
63
+ run_generator
64
+ assert_file "app/helpers/admin/users_helper.rb", /module Admin::UsersHelper/
65
+ assert_file "test/helpers/admin/users_helper_test.rb", /class Admin::UsersHelperTest < ActionView::TestCase/
66
+ end
67
+
68
+ def test_views_are_generated
69
+ run_generator
70
+
71
+ %w(index edit new show).each do |view|
72
+ assert_file "app/views/admin/users/#{view}.html.erb"
73
+ end
74
+ end
75
+
76
+ def test_functional_tests
77
+ run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}"]
78
+
79
+ assert_file "test/controllers/admin/users_controller_test.rb" do |content|
80
+ assert_match(/class Admin::UsersControllerTest < ActionController::TestCase/, content)
81
+ assert_match(/test "should get index"/, content)
82
+ assert_match(/post :create, user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \}/, content)
83
+ assert_match(/patch :update, id: @user, user: \{ age: @user\.age, name: @user\.name, organization_id: @user\.organization_id, organization_type: @user\.organization_type \}/, content)
84
+ end
85
+ end
86
+
87
+ def test_functional_tests_without_attributes
88
+ run_generator ["User"]
89
+
90
+ assert_file "test/controllers/admin/users_controller_test.rb" do |content|
91
+ assert_match(/class Admin::UsersControllerTest < ActionController::TestCase/, content)
92
+ assert_match(/test "should get index"/, content)
93
+ assert_match(/post :create, user: \{ \}/, content)
94
+ assert_match(/patch :update, id: @user, user: \{ \}/, content)
95
+ end
96
+ end
97
+
98
+ def test_skip_helper_if_required
99
+ run_generator ["User", "name:string", "age:integer", "--no-helper"]
100
+ assert_no_file "app/helpers/admin/users_helper.rb"
101
+ assert_no_file "test/helpers/admin/users_helper_test.rb"
102
+ end
103
+
104
+ def test_new_hash_style
105
+ run_generator
106
+ assert_file "app/controllers/admin/users_controller.rb" do |content|
107
+ assert_match(/render action: 'new'/, content)
108
+ end
109
+ end
110
+
111
+ end
@@ -0,0 +1 @@
1
+ require_generators :admin => ['scaffold_controller']
@@ -0,0 +1,74 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'rails/all'
4
+ require 'rails/generators'
5
+ require 'rails/generators/test_case'
6
+
7
+ class TestApp < Rails::Application
8
+ config.root = File.dirname(__FILE__)
9
+ end
10
+ Rails.application = TestApp
11
+
12
+ module Rails
13
+ def self.root
14
+ @root ||= File.expand_path(File.join(File.dirname(__FILE__), '..', 'tmp', 'rails'))
15
+ end
16
+ end
17
+ Rails.application.config.root = Rails.root
18
+
19
+ # Call configure to load the settings from
20
+ # Rails.application.config.generators to Rails::Generators
21
+ Rails::Generators.configure! Rails.application.config.generators
22
+
23
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
24
+
25
+ def copy_routes
26
+ routes = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures', 'routes.rb'))
27
+ destination = File.join(Rails.root, "config")
28
+ FileUtils.mkdir_p(destination)
29
+ FileUtils.cp File.expand_path(routes), destination
30
+ end
31
+
32
+ # Asserts the given class exists in the given content. When a block is given,
33
+ # it yields the content of the class.
34
+ #
35
+ # assert_file "test/functional/accounts_controller_test.rb" do |controller_test|
36
+ # assert_class "AccountsControllerTest", controller_test do |klass|
37
+ # assert_match /context "index action"/, klass
38
+ # end
39
+ # end
40
+ #
41
+ def assert_class(klass, content)
42
+ assert content =~ /class #{klass}(\(.+\))?(.*?)\nend/m, "Expected to have class #{klass}"
43
+ yield $2.strip if block_given?
44
+ end
45
+
46
+ def generator_list
47
+ {
48
+ :admin => ['scaffold_controller']
49
+ }
50
+ end
51
+
52
+ def path_prefix(name)
53
+ case name
54
+ when :rails
55
+ 'rails/generators'
56
+ else
57
+ 'generators'
58
+ end
59
+ end
60
+
61
+ def require_generators(generator_list)
62
+ generator_list.each do |name, generators|
63
+ generators.each do |generator_name|
64
+ if name.to_s == 'rails' && generator_name.to_s == 'mailer'
65
+ require File.join(path_prefix(name), generator_name.to_s, "#{generator_name}_generator")
66
+ else
67
+ require File.join(path_prefix(name), name.to_s, generator_name.to_s, "#{generator_name}_generator")
68
+ end
69
+ end
70
+ end
71
+ end
72
+ alias :require_generator :require_generators
73
+
74
+ require_generators generator_list
metadata ADDED
@@ -0,0 +1,134 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-admin-scaffold
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Kirill Kalachev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-15 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: railties
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '4.0'
20
+ - - <
21
+ - !ruby/object:Gem::Version
22
+ version: '4.1'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '4.0'
30
+ - - <
31
+ - !ruby/object:Gem::Version
32
+ version: '4.1'
33
+ - !ruby/object:Gem::Dependency
34
+ name: rails
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - '>='
38
+ - !ruby/object:Gem::Version
39
+ version: '3.1'
40
+ - - <
41
+ - !ruby/object:Gem::Version
42
+ version: '4.1'
43
+ type: :development
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '3.1'
50
+ - - <
51
+ - !ruby/object:Gem::Version
52
+ version: '4.1'
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: '1.2'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ~>
65
+ - !ruby/object:Gem::Version
66
+ version: '1.2'
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - '>='
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ description: Rails generator which allows to scaffold admin controllers, views with
82
+ proper (non-namespaced) models, helpers, tests and routes
83
+ email:
84
+ - dhampik@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - LICENSE
90
+ - README.md
91
+ - lib/rails-admin-scaffold/version.rb
92
+ - lib/generators/admin/scaffold_controller/templates/tests/test_unit/functional_test.erb
93
+ - lib/generators/admin/scaffold_controller/templates/controllers/controller.erb
94
+ - lib/generators/admin/scaffold_controller/templates/views/erb/new.html.erb
95
+ - lib/generators/admin/scaffold_controller/templates/views/erb/show.html.erb
96
+ - lib/generators/admin/scaffold_controller/templates/views/erb/edit.html.erb
97
+ - lib/generators/admin/scaffold_controller/templates/views/erb/index.html.erb
98
+ - lib/generators/admin/scaffold_controller/templates/views/erb/_form.html.erb
99
+ - lib/generators/admin/scaffold_controller/scaffold_controller_generator.rb
100
+ - lib/generators/admin/scaffold_controller/USAGE
101
+ - lib/rails_admin_scaffold.rb
102
+ - test/fixtures/routes.rb
103
+ - test/test_helper.rb
104
+ - test/lib/generators/admin/scaffold_controller_generator_test.rb
105
+ - test/lib/generators/admin/testing_helper.rb
106
+ homepage: http://github.com/dhampik/rails-admin-scaffold
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - '>='
122
+ - !ruby/object:Gem::Version
123
+ version: 1.3.6
124
+ requirements: []
125
+ rubyforge_project: rails-admin-scaffold
126
+ rubygems_version: 2.0.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Rails admin controllers scaffolding generator
130
+ test_files:
131
+ - test/fixtures/routes.rb
132
+ - test/test_helper.rb
133
+ - test/lib/generators/admin/scaffold_controller_generator_test.rb
134
+ - test/lib/generators/admin/testing_helper.rb