it 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +13 -0
- data/lib/it/plain.rb +12 -0
- data/lib/it.rb +9 -0
- data/spec/it/helper_spec.rb +10 -0
- data/spec/it/plain_spec.rb +30 -0
- data/spec/it_spec.rb +19 -1
- metadata +32 -4
data/README.textile
CHANGED
@@ -52,6 +52,19 @@ Even nested interpolations are possible:
|
|
52
52
|
|
53
53
|
<pre><code><%=it "copy", link: "mailto:igel@igels.net", user: 'iGEL', :b => It.tag(:b) %></code></pre>
|
54
54
|
|
55
|
+
If you would like to use the same translations in your html and plain text mails, you will like the +It.plain+ method:
|
56
|
+
<pre><code>en:
|
57
|
+
mail_copy: "Do you like %{link:Rails}?"</code></pre>
|
58
|
+
|
59
|
+
<pre><code>HTML mail:
|
60
|
+
<%= it "mail_copy", link: It.link("http://www.rubyonrails.org/") %>
|
61
|
+
|
62
|
+
Plain mail:
|
63
|
+
<%= it "mail_copy", link: It.plain("%s[http://www.rubyonrails.org/]") %>
|
64
|
+
</code></pre>
|
65
|
+
|
66
|
+
The +%s+ will be replaced with the label, in the example with Rails. You could provide any other string containing +%s+. The default is just +%s+, so it will return only the label itself.
|
67
|
+
|
55
68
|
h2. isit18.com?
|
56
69
|
|
57
70
|
Well, the specs pass on 1.8.7, but I never tried it in a real app. Report any issues on "github":https://github.com/iGEL/it/issues
|
data/lib/it/plain.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
module It
|
2
|
+
class Plain < Tag
|
3
|
+
def initialize(template = "%s")
|
4
|
+
raise TypeError, "expected a String, got #{template.class}" unless template.is_a?(String)
|
5
|
+
@template = template
|
6
|
+
end
|
7
|
+
|
8
|
+
def process(content)
|
9
|
+
sprintf(@template, content)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
data/lib/it.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'it/tag'
|
2
2
|
require 'it/link'
|
3
|
+
require 'it/plain'
|
3
4
|
require 'it/helper'
|
4
5
|
|
5
6
|
ActiveSupport.on_load(:action_view) do
|
@@ -18,6 +19,14 @@ module It
|
|
18
19
|
It::Link.new(href, options)
|
19
20
|
end
|
20
21
|
|
22
|
+
# Creates a new plain replacement to be used in +it+.
|
23
|
+
#
|
24
|
+
# * +template+: A string to be used as the template. An example would be <code>"%s[http://www.rubyonrails.org]"</code>. Defaults to
|
25
|
+
# <code>"%s"</code>. <em>(optional)</em>
|
26
|
+
def self.plain(template = "%s")
|
27
|
+
It::Plain.new(template)
|
28
|
+
end
|
29
|
+
|
21
30
|
# Creates a new tag to be used in +it+.
|
22
31
|
#
|
23
32
|
# * +tag_name+: The name of the tag as a Symbol or String.
|
data/spec/it/helper_spec.rb
CHANGED
@@ -30,6 +30,10 @@ describe It::Helper, "#it" do
|
|
30
30
|
@view.it("test1", :link => It.link("http://www.rubyonrails.org", :target => "_blank")).should == 'I\'m containing a <a href="http://www.rubyonrails.org" target="_blank">link to Rails</a> in the middle.'
|
31
31
|
end
|
32
32
|
|
33
|
+
it "should support the plain thing" do
|
34
|
+
@view.it("test1", :link => It.plain("%s[http://www.rubyonrails.org]")).should == 'I\'m containing a link to Rails[http://www.rubyonrails.org] in the middle.'
|
35
|
+
end
|
36
|
+
|
33
37
|
it "should parse other tags as well" do
|
34
38
|
@view.it("test1", :link => It.tag(:b, :class => "classy")).should == 'I\'m containing a <b class="classy">link to Rails</b> in the middle.'
|
35
39
|
end
|
@@ -101,4 +105,10 @@ describe It::Helper, "#it" do
|
|
101
105
|
I18n.backend.store_translations(:en, :test9 => "We can %{br} do line breaks")
|
102
106
|
@view.it("test9", :br => It.tag(:br)).should == 'We can <br /> do line breaks'
|
103
107
|
end
|
108
|
+
|
109
|
+
it 'should support dot-prefixed keys' do
|
110
|
+
I18n.backend.store_translations(:en, :widgets => { :show => { :all_widgets => "See %{widgets_link:all widgets}" } })
|
111
|
+
@view.instance_variable_set(:"@_virtual_path", "widgets/show")
|
112
|
+
@view.it('.all_widgets', :widgets_link => '/widgets').should == 'See <a href="/widgets">all widgets</a>'
|
113
|
+
end
|
104
114
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'it'
|
3
|
+
|
4
|
+
describe It::Plain, '.new' do
|
5
|
+
it "should work with no params" do
|
6
|
+
expect { It::Plain.new }.not_to raise_error
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should work with a String" do
|
10
|
+
expect { It::Plain.new("%s[http://www.rubyonrails.org]") }.not_to raise_error
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should raise ArgumentError with 2 params" do
|
14
|
+
expect { It::Plain.new("asdf", "asdf")}.to raise_error(ArgumentError, "wrong number of arguments (2 for 1)")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should raise a TypeError, if the first param is not a String" do
|
18
|
+
expect { It::Plain.new(1)}.to raise_error(TypeError)
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
describe It::Plain, '#process' do
|
23
|
+
it "should return 'Ruby on Rails', if no param was given" do
|
24
|
+
It::Plain.new.process("Ruby on Rails").should == 'Ruby on Rails'
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return 'Ruby on Rails[http://www.rubyonrails.org/]'" do
|
28
|
+
It::Plain.new("%s[http://www.rubyonrails.org/]").process("Ruby on Rails").should == 'Ruby on Rails[http://www.rubyonrails.org/]'
|
29
|
+
end
|
30
|
+
end
|
data/spec/it_spec.rb
CHANGED
@@ -17,7 +17,7 @@ describe It, '.link' do
|
|
17
17
|
end
|
18
18
|
|
19
19
|
it "should raise ArgumentError, if called with three params" do
|
20
|
-
expect { It
|
20
|
+
expect { It.link("http://www.rubyonrails.org/", {}, :blubb) }.to raise_error(ArgumentError)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
@@ -37,4 +37,22 @@ describe It, '.tag' do
|
|
37
37
|
it "should raise an ArgumentError if called with three params" do
|
38
38
|
expect { It.tag(:b, {}, :blubb) }.to raise_error(ArgumentError)
|
39
39
|
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe It, '.plain' do
|
43
|
+
it "should return an It::Plain object" do
|
44
|
+
It.plain.class.should == It::Plain
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should work without params" do
|
48
|
+
expect { It.plain }.not_to raise_error
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should accept one param" do
|
52
|
+
expect { It.plain("%s[http://www.rubyonrails.org/]") }.not_to raise_error
|
53
|
+
end
|
54
|
+
|
55
|
+
it "should raise ArgumentError, if called with two params" do
|
56
|
+
expect { It.plain("%s[http://www.rubyonrails.org/]", :blubb) }.to raise_error(ArgumentError)
|
57
|
+
end
|
40
58
|
end
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
4
|
+
hash: 21
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 2
|
9
|
+
- 1
|
10
|
+
version: 0.2.1
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Johannes Barre
|
@@ -10,7 +15,8 @@ autorequire:
|
|
10
15
|
bindir: bin
|
11
16
|
cert_chain: []
|
12
17
|
|
13
|
-
date: 2011-
|
18
|
+
date: 2011-08-05 00:00:00 +02:00
|
19
|
+
default_executable:
|
14
20
|
dependencies:
|
15
21
|
- !ruby/object:Gem::Dependency
|
16
22
|
name: actionpack
|
@@ -20,6 +26,11 @@ dependencies:
|
|
20
26
|
requirements:
|
21
27
|
- - ">="
|
22
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 7
|
30
|
+
segments:
|
31
|
+
- 3
|
32
|
+
- 0
|
33
|
+
- 0
|
23
34
|
version: 3.0.0
|
24
35
|
type: :runtime
|
25
36
|
version_requirements: *id001
|
@@ -31,6 +42,11 @@ dependencies:
|
|
31
42
|
requirements:
|
32
43
|
- - ~>
|
33
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
46
|
+
segments:
|
47
|
+
- 2
|
48
|
+
- 6
|
49
|
+
- 0
|
34
50
|
version: 2.6.0
|
35
51
|
type: :development
|
36
52
|
version_requirements: *id002
|
@@ -51,11 +67,14 @@ files:
|
|
51
67
|
- lib/it/helper.rb
|
52
68
|
- lib/it/tag.rb
|
53
69
|
- lib/it/link.rb
|
70
|
+
- lib/it/plain.rb
|
54
71
|
- spec/it/helper_spec.rb
|
55
72
|
- spec/it/link_spec.rb
|
56
73
|
- spec/it/tag_spec.rb
|
74
|
+
- spec/it/plain_spec.rb
|
57
75
|
- spec/it_spec.rb
|
58
76
|
- spec/spec_helper.rb
|
77
|
+
has_rdoc: true
|
59
78
|
homepage: https://github.com/igel/it
|
60
79
|
licenses: []
|
61
80
|
|
@@ -69,17 +88,25 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
88
|
requirements:
|
70
89
|
- - ">="
|
71
90
|
- !ruby/object:Gem::Version
|
91
|
+
hash: 3
|
92
|
+
segments:
|
93
|
+
- 0
|
72
94
|
version: "0"
|
73
95
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
96
|
none: false
|
75
97
|
requirements:
|
76
98
|
- - ">="
|
77
99
|
- !ruby/object:Gem::Version
|
100
|
+
hash: 23
|
101
|
+
segments:
|
102
|
+
- 1
|
103
|
+
- 3
|
104
|
+
- 6
|
78
105
|
version: 1.3.6
|
79
106
|
requirements: []
|
80
107
|
|
81
108
|
rubyforge_project:
|
82
|
-
rubygems_version: 1.
|
109
|
+
rubygems_version: 1.3.7
|
83
110
|
signing_key:
|
84
111
|
specification_version: 3
|
85
112
|
summary: A helper for links and other html tags in your translations
|
@@ -87,5 +114,6 @@ test_files:
|
|
87
114
|
- spec/it/helper_spec.rb
|
88
115
|
- spec/it/link_spec.rb
|
89
116
|
- spec/it/tag_spec.rb
|
117
|
+
- spec/it/plain_spec.rb
|
90
118
|
- spec/it_spec.rb
|
91
119
|
- spec/spec_helper.rb
|