it 0.2.4 → 0.2.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,4 +1,4 @@
1
- "!https://codeclimate.com/github/iGEL/it.png!":https://codeclimate.com/github/iGEL/it "!https://travis-ci.org/iGEL/it.png!":https://travis-ci.org/iGEL/it (Specs pass on Ruby 1.8.7, 1.9.2, 1.9.3, 2.0.0, Rubinius and Jruby)
1
+ "!https://codeclimate.com/github/iGEL/it.png!":https://codeclimate.com/github/iGEL/it "!https://travis-ci.org/iGEL/it.png!":https://travis-ci.org/iGEL/it (Tests Ruby 1.9.2, 1.9.3, 2.0.0, Rubinius and Jruby)
2
2
 
3
3
  h1. What is *it*?
4
4
 
@@ -38,7 +38,7 @@ As you see above, unless the interpolation name is @link@ or starts with @_link@
38
38
 
39
39
  <pre><code><%=it "copy", guide: It.link("http://guides.rubyonrails.org/i18n.html", target: '_blank', class: "important") %></code></pre>
40
40
 
41
- You may pass any kind of object accepted by @link_to@ as the link target, so your loved named routes like @article_path(:id => article.id)@ will all work fine.
41
+ You may pass any kind of object accepted by @link_to@ as the link target, so your loved named routes like @article_path(id: article.id)@ will all work fine.
42
42
 
43
43
  Want to introduce some markup into your sentences? *it* will help you:
44
44
 
@@ -52,7 +52,7 @@ Even nested interpolations are possible:
52
52
  <pre><code>en:
53
53
  copy: "Want to contact %{user}%? %{link:send %{b:%{user} a message}}!"</code></pre>
54
54
 
55
- <pre><code><%=it "copy", link: "mailto:igel@igels.net", user: 'iGEL', :b => It.tag(:b) %></code></pre>
55
+ <pre><code><%=it "copy", link: "mailto:igel@igels.net", user: 'iGEL', b: It.tag(:b) %></code></pre>
56
56
 
57
57
  If you would like to use the same translations in your html and plain text mails, you will like the @It.plain@ method:
58
58
  <pre><code>en:
data/Rakefile CHANGED
@@ -2,4 +2,4 @@ require 'rspec/core/rake_task'
2
2
 
3
3
  RSpec::Core::RakeTask.new(:spec)
4
4
 
5
- task :default => :spec
5
+ task default: :spec
data/lib/it.rb CHANGED
@@ -14,13 +14,13 @@ module It
14
14
  # It outside of your views. See documentation at Helper#it
15
15
  def self.it(identifier, options = {})
16
16
  options.stringify_keys!
17
- Parser.new(I18n.t(identifier, :locale => options["locale"]), options).process
17
+ Parser.new(I18n.t(identifier, locale: (options["locale"] || I18n.locale), default: options['default']), options).process
18
18
  end
19
19
 
20
20
  # Creates a new link to be used in +it+.
21
21
  #
22
22
  # * +href+: The url for the link. You may specify it as a String or as a named route like +article_path+. It's not possible to specify
23
- # a Hash like <code>{:controller => "articles", :action => "index"}</code> directly. Use the +url_for+ helper, if you would like to specify your
23
+ # a Hash like <code>{controller: "articles", action: "index"}</code> directly. Use the +url_for+ helper, if you would like to specify your
24
24
  # links like that.
25
25
  # * +options+: The options as an Hash. Use them like you would with +link_to+. <em>(optional)</em>
26
26
  def self.link(href, options = {})
@@ -13,21 +13,21 @@ module It
13
13
  #
14
14
  # # translation: "Already signed up? %{login_link:Sign in}!"
15
15
  #
16
- # <%=it("translation", :login_link => It.link(login_path))
16
+ # <%=it("translation", login_link: It.link(login_path))
17
17
  #
18
18
  # If your link doesn't require additional attributes and the name is +link+, starts with +link_+ or ends with +_link+,
19
19
  # you may specify the argument as a String or your helper.
20
20
  #
21
21
  # # translation: "Already signed up? %{login_link:Sign in}!"
22
22
  #
23
- # <%=it("translation", :login_link => login_path)
23
+ # <%=it("translation", login_link: login_path)
24
24
  #
25
25
  # You may have as many tags inside of one translation as you like, and you even may nest them into each other. Also you
26
26
  # may specify arguments to links and other tags.
27
27
  #
28
28
  # # translation: "The top contributor of %{wiki_link:our wiki} is currently %{user_link:%{b:%{name}}}. Thanks a lot, %{name}!"
29
29
  #
30
- # <%= it("translation", :wiki_link => wiki_path, :name => user.name, :b => It.tag(:b, :class => "user"), :user_link => It.link(user_path(user), :target => "_blank"))
30
+ # <%= it("translation", wiki_link: wiki_path, name: user.name, b: It.tag(:b, class: "user"), user_link: It.link(user_path(user), target: "_blank"))
31
31
  #
32
32
  # I recommend to limit the use of +it+ as much as possible. You could use it for <code><div></code> or <code><br /></code>, but I think,
33
33
  # things seperated over multiple lines should go into different translations. Use it for inline tags like links, <code><span></code>,
@@ -40,7 +40,7 @@ module It
40
40
  #
41
41
  def it(identifier, options = {})
42
42
  options.stringify_keys!
43
- It::Parser.new(t(identifier, :locale => options["locale"]), options).process
43
+ It::Parser.new(t(identifier, locale: (options["locale"] || I18n.locale)), options).process
44
44
  end
45
45
  end
46
46
  end
@@ -2,11 +2,12 @@
2
2
 
3
3
  require 'spec_helper'
4
4
  require 'it'
5
+ require 'active_support/core_ext/string'
5
6
 
6
7
  describe It::Helper, "#it" do
7
8
  before do
8
- I18n.backend.store_translations(:en, :test1 => "I have a %{link:link to Rails} in the middle.")
9
- I18n.backend.store_translations(:de, :test1 => "Ich habe einen %{link:Link zu Rails} in der Mitte.")
9
+ I18n.backend.store_translations(:en, test1: "I have a %{link:link to Rails} in the middle.")
10
+ I18n.backend.store_translations(:de, test1: "Ich habe einen %{link:Link zu Rails} in der Mitte.")
10
11
 
11
12
  @view = ActionView::Base.new
12
13
  @controller = ActionController::Base.new
@@ -18,120 +19,120 @@ describe It::Helper, "#it" do
18
19
  end
19
20
 
20
21
  it "should insert the link into the string" do
21
- expect(@view.it("test1", :link => It.link("http://www.rubyonrails.org"))).to eq('I have a <a href="http://www.rubyonrails.org">link to Rails</a> in the middle.')
22
+ expect(@view.it("test1", link: It.link("http://www.rubyonrails.org"))).to eq('I have a <a href="http://www.rubyonrails.org">link to Rails</a> in the middle.')
22
23
  end
23
24
 
24
25
  it "should insert the link into the German translation" do
25
26
  I18n.locale = :de
26
- expect(@view.it("test1", :link => It.link("http://www.rubyonrails.org"))).to eq('Ich habe einen <a href="http://www.rubyonrails.org">Link zu Rails</a> in der Mitte.')
27
+ expect(@view.it("test1", link: It.link("http://www.rubyonrails.org"))).to eq('Ich habe einen <a href="http://www.rubyonrails.org">Link zu Rails</a> in der Mitte.')
27
28
  end
28
29
 
29
30
  it "should allow link options to be set" do
30
- expect(@view.it("test1", :link => It.link("http://www.rubyonrails.org", :target => "_blank"))).to eq('I have a <a href="http://www.rubyonrails.org" target="_blank">link to Rails</a> in the middle.')
31
+ expect(@view.it("test1", link: It.link("http://www.rubyonrails.org", target: "_blank"))).to eq('I have a <a href="http://www.rubyonrails.org" target="_blank">link to Rails</a> in the middle.')
31
32
  end
32
33
 
33
34
  it "should support the plain thing" do
34
- expect(@view.it("test1", :link => It.plain("%s[http://www.rubyonrails.org]"))).to eq('I have a link to Rails[http://www.rubyonrails.org] in the middle.')
35
+ expect(@view.it("test1", link: It.plain("%s[http://www.rubyonrails.org]"))).to eq('I have a link to Rails[http://www.rubyonrails.org] in the middle.')
35
36
  end
36
37
 
37
38
  it "should parse other tags as well" do
38
- expect(@view.it("test1", :link => It.tag(:b, :class => "classy"))).to eq('I have a <b class="classy">link to Rails</b> in the middle.')
39
+ expect(@view.it("test1", link: It.tag(:b, class: "classy"))).to eq('I have a <b class="classy">link to Rails</b> in the middle.')
39
40
  end
40
41
 
41
42
  it "should mark the result as html safe" do
42
- expect(@view.it("test1", :link => It.link("http://www.rubyonrails.org")).html_safe?).to be_true
43
+ expect(@view.it("test1", link: It.link("http://www.rubyonrails.org")).html_safe?).to be_true
43
44
  end
44
45
 
45
46
  it "should escape all html in the translation" do
46
- I18n.backend.store_translations(:en, :test2 => "<a href=\"hax0r\"> & %{link:link -> Rails} in <b>the middle</b>.")
47
- expect(@view.it("test2", :link => It.link("http://www.rubyonrails.org"))).to eq('&lt;a href=&quot;hax0r&quot;&gt; &amp; <a href="http://www.rubyonrails.org">link -&gt; Rails</a> in &lt;b&gt;the middle&lt;/b&gt;.')
47
+ I18n.backend.store_translations(:en, test2: "<a href=\"hax0r\"> & %{link:link -> Rails} in <b>the middle</b>.")
48
+ expect(@view.it("test2", link: It.link("http://www.rubyonrails.org"))).to eq('&lt;a href=&quot;hax0r&quot;&gt; &amp; <a href="http://www.rubyonrails.org">link -&gt; Rails</a> in &lt;b&gt;the middle&lt;/b&gt;.')
48
49
  end
49
50
 
50
51
  it "should also work with 2 links" do
51
- I18n.backend.store_translations(:en, :test3 => "I like %{link1:rails} and %{link2:github}.")
52
- expect(@view.it("test3", :link1 => It.link("http://www.rubyonrails.org"), :link2 => It.link("http://www.github.com"))).to eq('I like <a href="http://www.rubyonrails.org">rails</a> and <a href="http://www.github.com">github</a>.')
52
+ I18n.backend.store_translations(:en, test3: "I like %{link1:rails} and %{link2:github}.")
53
+ expect(@view.it("test3", link1: It.link("http://www.rubyonrails.org"), link2: It.link("http://www.github.com"))).to eq('I like <a href="http://www.rubyonrails.org">rails</a> and <a href="http://www.github.com">github</a>.')
53
54
  end
54
55
 
55
56
  it "should allow normal I18n interpolations" do
56
- I18n.backend.store_translations(:en, :test4 => "I have a %{link:link to Rails} in the %{position}.")
57
- expect(@view.it("test4", :link => It.link("http://www.rubyonrails.org"), :position => "middle")).to eq('I have a <a href="http://www.rubyonrails.org">link to Rails</a> in the middle.')
57
+ I18n.backend.store_translations(:en, test4: "I have a %{link:link to Rails} in the %{position}.")
58
+ expect(@view.it("test4", link: It.link("http://www.rubyonrails.org"), position: "middle")).to eq('I have a <a href="http://www.rubyonrails.org">link to Rails</a> in the middle.')
58
59
  end
59
60
 
60
61
  it "should allow Integers as normal interpolation" do
61
- I18n.backend.store_translations(:en, :test5 => "Hello %{name}.")
62
- expect(@view.it("test5", :name => 2)).to eq('Hello 2.')
62
+ I18n.backend.store_translations(:en, test5: "Hello %{name}.")
63
+ expect(@view.it("test5", name: 2)).to eq('Hello 2.')
63
64
  end
64
65
 
65
66
  it "should escape the HTML in normal interpolations" do
66
- I18n.backend.store_translations(:en, :test5 => "Hello %{name}.")
67
- expect(@view.it("test5", :name => '<a href="http://evil.haxor.com">victim</a>')).to eq('Hello &lt;a href=&quot;http://evil.haxor.com&quot;&gt;victim&lt;/a&gt;.')
67
+ I18n.backend.store_translations(:en, test5: "Hello %{name}.")
68
+ expect(@view.it("test5", name: '<a href="http://evil.haxor.com">victim</a>')).to eq('Hello &lt;a href=&quot;http://evil.haxor.com&quot;&gt;victim&lt;/a&gt;.')
68
69
  end
69
70
 
70
71
  it "should not escape html_safe interpolations" do
71
- I18n.backend.store_translations(:en, :test5 => "Hello %{name}.")
72
- expect(@view.it("test5", :name => '<a href="http://www.rubyonrails.org">Rails</a>'.html_safe)).to eq('Hello <a href="http://www.rubyonrails.org">Rails</a>.')
72
+ I18n.backend.store_translations(:en, test5: "Hello %{name}.")
73
+ expect(@view.it("test5", name: '<a href="http://www.rubyonrails.org">Rails</a>'.html_safe)).to eq('Hello <a href="http://www.rubyonrails.org">Rails</a>.')
73
74
  end
74
75
 
75
76
  it "should allow interpolations inside of links" do
76
- I18n.backend.store_translations(:en, :test6 => "Did you read our %{link:nice %{article}}?")
77
- expect(@view.it("test6", :link => It.link("/article/2"), :article => "article")).to eq('Did you read our <a href="/article/2">nice article</a>?')
77
+ I18n.backend.store_translations(:en, test6: "Did you read our %{link:nice %{article}}?")
78
+ expect(@view.it("test6", link: It.link("/article/2"), article: "article")).to eq('Did you read our <a href="/article/2">nice article</a>?')
78
79
  end
79
80
 
80
81
  it "should raise a KeyError, if the key was not given" do
81
- expect { @view.it("test1", :blubb => true) }.to raise_error(KeyError, "key{link} not found")
82
+ expect { @view.it("test1", blubb: true) }.to raise_error(KeyError, "key{link} not found")
82
83
  end
83
84
 
84
85
  it "should raise an ArgumentError, if a String was given for an interpolation with argument" do
85
- I18n.backend.store_translations(:en, :test7 => "Sign up %{asdf:here}!")
86
- expect { @view.it("test7", :asdf => "Heinz") }.to raise_error(ArgumentError, "key{asdf} has an argument, so it cannot resolved with a String")
86
+ I18n.backend.store_translations(:en, test7: "Sign up %{asdf:here}!")
87
+ expect { @view.it("test7", asdf: "Heinz") }.to raise_error(ArgumentError, "key{asdf} has an argument, so it cannot resolved with a String")
87
88
  end
88
89
 
89
90
  it "should allow Strings, if the interpolation name is link" do
90
- I18n.backend.store_translations(:en, :test8 => "Sign up %{link:here}!")
91
- expect(@view.it("test8", :link => "/register")).to eq('Sign up <a href="/register">here</a>!')
91
+ I18n.backend.store_translations(:en, test8: "Sign up %{link:here}!")
92
+ expect(@view.it("test8", link: "/register")).to eq('Sign up <a href="/register">here</a>!')
92
93
  end
93
94
 
94
95
  it "should allow Strings, if the interpolation name ends with _link" do
95
- I18n.backend.store_translations(:en, :test8 => "Sign up %{register_link:here}!")
96
- expect(@view.it("test8", :register_link => "/register")).to eq('Sign up <a href="/register">here</a>!')
96
+ I18n.backend.store_translations(:en, test8: "Sign up %{register_link:here}!")
97
+ expect(@view.it("test8", register_link: "/register")).to eq('Sign up <a href="/register">here</a>!')
97
98
  end
98
99
 
99
100
  it "should allow Strings, if the interpolation name starts with link_" do
100
- I18n.backend.store_translations(:en, :test8 => "Sign up %{link_to_register:here}!")
101
- expect(@view.it("test8", :link_to_register => "/register")).to eq('Sign up <a href="/register">here</a>!')
101
+ I18n.backend.store_translations(:en, test8: "Sign up %{link_to_register:here}!")
102
+ expect(@view.it("test8", link_to_register: "/register")).to eq('Sign up <a href="/register">here</a>!')
102
103
  end
103
104
 
104
105
  it "should work with tags without arguments" do
105
- I18n.backend.store_translations(:en, :test9 => "We can %{br} do line breaks")
106
- expect(@view.it("test9", :br => It.tag(:br))).to eq('We can <br /> do line breaks')
106
+ I18n.backend.store_translations(:en, test9: "We can %{br} do line breaks")
107
+ expect(@view.it("test9", br: It.tag(:br))).to eq('We can <br /> do line breaks')
107
108
  end
108
109
 
109
110
  it 'should support dot-prefixed keys' do
110
- I18n.backend.store_translations(:en, :widgets => { :show => { :all_widgets => "See %{widgets_link:all widgets}" } })
111
+ I18n.backend.store_translations(:en, widgets: { show: { all_widgets: "See %{widgets_link:all widgets}" } })
111
112
  @view.instance_variable_set(:"@_virtual_path", "widgets/show") # For Rails 3.0
112
113
  @view.instance_variable_set(:"@virtual_path", "widgets/show") # For Rails 3.1, 3.2 and probably 4.0
113
- expect(@view.it('.all_widgets', :widgets_link => '/widgets')).to eq('See <a href="/widgets">all widgets</a>')
114
+ expect(@view.it('.all_widgets', widgets_link: '/widgets')).to eq('See <a href="/widgets">all widgets</a>')
114
115
  end
115
116
 
116
117
  it 'should support the locale option' do
117
- expect(@view.it('test1', :locale => "de", :link => It.link("http://www.rubyonrails.org"))).to eq('Ich habe einen <a href="http://www.rubyonrails.org">Link zu Rails</a> in der Mitte.')
118
+ expect(@view.it('test1', locale: "de", link: It.link("http://www.rubyonrails.org"))).to eq('Ich habe einen <a href="http://www.rubyonrails.org">Link zu Rails</a> in der Mitte.')
118
119
  end
119
120
 
120
121
  context "With a pluralized translation" do
121
122
  before do
122
- I18n.backend.store_translations(:en, :test10 => {:zero => "You have zero messages.", :one => "You have %{link:one message}.", :other => "You have %{link:%{count} messages}."})
123
+ I18n.backend.store_translations(:en, test10: {zero: "You have zero messages.", one: "You have %{link:one message}.", other: "You have %{link:%{count} messages}."})
123
124
  end
124
125
 
125
126
  it 'should work with count = 0' do
126
- expect(@view.it("test10", :count => 0, :link => "/messages")).to eq('You have zero messages.')
127
+ expect(@view.it("test10", count: 0, link: "/messages")).to eq('You have zero messages.')
127
128
  end
128
129
 
129
130
  it 'should work with count = 1' do
130
- expect(@view.it("test10", :count => 1, :link => "/messages")).to eq('You have <a href="/messages">one message</a>.')
131
+ expect(@view.it("test10", count: 1, link: "/messages")).to eq('You have <a href="/messages">one message</a>.')
131
132
  end
132
133
 
133
134
  it 'should work with count > 1' do
134
- expect(@view.it("test10", :count => 2, :link => "/messages")).to eq('You have <a href="/messages">2 messages</a>.')
135
+ expect(@view.it("test10", count: 2, link: "/messages")).to eq('You have <a href="/messages">2 messages</a>.')
135
136
  end
136
137
  end
137
138
  end
@@ -9,7 +9,7 @@ describe It::Link, '.new' do
9
9
  end
10
10
 
11
11
  it "should accept a Hash as first param" do
12
- expect { It::Link.new({:controller => "articles", :action => "index"}) }.not_to raise_error
12
+ expect { It::Link.new({controller: "articles", action: "index"}) }.not_to raise_error
13
13
  end
14
14
 
15
15
  it "should raise a TypeError if the first param is an Integer" do
@@ -17,7 +17,7 @@ describe It::Link, '.new' do
17
17
  end
18
18
 
19
19
  it "should accept options as a Hash" do
20
- expect { It::Link.new("http://www.rubyonrails.org/", {:id => "identity", :class => "classy"}) }.not_to raise_error
20
+ expect { It::Link.new("http://www.rubyonrails.org/", {id: "identity", class: "classy"}) }.not_to raise_error
21
21
  end
22
22
 
23
23
  it "should raise a TypeError, if the options are a String" do
@@ -37,6 +37,6 @@ end
37
37
 
38
38
  describe It::Link, '#process' do
39
39
  it "should return a link with the options set and the content as label" do
40
- expect(It::Link.new("http://www.rubyonrails.org", :target => "_blank").process("Rails")).to eq('<a href="http://www.rubyonrails.org" target="_blank">Rails</a>')
40
+ expect(It::Link.new("http://www.rubyonrails.org", target: "_blank").process("Rails")).to eq('<a href="http://www.rubyonrails.org" target="_blank">Rails</a>')
41
41
  end
42
42
  end
@@ -7,10 +7,10 @@ describe It::Parser do
7
7
  values = {'b' => It.tag(:b), 'link' => '/messages'}
8
8
  parser = It::Parser.new('You have %{b:%{link:new messages}}!', values)
9
9
 
10
- return1 = double('It::Interpolation', :process => '<a href="/messages">new messages</a>')
10
+ return1 = double('It::Interpolation', process: '<a href="/messages">new messages</a>')
11
11
  It::Interpolation.should_receive(:new).with('%{link:new messages}', values).and_return(return1)
12
12
 
13
- return2 = double('It::Interpolation', :process => '<b><a href="/messages">new messages</a></b>')
13
+ return2 = double('It::Interpolation', process: '<b><a href="/messages">new messages</a></b>')
14
14
  It::Interpolation.should_receive(:new).with('%{b:<a href="/messages">new messages</a>}', values).and_return(return2)
15
15
 
16
16
  expect(parser.process).to eq('You have <b><a href="/messages">new messages</a></b>!')
@@ -29,8 +29,8 @@ describe It::Parser do
29
29
  end
30
30
 
31
31
  it 'delegates pluralization to I18n' do
32
- I18n.backend.stub(:pluralize).with('en', {:other => 'You have %{count} messages'}, 2) { 'This is the pluralized string' }
33
- parser = It::Parser.new({:other => 'You have %{count} messages'}, 'locale' => 'en', 'count' => 2)
32
+ I18n.backend.stub(:pluralize).with('en', {other: 'You have %{count} messages'}, 2) { 'This is the pluralized string' }
33
+ parser = It::Parser.new({other: 'You have %{count} messages'}, 'locale' => 'en', 'count' => 2)
34
34
 
35
35
  expect(parser.process).to eq('This is the pluralized string')
36
36
  end
@@ -7,23 +7,23 @@ describe It::Tag, '.new' do
7
7
  it "should work with a parameter (Symbol)" do
8
8
  expect { It::Tag.new(:b) }.not_to raise_error
9
9
  end
10
-
10
+
11
11
  it "should work with a paramter (String)" do
12
12
  expect { It::Tag.new("b") }.not_to raise_error
13
13
  end
14
-
14
+
15
15
  it "should raise TypeError if called with an Integer" do
16
16
  expect { It::Tag.new(1) }.to raise_error(TypeError)
17
17
  end
18
-
18
+
19
19
  it "should accept an options Hash" do
20
- expect { It::Tag.new(:b, :class => "very_bold") }.not_to raise_error
20
+ expect { It::Tag.new(:b, class: "very_bold") }.not_to raise_error
21
21
  end
22
-
22
+
23
23
  it "should raise a TypeError if called with a String" do
24
24
  expect { It::Tag.new(:b, "very_bold") }.to raise_error(TypeError)
25
25
  end
26
-
26
+
27
27
  it "should raise an ArgumentError if called with three params" do
28
28
  expect { It::Tag.new(:b, {}, :blubb) }.to raise_error(ArgumentError)
29
29
  end
@@ -33,7 +33,7 @@ describe It::Tag, '#tag_name' do
33
33
  it "should return the tag as a Symbol if given as a Symbol" do
34
34
  expect(It::Tag.new(:i).tag_name).to eq(:i)
35
35
  end
36
-
36
+
37
37
  it "should return the tag_name as a Symbol if given as a String" do
38
38
  expect(It::Tag.new("i").tag_name).to eq(:i)
39
39
  end
@@ -41,7 +41,7 @@ end
41
41
 
42
42
  describe It::Tag, '#options' do
43
43
  it "should return the options with symbolized keys" do
44
- expect(It::Tag.new(:i, "id" => "cool", :class => "classy").options).to eq({:id => "cool", :class => "classy"})
44
+ expect(It::Tag.new(:i, "id" => "cool", class: "classy").options).to eq({id: "cool", class: "classy"})
45
45
  end
46
46
  end
47
47
 
@@ -49,19 +49,19 @@ describe It::Tag, '#process' do
49
49
  it "should return a tag with the options as attributes and the param as content" do
50
50
  expect(It::Tag.new(:i, "id" => "cool", "class" => "classy").process("some text")).to eq('<i class="classy" id="cool">some text</i>')
51
51
  end
52
-
52
+
53
53
  it "should be marked as html safe" do
54
54
  expect(It::Tag.new(:i).process("some text").html_safe).to be_true
55
55
  end
56
-
56
+
57
57
  it "should escape HTML" do
58
58
  expect(It::Tag.new(:i).process("some text & <b>html</b>")).to eq('<i>some text &amp; &lt;b&gt;html&lt;/b&gt;</i>')
59
59
  end
60
-
60
+
61
61
  it "should not escape strings marked as HTML safe" do
62
62
  expect(It::Tag.new(:i).process("some text & <b>html</b>".html_safe)).to eq('<i>some text & <b>html</b></i>')
63
63
  end
64
-
64
+
65
65
  it "should return an empty tag, if no content is provided" do
66
66
  expect(It::Tag.new(:br, "id" => "cool").process).to eq('<br id="cool" />')
67
67
  end
@@ -5,9 +5,19 @@ require 'it'
5
5
 
6
6
  describe It, '.it' do
7
7
  it "should translate inside the controller as well" do
8
- I18n.backend.store_translations(:en, :test1 => "I have a %{link:link to Rails} in the middle.")
9
- expect(It.it("test1", :link => It.link("http://www.rubyonrails.org"))).to eq('I have a <a href="http://www.rubyonrails.org">link to Rails</a> in the middle.')
8
+ I18n.backend.store_translations(:en, test1: "I have a %{link:link to Rails} in the middle.")
9
+ expect(It.it("test1", link: It.link("http://www.rubyonrails.org"))).to eq('I have a <a href="http://www.rubyonrails.org">link to Rails</a> in the middle.')
10
10
  end
11
+
12
+ it 'should use default key if no translation is present on specified key' do
13
+ I18n.backend.store_translations(:en, fallback: 'this is a fallback')
14
+ expect(It.it('a.missing.key', default: :fallback)).to eq('this is a fallback')
15
+ end
16
+
17
+ it 'should use default string if key is missing' do
18
+ expect(It.it('a.missing.key', default: 'this is a fallback string')).to eq('this is a fallback string')
19
+ end
20
+
11
21
  end
12
22
 
13
23
  describe It, '.link' do
@@ -20,7 +30,7 @@ describe It, '.link' do
20
30
  end
21
31
 
22
32
  it "should accept two params" do
23
- expect { It.link("http://www.rubyonrails.org/", {:id => "identity", :class => "classy"}) }.not_to raise_error
33
+ expect { It.link("http://www.rubyonrails.org/", {id: "identity", class: "classy"}) }.not_to raise_error
24
34
  end
25
35
 
26
36
  it "should raise ArgumentError, if called with three params" do
@@ -38,7 +48,7 @@ describe It, '.tag' do
38
48
  end
39
49
 
40
50
  it "should accept two params" do
41
- expect { It.tag(:b, :class => "very_bold") }.not_to raise_error
51
+ expect { It.tag(:b, class: "very_bold") }.not_to raise_error
42
52
  end
43
53
 
44
54
  it "should raise an ArgumentError if called with three params" do
metadata CHANGED
@@ -1,32 +1,36 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: it
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.4
4
+ version: 0.2.5
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Johannes Barre
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-03-30 00:00:00.000000000 Z
12
+ date: 2013-07-15 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: actionpack
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: 3.0.0
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: 3.0.0
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rspec
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ~>
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ~>
39
44
  - !ruby/object:Gem::Version
@@ -41,15 +46,17 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: rake
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: '10.0'
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: '10.0'
55
62
  description:
@@ -63,50 +70,52 @@ files:
63
70
  - README.textile
64
71
  - Rakefile
65
72
  - Gemfile
66
- - spec/spec_helper.rb
67
- - spec/it_spec.rb
68
- - spec/it/link_spec.rb
69
- - spec/it/helper_spec.rb
70
- - spec/it/parser_spec.rb
71
- - spec/it/tag_spec.rb
72
- - spec/it/plain_spec.rb
73
- - spec/it/interpolation_spec.rb
74
- - lib/it.rb
75
- - lib/it/interpolation.rb
76
73
  - lib/it/helper.rb
77
- - lib/it/parser.rb
78
74
  - lib/it/link.rb
79
75
  - lib/it/plain.rb
76
+ - lib/it/parser.rb
80
77
  - lib/it/tag.rb
78
+ - lib/it/interpolation.rb
79
+ - lib/it.rb
80
+ - spec/it/link_spec.rb
81
+ - spec/it/interpolation_spec.rb
82
+ - spec/it/plain_spec.rb
83
+ - spec/it/parser_spec.rb
84
+ - spec/it/helper_spec.rb
85
+ - spec/it/tag_spec.rb
86
+ - spec/spec_helper.rb
87
+ - spec/it_spec.rb
81
88
  homepage: https://github.com/igel/it
82
- licenses: []
83
- metadata: {}
89
+ licenses:
90
+ - MIT
84
91
  post_install_message:
85
92
  rdoc_options: []
86
93
  require_paths:
87
94
  - lib
88
95
  required_ruby_version: !ruby/object:Gem::Requirement
96
+ none: false
89
97
  requirements:
90
- - - '>='
98
+ - - ! '>='
91
99
  - !ruby/object:Gem::Version
92
- version: '0'
100
+ version: 1.9.2
93
101
  required_rubygems_version: !ruby/object:Gem::Requirement
102
+ none: false
94
103
  requirements:
95
- - - '>='
104
+ - - ! '>='
96
105
  - !ruby/object:Gem::Version
97
106
  version: 1.3.6
98
107
  requirements: []
99
108
  rubyforge_project:
100
- rubygems_version: 2.0.0.rc.2
109
+ rubygems_version: 1.8.23
101
110
  signing_key:
102
- specification_version: 4
111
+ specification_version: 3
103
112
  summary: A helper for links and other html tags in your translations
104
113
  test_files:
105
- - spec/it_spec.rb
106
114
  - spec/it/link_spec.rb
107
- - spec/it/helper_spec.rb
115
+ - spec/it/interpolation_spec.rb
116
+ - spec/it/plain_spec.rb
108
117
  - spec/it/parser_spec.rb
118
+ - spec/it/helper_spec.rb
109
119
  - spec/it/tag_spec.rb
110
- - spec/it/plain_spec.rb
111
- - spec/it/interpolation_spec.rb
120
+ - spec/it_spec.rb
112
121
  - spec/spec_helper.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 540cf86712cced87828cbb22246c440c4fff172b
4
- data.tar.gz: 58c4b692810db1b1732ad21d31394c5cec10b2a1
5
- SHA512:
6
- metadata.gz: f16fe37fd4a51ee176710ed9efec3e6874a3c1d86daefc128d48c718b81766701977aa1a5e180447a70ec344d4463b6f4fbf7081c0bc271973733d60ff07ce15
7
- data.tar.gz: 9a98bc3f607fb8d6903c2ed5fae6b0aec9e416f36fa1897f75474176a2c3819326ed81a7d933c7a47abc7820edd18333ec803145ccdc18c97971f06dc844924d