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.
- checksums.yaml +5 -5
- data/.gitignore +2 -0
- data/CHANGELOG +73 -1
- data/Gemfile +25 -17
- 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 +112 -88
- data/lib/generators/beautiful_migration_generator.rb +14 -20
- data/lib/generators/beautiful_scaffold_common_methods.rb +92 -25
- data/lib/generators/beautiful_scaffold_generator.rb +164 -101
- 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 +7 -7
- data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +70 -47
- data/lib/generators/templates/app/assets/javascripts/bootstrap-datetimepicker-for-beautiful-scaffold.js +23 -42
- 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 +38 -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 +31 -14
- data/lib/generators/templates/app/controllers/master_base.rb +55 -47
- data/lib/generators/templates/app/controllers/user_sessions_controller.rb +20 -0
- data/lib/generators/templates/app/helpers/beautiful_helper.rb +122 -72
- data/lib/generators/templates/app/helpers/model_helper.rb +14 -3
- data/lib/generators/templates/app/initializers/link_renderer.rb +23 -18
- data/lib/generators/templates/app/initializers/ransack.rb +16 -0
- 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 +40 -31
- data/lib/generators/templates/app/views/_modal_columns.html.erb +4 -4
- data/lib/generators/templates/app/views/edit.html.erb +1 -3
- data/lib/generators/templates/app/views/index.html.erb +84 -58
- data/lib/generators/templates/app/views/layout.html.erb +36 -47
- 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 +7 -7
- data/lib/generators/templates/app/views/partials/_index_batch.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_index_column.html.erb +4 -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 +2 -2
- data/lib/generators/templates/app/views/partials/_index_search_default_fields.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 +3 -3
- data/lib/generators/templates/app/views/show.html.erb +2 -2
- data/lib/generators/templates/app/views/treeview.html.erb +8 -5
- metadata +41 -26
- data/lib/generators/beautiful_devisecancan_generator.rb +0 -128
- data/lib/generators/templates/app/assets/javascripts/bootstrap-datepicker.js +0 -834
- data/lib/generators/templates/app/assets/javascripts/bootstrap-timepicker.js +0 -797
- 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/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,33 +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
|
9
|
-
|
10
|
-
|
8
|
+
argument :name, :type => :string, :desc => "type of locale : fr, en, de, all"
|
9
|
+
|
10
|
+
class_option :mountable_engine, :default => nil
|
11
|
+
|
12
|
+
def list_locales
|
11
13
|
availablelocale = ["fr", "en", "ja"]
|
12
|
-
|
13
|
-
localestr = name.downcase
|
14
|
-
|
15
|
-
locale_to_process = []
|
16
14
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
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
|
31
30
|
end
|
32
31
|
|
33
32
|
rails_locale_file = "#{temp_locale}.yml"
|
@@ -39,7 +38,7 @@ class BeautifulLocaleGenerator < Rails::Generators::Base
|
|
39
38
|
end
|
40
39
|
|
41
40
|
willpaginate_locale_file = "will_paginate.#{temp_locale}.yml"
|
42
|
-
download_path = "https://raw.
|
41
|
+
download_path = "https://raw.githubusercontent.com/tigrish/will-paginate-i18n/master/config/locales/#{temp_locale}.yml"
|
43
42
|
begin
|
44
43
|
get download_path, "config/locales/#{willpaginate_locale_file}"
|
45
44
|
say_status("Warning", "You must modify Will_paginate locale at : Rails.root/config/locale/#{willpaginate_locale_file}", :red)
|
@@ -54,86 +53,112 @@ class BeautifulLocaleGenerator < Rails::Generators::Base
|
|
54
53
|
def regenerate_app_locale
|
55
54
|
require 'net/http'
|
56
55
|
|
57
|
-
|
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}::"
|
58
59
|
|
59
|
-
|
60
|
-
|
61
|
-
hi18n = YAML.load_file(filepath)
|
62
|
-
rescue
|
63
|
-
puts "Error loading locale file : #{filepath}"
|
64
|
-
end
|
60
|
+
already_processed = {}
|
61
|
+
hi18n = {}
|
65
62
|
|
66
|
-
|
67
|
-
|
68
|
-
hi18n[name.downcase]['app'] ||= { 'models' => {} }
|
69
|
-
hi18n[name.downcase]['app']['models'] ||= {}
|
63
|
+
list_locales.each do |locale_str|
|
64
|
+
locale = locale_str.downcase
|
70
65
|
|
71
|
-
|
72
|
-
hi18n[name.downcase]['app']['models'].each{ |modelname,hshtranslations|
|
73
|
-
hshtranslations['bs_attributes'].each{ |attr, translated_attr|
|
74
|
-
already_processed[name.downcase][attr] = translated_attr
|
75
|
-
}
|
76
|
-
}
|
77
|
-
|
78
|
-
Dir.glob("app/models/**/*").each { |model_file|
|
79
|
-
puts model_file
|
80
|
-
next if File.directory?(model_file) or File.basename(model_file).first == '.'
|
81
|
-
model = File.basename(model_file, File.extname(model_file))
|
82
|
-
klass = model.camelize.constantize
|
66
|
+
already_processed[locale] ||= {}
|
83
67
|
|
68
|
+
filepath = File.join(app_path, 'config', 'locales', "#{app_name}.#{locale}.yml")
|
84
69
|
begin
|
85
|
-
|
70
|
+
if File.exist?(filepath)
|
71
|
+
hi18n = YAML.load_file(filepath)
|
72
|
+
end
|
86
73
|
rescue
|
87
|
-
|
74
|
+
puts "Error loading locale file (YAML invalid?) : #{filepath}"
|
88
75
|
end
|
89
76
|
|
90
|
-
|
77
|
+
hi18n[locale] ||= { 'app' => {} }
|
78
|
+
hi18n[locale]['app'] ||= { 'models' => {} }
|
79
|
+
hi18n[locale]['app']['models'] ||= {}
|
91
80
|
|
92
|
-
|
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
|
+
|
88
|
+
Dir.glob("app/models/**/*").each do |model_file|
|
89
|
+
puts model_file
|
90
|
+
|
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')
|
96
|
+
|
97
|
+
model = File.basename(model_file, File.extname(model_file))
|
98
|
+
|
99
|
+
klass = "#{prefix}#{model}".camelize.constantize
|
100
|
+
sorted_attr = klass.attribute_names.sort
|
101
|
+
|
102
|
+
newmodel = !hi18n[locale]['app']['models'].has_key?(model)
|
103
|
+
|
104
|
+
hi18n[locale]['app']['models'][model] ||= {
|
93
105
|
'bs_caption' => model,
|
94
106
|
'bs_caption_plural' => model.pluralize,
|
95
107
|
'bs_attributes' => {},
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
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
|
101
125
|
|
102
|
-
|
103
|
-
|
104
|
-
|
126
|
+
hi18n[locale]['app']['models'][model]['bs_caption'] = bs_caption
|
127
|
+
hi18n[locale]['app']['models'][model]['bs_caption_plural'] = bs_caption_plural
|
128
|
+
end
|
105
129
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
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]
|
119
146
|
end
|
120
147
|
else
|
121
|
-
|
148
|
+
# Récupère l'attribut traduit
|
149
|
+
attr_translate = hi18n[locale]['app']['models'][model]['bs_attributes'][k]
|
122
150
|
end
|
123
|
-
else
|
124
|
-
# Récupère l'attribut traduit
|
125
|
-
attr_translate = hi18n[name.downcase]['app']['models'][model]['bs_attributes'][k]
|
126
|
-
end
|
127
151
|
|
128
|
-
|
129
|
-
|
130
|
-
|
152
|
+
hi18n[locale]['app']['models'][model]['bs_attributes'][k] = attr_translate
|
153
|
+
end
|
154
|
+
end
|
131
155
|
|
132
|
-
|
156
|
+
File.unlink(filepath) if File.exist?(filepath)
|
133
157
|
|
134
|
-
|
135
|
-
|
136
|
-
|
158
|
+
file = File.open(filepath, "w")
|
159
|
+
file.write(hi18n[locale].to_yaml)
|
160
|
+
file.close
|
161
|
+
end
|
137
162
|
end
|
138
163
|
|
139
164
|
private
|
@@ -141,14 +166,13 @@ class BeautifulLocaleGenerator < Rails::Generators::Base
|
|
141
166
|
def translate_string(locale, str)
|
142
167
|
# See http://www.microsofttranslator.com/dev/
|
143
168
|
#
|
144
|
-
if locale == "en"
|
169
|
+
if locale == "en"
|
145
170
|
attr_translate = "#{str.gsub(/_/, " ")}"
|
146
171
|
else
|
147
|
-
url_domain
|
148
|
-
|
172
|
+
url_domain = "api.mymemory.translated.net"
|
173
|
+
url_query = "/get?q=#{str.gsub(/_/, "%20")}&langpair=en%7C#{locale}"
|
149
174
|
|
150
|
-
|
151
|
-
json = JSON.parse(Net::HTTP.get(url_domain, urlstr))
|
175
|
+
json = JSON.parse(Net::HTTP.get(url_domain, url_query))
|
152
176
|
attr_translate = json["responseData"]["translatedText"].strip.downcase
|
153
177
|
end
|
154
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
|
@@ -3,35 +3,51 @@ module BeautifulScaffoldCommonMethods
|
|
3
3
|
|
4
4
|
private
|
5
5
|
|
6
|
+
#############
|
7
|
+
# Engine
|
8
|
+
#############
|
9
|
+
|
10
|
+
def engine_opt
|
11
|
+
options[:mountable_engine].to_s.downcase
|
12
|
+
end
|
13
|
+
|
14
|
+
def engine_name
|
15
|
+
engine_opt.blank? ? '' : "#{engine_opt}/"
|
16
|
+
end
|
17
|
+
|
18
|
+
def engine_camel
|
19
|
+
options[:mountable_engine].to_s.camelize
|
20
|
+
end
|
21
|
+
|
6
22
|
#############
|
7
23
|
# Namespace
|
8
24
|
#############
|
9
|
-
|
25
|
+
|
10
26
|
def namespace_for_class
|
11
27
|
str = namespace_alone
|
12
28
|
str = str.camelcase + '::' if not str.blank?
|
13
29
|
return str
|
14
30
|
end
|
15
|
-
|
31
|
+
|
16
32
|
def namespace_for_route
|
17
33
|
str = namespace_alone
|
18
34
|
str = str.downcase + '_' if not str.blank?
|
19
35
|
return str
|
20
36
|
end
|
21
|
-
|
37
|
+
|
22
38
|
def namespace_for_url
|
23
39
|
str = namespace_alone
|
24
40
|
str = str.downcase + '/' if not str.blank?
|
25
41
|
return str
|
26
42
|
end
|
27
|
-
|
43
|
+
|
28
44
|
def namespace_alone
|
29
45
|
return options[:namespace].to_s.downcase
|
30
46
|
end
|
31
47
|
|
32
48
|
def render_partial(path)
|
33
49
|
source = File.expand_path(find_in_source_paths(path.to_s))
|
34
|
-
result = ERB.new(::File.binread(source),
|
50
|
+
result = ERB.new(::File.binread(source), trim_mode: '-').result(binding)
|
35
51
|
return result
|
36
52
|
end
|
37
53
|
|
@@ -39,10 +55,18 @@ module BeautifulScaffoldCommonMethods
|
|
39
55
|
# Models
|
40
56
|
############
|
41
57
|
|
58
|
+
def model
|
59
|
+
model_opt.underscore
|
60
|
+
end
|
61
|
+
|
42
62
|
def model_camelize
|
43
63
|
model.camelize
|
44
64
|
end
|
45
65
|
|
66
|
+
def model_with_engine_camelize
|
67
|
+
(engine_name.blank? ? model.camelize : "#{engine_camel}::#{model_camelize}")
|
68
|
+
end
|
69
|
+
|
46
70
|
def model_pluralize
|
47
71
|
model.pluralize
|
48
72
|
end
|
@@ -50,7 +74,7 @@ module BeautifulScaffoldCommonMethods
|
|
50
74
|
def model_class
|
51
75
|
model.camelize
|
52
76
|
end
|
53
|
-
|
77
|
+
|
54
78
|
############
|
55
79
|
# Table
|
56
80
|
############
|
@@ -93,7 +117,7 @@ module BeautifulScaffoldCommonMethods
|
|
93
117
|
def available_views
|
94
118
|
%w(index edit show new _form)
|
95
119
|
end
|
96
|
-
|
120
|
+
|
97
121
|
def attributes
|
98
122
|
# https://raw.github.com/rails/rails/master/railties/lib/rails/generators/generated_attribute.rb
|
99
123
|
require 'rails/generators/generated_attribute'
|
@@ -103,19 +127,21 @@ module BeautifulScaffoldCommonMethods
|
|
103
127
|
}
|
104
128
|
end
|
105
129
|
|
106
|
-
def beautiful_attr_to_rails_attr(for_migration = false)
|
130
|
+
def beautiful_attr_to_rails_attr #(for_migration = false)
|
107
131
|
newmyattributes = []
|
108
132
|
myattributes.each{ |attr|
|
109
133
|
a,t = attr.split(':')
|
110
134
|
newt = t
|
111
|
-
|
135
|
+
|
136
|
+
# Special columns
|
137
|
+
if ['wysiwyg'].include?(t)
|
112
138
|
newt = 'text'
|
113
|
-
elsif t == 'price'
|
139
|
+
elsif t == 'price'
|
114
140
|
newt = 'float'
|
115
|
-
elsif ['references', 'reference'].include?(t)
|
116
|
-
a = a
|
141
|
+
elsif ['references', 'reference'].include?(t) # Because Rails generate corrupted files (migrations)
|
142
|
+
a = "#{a}_id"
|
117
143
|
newt = 'integer:index'
|
118
|
-
elsif t == 'color'
|
144
|
+
elsif t == 'color'
|
119
145
|
newt = 'string'
|
120
146
|
end
|
121
147
|
|
@@ -130,10 +156,15 @@ module BeautifulScaffoldCommonMethods
|
|
130
156
|
myattributes.each{ |attr|
|
131
157
|
a,t = attr.split(':')
|
132
158
|
|
133
|
-
if ['references', 'reference'].include?(t)
|
159
|
+
if ['references', 'reference'].include?(t)
|
134
160
|
a = a + '_id'
|
135
161
|
end
|
136
162
|
|
163
|
+
# Add the typetext to permitted_attr
|
164
|
+
if t == 'wysiwyg'
|
165
|
+
newmyattributes << "#{a}_typetext"
|
166
|
+
end
|
167
|
+
|
137
168
|
newmyattributes << a
|
138
169
|
}
|
139
170
|
|
@@ -144,7 +175,7 @@ module BeautifulScaffoldCommonMethods
|
|
144
175
|
fulltext_field = []
|
145
176
|
myattributes.each{ |attr|
|
146
177
|
a,t = attr.split(':')
|
147
|
-
if ['wysiwyg'].include?(t)
|
178
|
+
if ['wysiwyg'].include?(t)
|
148
179
|
fulltext_field << a
|
149
180
|
end
|
150
181
|
}
|
@@ -156,16 +187,52 @@ module BeautifulScaffoldCommonMethods
|
|
156
187
|
end
|
157
188
|
|
158
189
|
def require_gems
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
190
|
+
gems = {
|
191
|
+
'will_paginate' => nil, # v 3.1.5
|
192
|
+
'ransack' => nil, #'2.3.2',
|
193
|
+
'jquery-ui-rails' => nil,
|
194
|
+
'prawn' => nil, #'2.1.0',
|
195
|
+
'prawn-table' => nil, #'0.2.2',
|
196
|
+
'sanitize' => nil,
|
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',
|
200
|
+
'momentjs-rails' => '>= 2.9.0',
|
201
|
+
'bootstrap4-datetime-picker-rails' => nil,
|
202
|
+
'jquery-rails' => '4.3.1',
|
203
|
+
'jstree-rails-4' => '3.3.8'
|
204
|
+
}
|
205
|
+
|
206
|
+
# Si engine il faut mettre les gems dans le gemspec et faire le require
|
207
|
+
if !Dir.glob('./*.gemspec').empty?
|
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")}"
|
209
|
+
end
|
210
|
+
|
211
|
+
gemfile_content = File.read('Gemfile')
|
212
|
+
gems.each{ |gem_to_add, version|
|
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 ")
|
235
|
+
}
|
169
236
|
end
|
170
237
|
|
171
238
|
end
|