tmatt_cms 0.0.0 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/generators/tmatt_cms/install_generator.rb +316 -0
- data/lib/generators/tmatt_cms/templates/.keep +0 -0
- data/lib/generators/tmatt_cms/templates/concerns/db_init.rb +12 -0
- data/lib/generators/tmatt_cms/templates/concerns/pretty_url.rb +38 -0
- data/lib/generators/tmatt_cms/templates/concerns/string_addition.rb +8 -0
- data/lib/generators/tmatt_cms/templates/concerns/translatable.rb +43 -0
- data/lib/generators/tmatt_cms/templates/config/application.rb +41 -0
- data/lib/generators/tmatt_cms/templates/config/application.yml +12 -0
- data/lib/generators/tmatt_cms/templates/config/initializers/active_job.rb +3 -0
- data/lib/generators/tmatt_cms/templates/config/locales/views/dashboard/en.yml +11 -0
- data/lib/generators/tmatt_cms/templates/config/locales/views/dashboard/zh.yml +11 -0
- data/lib/generators/tmatt_cms/templates/config/locales/views/global/en.yml +2 -0
- data/lib/generators/tmatt_cms/templates/config/locales/views/global/zh.yml +2 -0
- data/lib/generators/tmatt_cms/templates/css/application/application.css +18 -0
- data/lib/generators/tmatt_cms/templates/css/application/ckeditor.css.scss +4 -0
- data/lib/generators/tmatt_cms/templates/css/application/index.css.scss +40 -0
- data/lib/generators/tmatt_cms/templates/css/application/magnific_popup_rails.css.scss +45 -0
- data/lib/generators/tmatt_cms/templates/css/application/main.css.scss +0 -0
- data/lib/generators/tmatt_cms/templates/css/application/mixin.css.scss +43 -0
- data/lib/generators/tmatt_cms/templates/css/application/variables.css.scss +55 -0
- data/lib/generators/tmatt_cms/templates/css/application/z_index.css.scss +2 -0
- data/lib/generators/tmatt_cms/templates/css/layouts/footer.css.scss +3 -0
- data/lib/generators/tmatt_cms/templates/css/layouts/form.css.scss +3 -0
- data/lib/generators/tmatt_cms/templates/css/layouts/header.css.scss +0 -0
- data/lib/generators/tmatt_cms/templates/css/style.css.scss +242 -0
- data/lib/generators/tmatt_cms/templates/css/utils/jasny-bootstrap.min.css +7 -0
- data/lib/generators/tmatt_cms/templates/gemfile/Gemfile +128 -0
- data/lib/generators/tmatt_cms/templates/git_ignore/gitignore +29 -0
- data/lib/generators/tmatt_cms/templates/inputs/ckeditor_translation_input.rb +11 -0
- data/lib/generators/tmatt_cms/templates/inputs/concerns/translation_hint.rb +12 -0
- data/lib/generators/tmatt_cms/templates/inputs/translation_input.rb +11 -0
- data/lib/generators/tmatt_cms/templates/js/application.js +23 -0
- data/lib/generators/tmatt_cms/templates/js/utils/jasny-bootstrap.min.js +6 -0
- data/lib/generators/tmatt_cms/templates/js/utils/magnificPopup.js +16 -0
- data/lib/generators/tmatt_cms/templates/seed_bank/all.seeds.rb +0 -0
- data/lib/generators/tmatt_cms/templates/views/dashboard/partial/_sidebar.html.haml +29 -0
- data/lib/generators/tmatt_cms/templates/views/layouts/dashboard.html.haml +19 -0
- data/lib/generators/tmatt_cms/templates/views/utils/_image_cover.html.haml +2 -0
- data/lib/tmatt_cms.rb +1 -5
- data/lib/tmatt_cms/version.rb +1 -1
- data/spec/spec_helper.rb +2 -0
- data/spec/tmatt_cms_spec.rb +11 -0
- data/tmatt_cms.gemspec +6 -7
- metadata +57 -30
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02e95bac19fa0175a01bc2ecbd23aea61aa24534
|
4
|
+
data.tar.gz: 23f924291747b915c9d6b3d9f1e1e203e4cad6ab
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 98fddb679bf32bb56410f396fae29eebf5901ebaa04348e3339d9ffb630b6cb2ec9049116d1d7beb8163d44fd507f0515038716e0f56b1e81c158c505037c978
|
7
|
+
data.tar.gz: 48ff46806466be9702d21b4785989d5b044c29f42dcc05cc14b507eb353a4da3faccb72c5fe2572f3634f7c1fbcd0f6e55d9cd701f636f4b672497ae29cf68f3
|
@@ -0,0 +1,316 @@
|
|
1
|
+
require 'rails/generators'
|
2
|
+
|
3
|
+
module TmattCms
|
4
|
+
module Generators
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
6
|
+
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
8
|
+
|
9
|
+
# class_option :globalize, :type => :boolean, :default => true, :description => 'Include translatable files'
|
10
|
+
|
11
|
+
def remove_double
|
12
|
+
remove_file 'app/models/double.rb'
|
13
|
+
end
|
14
|
+
|
15
|
+
def copy_git_ignore
|
16
|
+
copy_file 'git_ignore/gitignore', '.gitignore'
|
17
|
+
end
|
18
|
+
|
19
|
+
def config_application_rb
|
20
|
+
filename = 'config/application.rb'
|
21
|
+
|
22
|
+
if File.readlines(filename).grep(/concerns/).size == 0
|
23
|
+
line_count = get_line_count filename
|
24
|
+
insert_at_line(filename, line_count - 2, [
|
25
|
+
"\n\t\tconfig.autoload_paths += %W(\#{config.root}/app/models/concerns)"
|
26
|
+
])
|
27
|
+
end
|
28
|
+
|
29
|
+
if File.readlines(filename).grep(/DATE_FORMATS/).size == 0
|
30
|
+
line_count = get_line_count filename
|
31
|
+
insert_at_line(filename, line_count - 2, [
|
32
|
+
"\n\t\tTime::DATE_FORMATS[:aus] = '%l:%M %p on %d %B %Y'",
|
33
|
+
"\t\tDate::DATE_FORMATS[:aus] = '%d %B %Y'",
|
34
|
+
"\t\tTime::DATE_FORMATS[:zh] = '%l:%M %p on %d %B %Y'",
|
35
|
+
"\t\tDate::DATE_FORMATS[:zh] = '%d %B %Y'",
|
36
|
+
])
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def add_application_yml
|
41
|
+
copy_file 'config/application.yml', 'config/application.yml'
|
42
|
+
|
43
|
+
filename = 'config/application.rb'
|
44
|
+
if File.readlines(filename).grep(/application\.yml/).size == 0
|
45
|
+
insert_at_line(filename, 8, ["\nENV.update YAML.load_file('config/application.yml')[Rails.env] rescue {}"])
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def config_google_smtp
|
50
|
+
filename = 'config/environments/development.rb'
|
51
|
+
if File.readlines(filename).grep(/smtp/).size == 0
|
52
|
+
line_count = get_line_count filename
|
53
|
+
insert_at_line(filename, line_count - 1, [
|
54
|
+
"\n\tconfig.action_mailer.default_url_options = { :host => '0.0.0.0:3000' }",
|
55
|
+
"\tconfig.action_mailer.delivery_method = :smtp",
|
56
|
+
"\tconfig.action_mailer.smtp_settings = {",
|
57
|
+
"\t\t:address => 'smtp.gmail.com',",
|
58
|
+
"\t\t:port => 587,",
|
59
|
+
"\t\t:user_name => ENV['MAILER_EMAIL'],",
|
60
|
+
"\t\t:password => ENV['MAILER_PASSWORD'],",
|
61
|
+
"\t\t:authentication => :plain",
|
62
|
+
"\t}",
|
63
|
+
])
|
64
|
+
end
|
65
|
+
|
66
|
+
filename = 'config/environments/production.rb'
|
67
|
+
if File.readlines(filename).grep(/smtp/).size == 0
|
68
|
+
line_count = get_line_count filename
|
69
|
+
insert_at_line(filename, line_count - 1, [
|
70
|
+
"\n\tconfig.action_mailer.default_url_options = { :host => 'tmatt.com.au' }",
|
71
|
+
"\tconfig.action_mailer.asset_host = 'http://tmatt.com.au'",
|
72
|
+
"\tconfig.action_mailer.delivery_method = :smtp",
|
73
|
+
"\tconfig.action_mailer.smtp_settings = {",
|
74
|
+
"\t\t:address => 'smtp.gmail.com',",
|
75
|
+
"\t\t:port => 587,",
|
76
|
+
"\t\t:user_name => ENV['MAILER_EMAIL'],",
|
77
|
+
"\t\t:password => ENV['MAILER_PASSWORD'],",
|
78
|
+
"\t\t:authentication => :plain,",
|
79
|
+
"\t\t:enable_starttls_auto => true",
|
80
|
+
"\t}",
|
81
|
+
])
|
82
|
+
end
|
83
|
+
end
|
84
|
+
|
85
|
+
def copy_input_files
|
86
|
+
copy_file 'inputs/concerns/translation_hint.rb', 'app/inputs/concerns/translation_hint.rb'
|
87
|
+
copy_file 'inputs/ckeditor_translation_input.rb', 'app/inputs/ckeditor_translation_input.rb'
|
88
|
+
copy_file 'inputs/translation_input.rb', 'app/inputs/translation_input.rb'
|
89
|
+
end
|
90
|
+
|
91
|
+
def copy_translatable
|
92
|
+
copy_file 'concerns/translatable.rb', 'app/models/concerns/translatable.rb'
|
93
|
+
end
|
94
|
+
|
95
|
+
def config_locales
|
96
|
+
copy_file 'config/locales/views/dashboard/en.yml', 'config/locales/views/dashboard/en.yml'
|
97
|
+
copy_file 'config/locales/views/dashboard/zh.yml', 'config/locales/views/dashboard/zh.yml'
|
98
|
+
copy_file 'config/locales/views/global/en.yml', 'config/locales/views/global/en.yml'
|
99
|
+
copy_file 'config/locales/views/global/zh.yml', 'config/locales/views/global/zh.yml'
|
100
|
+
|
101
|
+
filename = 'config/application.rb'
|
102
|
+
if File.readlines(filename).grep(/config', 'locales', '\*\*'/).size == 0
|
103
|
+
line_count = get_line_count filename
|
104
|
+
insert_at_line(filename, line_count - 2, [
|
105
|
+
"\n\t\tconfig.i18n.enforce_available_locales = false",
|
106
|
+
"\t\tconfig.i18n.fallbacks = true",
|
107
|
+
"\t\tconfig.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]",
|
108
|
+
"\t\tconfig.i18n.default_locale = 'en'",
|
109
|
+
])
|
110
|
+
end
|
111
|
+
end
|
112
|
+
|
113
|
+
def copy_db_init
|
114
|
+
copy_file 'concerns/db_init.rb', 'app/models/concerns/db_init.rb'
|
115
|
+
end
|
116
|
+
|
117
|
+
def copy_pretty_url
|
118
|
+
remove_file 'app/models/concerns/pretty_url.rb'
|
119
|
+
copy_file 'concerns/pretty_url.rb', 'app/models/concerns/pretty_url.rb'
|
120
|
+
end
|
121
|
+
|
122
|
+
def copy_string_addition
|
123
|
+
copy_file 'concerns/string_addition.rb', 'app/models/concerns/string_addition.rb'
|
124
|
+
end
|
125
|
+
|
126
|
+
def copy_stylesheet_files
|
127
|
+
copy_file 'css/application/main.css.scss', 'app/assets/stylesheets/application/main.css.scss'
|
128
|
+
copy_file 'css/application/mixin.css.scss', 'app/assets/stylesheets/application/mixin.css.scss'
|
129
|
+
copy_file 'css/application/z_index.css.scss', 'app/assets/stylesheets/application/z_index.css.scss'
|
130
|
+
copy_file 'css/application/variables.css.scss', 'app/assets/stylesheets/application/variables.css.scss'
|
131
|
+
|
132
|
+
remove_file 'app/assets/stylesheets/application/application.css'
|
133
|
+
copy_file 'css/application/application.css', 'app/assets/stylesheets/application/application.css'
|
134
|
+
|
135
|
+
remove_file 'app/assets/stylesheets/application/index.css.scss'
|
136
|
+
copy_file 'css/application/index.css.scss', 'app/assets/stylesheets/application/index.css.scss'
|
137
|
+
|
138
|
+
remove_file 'app/assets/stylesheets/style.css.scss'
|
139
|
+
copy_file 'css/style.css.scss', 'app/assets/stylesheets/style.css.scss'
|
140
|
+
|
141
|
+
copy_file 'css/layouts/header.css.scss', 'app/assets/stylesheets/layouts/header.css.scss'
|
142
|
+
copy_file 'css/layouts/footer.css.scss', 'app/assets/stylesheets/layouts/footer.css.scss'
|
143
|
+
end
|
144
|
+
|
145
|
+
def copy_javascript_files
|
146
|
+
remove_file 'app/assets/javascripts/application.js'
|
147
|
+
copy_file 'js/application.js', 'app/assets/javascripts/application.js'
|
148
|
+
end
|
149
|
+
|
150
|
+
def add_custom_javascripts
|
151
|
+
if File.readlines('app/views/layouts/application.html.haml').grep(/custom_javascripts/).size == 0
|
152
|
+
File.open(File.join('app', 'views', 'layouts', 'application.html.haml'), 'a+') do |f|
|
153
|
+
f.puts "\n\t\t= yield :custom_javascripts"
|
154
|
+
end
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
def config_seed_bank
|
159
|
+
copy_file 'seed_bank/all.seeds.rb', 'db/seeds/all.seeds.rb'
|
160
|
+
copy_file '.keep', 'db/seeds/resources/images/.keep'
|
161
|
+
copy_file '.keep', 'db/seeds/resources/csv/.keep'
|
162
|
+
end
|
163
|
+
|
164
|
+
def config_magnific_popup_rails
|
165
|
+
copy_file 'css/application/magnific_popup_rails.css.scss', 'app/assets/stylesheets/application/magnific_popup_rails.css.scss'
|
166
|
+
copy_file 'js/utils/magnificPopup.js', 'app/assets/javascripts/utils/magnificPopup.js'
|
167
|
+
|
168
|
+
if File.readlines('config/initializers/assets.rb').grep(/magnificPopup/).size == 0
|
169
|
+
File.open(File.join('config', 'initializers', 'assets.rb'), 'a+') do |f|
|
170
|
+
f.puts "\n\n"
|
171
|
+
f.puts 'Rails.application.config.assets.precompile += %w( utils/magnificPopup.js )'
|
172
|
+
end
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
176
|
+
def config_sidekiq
|
177
|
+
copy_file 'config/initializers/active_job.rb', 'config/initializers/active_job.rb'
|
178
|
+
|
179
|
+
if File.readlines('Capfile').grep(/sidekiq/).size == 0
|
180
|
+
File.open(File.join('Capfile'), 'a+') do |f|
|
181
|
+
f.puts "\n\n"
|
182
|
+
f.puts "require 'capistrano/sidekiq'"
|
183
|
+
f.puts "# require 'capistrano/sidekiq/monit'"
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
|
188
|
+
def config_ckeditor
|
189
|
+
filename = 'config/application.rb'
|
190
|
+
|
191
|
+
if File.readlines(filename).grep(/ckeditor/).size == 0
|
192
|
+
line_count = get_line_count filename
|
193
|
+
insert_at_line(filename, line_count - 2, ["\n\t\tconfig.assets.precompile += %w( ckeditor/* )"])
|
194
|
+
end
|
195
|
+
|
196
|
+
copy_file 'css/application/ckeditor.css.scss', 'app/assets/stylesheets/application/ckeditor.css.scss'
|
197
|
+
|
198
|
+
if File.readlines('config/initializers/assets.rb').grep(/ckeditor/).size == 0
|
199
|
+
File.open(File.join('config', 'initializers', 'assets.rb'), 'a+') do |f|
|
200
|
+
f.puts "\n\n"
|
201
|
+
f.puts 'Rails.application.config.assets.precompile += %w( ckeditor/* )'
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def config_paperclip
|
207
|
+
filename = 'config/environments/development.rb'
|
208
|
+
if File.readlines(filename).grep(/Paperclip/).size == 0
|
209
|
+
line_count = get_line_count filename
|
210
|
+
insert_at_line(filename, line_count - 1, ["\n\tPaperclip.options[:command_path] = '/usr/local/bin/'"])
|
211
|
+
end
|
212
|
+
|
213
|
+
|
214
|
+
filename = 'config/environments/production.rb'
|
215
|
+
if File.readlines(filename).grep(/Paperclip/).size == 0
|
216
|
+
line_count = get_line_count filename
|
217
|
+
insert_at_line(filename, line_count - 1, ["\n\tPaperclip.options[:command_path] = '/usr/bin/'"])
|
218
|
+
end
|
219
|
+
end
|
220
|
+
|
221
|
+
def config_jasny_bootstrap
|
222
|
+
copy_file 'css/utils/jasny-bootstrap.min.css', 'app/assets/stylesheets/utils/jasny-bootstrap.min.css'
|
223
|
+
copy_file 'js/utils/jasny-bootstrap.min.js', 'app/assets/javascripts/utils/jasny-bootstrap.min.js'
|
224
|
+
|
225
|
+
if File.readlines('config/initializers/assets.rb').grep(/jasny/).size == 0
|
226
|
+
File.open(File.join('config', 'initializers', 'assets.rb'), 'a+') do |f|
|
227
|
+
f.puts "\n\n"
|
228
|
+
f.puts 'Rails.application.config.assets.precompile += %w( utils/jasny-bootstrap.min.css )'
|
229
|
+
f.puts 'Rails.application.config.assets.precompile += %w( utils/jasny-bootstrap.min.js )'
|
230
|
+
end
|
231
|
+
end
|
232
|
+
end
|
233
|
+
|
234
|
+
def add_dashboard
|
235
|
+
copy_file 'views/dashboard/partial/_sidebar.html.haml', 'app/views/dashboard/partial/_sidebar.html.haml'
|
236
|
+
copy_file 'views/layouts/dashboard.html.haml', 'app/views/layouts/dashboard.html.haml'
|
237
|
+
|
238
|
+
filename = 'config/routes.rb'
|
239
|
+
if File.readlines(filename).grep(/dashboard/).size == 0
|
240
|
+
line_count = get_line_count filename
|
241
|
+
insert_at_line(filename, line_count - 1, ["\n\tnamespace :dashboard do", "\n\tend"])
|
242
|
+
end
|
243
|
+
end
|
244
|
+
|
245
|
+
def add_image_cover
|
246
|
+
copy_file 'views/utils/_image_cover.html.haml', 'app/views/utils/_image_cover.html.haml'
|
247
|
+
end
|
248
|
+
|
249
|
+
def copy_gemfile
|
250
|
+
copy_file 'gemfile/Gemfile', 'Gemfile'
|
251
|
+
end
|
252
|
+
|
253
|
+
def config_deploy
|
254
|
+
filename = 'config/deploy.rb'
|
255
|
+
|
256
|
+
text = File.read(filename)
|
257
|
+
new_contents = text.gsub(/vm_ruby_string, '2\.0\.0'/, "vm_ruby_string, '2.3.1'")
|
258
|
+
File.open(filename, "w") {|file| file.puts new_contents }
|
259
|
+
|
260
|
+
if File.readlines(filename).grep(/capistrano-db-tasks/).size == 0
|
261
|
+
insert_at_line(filename, 4, ["require 'capistrano-db-tasks'"])
|
262
|
+
end
|
263
|
+
|
264
|
+
if File.readlines(filename).grep(/migrate_only/).size == 0
|
265
|
+
line_count = get_line_count filename
|
266
|
+
insert_at_line(filename, line_count - 3, [
|
267
|
+
"\n\nproject_name = 'project_name'",
|
268
|
+
"\n\nputs 'Enter rake command[db:migrate]: '",
|
269
|
+
'db_cmd = STDIN.gets.chomp',
|
270
|
+
"db_cmd = 'db:migrate' if db_cmd == ''",
|
271
|
+
"\nset :server_address, 'tmatt.com.au'",
|
272
|
+
"server '0.0.0.0', :app, :web, :db, :primary => true",
|
273
|
+
"\nafter 'deploy:restart', 'deploy:cleanup'",
|
274
|
+
"after 'deploy:restart', 'unicorn:restart'",
|
275
|
+
"after 'deploy:restart', 'sidekiq:restart'",
|
276
|
+
"after 'deploy', 'assets:precompile'",
|
277
|
+
"\nafter 'bundle:install', :roles => :web do",
|
278
|
+
"\trun \"ln -s \#{shared_path}/config/application.yml \#{release_path}/config/application.yml\"",
|
279
|
+
"\trun \"ln -s \#{shared_path}/config/database.yml \#{release_path}/config/database.yml\"",
|
280
|
+
"\trun \"ln -s \#{shared_path}/config/secrets.yml \#{release_path}/config/secrets.yml\"",
|
281
|
+
'end',
|
282
|
+
"\nnamespace :deploy do",
|
283
|
+
"\ttask :start do ; end",
|
284
|
+
"\ttask :stop do ; end",
|
285
|
+
"\ttask :restart, :roles => :app, :except => { :no_release => true } do",
|
286
|
+
|
287
|
+
"\t\trun \"cd '/home/deploy/\#{project_name}/current' ; bundle exec rake \#{db_cmd} RAILS_ENV=production\"",
|
288
|
+
|
289
|
+
"\tend",
|
290
|
+
'end',
|
291
|
+
], false)
|
292
|
+
end
|
293
|
+
end
|
294
|
+
|
295
|
+
private
|
296
|
+
|
297
|
+
def get_line_count(filename)
|
298
|
+
`wc -l "#{filename}"`.strip.split(' ')[0].to_i + 1
|
299
|
+
end
|
300
|
+
|
301
|
+
def insert_at_line(filename, at_line, contents, append_rest = true)
|
302
|
+
open(filename, 'r+') do |f|
|
303
|
+
while (at_line-=1) > 0
|
304
|
+
f.readline
|
305
|
+
end
|
306
|
+
|
307
|
+
pos = f.pos
|
308
|
+
rest = f.read
|
309
|
+
f.seek pos
|
310
|
+
|
311
|
+
f.puts append_rest ? contents + [rest] : contents
|
312
|
+
end
|
313
|
+
end
|
314
|
+
end
|
315
|
+
end
|
316
|
+
end
|
File without changes
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module PrettyUrl
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
after_save :update_url_name
|
6
|
+
end
|
7
|
+
|
8
|
+
module ClassMethods
|
9
|
+
def find(id)
|
10
|
+
if id.is_a?(String)
|
11
|
+
real_id = /(.*\-)?(?<id>\d+)\Z/.match(id)[:id]
|
12
|
+
else
|
13
|
+
real_id = id
|
14
|
+
end
|
15
|
+
super(real_id)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_param
|
20
|
+
url_name
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
def update_url_name
|
25
|
+
if I18n.locale == :en
|
26
|
+
if self.has_attribute?(:name) || self.translations.first.has_attribute?(:name)
|
27
|
+
self.update_column :url_name, "#{name.to_url}-#{id}"
|
28
|
+
elsif self.has_attribute?(:title) || self.translations.first.has_attribute?(:title)
|
29
|
+
self.update_column :url_name, "#{title.to_url}-#{id}"
|
30
|
+
else
|
31
|
+
self.update_column :url_name, self.id
|
32
|
+
end
|
33
|
+
elsif url_name.blank?
|
34
|
+
self.update_column :url_name, self.id
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
module Translatable
|
2
|
+
extend ActiveSupport::Concern
|
3
|
+
|
4
|
+
included do
|
5
|
+
def self.translate_field(field)
|
6
|
+
define_method(field) do
|
7
|
+
self.public_send "#{field}_#{I18n.locale}"
|
8
|
+
end
|
9
|
+
|
10
|
+
define_method("#{field}_dashboard") do
|
11
|
+
I18n.locale == :zh ? to_dashboard(to_s_zh(field), to_s_en(field)) : to_dashboard(to_s_en(field), to_s_zh(field))
|
12
|
+
end
|
13
|
+
|
14
|
+
define_method("#{field}_trans") do
|
15
|
+
I18n.locale == :en ? self.public_send("#{field}_zh").to_s : self.public_send("#{field}_en").to_s
|
16
|
+
end
|
17
|
+
|
18
|
+
define_method("print_#{field}_trans") do
|
19
|
+
I18n.locale == :en ? '中文: ' + self.public_send("#{field}_zh").to_s : 'English: ' + self.public_send("#{field}_en").to_s
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def self.globalize(*fields)
|
24
|
+
fields.each do |field|
|
25
|
+
translates field
|
26
|
+
globalize_accessors :attributes => [field]
|
27
|
+
translate_field field
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def to_s_en(field)
|
33
|
+
self.public_send("#{field}_en").to_s
|
34
|
+
end
|
35
|
+
|
36
|
+
def to_s_zh(field)
|
37
|
+
self.public_send("#{field}_zh").to_s
|
38
|
+
end
|
39
|
+
|
40
|
+
def to_dashboard(main, trans)
|
41
|
+
'<span>' + main + '</span><br/><span class="font-italic font-grey">' + trans + '</span>'
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
require File.expand_path('../boot', __FILE__)
|
2
|
+
|
3
|
+
require 'rails/all'
|
4
|
+
|
5
|
+
# Require the gems listed in Gemfile, including any gems
|
6
|
+
# you've limited to :test, :development, or :production.
|
7
|
+
Bundler.require(*Rails.groups)
|
8
|
+
|
9
|
+
ENV.update YAML.load_file('config/application.yml')[Rails.env] rescue {}
|
10
|
+
|
11
|
+
module LannisterWebsite
|
12
|
+
class Application < Rails::Application
|
13
|
+
# Settings in config/environments/* take precedence over those specified here.
|
14
|
+
# Application configuration should go into files in config/initializers
|
15
|
+
# -- all .rb files in that directory are automatically loaded.
|
16
|
+
|
17
|
+
# Set Time.zone default to the specified zone and make Active Record auto-convert to this zone.
|
18
|
+
# Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC.
|
19
|
+
# config.time_zone = 'Central Time (US & Canada)'
|
20
|
+
|
21
|
+
config.autoload_paths += %W(#{config.root}/app/models/concerns)
|
22
|
+
|
23
|
+
# The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded.
|
24
|
+
# config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s]
|
25
|
+
# config.i18n.default_locale = :de
|
26
|
+
config.i18n.enforce_available_locales = false
|
27
|
+
config.i18n.fallbacks = true
|
28
|
+
|
29
|
+
Time::DATE_FORMATS[:aus] = '%l:%M %p on %d %B %Y'
|
30
|
+
Date::DATE_FORMATS[:aus] = '%d %B %Y'
|
31
|
+
|
32
|
+
Time::DATE_FORMATS[:zh] = '%l:%M %p on %d %B %Y'
|
33
|
+
Date::DATE_FORMATS[:zh] = '%d %B %Y'
|
34
|
+
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
|
35
|
+
|
36
|
+
config.i18n.default_locale = 'en'
|
37
|
+
|
38
|
+
|
39
|
+
config.assets.precompile += %w( ckeditor/* )
|
40
|
+
end
|
41
|
+
end
|