beautiful_scaffold 1.0.1 → 2.0.2
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -1,35 +1,32 @@
|
|
1
1
|
# encoding : utf-8
|
2
2
|
class BeautifulLocaleGenerator < 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 :name, :type => :string, :desc => "type of locale : fr
|
8
|
+
argument :name, :type => :string, :desc => "type of locale : fr, en, de, all"
|
9
9
|
|
10
10
|
class_option :mountable_engine, :default => nil
|
11
|
-
|
12
|
-
def
|
11
|
+
|
12
|
+
def list_locales
|
13
13
|
availablelocale = ["fr", "en", "ja"]
|
14
|
-
|
15
|
-
localestr = name.downcase
|
16
|
-
|
17
|
-
locale_to_process = []
|
18
14
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
15
|
+
localestr = name.downcase
|
16
|
+
(localestr == 'all' ? availablelocale : [localestr])
|
17
|
+
end
|
18
|
+
|
19
|
+
def install_locale
|
20
|
+
list_locales.each{ |temp_locale|
|
21
|
+
|
22
|
+
["beautiful_scaffold.#{temp_locale}.yml"].each do |filename|
|
23
|
+
gem_localepath = "app/locales/#{filename}"
|
24
|
+
app_localepath = "config/locales/#{filename}"
|
25
|
+
begin
|
26
|
+
copy_file gem_localepath, app_localepath
|
27
|
+
rescue
|
28
|
+
say_status("Error", "This beautiful_locale #{temp_locale} doesn't exist !", :red)
|
29
|
+
end
|
33
30
|
end
|
34
31
|
|
35
32
|
rails_locale_file = "#{temp_locale}.yml"
|
@@ -41,7 +38,7 @@ class BeautifulLocaleGenerator < Rails::Generators::Base
|
|
41
38
|
end
|
42
39
|
|
43
40
|
willpaginate_locale_file = "will_paginate.#{temp_locale}.yml"
|
44
|
-
download_path = "https://raw.
|
41
|
+
download_path = "https://raw.githubusercontent.com/tigrish/will-paginate-i18n/master/config/locales/#{temp_locale}.yml"
|
45
42
|
begin
|
46
43
|
get download_path, "config/locales/#{willpaginate_locale_file}"
|
47
44
|
say_status("Warning", "You must modify Will_paginate locale at : Rails.root/config/locale/#{willpaginate_locale_file}", :red)
|
@@ -56,105 +53,112 @@ class BeautifulLocaleGenerator < Rails::Generators::Base
|
|
56
53
|
def regenerate_app_locale
|
57
54
|
require 'net/http'
|
58
55
|
|
59
|
-
|
56
|
+
app_path = (Rails.root || engine_opt)
|
57
|
+
app_name = Rails.application.class.name.split('::').first.downcase
|
58
|
+
prefix = engine_opt.blank? ? '' : "#{engine_opt.camelize}::"
|
60
59
|
|
61
|
-
|
62
|
-
|
60
|
+
already_processed = {}
|
61
|
+
hi18n = {}
|
63
62
|
|
64
|
-
|
65
|
-
|
66
|
-
puts "=======>"
|
67
|
-
puts engine_or_apps
|
63
|
+
list_locales.each do |locale_str|
|
64
|
+
locale = locale_str.downcase
|
68
65
|
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
66
|
+
already_processed[locale] ||= {}
|
67
|
+
|
68
|
+
filepath = File.join(app_path, 'config', 'locales', "#{app_name}.#{locale}.yml")
|
69
|
+
begin
|
70
|
+
if File.exist?(filepath)
|
71
|
+
hi18n = YAML.load_file(filepath)
|
72
|
+
end
|
73
|
+
rescue
|
74
|
+
puts "Error loading locale file (YAML invalid?) : #{filepath}"
|
75
|
+
end
|
75
76
|
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
hi18n[name.downcase]['app']['models'] ||= {}
|
77
|
+
hi18n[locale] ||= { 'app' => {} }
|
78
|
+
hi18n[locale]['app'] ||= { 'models' => {} }
|
79
|
+
hi18n[locale]['app']['models'] ||= {}
|
80
80
|
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
81
|
+
# Feed data already translated
|
82
|
+
hi18n[locale]['app']['models'].each do |modelname, hshtranslations|
|
83
|
+
hshtranslations['bs_attributes'].each do |attr, translated_attr|
|
84
|
+
already_processed[locale][attr] = translated_attr
|
85
|
+
end
|
86
|
+
end
|
87
87
|
|
88
|
-
|
89
|
-
|
90
|
-
next if File.directory?(model_file) or
|
91
|
-
File.basename(model_file).first == '.' or
|
92
|
-
model_file.include?('/concerns/') or
|
93
|
-
model_file.include?('pdf_report.rb') or
|
94
|
-
model_file.include?('application_record.rb')
|
88
|
+
Dir.glob("app/models/**/*").each do |model_file|
|
89
|
+
puts model_file
|
95
90
|
|
96
|
-
|
91
|
+
next if File.directory?(model_file) or
|
92
|
+
File.basename(model_file).first == '.' or
|
93
|
+
model_file.include?('/concerns/') or
|
94
|
+
model_file.include?('pdf_report.rb') or
|
95
|
+
model_file.include?('application_record.rb')
|
97
96
|
|
98
|
-
|
99
|
-
prefix = "#{engine_opt.camelize}::"
|
100
|
-
else
|
101
|
-
prefix = ''
|
102
|
-
end
|
103
|
-
klass = "#{prefix}#{model.camelize.constantize}"
|
97
|
+
model = File.basename(model_file, File.extname(model_file))
|
104
98
|
|
105
|
-
|
99
|
+
klass = "#{prefix}#{model}".camelize.constantize
|
106
100
|
sorted_attr = klass.attribute_names.sort
|
107
|
-
rescue
|
108
|
-
next
|
109
|
-
end
|
110
101
|
|
111
|
-
|
102
|
+
newmodel = !hi18n[locale]['app']['models'].has_key?(model)
|
112
103
|
|
113
|
-
|
104
|
+
hi18n[locale]['app']['models'][model] ||= {
|
114
105
|
'bs_caption' => model,
|
115
106
|
'bs_caption_plural' => model.pluralize,
|
116
107
|
'bs_attributes' => {},
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
108
|
+
}
|
109
|
+
|
110
|
+
if newmodel then
|
111
|
+
bs_caption = ""
|
112
|
+
begin
|
113
|
+
bs_caption = translate_string(locale, model)
|
114
|
+
rescue Exception => e
|
115
|
+
puts "Erreur traduction #{e.backtrace}"
|
116
|
+
bs_caption = model
|
117
|
+
end
|
118
|
+
bs_caption_plural = ""
|
119
|
+
begin
|
120
|
+
bs_caption_plural = translate_string(locale, model.pluralize)
|
121
|
+
rescue Exception => e
|
122
|
+
puts "Erreur traduction #{e.backtrace}"
|
123
|
+
bs_caption_plural = model.pluralize
|
124
|
+
end
|
122
125
|
|
123
|
-
|
124
|
-
|
125
|
-
|
126
|
+
hi18n[locale]['app']['models'][model]['bs_caption'] = bs_caption
|
127
|
+
hi18n[locale]['app']['models'][model]['bs_caption_plural'] = bs_caption_plural
|
128
|
+
end
|
126
129
|
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
130
|
+
hi18n[locale]['app']['models'][model]['bs_attributes'] ||= {}
|
131
|
+
|
132
|
+
sorted_attr.each do |k|
|
133
|
+
# Si pas déjà renseigné
|
134
|
+
if hi18n[locale]['app']['models'][model]['bs_attributes'][k].blank?
|
135
|
+
# Si pas déjà traduit
|
136
|
+
if already_processed[locale][k].blank?
|
137
|
+
begin
|
138
|
+
attr_translate = translate_string(locale, k)
|
139
|
+
already_processed[locale][k] = attr_translate
|
140
|
+
rescue
|
141
|
+
puts "Plantage translate API"
|
142
|
+
attr_translate = k
|
143
|
+
end
|
144
|
+
else
|
145
|
+
attr_translate = already_processed[locale][k]
|
140
146
|
end
|
141
147
|
else
|
142
|
-
|
148
|
+
# Récupère l'attribut traduit
|
149
|
+
attr_translate = hi18n[locale]['app']['models'][model]['bs_attributes'][k]
|
143
150
|
end
|
144
|
-
else
|
145
|
-
# Récupère l'attribut traduit
|
146
|
-
attr_translate = hi18n[name.downcase]['app']['models'][model]['bs_attributes'][k]
|
147
|
-
end
|
148
151
|
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
+
hi18n[locale]['app']['models'][model]['bs_attributes'][k] = attr_translate
|
153
|
+
end
|
154
|
+
end
|
152
155
|
|
153
|
-
|
156
|
+
File.unlink(filepath) if File.exist?(filepath)
|
154
157
|
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
+
file = File.open(filepath, "w")
|
159
|
+
file.write(hi18n[locale].to_yaml)
|
160
|
+
file.close
|
161
|
+
end
|
158
162
|
end
|
159
163
|
|
160
164
|
private
|
@@ -162,14 +166,13 @@ class BeautifulLocaleGenerator < Rails::Generators::Base
|
|
162
166
|
def translate_string(locale, str)
|
163
167
|
# See http://www.microsofttranslator.com/dev/
|
164
168
|
#
|
165
|
-
if locale == "en"
|
169
|
+
if locale == "en"
|
166
170
|
attr_translate = "#{str.gsub(/_/, " ")}"
|
167
171
|
else
|
168
|
-
url_domain
|
169
|
-
|
172
|
+
url_domain = "api.mymemory.translated.net"
|
173
|
+
url_query = "/get?q=#{str.gsub(/_/, "%20")}&langpair=en%7C#{locale}"
|
170
174
|
|
171
|
-
|
172
|
-
json = JSON.parse(Net::HTTP.get(url_domain, urlstr))
|
175
|
+
json = JSON.parse(Net::HTTP.get(url_domain, url_query))
|
173
176
|
attr_translate = json["responseData"]["translatedText"].strip.downcase
|
174
177
|
end
|
175
178
|
raise 'Free Limit' if attr_translate =~ /mymemory/
|
@@ -1,20 +1,21 @@
|
|
1
1
|
# encoding : utf-8
|
2
2
|
class BeautifulMigrationGenerator < Rails::Generators::Base
|
3
|
-
|
3
|
+
require_relative 'beautiful_scaffold_common_methods'
|
4
4
|
include BeautifulScaffoldCommonMethods
|
5
5
|
|
6
6
|
#include Rails::Generators::ResourceHelpers
|
7
7
|
|
8
8
|
source_root File.expand_path('../templates', __FILE__)
|
9
9
|
|
10
|
-
argument :name, :
|
11
|
-
argument :myattributes, :
|
10
|
+
argument :name, type: :string, desc: "Name of the migration (in CamelCase) AddXxxTo[Engine]Yyy (Yyy must be plural)"
|
11
|
+
argument :myattributes, type: :array, default: [], banner: "field:type field:type (for bt relation model:references)"
|
12
12
|
|
13
|
-
class_option :namespace, :
|
14
|
-
class_option :donttouchgem, :
|
13
|
+
class_option :namespace, default: nil
|
14
|
+
class_option :donttouchgem, default: nil
|
15
|
+
class_option :mountable_engine, default: nil
|
15
16
|
|
16
17
|
def install_gems
|
17
|
-
if options[:donttouchgem].blank?
|
18
|
+
if options[:donttouchgem].blank?
|
18
19
|
require_gems
|
19
20
|
end
|
20
21
|
end
|
@@ -24,7 +25,7 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
|
|
24
25
|
@fulltext_field = []
|
25
26
|
myattributes.each{ |attr|
|
26
27
|
a,t = attr.split(':')
|
27
|
-
if ['richtext', 'wysiwyg'].include?(t)
|
28
|
+
if ['richtext', 'wysiwyg'].include?(t)
|
28
29
|
# _typetext = {bbcode|html|text|wiki|textile|markdown}
|
29
30
|
# _fulltext = text without any code
|
30
31
|
@fulltext_field << [a + '_typetext', 'string'].join(':')
|
@@ -34,24 +35,15 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
|
|
34
35
|
end
|
35
36
|
|
36
37
|
def generate_model
|
37
|
-
generate("migration", "#{name} #{beautiful_attr_to_rails_attr
|
38
|
+
generate("migration", "#{name} #{beautiful_attr_to_rails_attr.join(' ')} #{@fulltext_field.join(' ')}")
|
38
39
|
end
|
39
40
|
|
40
41
|
def add_to_model
|
41
|
-
|
42
|
-
a,t = attr.split(':')
|
43
|
-
if ['references', 'reference'].include?(t) then
|
44
|
-
inject_into_file("app/models/#{model}.rb", "\n belongs_to :#{a}", :after => "ApplicationRecord")
|
45
|
-
inject_into_file("app/models/#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ApplicationRecord")
|
46
|
-
a += "_id"
|
47
|
-
end
|
48
|
-
|
49
|
-
inject_into_file("app/models/#{model}.rb", ":#{a},", :after => "def self.permitted_attributes\n return ")
|
50
|
-
}
|
42
|
+
add_relation
|
51
43
|
end
|
52
44
|
|
53
45
|
def generate_views
|
54
|
-
commonpath = "app/views/#{namespace_for_url}#{model_pluralize}/"
|
46
|
+
commonpath = "app/views/#{engine_name}#{namespace_for_url}#{model_pluralize}/"
|
55
47
|
|
56
48
|
# Form
|
57
49
|
inject_into_file("#{commonpath}_form.html.erb", render_partial("app/views/partials/_form_field.html.erb"), :before => "<!-- Beautiful_scaffold - AddField - Do not remove -->\n" )
|
@@ -68,7 +60,9 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
|
|
68
60
|
private
|
69
61
|
|
70
62
|
def model
|
71
|
-
|
63
|
+
model_extracted = name.scan(/^Add(.*)To(.*)$/).flatten[1].underscore.singularize
|
64
|
+
model_extracted = model_extracted.gsub("#{options[:mountable_engine].underscore}_",'') if !options[:mountable_engine].blank?
|
65
|
+
return model_extracted
|
72
66
|
end
|
73
67
|
|
74
68
|
end
|
@@ -8,7 +8,7 @@ module BeautifulScaffoldCommonMethods
|
|
8
8
|
#############
|
9
9
|
|
10
10
|
def engine_opt
|
11
|
-
options[:mountable_engine].to_s
|
11
|
+
options[:mountable_engine].to_s.downcase
|
12
12
|
end
|
13
13
|
|
14
14
|
def engine_name
|
@@ -16,38 +16,38 @@ module BeautifulScaffoldCommonMethods
|
|
16
16
|
end
|
17
17
|
|
18
18
|
def engine_camel
|
19
|
-
options[:mountable_engine].camelize
|
19
|
+
options[:mountable_engine].to_s.camelize
|
20
20
|
end
|
21
21
|
|
22
22
|
#############
|
23
23
|
# Namespace
|
24
24
|
#############
|
25
|
-
|
25
|
+
|
26
26
|
def namespace_for_class
|
27
27
|
str = namespace_alone
|
28
28
|
str = str.camelcase + '::' if not str.blank?
|
29
29
|
return str
|
30
30
|
end
|
31
|
-
|
31
|
+
|
32
32
|
def namespace_for_route
|
33
33
|
str = namespace_alone
|
34
34
|
str = str.downcase + '_' if not str.blank?
|
35
35
|
return str
|
36
36
|
end
|
37
|
-
|
37
|
+
|
38
38
|
def namespace_for_url
|
39
39
|
str = namespace_alone
|
40
40
|
str = str.downcase + '/' if not str.blank?
|
41
41
|
return str
|
42
42
|
end
|
43
|
-
|
43
|
+
|
44
44
|
def namespace_alone
|
45
45
|
return options[:namespace].to_s.downcase
|
46
46
|
end
|
47
47
|
|
48
48
|
def render_partial(path)
|
49
49
|
source = File.expand_path(find_in_source_paths(path.to_s))
|
50
|
-
result = ERB.new(::File.binread(source),
|
50
|
+
result = ERB.new(::File.binread(source), trim_mode: '-').result(binding)
|
51
51
|
return result
|
52
52
|
end
|
53
53
|
|
@@ -74,7 +74,7 @@ module BeautifulScaffoldCommonMethods
|
|
74
74
|
def model_class
|
75
75
|
model.camelize
|
76
76
|
end
|
77
|
-
|
77
|
+
|
78
78
|
############
|
79
79
|
# Table
|
80
80
|
############
|
@@ -117,7 +117,7 @@ module BeautifulScaffoldCommonMethods
|
|
117
117
|
def available_views
|
118
118
|
%w(index edit show new _form)
|
119
119
|
end
|
120
|
-
|
120
|
+
|
121
121
|
def attributes
|
122
122
|
# https://raw.github.com/rails/rails/master/railties/lib/rails/generators/generated_attribute.rb
|
123
123
|
require 'rails/generators/generated_attribute'
|
@@ -127,19 +127,21 @@ module BeautifulScaffoldCommonMethods
|
|
127
127
|
}
|
128
128
|
end
|
129
129
|
|
130
|
-
def beautiful_attr_to_rails_attr(for_migration = false)
|
130
|
+
def beautiful_attr_to_rails_attr #(for_migration = false)
|
131
131
|
newmyattributes = []
|
132
132
|
myattributes.each{ |attr|
|
133
133
|
a,t = attr.split(':')
|
134
134
|
newt = t
|
135
|
-
|
135
|
+
|
136
|
+
# Special columns
|
137
|
+
if ['wysiwyg'].include?(t)
|
136
138
|
newt = 'text'
|
137
|
-
elsif t == 'price'
|
139
|
+
elsif t == 'price'
|
138
140
|
newt = 'float'
|
139
|
-
elsif ['references', 'reference'].include?(t)
|
140
|
-
a = a
|
141
|
+
elsif ['references', 'reference'].include?(t) # Because Rails generate corrupted files (migrations)
|
142
|
+
a = "#{a}_id"
|
141
143
|
newt = 'integer:index'
|
142
|
-
elsif t == 'color'
|
144
|
+
elsif t == 'color'
|
143
145
|
newt = 'string'
|
144
146
|
end
|
145
147
|
|
@@ -154,10 +156,15 @@ module BeautifulScaffoldCommonMethods
|
|
154
156
|
myattributes.each{ |attr|
|
155
157
|
a,t = attr.split(':')
|
156
158
|
|
157
|
-
if ['references', 'reference'].include?(t)
|
159
|
+
if ['references', 'reference'].include?(t)
|
158
160
|
a = a + '_id'
|
159
161
|
end
|
160
162
|
|
163
|
+
# Add the typetext to permitted_attr
|
164
|
+
if t == 'wysiwyg'
|
165
|
+
newmyattributes << "#{a}_typetext"
|
166
|
+
end
|
167
|
+
|
161
168
|
newmyattributes << a
|
162
169
|
}
|
163
170
|
|
@@ -168,7 +175,7 @@ module BeautifulScaffoldCommonMethods
|
|
168
175
|
fulltext_field = []
|
169
176
|
myattributes.each{ |attr|
|
170
177
|
a,t = attr.split(':')
|
171
|
-
if ['wysiwyg'].include?(t)
|
178
|
+
if ['wysiwyg'].include?(t)
|
172
179
|
fulltext_field << a
|
173
180
|
end
|
174
181
|
}
|
@@ -181,18 +188,19 @@ module BeautifulScaffoldCommonMethods
|
|
181
188
|
|
182
189
|
def require_gems
|
183
190
|
gems = {
|
184
|
-
'less-rails' => '2.8.0',
|
185
191
|
'will_paginate' => nil, # v 3.1.5
|
186
|
-
'ransack' => '
|
187
|
-
'polyamorous' => '1.3.1',
|
192
|
+
'ransack' => nil, #'2.3.2',
|
188
193
|
'jquery-ui-rails' => nil,
|
189
|
-
'prawn' => '2.1.0',
|
190
|
-
'prawn-table' => '0.2.2',
|
194
|
+
'prawn' => nil, #'2.1.0',
|
195
|
+
'prawn-table' => nil, #'0.2.2',
|
191
196
|
'sanitize' => nil,
|
192
|
-
'twitter-bootstrap-rails' => '3.2.2',
|
193
|
-
'
|
197
|
+
#'twitter-bootstrap-rails' => '3.2.2', # Bootstrap 3 for Rails 6+
|
198
|
+
'bootstrap' => '~> 4.3.1', # Bootstrap 4 for Rails 6+
|
199
|
+
'font-awesome-sass' => '~> 5.13.0',
|
194
200
|
'momentjs-rails' => '>= 2.9.0',
|
195
|
-
'
|
201
|
+
'bootstrap4-datetime-picker-rails' => nil,
|
202
|
+
'jquery-rails' => '4.3.1',
|
203
|
+
'jstree-rails-4' => '3.3.8'
|
196
204
|
}
|
197
205
|
|
198
206
|
# Si engine il faut mettre les gems dans le gemspec et faire le require
|
@@ -200,8 +208,30 @@ module BeautifulScaffoldCommonMethods
|
|
200
208
|
puts "============> Engine : You must add gems to your main app \n #{gems.to_a.map{ |a| "gem '#{a[0]}'#{(a[1].nil? ? '' : ", '#{a[1]}'")} " }.join("\n")}"
|
201
209
|
end
|
202
210
|
|
211
|
+
gemfile_content = File.read('Gemfile')
|
203
212
|
gems.each{ |gem_to_add, version|
|
204
|
-
|
213
|
+
# Bug add at every times, need to check if already present
|
214
|
+
if !gemfile_content.include?(gem_to_add)
|
215
|
+
gem(gem_to_add, version)
|
216
|
+
end
|
217
|
+
}
|
218
|
+
end
|
219
|
+
|
220
|
+
def add_relation
|
221
|
+
myattributes.each{ |attr|
|
222
|
+
a,t = attr.split(':')
|
223
|
+
|
224
|
+
foreign_key = a
|
225
|
+
|
226
|
+
if ['references', 'reference'].include?(t)
|
227
|
+
foreign_key = "#{a}_id"
|
228
|
+
|
229
|
+
# question (model) belongs_to user (a)
|
230
|
+
inject_into_file("app/models/#{engine_name}#{model}.rb", "\n belongs_to :#{a}, optional: true", :after => "ApplicationRecord")
|
231
|
+
inject_into_file("app/models/#{engine_name}#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ApplicationRecord")
|
232
|
+
end
|
233
|
+
|
234
|
+
inject_into_file("app/models/#{engine_name}#{model}.rb", ":#{foreign_key},", :after => "def self.permitted_attributes\n return ")
|
205
235
|
}
|
206
236
|
end
|
207
237
|
|