beautiful_scaffold 1.0.1 → 2.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.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/CHANGELOG +78 -1
- data/Gemfile +25 -9
- data/README.rdoc +45 -28
- data/Rakefile +29 -0
- data/beautiful_scaffold.gemspec +7 -7
- data/lib/beautiful_scaffold/version.rb +3 -0
- data/lib/generators/USAGE +3 -1
- data/lib/generators/beautiful_cancancan_generator.rb +51 -0
- data/lib/generators/beautiful_jointable_generator.rb +41 -8
- data/lib/generators/beautiful_locale_generator.rb +107 -104
- data/lib/generators/beautiful_migration_generator.rb +14 -20
- data/lib/generators/beautiful_scaffold_common_methods.rb +56 -26
- data/lib/generators/beautiful_scaffold_generator.rb +116 -78
- data/lib/generators/beautiful_sorcery_generator.rb +137 -0
- data/lib/generators/beautiful_storage_generator.rb +61 -0
- data/lib/generators/templates/app/assets/javascripts/application-bs.js +5 -7
- data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +65 -79
- data/lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js +26 -23
- data/lib/generators/templates/app/assets/javascripts/fixed_menu.js +3 -1
- data/lib/generators/templates/app/assets/javascripts/jstree.min.js +6 -0
- data/lib/generators/templates/app/assets/stylesheets/application-bs.css +14 -6
- data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +20 -3
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/32px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/40px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/style.scss +1146 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/throbber.gif +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/32px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/40px.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/style.scss +1102 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/throbber.gif +0 -0
- data/lib/generators/templates/app/controllers/base.rb +14 -7
- data/lib/generators/templates/app/controllers/master_base.rb +19 -25
- data/lib/generators/templates/app/controllers/user_sessions_controller.rb +20 -0
- data/lib/generators/templates/app/helpers/beautiful_helper.rb +102 -66
- data/lib/generators/templates/app/initializers/link_renderer.rb +23 -18
- data/lib/generators/templates/app/locales/beautiful_scaffold.en.yml +8 -0
- data/lib/generators/templates/app/locales/beautiful_scaffold.fr.yml +9 -1
- data/lib/generators/templates/app/locales/beautiful_scaffold.ja.yml +9 -2
- data/lib/generators/templates/app/mailers/user_mailer.rb +13 -0
- data/lib/generators/templates/app/models/ability.rb +39 -0
- data/lib/generators/templates/app/models/concerns/caption_concern.rb +1 -1
- data/lib/generators/templates/app/models/user.rb +11 -0
- data/lib/generators/templates/app/views/_form.html.erb +4 -1
- data/lib/generators/templates/app/views/_form_habtm_tag.html.erb +6 -2
- data/lib/generators/templates/app/views/_mass_inserting.html.erb +38 -30
- data/lib/generators/templates/app/views/_modal_columns.html.erb +3 -3
- data/lib/generators/templates/app/views/edit.html.erb +1 -3
- data/lib/generators/templates/app/views/index.html.erb +83 -79
- data/lib/generators/templates/app/views/layout.html.erb +36 -36
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.en.html.erb +16 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.en.text.erb +9 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.fr.html.erb +16 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.fr.text.erb +8 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.en.html.erb +19 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.en.text.erb +8 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.fr.html.erb +19 -0
- data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.fr.text.erb +8 -0
- data/lib/generators/templates/app/views/login_logout/user_sessions/_form.html.erb +15 -0
- data/lib/generators/templates/app/views/login_logout/user_sessions/new.html.erb +3 -0
- data/lib/generators/templates/app/views/new.html.erb +0 -2
- data/lib/generators/templates/app/views/partials/_forget_password.html.erb +2 -2
- data/lib/generators/templates/app/views/partials/_form_field.html.erb +37 -29
- data/lib/generators/templates/app/views/partials/_index_batch.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_index_column.html.erb +6 -4
- data/lib/generators/templates/app/views/partials/_index_header.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_index_search.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_login_logout_register.html.erb +7 -0
- data/lib/generators/templates/app/views/partials/_show_field.html.erb +5 -3
- data/lib/generators/templates/app/views/show.html.erb +2 -2
- data/lib/generators/templates/app/views/treeview.html.erb +8 -5
- metadata +38 -24
- data/lib/generators/beautiful_devisecancan_generator.rb +0 -128
- data/lib/generators/templates/app/assets/javascripts/bootstrap-colorpicker.js +0 -520
- data/lib/generators/templates/app/assets/javascripts/jquery.jstree.js +0 -4551
- data/lib/generators/templates/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -40
- data/lib/generators/templates/app/assets/stylesheets/colorpicker.css +0 -127
- data/lib/generators/templates/app/assets/stylesheets/datepicker.css +0 -224
- data/lib/generators/templates/app/assets/stylesheets/reset.css +0 -48
- data/lib/generators/templates/app/assets/stylesheets/themes/default/d.gif +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/d.png +0 -0
- data/lib/generators/templates/app/assets/stylesheets/themes/default/style.css +0 -74
- data/lib/generators/templates/app/assets/stylesheets/timepicker.css +0 -89
- data/lib/generators/templates/app/views/partials/_register_form.html.erb +0 -44
- data/lib/generators/templates/app/views/partials/_sign_in_form.html.erb +0 -18
- data/lib/generators/templates/app/views/partials/_sign_in_sign_out.html.erb +0 -19
- data/lib/generators/templates/lib/custom_failure.rb +0 -15
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
|
-
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: 29b4c80363aba59d47f1219a1dbc4b205a149b0d2745f6a295e1511a2898d96f
|
|
4
|
+
data.tar.gz: 13fe2f58f7b2a30e7eff49e55ab8d8ec1ac5e7d77f78b41f50ec18919fb2cb98
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: ebd54c4c42924851fb5039d1edf3a749ff0b153f605cd1b9671c0a292d030a43d839bac61b8e830b3733d35694425a602f63f24fa81a357bd099dd1f12d91a43
|
|
7
|
+
data.tar.gz: 370ee3d28e84836c4f81d7dbedd894c5ccd56997d00e598d10959375c0037b5c8ce4802a28d1e6f819532c57b6d929583e3649a1d5cd8045f5bba225262bed2b
|
data/.gitignore
ADDED
data/CHANGELOG
CHANGED
|
@@ -1,3 +1,80 @@
|
|
|
1
|
+
== master
|
|
2
|
+
|
|
3
|
+
* enhancement
|
|
4
|
+
|
|
5
|
+
* bugfix
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
== Soon
|
|
9
|
+
|
|
10
|
+
ActionText / trix.
|
|
11
|
+
|
|
12
|
+
== 2.0.2
|
|
13
|
+
|
|
14
|
+
* enhancement
|
|
15
|
+
* Native html colorpicker
|
|
16
|
+
|
|
17
|
+
* bugfix
|
|
18
|
+
* Datetime picker for model form
|
|
19
|
+
* Display price in model form
|
|
20
|
+
|
|
21
|
+
== 2.0.1
|
|
22
|
+
|
|
23
|
+
* enhancement
|
|
24
|
+
* Replace Devise by Sorcery
|
|
25
|
+
* Tests Sorcery and Cancancan generators
|
|
26
|
+
* New generator for ActiveStorage
|
|
27
|
+
|
|
28
|
+
* bugfix
|
|
29
|
+
* Locale : fix all locale in the same file.
|
|
30
|
+
* Visual fix ('-' in menu)
|
|
31
|
+
* Will_paginate right locales
|
|
32
|
+
* Avoid adding gems multiple times
|
|
33
|
+
|
|
34
|
+
== 2.0.0
|
|
35
|
+
|
|
36
|
+
* enhancement
|
|
37
|
+
* Bootstrap 4.5 for search field.
|
|
38
|
+
|
|
39
|
+
* bugfix
|
|
40
|
+
* Beautiful migration & Rails 6 (fix #23)
|
|
41
|
+
|
|
42
|
+
== 2.0.0.pre
|
|
43
|
+
|
|
44
|
+
* enhancement
|
|
45
|
+
* replace chardinjs by driverjs : https://github.com/kamranahmedse/driver.js
|
|
46
|
+
* replace bootstrapdatetimepicker by https://tempusdominus.github.io/bootstrap-4/Usage/
|
|
47
|
+
* Update JStreeview
|
|
48
|
+
* Update Bootstrap 4.2
|
|
49
|
+
* Update FontAwesome 5
|
|
50
|
+
* Generate beautiful scaffold for mountable engine
|
|
51
|
+
* Tests generators works !
|
|
52
|
+
* Refactoring ruby code.
|
|
53
|
+
|
|
54
|
+
* bugfix
|
|
55
|
+
* Bugfix for engine
|
|
56
|
+
|
|
57
|
+
== 1.0.3
|
|
58
|
+
|
|
59
|
+
* enhancement
|
|
60
|
+
* You can generate scaffold in a mountable engine, now. (see README for syntax)
|
|
61
|
+
|
|
62
|
+
* Bugfix
|
|
63
|
+
* I18n translation default value (model.column).
|
|
64
|
+
|
|
65
|
+
== 1.0.2
|
|
66
|
+
|
|
67
|
+
* enhancement
|
|
68
|
+
* Using static twitter bootstrap files
|
|
69
|
+
* UI : button back & submit on the same line
|
|
70
|
+
* Add tests (better late than never :/)
|
|
71
|
+
|
|
72
|
+
* bugfix
|
|
73
|
+
* Fix #18 : Responsive Theme Navbar Overlaps Content When Resizing Below ~979px
|
|
74
|
+
* Fix generator locales
|
|
75
|
+
* Fix icon datetimepicker
|
|
76
|
+
* render nothing: true replace with head :ok
|
|
77
|
+
|
|
1
78
|
== 1.0.1
|
|
2
79
|
|
|
3
80
|
* enhancement
|
|
@@ -183,4 +260,4 @@
|
|
|
183
260
|
|
|
184
261
|
== Previous versions
|
|
185
262
|
|
|
186
|
-
* See commits on github
|
|
263
|
+
* See commits on github
|
data/Gemfile
CHANGED
|
@@ -2,12 +2,28 @@ source "http://rubygems.org"
|
|
|
2
2
|
|
|
3
3
|
gemspec
|
|
4
4
|
|
|
5
|
-
gem "rails", "~>
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
gem "rails", "~> 6.1"
|
|
6
|
+
|
|
7
|
+
group :test do
|
|
8
|
+
gem 'sqlite3'
|
|
9
|
+
|
|
10
|
+
gems = {
|
|
11
|
+
'will_paginate' => nil, # v 3.1.5
|
|
12
|
+
'ransack' => nil, #'2.3.2',
|
|
13
|
+
'jquery-ui-rails' => nil,
|
|
14
|
+
'prawn' => nil, #'2.1.0',
|
|
15
|
+
'prawn-table' => nil, #'0.2.2',
|
|
16
|
+
'sanitize' => nil,
|
|
17
|
+
'bootstrap' => '~> 4.3.1',
|
|
18
|
+
'font-awesome-rails' => '4.7.0.7',
|
|
19
|
+
'momentjs-rails' => '>= 2.9.0',
|
|
20
|
+
'bootstrap4-datetime-picker-rails' => nil,
|
|
21
|
+
'jquery-rails' => '4.3.1',
|
|
22
|
+
'sorcery' => '0.15.0'
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
gems.each{ |gem_to_add, version|
|
|
26
|
+
gem(gem_to_add, version)
|
|
27
|
+
}
|
|
28
|
+
end
|
|
29
|
+
|
data/README.rdoc
CHANGED
|
@@ -2,28 +2,18 @@
|
|
|
2
2
|
|
|
3
3
|
Beautiful Scaffold is a gem which propose generators for a complete scaffold with paginate, sort and filter.
|
|
4
4
|
Fully customizable.
|
|
5
|
-
Info : https://github.com/rivsc/Beautiful-Scaffold
|
|
6
|
-
Demo : http://demo.beautiful-scaffold.escarworld.com/
|
|
7
|
-
|
|
8
|
-
== Install
|
|
9
|
-
|
|
10
|
-
=== RubyOnRails 4.1
|
|
11
|
-
|
|
12
|
-
Add this in your Gemfile :
|
|
13
5
|
|
|
14
|
-
|
|
6
|
+
Note : Avoid to change Beautiful-Scaffold version in your project (incompatibility between generated code).
|
|
7
|
+
Note 2 : Be careful to have a clean git repository for your project because Beautiful-Scaffold change many files.
|
|
8
|
+
It will be easier to revert changes.
|
|
15
9
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
Add this in your Gemfile :
|
|
19
|
-
|
|
20
|
-
gem 'beautiful_scaffold', '0.3.5'
|
|
21
|
-
|
|
22
|
-
=== RubyOnRails 5+
|
|
10
|
+
Info : https://github.com/rivsc/Beautiful-Scaffold
|
|
11
|
+
Demo : http://beautiful-scaffold.rivsc.ovh/
|
|
23
12
|
|
|
24
|
-
|
|
13
|
+
== Install
|
|
25
14
|
|
|
26
|
-
|
|
15
|
+
Add this in the Gemfile of your rails app or engine :
|
|
16
|
+
gem 'beautiful_scaffold'
|
|
27
17
|
|
|
28
18
|
=== Next
|
|
29
19
|
|
|
@@ -35,7 +25,10 @@ And run
|
|
|
35
25
|
|
|
36
26
|
=== Scaffold
|
|
37
27
|
|
|
38
|
-
|
|
28
|
+
# model : underscore and singular
|
|
29
|
+
# mountable_engine : underscore
|
|
30
|
+
# namespace : underscore
|
|
31
|
+
rails generate beautiful_scaffold model attr:type attr:type... [--namespace=name] [--donttouchgem=yes] [--mountable_engine=name]
|
|
39
32
|
|
|
40
33
|
Types available:
|
|
41
34
|
* integer
|
|
@@ -46,6 +39,8 @@ Types available:
|
|
|
46
39
|
* color
|
|
47
40
|
* wysiwyg
|
|
48
41
|
|
|
42
|
+
(See below #label-Barcodes)
|
|
43
|
+
|
|
49
44
|
# Example : products
|
|
50
45
|
|
|
51
46
|
rails g beautiful_scaffold product name:string price:price tva:float description:wysiwyg visible:boolean && rake db:migrate
|
|
@@ -54,6 +49,15 @@ Types available:
|
|
|
54
49
|
|
|
55
50
|
rails g beautiful_scaffold product name:string price:price tva:float description:wysiwyg overview_description:wysiwyg visible:boolean --namespace=admin && rake db:migrate
|
|
56
51
|
|
|
52
|
+
# Example (for an engine) :
|
|
53
|
+
# You need to add beautiful-scaffold to the gemfile of the engine (not the gemspec !).
|
|
54
|
+
|
|
55
|
+
rails g beautiful_scaffold user code:string --mountable-engine=faq
|
|
56
|
+
rails g beautiful_scaffold question title:string description:wysiwyg user:references resolved:boolean --mountable-engine=faq
|
|
57
|
+
rails g beautiful_scaffold answer description:wysiwyg user:references up:integer down:integer --mountable-engine=faq
|
|
58
|
+
rails g beautiful_migration AddPositionToFaqAnswers position:integer --mountable-engine=faq
|
|
59
|
+
rails g beautiful_jointable answer tag --mountable-engine=faq
|
|
60
|
+
|
|
57
61
|
=== Migration (Use Add[Field]To[ModelPluralize] syntax)
|
|
58
62
|
|
|
59
63
|
rails g beautiful_migration AddFieldToModels field:type
|
|
@@ -71,9 +75,23 @@ Run `rake db:migrate` before `rails g beautiful_locale` (to get lastest attribut
|
|
|
71
75
|
|
|
72
76
|
rails g beautiful_jointable model1 model2
|
|
73
77
|
|
|
74
|
-
=== Install et
|
|
78
|
+
=== Install et preconfigure Sorcery (authentification) (this generator doesn't work on engine)
|
|
79
|
+
|
|
80
|
+
# If it is not done yet
|
|
81
|
+
rails g beautiful_scaffold user email:string
|
|
82
|
+
rails g beautiful_sorcery
|
|
83
|
+
|
|
84
|
+
=== Install et preconfigure Cancancan (authorization) (this generator doesn't work on engine)
|
|
85
|
+
|
|
86
|
+
# If it is not done yet
|
|
87
|
+
rails g beautiful_scaffold user email:string
|
|
88
|
+
# If it is not done yet
|
|
89
|
+
rails g beautiful_sorcery
|
|
90
|
+
rails g beautiful_cancancan
|
|
91
|
+
|
|
92
|
+
=== Storage (ActiveStorage)
|
|
75
93
|
|
|
76
|
-
|
|
94
|
+
rails g beautiful_storage model attachment_field
|
|
77
95
|
|
|
78
96
|
=== In views
|
|
79
97
|
|
|
@@ -97,16 +115,15 @@ data-type-barcode can be :
|
|
|
97
115
|
msi
|
|
98
116
|
datamatrix (ASCII + extended)
|
|
99
117
|
|
|
100
|
-
====
|
|
118
|
+
==== Driverjs (overlay instructions)
|
|
101
119
|
|
|
102
|
-
Example :
|
|
120
|
+
Example : when you click on the #bs-help tag presentation tour display on screen !
|
|
103
121
|
|
|
104
|
-
|
|
122
|
+
If you want to add 'slide' :
|
|
105
123
|
|
|
106
|
-
|
|
124
|
+
For add instruction to DOM element, add this to your markup :
|
|
107
125
|
|
|
108
|
-
|
|
126
|
+
id="myunique-id-in-the-page" data-present-title="Title for the slide" data-present-description="Short description" data-present-order="1"
|
|
109
127
|
|
|
110
|
-
|
|
128
|
+
And Beautiful-Scaffold does the job !
|
|
111
129
|
|
|
112
|
-
For add instruction to element, read official documentation : https://github.com/heelhook/chardin.js#adding-data-for-the-instructions
|
data/Rakefile
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'bundler/setup'
|
|
3
|
+
rescue LoadError
|
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
require 'rdoc/task'
|
|
8
|
+
|
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
|
11
|
+
rdoc.title = 'Beautiful-Scaffold'
|
|
12
|
+
rdoc.options << '--line-numbers'
|
|
13
|
+
rdoc.rdoc_files.include('README.md')
|
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
APP_RAKEFILE = File.expand_path("test/dummy/Rakefile", __dir__)
|
|
18
|
+
load 'rails/tasks/engine.rake'
|
|
19
|
+
load 'rails/tasks/statistics.rake'
|
|
20
|
+
require 'bundler/gem_tasks'
|
|
21
|
+
require 'rake/testtask'
|
|
22
|
+
|
|
23
|
+
Rake::TestTask.new(:test) do |t|
|
|
24
|
+
t.libs << 'test'
|
|
25
|
+
t.pattern = 'test/**/*_test.rb'
|
|
26
|
+
t.verbose = false
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
task default: :test
|
data/beautiful_scaffold.gemspec
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
|
2
2
|
$:.push File.expand_path("../lib", __FILE__)
|
|
3
3
|
|
|
4
|
+
require "beautiful_scaffold/version"
|
|
5
|
+
|
|
4
6
|
Gem::Specification.new do |s|
|
|
5
7
|
s.name = "beautiful_scaffold"
|
|
6
|
-
s.version =
|
|
8
|
+
s.version = BeautifulScaffold::VERSION
|
|
7
9
|
s.platform = Gem::Platform::RUBY
|
|
8
10
|
s.summary = "Beautiful Scaffold generate fully customizable scaffold"
|
|
9
11
|
s.email = "claudel.sylvain@gmail.com"
|
|
10
|
-
s.homepage = "
|
|
11
|
-
s.description = "Beautiful Scaffold generate a complete scaffold (sort, export, paginate and filter data) http://
|
|
12
|
+
s.homepage = "https://blog.rivsc.ovh"
|
|
13
|
+
s.description = "Beautiful Scaffold generate a complete scaffold (sort, export, paginate and filter data) http://beautiful-scaffold.rivsc.ovh"
|
|
12
14
|
s.authors = ['Sylvain Claudel']
|
|
13
|
-
s.files = `git ls-files`.split("\n")
|
|
15
|
+
s.files = `git ls-files`.split("\n").reject{ |filepath| filepath.start_with? 'test/' }
|
|
14
16
|
s.licenses = ['MIT']
|
|
15
17
|
|
|
16
|
-
s.
|
|
17
|
-
|
|
18
|
-
s.require_paths = ["lib","lib/generators"]
|
|
18
|
+
s.require_paths = ["lib","lib/generators","test/*"]
|
|
19
19
|
end
|
data/lib/generators/USAGE
CHANGED
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
# encoding : utf-8
|
|
2
|
+
class BeautifulCancancanGenerator < Rails::Generators::Base
|
|
3
|
+
require_relative 'beautiful_scaffold_common_methods'
|
|
4
|
+
include BeautifulScaffoldCommonMethods
|
|
5
|
+
|
|
6
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
7
|
+
|
|
8
|
+
#argument :model, :type => :string, :desc => "Name of model (ex: user)"
|
|
9
|
+
|
|
10
|
+
def install_cancancan
|
|
11
|
+
model = "user"
|
|
12
|
+
|
|
13
|
+
gem("cancancan", "3.2.1")
|
|
14
|
+
|
|
15
|
+
Bundler.with_unbundled_env do
|
|
16
|
+
run "bundle install"
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Because generators doesn't work !
|
|
20
|
+
copy_file("app/models/ability.rb")
|
|
21
|
+
|
|
22
|
+
# Why that doesn't work... boring...
|
|
23
|
+
#puts rails_command("generate cancan:ability", capture: true)
|
|
24
|
+
# Why that doesn't work too... boring...
|
|
25
|
+
#generate("cancan:ability")
|
|
26
|
+
|
|
27
|
+
# current_user method need for CanCan
|
|
28
|
+
current_user_method = ""
|
|
29
|
+
if model != "user" then
|
|
30
|
+
current_user_method = "
|
|
31
|
+
def current_user
|
|
32
|
+
current_#{model}
|
|
33
|
+
end"
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Exception for AccessDenied
|
|
37
|
+
inject_into_file("app/controllers/application_controller.rb", "
|
|
38
|
+
rescue_from CanCan::AccessDenied do |exception|
|
|
39
|
+
respond_to do |format|
|
|
40
|
+
format.json { head :forbidden, content_type: 'text/html' }
|
|
41
|
+
format.html { redirect_to root_url, :alert => exception.message }
|
|
42
|
+
format.js { head :forbidden, content_type: 'text/html' }
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
#{current_user_method}
|
|
46
|
+
", :after => "class ApplicationController < ActionController::Base\n")
|
|
47
|
+
|
|
48
|
+
# Access controlled by CanCanCan (in beautiful_scaffold)
|
|
49
|
+
inject_into_file("app/controllers/application_controller.rb", "#", :before => "before_action :authenticate_#{model}!, :except => [:dashboard]")
|
|
50
|
+
end
|
|
51
|
+
end
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
# encoding : utf-8
|
|
2
2
|
class BeautifulJointableGenerator < Rails::Generators::Base
|
|
3
|
-
|
|
3
|
+
require_relative 'beautiful_scaffold_common_methods'
|
|
4
4
|
include BeautifulScaffoldCommonMethods
|
|
5
5
|
|
|
6
6
|
source_root File.expand_path('../templates', __FILE__)
|
|
7
7
|
|
|
8
|
-
argument :join_models, :type => :array, :default => [], :banner => "model
|
|
8
|
+
argument :join_models, :type => :array, :default => [], :banner => "Two model names singular downcase (ex: product family)"
|
|
9
|
+
|
|
10
|
+
class_option :mountable_engine, default: nil
|
|
9
11
|
|
|
10
12
|
def create_join_table
|
|
11
13
|
if join_models.length != 2 then
|
|
@@ -13,14 +15,21 @@ class BeautifulJointableGenerator < Rails::Generators::Base
|
|
|
13
15
|
else
|
|
14
16
|
sorted_model = join_models.sort
|
|
15
17
|
|
|
18
|
+
prefix_str = ''
|
|
19
|
+
if engine_name.present?
|
|
20
|
+
prefix_str = "#{engine_opt}_"
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
join_table_name = "#{prefix_str}#{sorted_model[0].pluralize}_#{sorted_model[1].pluralize}"
|
|
24
|
+
|
|
16
25
|
# Generate migration
|
|
17
26
|
migration_content = "
|
|
18
|
-
create_table :#{
|
|
27
|
+
create_table :#{join_table_name}, :id => false do |t|
|
|
19
28
|
t.integer :#{sorted_model[0]}_id
|
|
20
29
|
t.integer :#{sorted_model[1]}_id
|
|
21
30
|
end
|
|
22
31
|
|
|
23
|
-
add_index :#{
|
|
32
|
+
add_index :#{join_table_name}, [:#{sorted_model[0]}_id, :#{sorted_model[1]}_id]
|
|
24
33
|
"
|
|
25
34
|
|
|
26
35
|
migration_name = "create_join_table_for_#{sorted_model[0]}_and_#{sorted_model[1]}"
|
|
@@ -31,11 +40,35 @@ class BeautifulJointableGenerator < Rails::Generators::Base
|
|
|
31
40
|
inject_into_file(filename, migration_content, :after => "def change")
|
|
32
41
|
|
|
33
42
|
# Add habtm relation
|
|
34
|
-
inject_into_file("app/models/#{sorted_model[0]}.rb", "\n has_and_belongs_to_many :#{sorted_model[1].pluralize}", :after => "
|
|
35
|
-
inject_into_file("app/models/#{sorted_model[1]}.rb", "\n has_and_belongs_to_many :#{sorted_model[0].pluralize}", :after => "
|
|
36
|
-
inject_into_file("app/models/#{sorted_model[0]}.rb", ":#{sorted_model[1]}_ids, ", :after => "
|
|
37
|
-
|
|
43
|
+
inject_into_file("app/models/#{engine_name}#{sorted_model[0]}.rb", "\n #{engine_name.present? ? ' ' : ''}has_and_belongs_to_many :#{sorted_model[1].pluralize}", :after => "ApplicationRecord")
|
|
44
|
+
inject_into_file("app/models/#{engine_name}#{sorted_model[1]}.rb", "\n #{engine_name.present? ? ' ' : ''}has_and_belongs_to_many :#{sorted_model[0].pluralize}", :after => "ApplicationRecord")
|
|
45
|
+
inject_into_file("app/models/#{engine_name}#{sorted_model[0]}.rb", "{ :#{sorted_model[1]}_ids => [] }, ", :after => "permitted_attributes
|
|
46
|
+
return ")
|
|
47
|
+
inject_into_file("app/models/#{engine_name}#{sorted_model[1]}.rb", "{ :#{sorted_model[0]}_ids => [] }, ", :after => "permitted_attributes
|
|
48
|
+
return ")
|
|
38
49
|
end
|
|
39
50
|
end
|
|
40
51
|
|
|
52
|
+
def add_habtm_field_in_forms
|
|
53
|
+
models = join_models.sort
|
|
54
|
+
|
|
55
|
+
2.times do
|
|
56
|
+
html = "<%=
|
|
57
|
+
render :partial => 'layouts/#{engine_name}form_habtm_tag', :locals => {
|
|
58
|
+
:model_class => @#{models[0]},
|
|
59
|
+
:model_name => '#{models[0]}',
|
|
60
|
+
:plural_model_name => '#{models[0].pluralize}',
|
|
61
|
+
:linked_model_name => '#{models[1]}',
|
|
62
|
+
:plural_linked_model_name => '#{models[1].pluralize}',
|
|
63
|
+
:namespace_bs => '',
|
|
64
|
+
:engine_bs => '#{engine_opt}',
|
|
65
|
+
:field_to_search_for_linked_model => 'name',
|
|
66
|
+
:attr_to_show => 'caption',
|
|
67
|
+
:f => f
|
|
68
|
+
} %>"
|
|
69
|
+
|
|
70
|
+
inject_into_file("app/views/#{engine_name}#{models[0].pluralize}/_form.html.erb", html, :before => "<!-- Beautiful_scaffold - AddField - Do not remove -->")
|
|
71
|
+
models = models.reverse
|
|
72
|
+
end
|
|
73
|
+
end
|
|
41
74
|
end
|