beautiful_scaffold 1.0.0.pre → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (91) hide show
  1. checksums.yaml +5 -5
  2. data/.gitignore +2 -0
  3. data/CHANGELOG +73 -1
  4. data/Gemfile +25 -17
  5. data/README.rdoc +45 -28
  6. data/Rakefile +29 -0
  7. data/beautiful_scaffold.gemspec +7 -7
  8. data/lib/beautiful_scaffold/version.rb +3 -0
  9. data/lib/generators/USAGE +3 -1
  10. data/lib/generators/beautiful_cancancan_generator.rb +51 -0
  11. data/lib/generators/beautiful_jointable_generator.rb +41 -8
  12. data/lib/generators/beautiful_locale_generator.rb +112 -88
  13. data/lib/generators/beautiful_migration_generator.rb +14 -20
  14. data/lib/generators/beautiful_scaffold_common_methods.rb +92 -25
  15. data/lib/generators/beautiful_scaffold_generator.rb +164 -101
  16. data/lib/generators/beautiful_sorcery_generator.rb +137 -0
  17. data/lib/generators/beautiful_storage_generator.rb +61 -0
  18. data/lib/generators/templates/app/assets/javascripts/application-bs.js +7 -7
  19. data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +70 -47
  20. data/lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js +23 -42
  21. data/lib/generators/templates/app/assets/javascripts/fixed_menu.js +3 -1
  22. data/lib/generators/templates/app/assets/javascripts/jstree.min.js +6 -0
  23. data/lib/generators/templates/app/assets/stylesheets/application-bs.css +14 -6
  24. data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +38 -3
  25. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/32px.png +0 -0
  26. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/40px.png +0 -0
  27. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/style.scss +1146 -0
  28. data/lib/generators/templates/app/assets/stylesheets/themes/default-dark/throbber.gif +0 -0
  29. data/lib/generators/templates/app/assets/stylesheets/themes/default/32px.png +0 -0
  30. data/lib/generators/templates/app/assets/stylesheets/themes/default/40px.png +0 -0
  31. data/lib/generators/templates/app/assets/stylesheets/themes/default/style.scss +1102 -0
  32. data/lib/generators/templates/app/assets/stylesheets/themes/default/throbber.gif +0 -0
  33. data/lib/generators/templates/app/controllers/base.rb +31 -14
  34. data/lib/generators/templates/app/controllers/master_base.rb +55 -47
  35. data/lib/generators/templates/app/controllers/user_sessions_controller.rb +20 -0
  36. data/lib/generators/templates/app/helpers/beautiful_helper.rb +122 -72
  37. data/lib/generators/templates/app/helpers/model_helper.rb +14 -3
  38. data/lib/generators/templates/app/initializers/link_renderer.rb +23 -18
  39. data/lib/generators/templates/app/initializers/ransack.rb +16 -0
  40. data/lib/generators/templates/app/locales/beautiful_scaffold.en.yml +8 -0
  41. data/lib/generators/templates/app/locales/beautiful_scaffold.fr.yml +9 -1
  42. data/lib/generators/templates/app/locales/beautiful_scaffold.ja.yml +9 -2
  43. data/lib/generators/templates/app/mailers/user_mailer.rb +13 -0
  44. data/lib/generators/templates/app/models/ability.rb +39 -0
  45. data/lib/generators/templates/app/models/concerns/caption_concern.rb +1 -1
  46. data/lib/generators/templates/app/models/user.rb +11 -0
  47. data/lib/generators/templates/app/views/_form.html.erb +4 -1
  48. data/lib/generators/templates/app/views/_form_habtm_tag.html.erb +6 -2
  49. data/lib/generators/templates/app/views/_mass_inserting.html.erb +40 -31
  50. data/lib/generators/templates/app/views/_modal_columns.html.erb +4 -4
  51. data/lib/generators/templates/app/views/edit.html.erb +1 -3
  52. data/lib/generators/templates/app/views/index.html.erb +84 -58
  53. data/lib/generators/templates/app/views/layout.html.erb +36 -47
  54. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.en.html.erb +16 -0
  55. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.en.text.erb +9 -0
  56. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.fr.html.erb +16 -0
  57. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_needed_email.fr.text.erb +8 -0
  58. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.en.html.erb +19 -0
  59. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.en.text.erb +8 -0
  60. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.fr.html.erb +19 -0
  61. data/lib/generators/templates/app/views/login_logout/user_mailer/activation_success_email.fr.text.erb +8 -0
  62. data/lib/generators/templates/app/views/login_logout/user_sessions/_form.html.erb +15 -0
  63. data/lib/generators/templates/app/views/login_logout/user_sessions/new.html.erb +3 -0
  64. data/lib/generators/templates/app/views/new.html.erb +0 -2
  65. data/lib/generators/templates/app/views/partials/_forget_password.html.erb +2 -2
  66. data/lib/generators/templates/app/views/partials/_form_field.html.erb +7 -7
  67. data/lib/generators/templates/app/views/partials/_index_batch.html.erb +1 -1
  68. data/lib/generators/templates/app/views/partials/_index_column.html.erb +4 -4
  69. data/lib/generators/templates/app/views/partials/_index_header.html.erb +1 -1
  70. data/lib/generators/templates/app/views/partials/_index_search.html.erb +2 -2
  71. data/lib/generators/templates/app/views/partials/_index_search_default_fields.html.erb +1 -1
  72. data/lib/generators/templates/app/views/partials/_login_logout_register.html.erb +7 -0
  73. data/lib/generators/templates/app/views/partials/_show_field.html.erb +3 -3
  74. data/lib/generators/templates/app/views/show.html.erb +2 -2
  75. data/lib/generators/templates/app/views/treeview.html.erb +8 -5
  76. metadata +41 -26
  77. data/lib/generators/beautiful_devisecancan_generator.rb +0 -128
  78. data/lib/generators/templates/app/assets/javascripts/bootstrap-datepicker.js +0 -834
  79. data/lib/generators/templates/app/assets/javascripts/bootstrap-timepicker.js +0 -797
  80. data/lib/generators/templates/app/assets/javascripts/jquery.jstree.js +0 -4551
  81. data/lib/generators/templates/app/assets/stylesheets/bootstrap_and_overrides.css.less +0 -40
  82. data/lib/generators/templates/app/assets/stylesheets/datepicker.css +0 -224
  83. data/lib/generators/templates/app/assets/stylesheets/reset.css +0 -48
  84. data/lib/generators/templates/app/assets/stylesheets/themes/default/d.gif +0 -0
  85. data/lib/generators/templates/app/assets/stylesheets/themes/default/d.png +0 -0
  86. data/lib/generators/templates/app/assets/stylesheets/themes/default/style.css +0 -74
  87. data/lib/generators/templates/app/assets/stylesheets/timepicker.css +0 -89
  88. data/lib/generators/templates/app/views/partials/_register_form.html.erb +0 -44
  89. data/lib/generators/templates/app/views/partials/_sign_in_form.html.erb +0 -18
  90. data/lib/generators/templates/app/views/partials/_sign_in_sign_out.html.erb +0 -19
  91. data/lib/generators/templates/lib/custom_failure.rb +0 -15
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: c788ac3707c3a554a7fd4b8d7796645899275068
4
- data.tar.gz: 194fa4ea7f3f50c1548dd1306d9718e3e6eaaf76
2
+ SHA256:
3
+ metadata.gz: f2c5cc9830b52e9bdc57663e3e93779e3457502e4f3656f0c541b8213775edca
4
+ data.tar.gz: 03260e7d438e1aa4c9161a5fdf1b221fd21c2acc4625857ac00eadf4686ac04c
5
5
  SHA512:
6
- metadata.gz: ccdaf02eeca18d1b3e84857a16ca055349207879ff83846b1e794d60efb0c2a6068f6a57351001eacbf96941ac3f3a3b293f3e2a72ac3be4efb0e10c2c337629
7
- data.tar.gz: cd77e358cab2f4c04db96e08d7b52357d07e2223121fa5f67dacf8fae893c971e403e32a039043b982a2051a52a437d6f3d9f801260318dea64a52e6fe9ef7bd
6
+ metadata.gz: d95e8b02e11a731844977432a230d83b200da69018184d3583a3ade48f448face2799f8e76bcb01ee13b40b7166813f0921fe57442db6fa7f18ec23eb6b62f79
7
+ data.tar.gz: 7ab3d32603cf3c89f6c34a7d5798610b60ccbf701a3c8583eee89bdabadb0a090c96436e8e17c11f2c9d41d7ba4262820414b1096e54124df2b02cccaf9b777e
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ test/dummy/log/test.log
2
+ Gemfile.lock
data/CHANGELOG CHANGED
@@ -1,3 +1,75 @@
1
+ == master
2
+
3
+ * enhancement
4
+
5
+ * bugfix
6
+
7
+ == 2.0.1
8
+
9
+ * enhancement
10
+ * Replace Devise by Sorcery
11
+ * Tests Sorcery and Cancancan generators
12
+ * New generator for ActiveStorage
13
+
14
+ * bugfix
15
+ * Locale : fix all locale in the same file.
16
+ * Visual fix ('-' in menu)
17
+ * Will_paginate right locales
18
+ * Avoid adding gems multiple times
19
+
20
+ == 2.0.0
21
+
22
+ * enhancement
23
+ * Bootstrap 4.5 for search field.
24
+
25
+ * bugfix
26
+ * Beautiful migration & Rails 6 (fix #23)
27
+
28
+ == 2.0.0.pre
29
+
30
+ * enhancement
31
+ * replace chardinjs by driverjs : https://github.com/kamranahmedse/driver.js
32
+ * replace bootstrapdatetimepicker by https://tempusdominus.github.io/bootstrap-4/Usage/
33
+ * Update JStreeview
34
+ * Update Bootstrap 4.2
35
+ * Update FontAwesome 5
36
+ * Generate beautiful scaffold for mountable engine
37
+ * Tests generators works !
38
+ * Refactoring ruby code.
39
+
40
+ * bugfix
41
+ * Bugfix for engine
42
+
43
+ == 1.0.3
44
+
45
+ * enhancement
46
+ * You can generate scaffold in a mountable engine, now. (see README for syntax)
47
+
48
+ * Bugfix
49
+ * I18n translation default value (model.column).
50
+
51
+ == 1.0.2
52
+
53
+ * enhancement
54
+ * Using static twitter bootstrap files
55
+ * UI : button back & submit on the same line
56
+ * Add tests (better late than never :/)
57
+
58
+ * bugfix
59
+ * Fix #18 : Responsive Theme Navbar Overlaps Content When Resizing Below ~979px
60
+ * Fix generator locales
61
+ * Fix icon datetimepicker
62
+ * render nothing: true replace with head :ok
63
+
64
+ == 1.0.1
65
+
66
+ * enhancement
67
+ * Change datetimepicker (eyecon.ro -> eonasdan)
68
+ * Support CamelCase syntaxe for models.
69
+
70
+ * bugfix
71
+ * Change keys symbol into string on session (begin at 0.3.5)
72
+
1
73
  == 1.0.0.pre
2
74
 
3
75
  * enhancement
@@ -174,4 +246,4 @@
174
246
 
175
247
  == Previous versions
176
248
 
177
- * See commits on github
249
+ * See commits on github
data/Gemfile CHANGED
@@ -2,20 +2,28 @@ source "http://rubygems.org"
2
2
 
3
3
  gemspec
4
4
 
5
- gem "rails", "~> 4.0"
6
- # Pagination
7
- gem "will_paginate"
8
- # Search and filter
9
- gem "ransack"
10
- # Pdf
11
- gem 'prawn', '1.0.0.rc2'
12
- # Textile
13
- gem 'RedCloth'
14
- # BBCode
15
- gem 'bb-ruby'
16
- # Markdown
17
- gem 'bluecloth'
18
- # Markdown
19
- gem 'rdiscount'
20
- # Clear html tag
21
- gem 'sanitize'
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
- gem 'beautiful_scaffold', '0.3.4'
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
- === RubyOnRails 4.2
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
- Add this in your Gemfile :
13
+ == Install
25
14
 
26
- gem 'beautiful_scaffold', '1.0.0.pre'
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
- rails generate beautiful_scaffold model attr:type attr:type... [--namespace=name] [--donttouchgem=name]
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 Configure Devise (authentification) and Cancan (authorization)
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
- rails g beautiful_devisecancan model
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
- ==== Chardinjs (overlay instructions)
118
+ ==== Driverjs (overlay instructions)
101
119
 
102
- Example : This button triggers chardinjs on element with 'menu' id.
120
+ Example : when you click on the #bs-help tag presentation tour display on screen !
103
121
 
104
- <a href="#" class="bs-chardinjs" data-selector="#menu">Help Menu</a>
122
+ If you want to add 'slide' :
105
123
 
106
- If you want display all chardinjs :
124
+ For add instruction to DOM element, add this to your markup :
107
125
 
108
- <a href="#" class="bs-chardinjs" data-selector="body">Help</a>
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
- Just add `class="bs-chardinjs"` in a button / link for trigger chardinjs. Beautiful-Scaffold does the job !
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
@@ -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 = "1.0.0.pre"
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 = "http://beautiful-scaffold.com"
11
- s.description = "Beautiful Scaffold generate a complete scaffold (sort, export, paginate and filter data) http://www.beautiful-scaffold.com"
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.rubyforge_project = "beautiful_scaffold"
17
-
18
- s.require_paths = ["lib","lib/generators"]
18
+ s.require_paths = ["lib","lib/generators","test/*"]
19
19
  end
@@ -0,0 +1,3 @@
1
+ module BeautifulScaffold
2
+ VERSION = '2.0.1'
3
+ end
data/lib/generators/USAGE CHANGED
@@ -12,5 +12,7 @@ Example:
12
12
 
13
13
  rails generate beautiful_jointable product tag
14
14
 
15
- rails generate beautiful_devisecancan user
15
+ rails generate beautiful_sorcery
16
+ rails generate beautiful_cancancan
17
+
16
18
 
@@ -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
- require 'beautiful_scaffold_common_methods'
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 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 :#{sorted_model[0].pluralize}_#{sorted_model[1].pluralize}, :id => false do |t|
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 :#{sorted_model[0].pluralize}_#{sorted_model[1].pluralize}, [:#{sorted_model[0]}_id, :#{sorted_model[1]}_id]
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 => "ActiveRecord::Base")
35
- inject_into_file("app/models/#{sorted_model[1]}.rb", "\n has_and_belongs_to_many :#{sorted_model[0].pluralize}", :after => "ActiveRecord::Base")
36
- inject_into_file("app/models/#{sorted_model[0]}.rb", ":#{sorted_model[1]}_ids, ", :after => "attr_accessible ")
37
- inject_into_file("app/models/#{sorted_model[1]}.rb", ":#{sorted_model[0]}_ids, ", :after => "attr_accessible ")
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