toronto 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fc86ef95f32e371597fa9a8ef03e6cee559ec574
4
- data.tar.gz: 021a63731b9e21901560d8531374c025c7a4f004
3
+ metadata.gz: 469462cba899157c14258af42ec9870165faa9c2
4
+ data.tar.gz: 43dea86b4a955b54335441dc917dab88185d136e
5
5
  SHA512:
6
- metadata.gz: 6cc1a08d590d87841dbc706767b9713db7befa06ece9dfbcf8f7f269a1993d1377b1c03701d1b6bdae69c25300d1ce9c8a6d191533270eb2754f7d5666fc97df
7
- data.tar.gz: e47e69e24e0676339517c2913de878fb9bc33c8d94a8a9e34f04836b235e1cd16b98918918dc5c77bb83505e33d4fcebf1ca0c1a7af3d3e61cc8793a377c1c22
6
+ metadata.gz: '028a6e9e281aeb522e7a8e149fd4d749d8d6132ff1c9d1f2c2567471bd5c0d363973846a9e51aaafe6eedab51b54a484bde0fdadc35968671ca76f1520e6619e'
7
+ data.tar.gz: 19ed3b651a491660f1ea1d0afe7c0b742ea7bada0d2b39be3dfb19e70bfa0b6387b46ded030c3c33739470f37dd719a2506ebfd1f4d51372ae5005de2312d0fb
data/README.md CHANGED
@@ -27,7 +27,7 @@ Run bundle install:
27
27
 
28
28
  ## Generators
29
29
 
30
- Get started:
30
+ Get started:
31
31
 
32
32
  rails generate toronto:install
33
33
 
@@ -54,7 +54,11 @@ To print the options and usage run the command `rails toronto:install --help`
54
54
  -se, [--stylesheet-engine=STYLESHEET_ENGINE] # Indicates when to generate stylesheet engine
55
55
  # Default: scss
56
56
  [--skip-turbolinks], [--no-skip-turbolinks] # Indicates when to generate skip turbolinks
57
-
57
+ [--languages=LANGUAGES_LIST] # Indicates wich languages to use
58
+ # Use --languages=en,fr,de,cn for english, french, german and chineese (the only languages that are implemented)
59
+ # The first language in the list will be the default language in rails.
60
+ # If option not given, then only the language english is generated
61
+
58
62
  Runtime options:
59
63
  -f, [--force] # Overwrite files that already exist
60
64
  -p, [--pretend], [--no-pretend] # Run but do not make any changes
@@ -9,6 +9,7 @@ module Toronto
9
9
  class_option :template_engine
10
10
  class_option :stylesheet_engine
11
11
  class_option :skip_turbolinks, type: :boolean, default: false, desc: "Skip Turbolinks on assets"
12
+ class_option :languages
12
13
 
13
14
  def copy_scaffold_generator
14
15
  directory 'lib/rails'
@@ -18,6 +19,10 @@ module Toronto
18
19
  directory "lib/templates/#{options[:template_engine]}"
19
20
  end
20
21
 
22
+ def copy_langs
23
+ directory 'lib/templates/lang', 'lib/rails/generators/lang'
24
+ end
25
+
21
26
  def copy_form_builder
22
27
  copy_file "form_builders/form_builder/_form.html.#{options[:template_engine]}", "lib/templates/#{options[:template_engine]}/scaffold/_form.html.#{options[:template_engine]}"
23
28
  end
@@ -41,8 +46,7 @@ module Toronto
41
46
  end
42
47
  end
43
48
 
44
- def copy_locale_files
45
- copy_file 'config/initializers/locales.rb', 'config/initializers/locales.rb'
49
+ def copy_locales_controller
46
50
  copy_file 'controllers/locales_controller.rb', 'app/controllers/locales_controller.rb'
47
51
  end
48
52
 
@@ -50,20 +54,41 @@ module Toronto
50
54
  # TODO : use a template file
51
55
  data = %{
52
56
  def set_locale
53
- I18n.locale = session[:locale] || I18n.default_locale
57
+ I18n.locale = params[:locale] || I18n.default_locale
54
58
  end
55
59
  }
56
- insert_into_file 'app/controllers/application_controller.rb', data, :before => /^end/
60
+ inject_into_file 'app/controllers/application_controller.rb', data, :before => /^end/
57
61
 
58
62
  data = "\n before_action :set_locale"
59
- insert_into_file 'app/controllers/application_controller.rb', data, :after => /^class ApplicationController < ActionController::Base/
63
+ inject_into_file 'app/controllers/application_controller.rb', data, :after => /^class ApplicationController < ActionController::Base/
60
64
  end
61
65
 
62
66
  def inject_locales_route
63
- route = "\n put 'set_locale/:locale', constraints: { locale: /en|fr/ }, to: 'locales#set'\n"
64
- insert_into_file 'config/routes.rb', route, :before => /^end/
67
+ p options
68
+ langs = !options['languages'] || options['languages'].empty? ? 'en' : options['languages']
69
+ langs_array = langs.split(',' )
70
+ langs.gsub!( ',', '|' )
71
+
72
+ # Create the routes for language management
73
+ # This way lead to a lot of problem. We use ?locale=
74
+ # route 'end'
75
+ # route ' # Put all your routes inside the scope'
76
+ # route "scope '(:locale)', locale: /#{langs}/ do"
77
+
78
+ # Create the local file
79
+ data = "I18n.config.load_path += Dir['#{Rails.root.to_s}/config/locales/**/*.{rb,yml}']\n\n"
80
+ data << "I18n.config.available_locales = [ #{langs_array.map{ |e| ':'+e }.join( ', ' )} ]\n"
81
+ data << "I18n.default_locale = :#{langs_array.first}"
82
+
83
+ create_file 'config/initializers/locales.rb', data
84
+
85
+ route "put 'set_locale/:locale', constraints: { locale: /#{langs}/ }, to: 'locales#set'"
65
86
  end
66
87
 
88
+ # def disable_regular_routes_generation
89
+ # create_file 'config/initializers/generators.rb', 'Rails.application.config.generators.skip_routes = true'
90
+ # end
91
+
67
92
  def inject_menu_helper
68
93
  # TODO : use a template file
69
94
  data = %{
@@ -1,14 +1,25 @@
1
1
  class LocalesController < ApplicationController
2
2
 
3
3
  def set
4
- # TODO : implement it this way : https://lingohub.com/frameworks-file-formats/rails5-i18n-ruby-on-rails/
4
+ # implement it this way : https://lingohub.com/frameworks-file-formats/rails5-i18n-ruby-on-rails/
5
+ # Lead to a lot of problems
5
6
 
6
- session[:return_to] ||= request.referer
7
+ if params[:locale]
8
+ I18n.locale = params[:locale]
9
+ return_to = request.referer
7
10
 
8
- # I18n.locale = params[:locale] || I18n.default_locale
9
- session[:locale] = params[:locale]
11
+ parsed_uri = URI.parse(return_to)
12
+ params = parsed_uri.query ? CGI::parse( parsed_uri.query ) : {}
13
+ params['locale'] = I18n.locale
10
14
 
11
- redirect_to session.delete(:return_to)
15
+ redirect_host = parsed_uri.scheme + '://' + parsed_uri.host
16
+ redirect_host += ( ':' + parsed_uri.port.to_s ) if parsed_uri.port && parsed_uri.port != 80 && parsed_uri.port != 443
17
+ redirect_host += parsed_uri.path
18
+
19
+ redirect_host += ( '?' + URI.encode_www_form(params) )
20
+
21
+ redirect_to redirect_host
22
+ end
12
23
  end
13
24
 
14
25
  end
@@ -40,6 +40,10 @@
40
40
  %span{ class: 'flag flag-gb' }
41
41
  = link_to '/set_locale/fr', method: :put do
42
42
  %span{ class: 'flag flag-fr' }
43
+ = link_to '/set_locale/de', method: :put do
44
+ %span{ class: 'flag flag-de' }
45
+ = link_to '/set_locale/cn', method: :put do
46
+ %span{ class: 'flag flag-cn' }
43
47
  .container
44
48
  - flash.each do |name, msg|
45
49
  = content_tag :div, class: "alert alert-#{name == :error ? 'danger' : 'success' } alert-dismissable", role: 'alert' do
@@ -4,17 +4,20 @@ require 'yaml'
4
4
  module Haml
5
5
  module Generators
6
6
  class ScaffoldGenerator < Erb::Generators::ScaffoldGenerator
7
- source_root File.expand_path("../templates", __FILE__)
7
+ source_root File.expand_path('../templates', __FILE__)
8
8
 
9
9
  def copy_view_files
10
10
  available_views.each do |view|
11
11
  filename = filename_with_extensions(view)
12
- template "#{view}.html.haml", File.join("app/views", controller_file_path, filename)
12
+ template "#{view}.html.haml", File.join('app/views', controller_file_path, filename)
13
13
  end
14
14
  end
15
15
 
16
16
  def copy_and_update_languages_files
17
- languages = %w( en fr )
17
+
18
+ languages = I18n.config.available_locales.map(&:to_s)
19
+ # source_paths << File.expand_path('../rails/lang', __FILE__)
20
+ source_paths << ::Rails.root + 'lib/rails/generators/lang'
18
21
 
19
22
  languages.each do |lang|
20
23
  yaml_path = File.join( 'config/locales', lang, "#{plural_table_name}.yml" )
@@ -54,6 +57,10 @@ module Haml
54
57
  insert_into_file 'app/views/layouts/application.html.haml', data, :after => '%ul.nav.navbar-nav'
55
58
  end
56
59
 
60
+ # def add_ressource_route
61
+ # inject_into_file 'config/routes.rb', "\n resources :#{plural_table_name}", after: /scope.*do/, verbose: false, force: false
62
+ # end
63
+
57
64
  protected
58
65
 
59
66
  def available_views
@@ -1,5 +1,5 @@
1
1
  .page-header
2
- = link_to new_<%= singular_table_name %>_path, class: 'btn btn-primary' do
2
+ = link_to new_<%= singular_table_name %>_path( locale: I18n.locale ), class: 'btn btn-primary' do
3
3
  %span.glyphicon.glyphicon-plus
4
4
  = t( '.new' )
5
5
  %h1= t( '.title' )
@@ -0,0 +1,23 @@
1
+ cn:
2
+ <%= plural_table_name %>:
3
+ index:
4
+ title: 目录
5
+ edit: 编辑
6
+ new: 新
7
+ show: 显示
8
+ delete: 删除
9
+ confirm: 你确定
10
+ edit:
11
+ title: 编辑
12
+ back: 以前
13
+ show: 显示
14
+ show:
15
+ title: 显示
16
+ back: 以前
17
+ edit: 编辑
18
+ new:
19
+ title: 新
20
+ back: 以前
21
+ form:
22
+ submit: 提交
23
+
@@ -0,0 +1,23 @@
1
+ de:
2
+ <%= plural_table_name %>:
3
+ index:
4
+ title: Liste
5
+ edit: Bearbeiten
6
+ new: Neu
7
+ show: Zeigen
8
+ delete: Entfernen
9
+ confirm: Sind sie sicher ?
10
+ edit:
11
+ title: Bearbeiten
12
+ back: Zurück
13
+ show: Zeigen
14
+ show:
15
+ title: Zeigen
16
+ back: Zurück
17
+ edit: Bearbeiten
18
+ new:
19
+ title: Neu
20
+ back: Zurück
21
+ form:
22
+ submit: Ubernehmen
23
+
@@ -1,3 +1,3 @@
1
1
  module Toronto
2
- VERSION = '0.0.3'
2
+ VERSION = '0.0.4'
3
3
  end
data/toronto.gemspec CHANGED
@@ -9,7 +9,7 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Cédric Zuger']
10
10
  spec.email = ['zuger.cedric@gmail.com']
11
11
  spec.summary = 'inTernatiOnalization Ready bOotstrap geNeraTOr'
12
- spec.description = 'This is a fork of Twitter Bootstrap generators where static fields are translated fields.'
12
+ spec.description = 'Internationalized bootstrap ready scaffold generator'
13
13
  spec.homepage = 'https://github.com/czuger/toronto'
14
14
  spec.license = 'MIT'
15
15
 
@@ -21,10 +21,13 @@ Gem::Specification.new do |spec|
21
21
  spec.require_paths = ['lib']
22
22
 
23
23
  spec.add_development_dependency 'bundler', '~> 1.5'
24
- spec.add_development_dependency 'rake'
24
+ spec.add_development_dependency 'rake', '~> 12'
25
25
  # spec.add_development_dependency 'haml-rails', '>= 0.9.0'
26
26
 
27
- spec.add_runtime_dependency 'railties', '~> 3.1'
27
+ spec.add_runtime_dependency 'railties', '~> 5'
28
+ spec.add_runtime_dependency 'bootstrap-sass', '~> 3.2', '>= 3.2.0'
28
29
  # spec.add_runtime_dependency 'haml-rails', '>= 0.9.0'
29
30
 
31
+ spec.required_ruby_version = '>= 2.3'
32
+
30
33
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: toronto
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cédric Zuger
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-26 00:00:00.000000000 Z
11
+ date: 2018-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -28,32 +28,51 @@ dependencies:
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '12'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '12'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: railties
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.1'
47
+ version: '5'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: bootstrap-sass
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.2'
62
+ - - ">="
63
+ - !ruby/object:Gem::Version
64
+ version: 3.2.0
48
65
  type: :runtime
49
66
  prerelease: false
50
67
  version_requirements: !ruby/object:Gem::Requirement
51
68
  requirements:
52
69
  - - "~>"
53
70
  - !ruby/object:Gem::Version
54
- version: '3.1'
55
- description: This is a fork of Twitter Bootstrap generators where static fields are
56
- translated fields.
71
+ version: '3.2'
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ version: 3.2.0
75
+ description: Internationalized bootstrap ready scaffold generator
57
76
  email:
58
77
  - zuger.cedric@gmail.com
59
78
  executables: []
@@ -75,7 +94,6 @@ files:
75
94
  - lib/generators/toronto/install/templates/assets/stylesheets/starter.css
76
95
  - lib/generators/toronto/install/templates/assets/stylesheets/starter.less
77
96
  - lib/generators/toronto/install/templates/assets/stylesheets/starter.scss
78
- - lib/generators/toronto/install/templates/config/initializers/locales.rb
79
97
  - lib/generators/toronto/install/templates/controllers/locales_controller.rb
80
98
  - lib/generators/toronto/install/templates/form_builders/form_builder/_form.html.erb
81
99
  - lib/generators/toronto/install/templates/form_builders/form_builder/_form.html.haml
@@ -92,11 +110,13 @@ files:
92
110
  - lib/generators/toronto/install/templates/lib/templates/erb/scaffold/show.html.erb
93
111
  - lib/generators/toronto/install/templates/lib/templates/haml/controller/view.html.haml
94
112
  - lib/generators/toronto/install/templates/lib/templates/haml/scaffold/edit.html.haml
95
- - lib/generators/toronto/install/templates/lib/templates/haml/scaffold/en.yml
96
- - lib/generators/toronto/install/templates/lib/templates/haml/scaffold/fr.yml
97
113
  - lib/generators/toronto/install/templates/lib/templates/haml/scaffold/index.html.haml
98
114
  - lib/generators/toronto/install/templates/lib/templates/haml/scaffold/new.html.haml
99
115
  - lib/generators/toronto/install/templates/lib/templates/haml/scaffold/show.html.haml
116
+ - lib/generators/toronto/install/templates/lib/templates/lang/cn.yml
117
+ - lib/generators/toronto/install/templates/lib/templates/lang/de.yml
118
+ - lib/generators/toronto/install/templates/lib/templates/lang/en.yml
119
+ - lib/generators/toronto/install/templates/lib/templates/lang/fr.yml
100
120
  - lib/generators/toronto/install/templates/lib/templates/slim/controller/view.html.slim
101
121
  - lib/generators/toronto/install/templates/lib/templates/slim/scaffold/edit.html.slim
102
122
  - lib/generators/toronto/install/templates/lib/templates/slim/scaffold/index.html.slim
@@ -291,7 +311,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
291
311
  requirements:
292
312
  - - ">="
293
313
  - !ruby/object:Gem::Version
294
- version: '0'
314
+ version: '2.3'
295
315
  required_rubygems_version: !ruby/object:Gem::Requirement
296
316
  requirements:
297
317
  - - ">="
@@ -299,7 +319,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
299
319
  version: '0'
300
320
  requirements: []
301
321
  rubyforge_project:
302
- rubygems_version: 2.6.9
322
+ rubygems_version: 2.6.13
303
323
  signing_key:
304
324
  specification_version: 4
305
325
  summary: inTernatiOnalization Ready bOotstrap geNeraTOr
@@ -1,4 +0,0 @@
1
- I18n.config.load_path += Dir["#{Rails.root.to_s}/config/locales/**/*.{rb,yml}"]
2
-
3
- I18n.config.available_locales = [ :en, :fr ]
4
- I18n.default_locale = :en