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 +1 -1
- data/less_simple.gemspec +1 -1
- data/lib/less_simple.rb +35 -0
- data/test/unit/test_less_simple.rb +30 -23
- metadata +2 -2
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/less_simple.gemspec
CHANGED
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
|
6
|
+
assert LessSimple
|
7
7
|
end
|
8
8
|
|
9
|
-
context "
|
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 "
|
21
|
-
assert_equal
|
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
|
-
|
26
|
-
|
27
|
-
|
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
|
-
|
32
|
-
|
33
|
-
@backend.interpolation_defaults
|
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 "
|
42
|
-
|
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
|