less_simple 0.1.0 → 0.1.1

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.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.0
1
+ 0.1.1
data/less_simple.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{less_simple}
8
- s.version = "0.1.0"
8
+ s.version = "0.1.1"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Ryan Angilly"]
data/lib/less_simple.rb CHANGED
@@ -13,3 +13,38 @@ module I18n
13
13
  end
14
14
  end
15
15
  end
16
+
17
+ class LessSimple
18
+ @@klass = I18n::Backend::Simple
19
+
20
+ def self.klass= val
21
+ @@klass = val
22
+ end
23
+
24
+ def self.klass
25
+ @@klass
26
+ end
27
+
28
+ def self.factory_backend
29
+ subclass.new
30
+ end
31
+
32
+ def self.subclass
33
+ subclass = eval("class LessSimple::#{klass.to_s.gsub('::', '')} < #{klass}; self; end")
34
+
35
+ subclass.class_eval do
36
+ attr_accessor :interpolation_defaults
37
+ include InstanceMethods
38
+ end
39
+
40
+ subclass
41
+ end
42
+
43
+ module InstanceMethods
44
+ def translate(locale, key, options = {})
45
+ options = (interpolation_defaults || {}).merge options
46
+ super locale, key, options
47
+ end
48
+ end
49
+
50
+ end
@@ -3,34 +3,24 @@ require File.join(File.dirname(__FILE__), 'test_helper')
3
3
  class TestLessSimple < Test::Unit::TestCase
4
4
 
5
5
  should "have LessSimple" do
6
- assert I18n::Backend::LessSimple
6
+ assert LessSimple
7
7
  end
8
8
 
9
- context "with a less_simple backend" do
10
- setup do
11
- @backend = I18n::Backend::LessSimple.new
12
- @backend.load_translations(File.join(File.dirname(__FILE__), 'en.yml'))
13
- end
14
-
15
- should "have interpolation_defaults" do
16
- assert @backend.respond_to?(:interpolation_defaults=)
17
- assert @backend.respond_to?(:interpolation_defaults)
18
- end
9
+ context "On top of the I18n Simple backend" do
19
10
 
20
- should "still work" do
21
- assert_equal "Oh hi there", @backend.translate('en', 'welcome')
22
- assert_equal "MPB Party Planner", @backend.translate('en', 'site', :site_name => 'MPB')
11
+ should "default to Simple" do
12
+ assert_equal I18n::Backend::Simple, LessSimple.klass
23
13
  end
24
14
 
25
- should "still throw exceptions on missing values" do
26
- assert_raises I18n::MissingInterpolationArgument do
27
- puts @backend.translate('en', 'site')
15
+ context "with a simple backend" do
16
+ setup do
17
+ @backend = LessSimple.factory_backend
18
+ @backend.load_translations(File.join(File.dirname(__FILE__), 'en.yml'))
28
19
  end
29
- end
30
20
 
31
- context "with defaults" do
32
- setup do
33
- @backend.interpolation_defaults = {:site_name => 'skin & bones'}
21
+ should "have interpolation_defaults" do
22
+ assert @backend.respond_to?(:interpolation_defaults=)
23
+ assert @backend.respond_to?(:interpolation_defaults)
34
24
  end
35
25
 
36
26
  should "still work" do
@@ -38,8 +28,25 @@ class TestLessSimple < Test::Unit::TestCase
38
28
  assert_equal "MPB Party Planner", @backend.translate('en', 'site', :site_name => 'MPB')
39
29
  end
40
30
 
41
- should "use defaults" do
42
- assert_equal 'skin & bones Party Planner', @backend.translate('en', 'site')
31
+ should "still throw exceptions on missing values" do
32
+ assert_raises I18n::MissingInterpolationArgument do
33
+ puts @backend.translate('en', 'site')
34
+ end
35
+ end
36
+
37
+ context "with defaults" do
38
+ setup do
39
+ @backend.interpolation_defaults = {:site_name => 'skin & bones'}
40
+ end
41
+
42
+ should "still work" do
43
+ assert_equal "Oh hi there", @backend.translate('en', 'welcome')
44
+ assert_equal "MPB Party Planner", @backend.translate('en', 'site', :site_name => 'MPB')
45
+ end
46
+
47
+ should "use defaults" do
48
+ assert_equal 'skin & bones Party Planner', @backend.translate('en', 'site')
49
+ end
43
50
  end
44
51
  end
45
52
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 0
9
- version: 0.1.0
8
+ - 1
9
+ version: 0.1.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Ryan Angilly