padrino-gen 0.8.5 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.5
1
+ 0.9.0
@@ -32,7 +32,6 @@ module Padrino
32
32
  self.class.send(:include, generator_module_for(choice, component))
33
33
  end
34
34
 
35
-
36
35
  # Returns the component choice stored within the .component file of an application
37
36
  # fetch_component_choice(:mock)
38
37
  def fetch_component_choice(component)
@@ -142,12 +141,12 @@ module Padrino
142
141
 
143
142
  # Tell to padrino that for this Thor::Group is necessary a task to run
144
143
  def require_arguments!
145
- @_require_arguments = true
144
+ @require_arguments = true
146
145
  end
147
146
 
148
147
  # Return true if we need an arguments for our Thor::Group
149
148
  def require_arguments?
150
- @_require_arguments
149
+ @require_arguments
151
150
  end
152
151
 
153
152
  # Returns the compiled list of component types which can be specified
@@ -9,12 +9,11 @@ class <%= @class_name %> < Padrino::Application
9
9
  # set :reload, false # Reload application files (default in development)
10
10
  # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
11
11
  # set :locale_path, "bar" # Set path for I18n translations (default your_app/locales)
12
- # enable :auto_locale # Auto Set locale if url match /:locale/foo/bar (disabled by default)
13
12
  # disable :padrino_helpers # Disables padrino markup helpers (enabled by default if present)
14
13
  # disable :padrino_mailer # Disables padrino mailer (enabled by default if present)
15
14
  # disable :flash # Disables rack-flash (enabled by default)
16
15
  # enable :authentication # Enable padrino-admin authentication (disabled by default)
17
- # layout :foo # Layout can be in views/layouts/foo.ext or views/foo.ext (:application is default)
16
+ # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
18
17
  #
19
18
  end
20
19
 
@@ -23,7 +23,7 @@ module Padrino
23
23
  DM
24
24
 
25
25
  def setup_orm
26
- require_dependencies 'data_objects', 'do_sqlite3', 'dm-core', 'dm-validations', 'dm-aggregates', 'dm-timestamps', 'dm-migrations'
26
+ require_dependencies 'data_objects', 'do_sqlite3', 'datamapper'
27
27
  create_file("config/database.rb", DM)
28
28
  empty_directory('app/models')
29
29
  end
@@ -27,6 +27,7 @@ module Padrino
27
27
 
28
28
  # key <name>, <type>
29
29
  !FIELDS!
30
+ timestamps!
30
31
  end
31
32
  MODEL
32
33
 
@@ -19,7 +19,7 @@ module Padrino
19
19
 
20
20
  def setup_renderer
21
21
  require_dependencies 'haml'
22
- create_file destination_root('/config/initializers/sass.rb'), SASS_INIT
22
+ create_file destination_root('/lib/sass.rb'), SASS_INIT
23
23
  end
24
24
  end
25
25
 
@@ -34,7 +34,7 @@ module Padrino
34
34
  simple_name = name.to_s.gsub(/mailer/i, '')
35
35
  @mailer_basename = "#{simple_name.downcase.underscore}_mailer"
36
36
  @mailer_klass = "#{simple_name.downcase.camelize}Mailer"
37
- template "templates/mailer_initializer.rb.tt", destination_root("config/initializers/mailer.rb"), :skip => true
37
+ template "templates/mailer_initializer.rb.tt", destination_root("lib/mailer.rb"), :skip => true
38
38
  template "templates/mailer.rb.tt", destination_root(app, "mailers", "#{@mailer_basename}.rb")
39
39
  empty_directory destination_root(app, 'views', @mailer_basename)
40
40
  else
@@ -20,7 +20,7 @@ module Padrino
20
20
 
21
21
  argument :name, :desc => "The name of your padrino project"
22
22
 
23
- class_option :run_bundler, :desc => "Run bundle install", :aliases => '-b', :default => false, :type => :boolean
23
+ class_option :run_bundle, :desc => "Run bundle install", :aliases => '-b', :default => false, :type => :boolean
24
24
  class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
25
25
  class_option :dev, :desc => "Use padrino from a git checkout", :default => false, :type => :boolean
26
26
 
@@ -9,12 +9,11 @@ class <%= @class_name %> < Padrino::Application
9
9
  # set :reload, false # Reload application files (default in development)
10
10
  # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
11
11
  # set :locale_path, "bar" # Set path for I18n translations (default your_app/locales)
12
- # enable :auto_locale # Auto Set locale if url match /:locale/foo/bar (disabled by default)
13
12
  # disable :padrino_helpers # Disables padrino markup helpers (enabled by default if present)
14
13
  # disable :padrino_mailer # Disables padrino mailer (enabled by default if present)
15
14
  # disable :flash # Disables rack-flash (enabled by default)
16
15
  # enable :authentication # Enable padrino-admin authentication (disabled by default)
17
- # layout :foo # Layout can be in views/layouts/foo.ext or views/foo.ext (:application is default)
16
+ # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
18
17
  #
19
18
  end
20
19
 
@@ -8,7 +8,7 @@ begin
8
8
  rescue LoadError
9
9
  # Fallback on doing the resolve at runtime.
10
10
  require 'rubygems'
11
- gem 'bundler', '0.9.5'
11
+ gem 'bundler', '0.9.7'
12
12
  require 'bundler'
13
13
  Bundler.setup(:default, PADRINO_ENV)
14
14
  end
@@ -1,4 +1,4 @@
1
- source 'http://gemcutter.org'
1
+ source :gemcutter
2
2
 
3
3
  # Project requirements
4
4
  gem 'rack-flash'
@@ -230,7 +230,7 @@ if defined?(ActiveRecord)
230
230
  end
231
231
 
232
232
  desc 'Create the database, load the schema, and initialize with the seed data'
233
- task :setup => [ 'ar:create', 'ar:schema:load', 'ar:seed' ]
233
+ task :setup => [ 'ar:create', 'ar:schema:load', 'seed' ]
234
234
 
235
235
  namespace :schema do
236
236
  desc "Create a db/schema.rb file that can be portably used against any DB supported by AR"
@@ -308,6 +308,45 @@ if defined?(ActiveRecord)
308
308
  end
309
309
  end
310
310
 
311
+ desc "Generates .yml files for I18n translations."
312
+ task :translate => :environment do
313
+ models = Dir["#{Padrino.root}/app/models/**/*.rb"].collect { |m| File.basename(m, ".rb") }
314
+
315
+ models.each do |m|
316
+ # Get the model class
317
+ klass = m.camelize.constantize
318
+
319
+ # Init the processing
320
+ print "Processing #{m.humanize}: "
321
+ FileUtils.mkdir_p("#{Padrino.root}/app/locale/models/#{m}")
322
+ langs = Array(I18n.locale) # for now we use only one
323
+
324
+ # Create models for it and en locales
325
+ langs.each do |lang|
326
+ filename = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml"
327
+ columns = klass.columns.collect(&:name)
328
+ # If the lang file already exist we need to check it
329
+ if File.exist?(filename)
330
+ locale = File.open(filename).read
331
+ columns.each do |c|
332
+ locale += "\n #{c}: #{klass.human_attribute_name(c)}" unless locale.include?("#{c}:")
333
+ end
334
+ print "Lang #{lang.to_s.upcase} already exist ... "; $stdout.flush
335
+ # Do some ere
336
+ else
337
+ locale = "#{lang}:" + "\n" +
338
+ " models:" + "\n" +
339
+ " #{m}:" + "\n" +
340
+ " name: #{klass.human_name}" + "\n" +
341
+ " attributes:" + "\n" +
342
+ columns.collect { |c| " #{c}: #{klass.human_attribute_name(c)}" }.join("\n")
343
+ print "created a new for #{lang.to_s.upcase} Lang ... "; $stdout.flush
344
+ end
345
+ File.open(filename, "w") { |f| f.puts locale }
346
+ end
347
+ puts
348
+ end
349
+ end
311
350
  end
312
351
 
313
352
  def drop_database(config)
data/padrino-gen.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{padrino-gen}
8
- s.version = "0.8.5"
8
+ s.version = "0.9.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Padrino Team", "Nathan Esquenazi", "Davide D'Agostino", "Arthur Chiu"]
12
- s.date = %q{2010-02-18}
12
+ s.date = %q{2010-02-23}
13
13
  s.default_executable = %q{padrino-gen}
14
14
  s.description = %q{Generators for easily creating and building padrino applications from the console}
15
15
  s.email = %q{padrinorb@gmail.com}
@@ -62,11 +62,10 @@ Gem::Specification.new do |s|
62
62
  "lib/padrino-gen/generators/project/app/controllers/.empty_directory",
63
63
  "lib/padrino-gen/generators/project/app/helpers/.empty_directory",
64
64
  "lib/padrino-gen/generators/project/app/views/.empty_directory",
65
+ "lib/padrino-gen/generators/project/app/views/layouts/.emptydirectory",
65
66
  "lib/padrino-gen/generators/project/config.ru",
66
67
  "lib/padrino-gen/generators/project/config/apps.rb.tt",
67
68
  "lib/padrino-gen/generators/project/config/boot.rb",
68
- "lib/padrino-gen/generators/project/config/initializers/.empty_directory",
69
- "lib/padrino-gen/generators/project/config/initializers/example.rb",
70
69
  "lib/padrino-gen/generators/project/public/images/.empty_directory",
71
70
  "lib/padrino-gen/generators/project/public/javascripts/.empty_directory",
72
71
  "lib/padrino-gen/generators/project/public/stylesheets/.empty_directory",
@@ -82,7 +81,6 @@ Gem::Specification.new do |s|
82
81
  "lib/padrino-gen/generators/templates/scripts/right.js",
83
82
  "lib/padrino-gen/padrino-tasks/activerecord.rb",
84
83
  "lib/padrino-gen/padrino-tasks/datamapper.rb",
85
- "lib/padrino-gen/padrino-tasks/locale.rb",
86
84
  "lib/padrino-gen/padrino-tasks/seed.rb",
87
85
  "padrino-gen.gemspec",
88
86
  "test/helper.rb",
@@ -107,7 +105,7 @@ Gem::Specification.new do |s|
107
105
  s.specification_version = 3
108
106
 
109
107
  if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
110
- s.add_runtime_dependency(%q<padrino-core>, ["= 0.8.5"])
108
+ s.add_runtime_dependency(%q<padrino-core>, ["= 0.9.0"])
111
109
  s.add_development_dependency(%q<haml>, [">= 2.2.1"])
112
110
  s.add_development_dependency(%q<shoulda>, [">= 2.10.3"])
113
111
  s.add_development_dependency(%q<mocha>, [">= 0.9.7"])
@@ -115,7 +113,7 @@ Gem::Specification.new do |s|
115
113
  s.add_development_dependency(%q<webrat>, [">= 0.5.1"])
116
114
  s.add_development_dependency(%q<fakeweb>, [">= 1.2.3"])
117
115
  else
118
- s.add_dependency(%q<padrino-core>, ["= 0.8.5"])
116
+ s.add_dependency(%q<padrino-core>, ["= 0.9.0"])
119
117
  s.add_dependency(%q<haml>, [">= 2.2.1"])
120
118
  s.add_dependency(%q<shoulda>, [">= 2.10.3"])
121
119
  s.add_dependency(%q<mocha>, [">= 0.9.7"])
@@ -124,7 +122,7 @@ Gem::Specification.new do |s|
124
122
  s.add_dependency(%q<fakeweb>, [">= 1.2.3"])
125
123
  end
126
124
  else
127
- s.add_dependency(%q<padrino-core>, ["= 0.8.5"])
125
+ s.add_dependency(%q<padrino-core>, ["= 0.9.0"])
128
126
  s.add_dependency(%q<haml>, [">= 2.2.1"])
129
127
  s.add_dependency(%q<shoulda>, [">= 2.10.3"])
130
128
  s.add_dependency(%q<mocha>, [">= 0.9.7"])
@@ -46,7 +46,7 @@ class TestAppGenerator < Test::Unit::TestCase
46
46
  silence_logger { @app.start(['demo', '--root=/tmp/sample_project']) }
47
47
  silence_logger { @mail_gen.start(['demo', '-r=/tmp/sample_project', '-a=demo']) }
48
48
  assert_match_in_file(/class DemoMailer < Padrino::Mailer::Base/m, '/tmp/sample_project/demo/mailers/demo_mailer.rb')
49
- assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_project/config/initializers/mailer.rb')
49
+ assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_project/lib/mailer.rb')
50
50
  assert_file_exists('/tmp/sample_project/demo/views/demo_mailer')
51
51
  end
52
52
 
@@ -19,7 +19,7 @@ class TestMailerGenerator < Test::Unit::TestCase
19
19
  silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon']) }
20
20
  silence_logger { @mail_gen.start(['demo', '-r=/tmp/sample_project']) }
21
21
  assert_match_in_file(/class DemoMailer < Padrino::Mailer::Base/m, '/tmp/sample_project/app/mailers/demo_mailer.rb')
22
- assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_project/config/initializers/mailer.rb')
22
+ assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_project/lib/mailer.rb')
23
23
  assert_file_exists('/tmp/sample_project/app/views/demo_mailer')
24
24
  end
25
25
 
@@ -27,7 +27,7 @@ class TestMailerGenerator < Test::Unit::TestCase
27
27
  silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon']) }
28
28
  silence_logger { @mail_gen.start(['user_notice', '-r=/tmp/sample_project']) }
29
29
  assert_match_in_file(/class UserNoticeMailer/m, '/tmp/sample_project/app/mailers/user_notice_mailer.rb')
30
- assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_project/config/initializers/mailer.rb')
30
+ assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_project/lib/mailer.rb')
31
31
  assert_file_exists('/tmp/sample_project/app/views/user_notice_mailer')
32
32
  end
33
33
 
@@ -35,7 +35,7 @@ class TestMailerGenerator < Test::Unit::TestCase
35
35
  silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-t=bacon']) }
36
36
  silence_logger { @mail_gen.start(['DEMO', '-r=/tmp/sample_project']) }
37
37
  assert_match_in_file(/class DemoMailer < Padrino::Mailer::Base/m, '/tmp/sample_project/app/mailers/demo_mailer.rb')
38
- assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_project/config/initializers/mailer.rb')
38
+ assert_match_in_file(/Padrino::Mailer::Base.smtp_settings/m, '/tmp/sample_project/lib/mailer.rb')
39
39
  assert_file_exists('/tmp/sample_project/app/views/demo_mailer')
40
40
  end
41
41
  end
@@ -48,7 +48,7 @@ class TestMailerGenerator < Test::Unit::TestCase
48
48
  silence_logger { @mail_gen.start(['demo', '-r=/tmp/sample_project','-d']) }
49
49
  assert_no_dir_exists('/tmp/sample_project/app/views/demo_mailer')
50
50
  assert_no_file_exists('/tmp/sample_project/app/mailers/demo_mailer.rb')
51
- assert_no_file_exists('/tmp/sample_project/config/initializers/mailer.rb')
51
+ assert_no_file_exists('/tmp/sample_project/lib/mailer.rb')
52
52
  end
53
53
  end
54
54
 
@@ -102,6 +102,13 @@ class TestModelGenerator < Test::Unit::TestCase
102
102
 
103
103
  # DATAMAPPER
104
104
  context "model generator using datamapper" do
105
+
106
+ should "generate gemfile gem" do
107
+ silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=datamapper']) }
108
+ silence_logger { @model_gen.start(['user', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project']) }
109
+ assert_match_in_file(/gem 'datamapper'/m,'/tmp/sample_project/Gemfile')
110
+ end
111
+
105
112
  should "generate model file with fields" do
106
113
  silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=datamapper']) }
107
114
  silence_logger { @model_gen.start(['user', "name:string", "age:integer", "created_at:datetime", '-r=/tmp/sample_project']) }
@@ -109,6 +116,7 @@ class TestModelGenerator < Test::Unit::TestCase
109
116
  assert_match_in_file(/property :name, String/m, '/tmp/sample_project/app/models/user.rb')
110
117
  assert_match_in_file(/property :age, Integer/m, '/tmp/sample_project/app/models/user.rb')
111
118
  assert_match_in_file(/property :created_at, DateTime/m, '/tmp/sample_project/app/models/user.rb')
119
+ assert_match_in_file(/gem 'datamapper'/m,'/tmp/sample_project/Gemfile')
112
120
  end
113
121
 
114
122
  should "properly generate version numbers" do
@@ -145,7 +153,8 @@ class TestModelGenerator < Test::Unit::TestCase
145
153
  silence_logger { @project.start(['sample_project', '--root=/tmp', '--script=none', '-d=mongomapper']) }
146
154
  silence_logger { @model_gen.start(['person', '-r=/tmp/sample_project']) }
147
155
  assert_match_in_file(/class Person\n\s+include MongoMapper::Document/m, '/tmp/sample_project/app/models/person.rb')
148
- assert_match_in_file(/# key <name>, <type>[\n\s]+end/m, '/tmp/sample_project/app/models/person.rb')
156
+ assert_match_in_file(/# key <name>, <type>/m, '/tmp/sample_project/app/models/person.rb')
157
+ assert_match_in_file(/timestamps![\n\s]+end/m, '/tmp/sample_project/app/models/person.rb')
149
158
  end
150
159
 
151
160
  should "generate model file with given fields" do
@@ -155,6 +164,7 @@ class TestModelGenerator < Test::Unit::TestCase
155
164
  assert_match_in_file(/key :name, String/m, '/tmp/sample_project/app/models/user.rb')
156
165
  assert_match_in_file(/key :age, Integer/m, '/tmp/sample_project/app/models/user.rb')
157
166
  assert_match_in_file(/key :email, String/m, '/tmp/sample_project/app/models/user.rb')
167
+ assert_match_in_file(/timestamps!/m, '/tmp/sample_project/app/models/user.rb')
158
168
  end
159
169
  end
160
170
 
@@ -125,7 +125,8 @@ class TestProjectGenerator < Test::Unit::TestCase
125
125
  should "properly generate default for datamapper" do
126
126
  buffer = silence_logger { @project.start(['sample_project', '--root=/tmp', '--orm=datamapper', '--script=none']) }
127
127
  assert_match /Applying.*?datamapper.*?orm/, buffer
128
- assert_match_in_file(/gem 'dm-core'/, '/tmp/sample_project/Gemfile')
128
+ assert_match_in_file(/gem 'data_objects'/, '/tmp/sample_project/Gemfile')
129
+ assert_match_in_file(/gem 'datamapper'/, '/tmp/sample_project/Gemfile')
129
130
  assert_match_in_file(/DataMapper.setup/, '/tmp/sample_project/config/database.rb')
130
131
  assert_dir_exists('/tmp/sample_project/app/models')
131
132
  end
@@ -158,7 +159,7 @@ class TestProjectGenerator < Test::Unit::TestCase
158
159
  buffer = silence_logger { @project.start(['sample_project', '--root=/tmp', '--renderer=haml','--script=none']) }
159
160
  assert_match /Applying.*?haml.*?renderer/, buffer
160
161
  assert_match_in_file(/gem 'haml'/, '/tmp/sample_project/Gemfile')
161
- assert_match_in_file(/module SassInitializer.*Sass::Plugin::Rack/m, '/tmp/sample_project/config/initializers/sass.rb')
162
+ assert_match_in_file(/module SassInitializer.*Sass::Plugin::Rack/m, '/tmp/sample_project/lib/sass.rb')
162
163
  end
163
164
  end
164
165
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -12,7 +12,7 @@ autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
14
 
15
- date: 2010-02-18 00:00:00 +01:00
15
+ date: 2010-02-23 00:00:00 -08:00
16
16
  default_executable: padrino-gen
17
17
  dependencies:
18
18
  - !ruby/object:Gem::Dependency
@@ -23,7 +23,7 @@ dependencies:
23
23
  requirements:
24
24
  - - "="
25
25
  - !ruby/object:Gem::Version
26
- version: 0.8.5
26
+ version: 0.9.0
27
27
  version:
28
28
  - !ruby/object:Gem::Dependency
29
29
  name: haml
@@ -138,11 +138,10 @@ files:
138
138
  - lib/padrino-gen/generators/project/app/controllers/.empty_directory
139
139
  - lib/padrino-gen/generators/project/app/helpers/.empty_directory
140
140
  - lib/padrino-gen/generators/project/app/views/.empty_directory
141
+ - lib/padrino-gen/generators/project/app/views/layouts/.emptydirectory
141
142
  - lib/padrino-gen/generators/project/config.ru
142
143
  - lib/padrino-gen/generators/project/config/apps.rb.tt
143
144
  - lib/padrino-gen/generators/project/config/boot.rb
144
- - lib/padrino-gen/generators/project/config/initializers/.empty_directory
145
- - lib/padrino-gen/generators/project/config/initializers/example.rb
146
145
  - lib/padrino-gen/generators/project/public/images/.empty_directory
147
146
  - lib/padrino-gen/generators/project/public/javascripts/.empty_directory
148
147
  - lib/padrino-gen/generators/project/public/stylesheets/.empty_directory
@@ -158,7 +157,6 @@ files:
158
157
  - lib/padrino-gen/generators/templates/scripts/right.js
159
158
  - lib/padrino-gen/padrino-tasks/activerecord.rb
160
159
  - lib/padrino-gen/padrino-tasks/datamapper.rb
161
- - lib/padrino-gen/padrino-tasks/locale.rb
162
160
  - lib/padrino-gen/padrino-tasks/seed.rb
163
161
  - padrino-gen.gemspec
164
162
  - test/helper.rb
@@ -1,27 +0,0 @@
1
- ##
2
- # Initializers can be used to configure information about your padrino app
3
- # The following format is used because initializers are applied as plugins into the application
4
- #
5
- module ExampleInitializer
6
- def self.registered(app)
7
- ##
8
- # Simple Redmine Issue
9
- #
10
- # app.error 500 do
11
- # # Delivery error to our server
12
- # boom = env['sinatra.error']
13
- # body = ["#{boom.class} - #{boom.message}:", *boom.backtrace].join("\n ")
14
- # redmine = ["project: foo", "tracker: Bug", "priority: high"].join("\n")
15
- # logger.error body
16
- # Padrino::Mailer::MailObject.new(
17
- # :subject => "[PROJECT] #{boom.class} - #{boom.message}",
18
- # :to => "exceptions@foo.com",
19
- # :from => "help@foo.com",
20
- # :body => [body, redmine].join("\n\n")
21
- # ).deliver
22
- # response.status = 500
23
- # content_type 'text/html', :charset => "utf-8"
24
- # render "errors"
25
- # end
26
- end
27
- end
@@ -1,42 +0,0 @@
1
- namespace :locale do
2
- desc "Create or update the app/models locale using your I18n.locale"
3
- task :models => :environment do
4
- models = Dir["#{Padrino.root}/app/models/**/*.rb"].collect { |m| File.basename(m, ".rb") }
5
-
6
- models.each do |m|
7
- # Get the model class
8
- klass = m.camelize.constantize
9
- next unless klass.respond_to?(:properties) || klass.respond_to?(:human_local_name) || klass.respond_to?(:human_local_attribute_name)
10
-
11
- # Init the processing
12
- print "Processing #{m.humanize}: "
13
- FileUtils.mkdir_p("#{Padrino.root}/app/locale/models/#{m}")
14
- langs = Array(I18n.locale) # for now we use only one
15
-
16
- # Create models for it and en locales
17
- langs.each do |lang|
18
- filename = "#{Padrino.root}/app/locale/models/#{m}/#{lang}.yml"
19
- columns = klass.properties.collect(&:name)
20
- # If the lang file already exist we need to check it
21
- if File.exist?(filename)
22
- locale = File.open(filename).read
23
- columns.each do |c|
24
- locale += "\n #{c}: #{klass.human_local_attribute_name(c)}" unless locale.include?("#{c}:")
25
- end
26
- print "Lang #{lang.to_s.upcase} already exist ... "; $stdout.flush
27
- # Do some ere
28
- else
29
- locale = "#{lang}:" + "\n" +
30
- " models:" + "\n" +
31
- " #{m}:" + "\n" +
32
- " name: #{klass.human_local_name}" + "\n" +
33
- " attributes:" + "\n" +
34
- columns.collect { |c| " #{c}: #{klass.human_local_attribute_name(c)}" }.join("\n")
35
- print "created a new for #{lang.to_s.upcase} Lang ... "; $stdout.flush
36
- end
37
- File.open(filename, "w") { |f| f.puts locale }
38
- end
39
- puts
40
- end
41
- end
42
- end