beautiful_scaffold 0.3.5 → 2.0.0.pre
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitattributes +2 -0
- data/.gitignore +1 -0
- data/CHANGELOG +66 -1
- data/Gemfile +24 -17
- data/Gemfile.lock +209 -0
- data/README.rdoc +56 -44
- data/Rakefile +32 -0
- data/beautiful_scaffold.gemspec +8 -5
- data/lib/beautiful_scaffold/version.rb +3 -0
- data/lib/generators/beautiful_devisecancan_generator.rb +1 -1
- data/lib/generators/beautiful_jointable_generator.rb +40 -7
- data/lib/generators/beautiful_locale_generator.rb +102 -80
- data/lib/generators/beautiful_migration_generator.rb +12 -20
- data/lib/generators/beautiful_scaffold_common_methods.rb +88 -29
- data/lib/generators/beautiful_scaffold_generator.rb +166 -111
- data/lib/generators/templates/app/assets/javascripts/application-bs.js +11 -19
- data/lib/generators/templates/app/assets/javascripts/beautiful_scaffold.js +68 -78
- 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 -12
- data/lib/generators/templates/app/assets/stylesheets/beautiful-scaffold.css.scss +36 -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 +32 -15
- data/lib/generators/templates/app/controllers/master_base.rb +55 -47
- data/lib/generators/templates/app/helpers/beautiful_helper.rb +104 -67
- data/lib/generators/templates/app/helpers/model_helper.rb +14 -3
- data/lib/generators/templates/app/initializers/link_renderer.rb +24 -17
- data/lib/generators/templates/app/initializers/ransack.rb +16 -0
- data/lib/generators/templates/app/locales/beautiful_scaffold.ja.yml +50 -0
- data/lib/generators/templates/app/models/concerns/fulltext_concern.rb +10 -10
- data/lib/generators/templates/app/views/_form.html.erb +5 -2
- 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 +29 -47
- 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 -33
- 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 -6
- 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 -4
- data/lib/generators/templates/app/views/partials/_index_search_default_fields.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_register_form.html.erb +2 -2
- data/lib/generators/templates/app/views/partials/_show_field.html.erb +3 -3
- data/lib/generators/templates/app/views/partials/_sign_in_form.html.erb +1 -1
- data/lib/generators/templates/app/views/partials/_sign_in_sign_out.html.erb +2 -2
- data/lib/generators/templates/app/views/show.html.erb +2 -2
- data/lib/generators/templates/app/views/treeview.html.erb +8 -5
- metadata +43 -188
- 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/javascripts/jquery.livequery.js +0 -226
- 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/markitup/jquery.markitup.js +0 -593
- data/lib/generators/templates/markitup/sets/bbcode/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/clean.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/code.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/fonts.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/list-item.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/quotes.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/stroke.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/images/underline.png +0 -0
- data/lib/generators/templates/markitup/sets/bbcode/readme.txt +0 -11
- data/lib/generators/templates/markitup/sets/bbcode/set.js +0 -39
- data/lib/generators/templates/markitup/sets/bbcode/style.css +0 -47
- data/lib/generators/templates/markitup/sets/default/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/clean.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/image.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/default/images/stroke.png +0 -0
- data/lib/generators/templates/markitup/sets/default/set.js +0 -30
- data/lib/generators/templates/markitup/sets/default/style.css +0 -34
- data/lib/generators/templates/markitup/sets/html/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/clean.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h1.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h2.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h3.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h4.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h5.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/h6.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/image.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/list-item.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/paragraph.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/html/images/stroke.png +0 -0
- data/lib/generators/templates/markitup/sets/html/readme.txt +0 -11
- data/lib/generators/templates/markitup/sets/html/set.js +0 -39
- data/lib/generators/templates/markitup/sets/html/style.css +0 -59
- data/lib/generators/templates/markitup/sets/markdown/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/code.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h1.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h2.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h3.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h4.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h5.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/h6.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/images/quotes.png +0 -0
- data/lib/generators/templates/markitup/sets/markdown/readme.txt +0 -11
- data/lib/generators/templates/markitup/sets/markdown/set.js +0 -52
- data/lib/generators/templates/markitup/sets/markdown/style.css +0 -54
- data/lib/generators/templates/markitup/sets/textile/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/code.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h1.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h2.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h3.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h4.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h5.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/h6.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/paragraph.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/quotes.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/images/stroke.png +0 -0
- data/lib/generators/templates/markitup/sets/textile/readme.txt +0 -11
- data/lib/generators/templates/markitup/sets/textile/set.js +0 -40
- data/lib/generators/templates/markitup/sets/textile/style.css +0 -60
- data/lib/generators/templates/markitup/sets/wiki/images/bold.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/code.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h1.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h2.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h3.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h4.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h5.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/h6.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/italic.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/link.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/list-bullet.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/list-numeric.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/picture.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/preview.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/quotes.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/stroke.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/images/url.png +0 -0
- data/lib/generators/templates/markitup/sets/wiki/readme.txt +0 -11
- data/lib/generators/templates/markitup/sets/wiki/set.js +0 -37
- data/lib/generators/templates/markitup/sets/wiki/style.css +0 -57
- data/lib/generators/templates/markitup/skins/markitup/images/bg-container.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-bbcode.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-dotclear.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-html.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-json.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-markdown.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-textile.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-wiki.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor-xml.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/bg-editor.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/handle.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/menu.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/images/submenu.png +0 -0
- data/lib/generators/templates/markitup/skins/markitup/style.css +0 -147
- data/lib/generators/templates/markitup/skins/simple/images/handle.png +0 -0
- data/lib/generators/templates/markitup/skins/simple/images/menu.png +0 -0
- data/lib/generators/templates/markitup/skins/simple/images/submenu.png +0 -0
- data/lib/generators/templates/markitup/skins/simple/style.css +0 -118
- data/lib/generators/templates/markitup/templates/preview.css +0 -5
- data/lib/generators/templates/markitup/templates/preview.html +0 -11
data/Rakefile
ADDED
@@ -0,0 +1,32 @@
|
|
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
|
+
|
20
|
+
load 'rails/tasks/statistics.rake'
|
21
|
+
|
22
|
+
require 'bundler/gem_tasks'
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
25
|
+
|
26
|
+
Rake::TestTask.new(:test) do |t|
|
27
|
+
t.libs << 'test'
|
28
|
+
t.pattern = 'test/**/*_test.rb'
|
29
|
+
t.verbose = false
|
30
|
+
end
|
31
|
+
|
32
|
+
task default: :test
|
data/beautiful_scaffold.gemspec
CHANGED
@@ -1,18 +1,21 @@
|
|
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/' }
|
16
|
+
s.licenses = ['MIT']
|
14
17
|
|
15
18
|
s.rubyforge_project = "beautiful_scaffold"
|
16
19
|
|
17
|
-
s.require_paths = ["lib","lib/generators"]
|
20
|
+
s.require_paths = ["lib","lib/generators","test/*"]
|
18
21
|
end
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# encoding : utf-8
|
2
2
|
class BeautifulDevisecancanGenerator < 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__)
|
@@ -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
8
|
argument :join_models, :type => :array, :default => [], :banner => "model model"
|
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
|
@@ -1,26 +1,23 @@
|
|
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 OR en OR de OR all..."
|
8
|
+
argument :name, :type => :string, :desc => "type of locale : fr OR en OR de OR ja all..."
|
9
|
+
|
10
|
+
class_option :mountable_engine, :default => nil
|
11
|
+
|
12
|
+
def list_locales
|
13
|
+
availablelocale = ["fr", "en", "ja"]
|
14
|
+
|
15
|
+
localestr = name.downcase
|
16
|
+
(localestr == 'all' ? availablelocale : [localestr])
|
17
|
+
end
|
9
18
|
|
10
19
|
def install_locale
|
11
|
-
|
12
|
-
|
13
|
-
localestr = name.downcase
|
14
|
-
|
15
|
-
locale_to_process = []
|
16
|
-
|
17
|
-
if localestr == 'all' then
|
18
|
-
locale_to_process = availablelocale
|
19
|
-
else
|
20
|
-
locale_to_process << localestr
|
21
|
-
end
|
22
|
-
|
23
|
-
locale_to_process.each{ |temp_locale|
|
20
|
+
list_locales.each{ |temp_locale|
|
24
21
|
filename = "beautiful_scaffold.#{temp_locale}.yml"
|
25
22
|
gem_localepath = "app/locales/#{filename}"
|
26
23
|
app_localepath = "config/locales/#{filename}"
|
@@ -54,86 +51,112 @@ class BeautifulLocaleGenerator < Rails::Generators::Base
|
|
54
51
|
def regenerate_app_locale
|
55
52
|
require 'net/http'
|
56
53
|
|
57
|
-
|
54
|
+
app_name = (Rails.root || engine_opt)
|
55
|
+
engine_or_apps = (Rails.application.class.parent_name || engine_opt).downcase
|
56
|
+
prefix = engine_opt.blank? ? '' : "#{engine_opt.camelize}::"
|
58
57
|
|
59
|
-
|
60
|
-
|
61
|
-
hi18n = YAML.load_file(filepath)
|
62
|
-
rescue
|
63
|
-
puts "Error loading locale file : #{filepath}"
|
64
|
-
end
|
65
|
-
|
66
|
-
hi18n ||= { name.downcase => {} }
|
67
|
-
hi18n[name.downcase] ||= { 'app' => {} }
|
68
|
-
hi18n[name.downcase]['app'] ||= { 'models' => {} }
|
69
|
-
hi18n[name.downcase]['app']['models'] ||= {}
|
58
|
+
already_processed = {}
|
59
|
+
hi18n = {}
|
70
60
|
|
71
|
-
|
72
|
-
|
73
|
-
hshtranslations['bs_attributes'].each{ |attr, translated_attr|
|
74
|
-
already_processed[name.downcase][attr] = translated_attr
|
75
|
-
}
|
76
|
-
}
|
61
|
+
list_locales.each do |locale_str|
|
62
|
+
locale = locale_str.downcase
|
77
63
|
|
78
|
-
|
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
|
64
|
+
already_processed[locale] ||= {}
|
83
65
|
|
66
|
+
filepath = File.join(app_name, 'config', 'locales', "#{engine_or_apps}.#{locale}.yml")
|
84
67
|
begin
|
85
|
-
|
68
|
+
if File.exist?(filepath)
|
69
|
+
hi18n = YAML.load_file(filepath)
|
70
|
+
end
|
86
71
|
rescue
|
87
|
-
|
72
|
+
puts "Error loading locale file (YAML invalid?) : #{filepath}"
|
88
73
|
end
|
89
74
|
|
90
|
-
|
75
|
+
hi18n[locale] ||= { 'app' => {} }
|
76
|
+
hi18n[locale]['app'] ||= { 'models' => {} }
|
77
|
+
hi18n[locale]['app']['models'] ||= {}
|
78
|
+
|
79
|
+
# Feed data already translated
|
80
|
+
hi18n[locale]['app']['models'].each do |modelname, hshtranslations|
|
81
|
+
hshtranslations['bs_attributes'].each do |attr, translated_attr|
|
82
|
+
already_processed[locale][attr] = translated_attr
|
83
|
+
end
|
84
|
+
end
|
91
85
|
|
92
|
-
|
86
|
+
Dir.glob("app/models/**/*").each do |model_file|
|
87
|
+
puts model_file
|
88
|
+
|
89
|
+
next if File.directory?(model_file) or
|
90
|
+
File.basename(model_file).first == '.' or
|
91
|
+
model_file.include?('/concerns/') or
|
92
|
+
model_file.include?('pdf_report.rb') or
|
93
|
+
model_file.include?('application_record.rb')
|
94
|
+
|
95
|
+
model = File.basename(model_file, File.extname(model_file))
|
96
|
+
|
97
|
+
klass = "#{prefix}#{model}".camelize.constantize
|
98
|
+
sorted_attr = klass.attribute_names.sort
|
99
|
+
|
100
|
+
newmodel = !hi18n[locale]['app']['models'].has_key?(model)
|
101
|
+
|
102
|
+
hi18n[locale]['app']['models'][model] ||= {
|
93
103
|
'bs_caption' => model,
|
94
104
|
'bs_caption_plural' => model.pluralize,
|
95
105
|
'bs_attributes' => {},
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
106
|
+
}
|
107
|
+
|
108
|
+
if newmodel then
|
109
|
+
bs_caption = ""
|
110
|
+
begin
|
111
|
+
bs_caption = translate_string(locale, model)
|
112
|
+
rescue Exception => e
|
113
|
+
puts "Erreur traduction #{e.backtrace}"
|
114
|
+
bs_caption = model
|
115
|
+
end
|
116
|
+
bs_caption_plural = ""
|
117
|
+
begin
|
118
|
+
bs_caption_plural = translate_string(locale, model.pluralize)
|
119
|
+
rescue Exception => e
|
120
|
+
puts "Erreur traduction #{e.backtrace}"
|
121
|
+
bs_caption_plural = model.pluralize
|
122
|
+
end
|
101
123
|
|
102
|
-
|
103
|
-
|
104
|
-
|
124
|
+
hi18n[locale]['app']['models'][model]['bs_caption'] = bs_caption
|
125
|
+
hi18n[locale]['app']['models'][model]['bs_caption_plural'] = bs_caption_plural
|
126
|
+
end
|
105
127
|
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
128
|
+
hi18n[locale]['app']['models'][model]['bs_attributes'] ||= {}
|
129
|
+
|
130
|
+
sorted_attr.each do |k|
|
131
|
+
# Si pas déjà renseigné
|
132
|
+
if hi18n[locale]['app']['models'][model]['bs_attributes'][k].blank?
|
133
|
+
# Si pas déjà traduit
|
134
|
+
if already_processed[locale][k].blank?
|
135
|
+
begin
|
136
|
+
attr_translate = translate_string(locale, k)
|
137
|
+
already_processed[locale][k] = attr_translate
|
138
|
+
rescue
|
139
|
+
puts "Plantage translate API"
|
140
|
+
attr_translate = k
|
141
|
+
end
|
142
|
+
else
|
143
|
+
attr_translate = already_processed[locale][k]
|
119
144
|
end
|
120
145
|
else
|
121
|
-
|
146
|
+
# Récupère l'attribut traduit
|
147
|
+
attr_translate = hi18n[locale]['app']['models'][model]['bs_attributes'][k]
|
122
148
|
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
149
|
|
128
|
-
|
129
|
-
|
130
|
-
|
150
|
+
hi18n[locale]['app']['models'][model]['bs_attributes'][k] = attr_translate
|
151
|
+
end
|
152
|
+
end
|
131
153
|
|
132
|
-
|
154
|
+
File.unlink(filepath) if File.exist?(filepath)
|
133
155
|
|
134
|
-
|
135
|
-
|
136
|
-
|
156
|
+
file = File.open(filepath, "w")
|
157
|
+
file.write(hi18n.to_yaml)
|
158
|
+
file.close
|
159
|
+
end
|
137
160
|
end
|
138
161
|
|
139
162
|
private
|
@@ -141,14 +164,13 @@ class BeautifulLocaleGenerator < Rails::Generators::Base
|
|
141
164
|
def translate_string(locale, str)
|
142
165
|
# See http://www.microsofttranslator.com/dev/
|
143
166
|
#
|
144
|
-
if locale == "en"
|
167
|
+
if locale == "en"
|
145
168
|
attr_translate = "#{str.gsub(/_/, " ")}"
|
146
169
|
else
|
147
|
-
url_domain
|
148
|
-
|
170
|
+
url_domain = "api.mymemory.translated.net"
|
171
|
+
url_query = "/get?q=#{str.gsub(/_/, "%20")}&langpair=en%7C#{locale}"
|
149
172
|
|
150
|
-
|
151
|
-
json = JSON.parse(Net::HTTP.get(url_domain, urlstr))
|
173
|
+
json = JSON.parse(Net::HTTP.get(url_domain, url_query))
|
152
174
|
attr_translate = json["responseData"]["translatedText"].strip.downcase
|
153
175
|
end
|
154
176
|
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 => "ActiveRecord::Base")
|
45
|
-
inject_into_file("app/models/#{a}.rb", "\n has_many :#{model_pluralize}, :dependent => :nullify", :after => "ActiveRecord::Base")
|
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,7 @@ class BeautifulMigrationGenerator < Rails::Generators::Base
|
|
68
60
|
private
|
69
61
|
|
70
62
|
def model
|
71
|
-
return name.scan(/^Add(.*)To(.*)$/).flatten[1].underscore.singularize
|
63
|
+
return name.scan(/^Add(.*)To(.*)$/).flatten[1].underscore.singularize.gsub("#{options[:mountable_engine].underscore}_",'')
|
72
64
|
end
|
73
65
|
|
74
66
|
end
|