Skip to content
Browse files

use railtie

  • Loading branch information...
1 parent 803d0bc commit a43ead29d8bb1fedaf47ce3275b207603a8ec5ec @clemens committed Oct 4, 2011
Showing with 27 additions and 6 deletions.
  1. +7 −2 lib/delocalize.rb
  2. +0 −3 lib/delocalize/rails_ext.rb
  3. +1 −1 lib/delocalize/rails_ext/time_zone.rb
  4. +15 −0 lib/delocalize/railtie.rb
  5. +4 −0 test/test_helper.rb
View
9 lib/delocalize.rb
@@ -1,4 +1,9 @@
require 'delocalize/ruby_ext'
require 'delocalize/i18n_ext'
-require 'delocalize/rails_ext'
-require 'delocalize/localized_date_time_parser'
+require 'delocalize/localized_date_time_parser'
+
+if defined?(Rails::Railtie)
+ require 'delocalize/railtie'
+elsif defined?(Rails::Initializer)
+ raise "This version of delocalize is only compatible with Rails 3.0 or newer"
+end
View
3 lib/delocalize/rails_ext.rb
@@ -1,3 +0,0 @@
-require 'delocalize/rails_ext/active_record'
-require 'delocalize/rails_ext/action_view'
-require 'delocalize/rails_ext/time_zone'
View
2 lib/delocalize/rails_ext/time_zone.rb
@@ -4,4 +4,4 @@
def parse_localized(time_with_zone)
Delocalize::LocalizedDateTimeParser.parse(time_with_zone, self.class)
end
-end
+end
View
15 lib/delocalize/railtie.rb
@@ -0,0 +1,15 @@
+module Delocalize
+ class Railtie < Rails::Railtie
+ initializer "delocalize" do |app|
+ ActiveSupport.on_load :active_record do
+ require 'delocalize/rails_ext/active_record'
+ end
+
+ ActiveSupport.on_load :action_view do
+ require 'delocalize/rails_ext/action_view'
+ end
+
+ require 'delocalize/rails_ext/time_zone'
+ end
+ end
+end
View
4 test/test_helper.rb
@@ -7,6 +7,10 @@
require 'test/unit'
+require 'delocalize/rails_ext/action_view'
+require 'delocalize/rails_ext/active_record'
+require 'delocalize/rails_ext/time_zone'
+
I18n.backend.store_translations :de, {
:date => {
:input => {

0 comments on commit a43ead2

Please sign in to comment.
Something went wrong with that request. Please try again.