rails-admin-scaffold 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (21) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -8
  3. data/lib/generators/admin/scaffold_controller/scaffold_controller_generator.rb +32 -5
  4. data/lib/generators/admin/scaffold_controller/templates/controllers/jbuilder/controller.rb.erb +84 -0
  5. data/lib/generators/admin/scaffold_controller/templates/controllers/{controller.erb → railties/controller.rb.erb} +0 -0
  6. data/lib/generators/admin/scaffold_controller/templates/tests/test_unit/{functional_test.erb → functional_test.rb.erb} +0 -0
  7. data/lib/generators/admin/scaffold_controller/templates/views/erb/{_form.html.erb → _form.html.erb.erb} +0 -0
  8. data/lib/generators/admin/scaffold_controller/templates/views/erb/{edit.html.erb → edit.html.erb.erb} +0 -0
  9. data/lib/generators/admin/scaffold_controller/templates/views/erb/{index.html.erb → index.html.erb.erb} +0 -0
  10. data/lib/generators/admin/scaffold_controller/templates/views/erb/{new.html.erb → new.html.erb.erb} +0 -0
  11. data/lib/generators/admin/scaffold_controller/templates/views/erb/{show.html.erb → show.html.erb.erb} +0 -0
  12. data/lib/generators/admin/scaffold_controller/templates/views/haml/_form.html.haml.erb +15 -0
  13. data/lib/generators/admin/scaffold_controller/templates/views/haml/edit.html.haml.erb +7 -0
  14. data/lib/generators/admin/scaffold_controller/templates/views/haml/index.html.haml.erb +23 -0
  15. data/lib/generators/admin/scaffold_controller/templates/views/haml/new.html.haml.erb +5 -0
  16. data/lib/generators/admin/scaffold_controller/templates/views/haml/show.html.haml.erb +11 -0
  17. data/lib/generators/admin/scaffold_controller/templates/views/jbuilder/index.json.jbuilder.erb +4 -0
  18. data/lib/generators/admin/scaffold_controller/templates/views/jbuilder/show.json.jbuilder.erb +1 -0
  19. data/lib/rails-admin-scaffold/version.rb +1 -1
  20. data/test/lib/generators/admin/scaffold_controller_generator_test.rb +9 -1
  21. metadata +18 -30
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4e1fac9b29b5562ab5219bf487e07bf173c8ba84
4
- data.tar.gz: bf8cc2870b83ef67ee11d82d057edf3987b5f7c0
3
+ metadata.gz: a96266607b8ef504727c283ca1094422c7f6c8f4
4
+ data.tar.gz: 4bccc40dc64fd7b2d1e32ecd1b2994fad397ba0a
5
5
  SHA512:
6
- metadata.gz: 482201651a09ede8bec6c05f08f3e467220ee4d0b81193e5c5aeec0817e208039e065565b280e9150f5d391541ab3c74e7c333bfda145654ec105b516d48d33a
7
- data.tar.gz: 6fef87346c1730351ee0712d342c89d43b9bd2731633a9e6edfb4808fabdb40ae0340af7ae64b300b80b6bf180992181c1a8136b187e616f515d48cd69955f11
6
+ metadata.gz: b94c0bbb4e6f67110212755cd457293284e5634031b71dc188adfa053dc19e0d3ccf2c0dfccd0e179bccfe335c9dc504a7f6961106d53d06d267065d0e9be8fc
7
+ data.tar.gz: 87b2f9c8a3e22a3c301582678d270064d28596d60afd6a7cf5bcf9c73ca9742c9df5bb4fbfeee2aafb4efbd36acbc798b1f16ed70237304483c9cd9c2ce91ddc
data/README.md CHANGED
@@ -1,17 +1,27 @@
1
- rails-admin-scaffold
1
+ rails-admin-scaffold [![Build Status](https://travis-ci.org/dhampik/rails-admin-scaffold.png?branch=master)](https://travis-ci.org/dhampik/rails-admin-scaffold)
2
2
  ====================
3
3
 
4
- Rails generator which allows to scaffold admin controllers, views with proper (non-namespaced) models, helpers, tests and routes
4
+ Rails 4 generator which allows to scaffold admin controllers, views with proper (non-namespaced) models, helpers, tests and routes
5
5
 
6
- How to use:
6
+ How to use
7
7
  -----------
8
8
  * Add ```gem 'rails-admin-scaffold', 'x.x.x'``` to your Gemfile
9
9
  * Run ```bundle install```
10
10
  * Create admin scaffold with e. g. ```bin/rails g admin:scaffold_controller Post title:string content:text published:boolean```
11
11
 
12
- Plans:
12
+ Supports
13
+ --------
14
+ * Rails 4 only
15
+ * Rails default generators (erb, test::unit)
16
+ * Haml (if haml is used for views generation)
17
+ * Jbuilder (if jbuilder is installed for the project)
18
+
19
+ Plans
13
20
  ------
14
- * add haml suppurt
15
- * add jbuilder support
16
- * improve tests
17
- * use travis for ci
21
+ * <del>add haml suppurt</del>
22
+ * <del>add jbuilder support</del>
23
+ * <del>improve tests</del>
24
+ * <del>use travis for ci</del>
25
+ * add minitest support
26
+ * add rspec support
27
+ * split controller_scaffold into several separate generators
@@ -1,3 +1,4 @@
1
+ require 'rubygems/specification'
1
2
  require 'rails/generators/named_base'
2
3
  require 'rails/generators/resource_helpers'
3
4
 
@@ -8,6 +9,8 @@ module Admin
8
9
 
9
10
  source_root File.expand_path('../templates', __FILE__)
10
11
 
12
+ class_option :template_engine, desc: 'Template engine to be invoked (erb or haml).'
13
+
11
14
  check_class_collision suffix: "Controller"
12
15
 
13
16
  check_class_collision suffix: "ControllerTest"
@@ -31,12 +34,17 @@ module Admin
31
34
  end
32
35
 
33
36
  def create_controller_files
34
- template "controllers/controller.erb", File.join('app/controllers', prefix, class_path, "#{controller_file_name}_controller.rb")
37
+ # I think there should be a better way to detect if jbuilder is in use
38
+ # If you know it, please let me know
39
+ if Gem::Specification.find_all_by_name('jbuilder').length >= 1
40
+ template "controllers/jbuilder/controller.rb.erb", File.join('app/controllers', prefix, class_path, "#{controller_file_name}_controller.rb")
41
+ else
42
+ template "controllers/railties/controller.rb.erb", File.join('app/controllers', prefix, class_path, "#{controller_file_name}_controller.rb")
43
+ end
35
44
  end
36
45
 
37
46
  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")
47
+ template "tests/test_unit/functional_test.rb.erb", File.join("test/controllers", prefix, controller_class_path, "#{controller_file_name}_controller_test.rb")
40
48
  end
41
49
 
42
50
  hook_for :helper, in: :rails do |helper|
@@ -50,7 +58,14 @@ module Admin
50
58
  def copy_view_files
51
59
  available_views.each do |view|
52
60
  filename = filename_with_extensions(view)
53
- template "views/#{handler}/#{filename}", File.join("app/views", prefix, controller_file_path, filename)
61
+ template "views/#{handler}/#{filename}.erb", File.join("app/views", prefix, controller_file_path, filename)
62
+ end
63
+
64
+ # I think there should be a better way to detect if jbuilder is in use
65
+ if Gem::Specification.find_all_by_name('jbuilder').length >= 1
66
+ %w(index show).each do |view|
67
+ template "views/jbuilder/#{view}.json.jbuilder.erb", File.join("app/views", prefix, controller_file_path, "#{view}.json.jbuilder")
68
+ end
54
69
  end
55
70
  end
56
71
 
@@ -93,7 +108,7 @@ module Admin
93
108
  end
94
109
 
95
110
  def handler
96
- :erb
111
+ options[:template_engine]
97
112
  end
98
113
 
99
114
  def filename_with_extensions(name)
@@ -136,6 +151,18 @@ module Admin
136
151
  end.sort.join(', ')
137
152
  end
138
153
 
154
+ def attributes_list_with_timestamps
155
+ attributes_list(attributes_names + %w(created_at updated_at))
156
+ end
157
+
158
+ def attributes_list(attributes = attributes_names)
159
+ if self.attributes.any? {|attr| attr.name == 'password' && attr.type == :digest}
160
+ attributes = attributes.reject {|name| %w(password password_confirmation).include? name}
161
+ end
162
+
163
+ attributes.map { |a| ":#{a}"} * ', '
164
+ end
165
+
139
166
  end
140
167
  end
141
168
  end
@@ -0,0 +1,84 @@
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
+ # GET <%= prefixed_route_url %>.json
11
+ def index
12
+ @<%= plural_table_name %> = <%= orm_class.all(class_name) %>
13
+ end
14
+
15
+ # GET <%= prefixed_route_url %>/1
16
+ # GET <%= prefixed_route_url %>/1.json
17
+ def show
18
+ end
19
+
20
+ # GET <%= prefixed_route_url %>/new
21
+ def new
22
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
23
+ end
24
+
25
+ # GET <%= prefixed_route_url %>/1/edit
26
+ def edit
27
+ end
28
+
29
+ # POST <%= prefixed_route_url %>
30
+ # POST <%= prefixed_route_url %>.json
31
+ def create
32
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
33
+
34
+ respond_to do |format|
35
+ if @<%= orm_instance.save %>
36
+ format.html { redirect_to <%= "[:#{prefix}, @#{singular_table_name}]" %>, notice: <%= "'#{human_name} was successfully created.'" %> }
37
+ format.json { render action: 'show', status: :created, location: <%= "@#{singular_table_name}" %> }
38
+ else
39
+ format.html { render action: 'new' }
40
+ format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
41
+ end
42
+ end
43
+ end
44
+
45
+ # PATCH/PUT <%= prefixed_route_url %>/1
46
+ # PATCH/PUT <%= prefixed_route_url %>/1.json
47
+ def update
48
+ respond_to do |format|
49
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
50
+ format.html { redirect_to <%= "[:#{prefix}, @#{singular_table_name}]" %>, notice: <%= "'#{human_name} was successfully updated.'" %> }
51
+ format.json { head :no_content }
52
+ else
53
+ format.html { render action: 'edit' }
54
+ format.json { render json: <%= "@#{orm_instance.errors}" %>, status: :unprocessable_entity }
55
+ end
56
+ end
57
+ end
58
+
59
+ # DELETE <%= prefixed_route_url %>/1
60
+ # DELETE <%= prefixed_route_url %>/1.json
61
+ def destroy
62
+ @<%= orm_instance.destroy %>
63
+ respond_to do |format|
64
+ format.html { redirect_to <%= prefixed_index_helper %>_url, notice: <%= "'#{human_name} was successfully destroyed.'" %> }
65
+ format.json { head :no_content }
66
+ end
67
+ end
68
+
69
+ private
70
+ # Use callbacks to share common setup or constraints between actions.
71
+ def set_<%= singular_table_name %>
72
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
73
+ end
74
+
75
+ # Never trust parameters from the scary internet, only allow the white list through.
76
+ def <%= "#{singular_table_name}_params" %>
77
+ <%- if attributes_names.empty? -%>
78
+ params[<%= ":#{singular_table_name}" %>]
79
+ <%- else -%>
80
+ params.require(<%= ":#{singular_table_name}" %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
81
+ <%- end -%>
82
+ end
83
+ end
84
+ <% end -%>
@@ -0,0 +1,15 @@
1
+ = form_for(<%= "[:#{prefix}, @#{singular_table_name}]" %>) do |f|
2
+ - if @<%= singular_table_name %>.errors.any?
3
+ #error_explanation
4
+ %h2= "#{pluralize(@<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:"
5
+ %ul
6
+ - @<%= singular_table_name %>.errors.full_messages.each do |msg|
7
+ %li= msg
8
+
9
+ <% for attribute in attributes -%>
10
+ .field
11
+ = f.label :<%= attribute.name %>
12
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
13
+ <% end -%>
14
+ .actions
15
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
1
+ %h1 Editing <%= singular_table_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Show', <%= "[:#{prefix}, @#{singular_table_name}]" %>
6
+ \|
7
+ = link_to 'Back', <%= prefixed_index_helper %>_path
@@ -0,0 +1,23 @@
1
+ %h1 Listing <%= plural_table_name %>
2
+
3
+ %table
4
+ %tr
5
+ <% for attribute in attributes -%>
6
+ %th <%= attribute.human_name %>
7
+ <% end -%>
8
+ %th
9
+ %th
10
+ %th
11
+
12
+ - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
13
+ %tr
14
+ <% for attribute in attributes -%>
15
+ %td= <%= singular_table_name %>.<%= attribute.name %>
16
+ <% end -%>
17
+ %td= link_to 'Show', <%= "[:#{prefix}, #{singular_table_name}]" %>
18
+ %td= link_to 'Edit', edit_<%= prefixed_plain_model_url %>_path(<%= singular_table_name %>)
19
+ %td= link_to 'Destroy', <%= "[:#{prefix}, #{singular_table_name}]" %>, :method => :delete, :data => { :confirm => 'Are you sure?' }
20
+
21
+ %br
22
+
23
+ = link_to 'New <%= human_name %>', new_<%= prefixed_plain_model_url %>_path
@@ -0,0 +1,5 @@
1
+ %h1 New <%= singular_table_name %>
2
+
3
+ = render 'form'
4
+
5
+ = link_to 'Back', <%= prefixed_index_helper %>_path
@@ -0,0 +1,11 @@
1
+ %p#notice= notice
2
+
3
+ <% for attribute in attributes -%>
4
+ %p
5
+ %b <%= attribute.human_name %>:
6
+ = @<%= singular_table_name %>.<%= attribute.name %>
7
+ <% end -%>
8
+
9
+ = link_to 'Edit', edit_<%= prefixed_plain_model_url %>_path(@<%= singular_table_name %>)
10
+ \|
11
+ = link_to 'Back', <%= prefixed_index_helper %>_path
@@ -0,0 +1,4 @@
1
+ json.array!(@<%= plural_table_name %>) do |<%= singular_table_name %>|
2
+ json.extract! <%= singular_table_name %>, <%= attributes_list %>
3
+ json.url <%= singular_table_name %>_url(<%= singular_table_name %>, format: :json)
4
+ end
@@ -0,0 +1 @@
1
+ json.extract! @<%= singular_table_name %>, <%= attributes_list_with_timestamps %>
@@ -1,3 +1,3 @@
1
1
  module RailsAdminScaffold
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -65,7 +65,7 @@ class Admin::Generators::ScaffoldControllerGeneratorTest < Rails::Generators::Te
65
65
  assert_file "test/helpers/admin/users_helper_test.rb", /class Admin::UsersHelperTest < ActionView::TestCase/
66
66
  end
67
67
 
68
- def test_views_are_generated
68
+ def test_erb_views_are_generated
69
69
  run_generator
70
70
 
71
71
  %w(index edit new show).each do |view|
@@ -73,6 +73,14 @@ class Admin::Generators::ScaffoldControllerGeneratorTest < Rails::Generators::Te
73
73
  end
74
74
  end
75
75
 
76
+ def test_haml_views_are_generated
77
+ run_generator ['user', '-e', 'haml']
78
+
79
+ %w(index edit new show).each do |view|
80
+ assert_file "app/views/admin/users/#{view}.html.haml"
81
+ end
82
+ end
83
+
76
84
  def test_functional_tests
77
85
  run_generator ["User", "name:string", "age:integer", "organization:references{polymorphic}"]
78
86
 
metadata CHANGED
@@ -1,17 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails-admin-scaffold
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kirill Kalachev
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-15 00:00:00.000000000 Z
11
+ date: 2013-08-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: railties
14
+ name: rails
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - '>='
@@ -30,26 +30,6 @@ dependencies:
30
30
  - - <
31
31
  - !ruby/object:Gem::Version
32
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
33
  - !ruby/object:Gem::Dependency
54
34
  name: bundler
55
35
  requirement: !ruby/object:Gem::Requirement
@@ -89,13 +69,21 @@ files:
89
69
  - LICENSE
90
70
  - README.md
91
71
  - 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
72
+ - lib/generators/admin/scaffold_controller/templates/tests/test_unit/functional_test.rb.erb
73
+ - lib/generators/admin/scaffold_controller/templates/controllers/jbuilder/controller.rb.erb
74
+ - lib/generators/admin/scaffold_controller/templates/controllers/railties/controller.rb.erb
75
+ - lib/generators/admin/scaffold_controller/templates/views/haml/new.html.haml.erb
76
+ - lib/generators/admin/scaffold_controller/templates/views/haml/_form.html.haml.erb
77
+ - lib/generators/admin/scaffold_controller/templates/views/haml/show.html.haml.erb
78
+ - lib/generators/admin/scaffold_controller/templates/views/haml/edit.html.haml.erb
79
+ - lib/generators/admin/scaffold_controller/templates/views/haml/index.html.haml.erb
80
+ - lib/generators/admin/scaffold_controller/templates/views/jbuilder/show.json.jbuilder.erb
81
+ - lib/generators/admin/scaffold_controller/templates/views/jbuilder/index.json.jbuilder.erb
82
+ - lib/generators/admin/scaffold_controller/templates/views/erb/show.html.erb.erb
83
+ - lib/generators/admin/scaffold_controller/templates/views/erb/_form.html.erb.erb
84
+ - lib/generators/admin/scaffold_controller/templates/views/erb/new.html.erb.erb
85
+ - lib/generators/admin/scaffold_controller/templates/views/erb/edit.html.erb.erb
86
+ - lib/generators/admin/scaffold_controller/templates/views/erb/index.html.erb.erb
99
87
  - lib/generators/admin/scaffold_controller/scaffold_controller_generator.rb
100
88
  - lib/generators/admin/scaffold_controller/USAGE
101
89
  - lib/rails_admin_scaffold.rb