diff --git a/.travis.yml b/.travis.yml index 2d6c854..694c9a7 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,6 @@ rvm: - 2.0.0 - 1.9.3 - 1.9.2 - - 1.8.7 - rbx-19mode - jruby-19mode + - ruby-head diff --git a/README.textile b/README.textile index 1ffac91..3bd21b3 100644 --- a/README.textile +++ b/README.textile @@ -1,4 +1,4 @@ -"!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) +"!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, HEAD, Rubinius and Jruby) h1. What is *it*? @@ -38,7 +38,7 @@ As you see above, unless the interpolation name is @link@ or starts with @_link@
<%=it "copy", guide: It.link("http://guides.rubyonrails.org/i18n.html", target: '_blank', class: "important") %>
-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. +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. Want to introduce some markup into your sentences? *it* will help you: @@ -52,7 +52,7 @@ Even nested interpolations are possible:
en:
   copy: "Want to contact %{user}%? %{link:send %{b:%{user} a message}}!"
-
<%=it "copy", link: "mailto:igel@igels.net", user: 'iGEL', :b => It.tag(:b) %>
+
<%=it "copy", link: "mailto:igel@igels.net", user: 'iGEL', b: It.tag(:b) %>
If you would like to use the same translations in your html and plain text mails, you will like the @It.plain@ method:
en:
diff --git a/Rakefile b/Rakefile
index 9e961e3..f34a48c 100644
--- a/Rakefile
+++ b/Rakefile
@@ -2,4 +2,4 @@ require 'rspec/core/rake_task'
 
 RSpec::Core::RakeTask.new(:spec)
 
-task :default => :spec
\ No newline at end of file
+task default: :spec
diff --git a/lib/it.rb b/lib/it.rb
index a05ae2c..c3321f8 100644
--- a/lib/it.rb
+++ b/lib/it.rb
@@ -14,13 +14,13 @@ module It
   # It outside of your views. See documentation at Helper#it
   def self.it(identifier, options = {})
     options.stringify_keys!
-    Parser.new(I18n.t(identifier, :locale => (options["locale"] || I18n.locale)), options).process
+    Parser.new(I18n.t(identifier, locale: (options["locale"] || I18n.locale)), options).process
   end
 
   # Creates a new link to be used in +it+.
   #
   # * +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
-  #   a Hash like {:controller => "articles", :action => "index"} directly. Use the +url_for+ helper, if you would like to specify your
+  #   a Hash like {controller: "articles", action: "index"} directly. Use the +url_for+ helper, if you would like to specify your
   #   links like that.
   # * +options+: The options as an Hash. Use them like you would with +link_to+. (optional)
   def self.link(href, options = {})
diff --git a/lib/it/helper.rb b/lib/it/helper.rb
index 77daf54..025e426 100644
--- a/lib/it/helper.rb
+++ b/lib/it/helper.rb
@@ -13,21 +13,21 @@ module Helper
     #
     #   # translation: "Already signed up? %{login_link:Sign in}!"
     #
-    #   <%=it("translation", :login_link => It.link(login_path))
+    #   <%=it("translation", login_link: It.link(login_path))
     #
     # If your link doesn't require additional attributes and the name is +link+, starts with +link_+ or ends with +_link+,
     # you may specify the argument as a String or your helper.
     #
     #   # translation: "Already signed up? %{login_link:Sign in}!"
     #
-    #   <%=it("translation", :login_link => login_path)
+    #   <%=it("translation", login_link: login_path)
     #
     # You may have as many tags inside of one translation as you like, and you even may nest them into each other. Also you
     # may specify arguments to links and other tags.
     #
     #   # translation: "The top contributor of %{wiki_link:our wiki} is currently %{user_link:%{b:%{name}}}. Thanks a lot, %{name}!"
     #
-    #   <%= it("translation", :wiki_link => wiki_path, :name => user.name, :b => It.tag(:b, :class => "user"), :user_link => It.link(user_path(user), :target => "_blank"))
+    #   <%= it("translation", wiki_link: wiki_path, name: user.name, b: It.tag(:b, class: "user"), user_link: It.link(user_path(user), target: "_blank"))
     #
     # I recommend to limit the use of +it+ as much as possible. You could use it for 
or
, but I think, # things seperated over multiple lines should go into different translations. Use it for inline tags like links, , @@ -40,7 +40,7 @@ module Helper # def it(identifier, options = {}) options.stringify_keys! - It::Parser.new(t(identifier, :locale => (options["locale"] || I18n.locale)), options).process + It::Parser.new(t(identifier, locale: (options["locale"] || I18n.locale)), options).process end end end diff --git a/spec/it/helper_spec.rb b/spec/it/helper_spec.rb index 135ceeb..03ee29a 100644 --- a/spec/it/helper_spec.rb +++ b/spec/it/helper_spec.rb @@ -5,8 +5,8 @@ describe It::Helper, "#it" do before do - I18n.backend.store_translations(:en, :test1 => "I have a %{link:link to Rails} in the middle.") - I18n.backend.store_translations(:de, :test1 => "Ich habe einen %{link:Link zu Rails} in der Mitte.") + I18n.backend.store_translations(:en, test1: "I have a %{link:link to Rails} in the middle.") + I18n.backend.store_translations(:de, test1: "Ich habe einen %{link:Link zu Rails} in der Mitte.") @view = ActionView::Base.new @controller = ActionController::Base.new @@ -18,120 +18,120 @@ end it "should insert the link into the string" do - expect(@view.it("test1", :link => It.link("http://www.rubyonrails.org"))).to eq('I have a link to Rails in the middle.') + expect(@view.it("test1", link: It.link("http://www.rubyonrails.org"))).to eq('I have a link to Rails in the middle.') end it "should insert the link into the German translation" do I18n.locale = :de - expect(@view.it("test1", :link => It.link("http://www.rubyonrails.org"))).to eq('Ich habe einen Link zu Rails in der Mitte.') + expect(@view.it("test1", link: It.link("http://www.rubyonrails.org"))).to eq('Ich habe einen Link zu Rails in der Mitte.') end it "should allow link options to be set" do - expect(@view.it("test1", :link => It.link("http://www.rubyonrails.org", :target => "_blank"))).to eq('I have a link to Rails in the middle.') + expect(@view.it("test1", link: It.link("http://www.rubyonrails.org", target: "_blank"))).to eq('I have a link to Rails in the middle.') end it "should support the plain thing" do - 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.') + 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.') end it "should parse other tags as well" do - expect(@view.it("test1", :link => It.tag(:b, :class => "classy"))).to eq('I have a link to Rails in the middle.') + expect(@view.it("test1", link: It.tag(:b, class: "classy"))).to eq('I have a link to Rails in the middle.') end it "should mark the result as html safe" do - expect(@view.it("test1", :link => It.link("http://www.rubyonrails.org")).html_safe?).to be_true + expect(@view.it("test1", link: It.link("http://www.rubyonrails.org")).html_safe?).to be_true end it "should escape all html in the translation" do - I18n.backend.store_translations(:en, :test2 => " & %{link:link -> Rails} in the middle.") - expect(@view.it("test2", :link => It.link("http://www.rubyonrails.org"))).to eq('<a href="hax0r"> & link -> Rails in <b>the middle</b>.') + I18n.backend.store_translations(:en, test2: " & %{link:link -> Rails} in the middle.") + expect(@view.it("test2", link: It.link("http://www.rubyonrails.org"))).to eq('<a href="hax0r"> & link -> Rails in <b>the middle</b>.') end it "should also work with 2 links" do - I18n.backend.store_translations(:en, :test3 => "I like %{link1:rails} and %{link2:github}.") - expect(@view.it("test3", :link1 => It.link("http://www.rubyonrails.org"), :link2 => It.link("http://www.github.com"))).to eq('I like rails and github.') + I18n.backend.store_translations(:en, test3: "I like %{link1:rails} and %{link2:github}.") + expect(@view.it("test3", link1: It.link("http://www.rubyonrails.org"), link2: It.link("http://www.github.com"))).to eq('I like rails and github.') end it "should allow normal I18n interpolations" do - I18n.backend.store_translations(:en, :test4 => "I have a %{link:link to Rails} in the %{position}.") - expect(@view.it("test4", :link => It.link("http://www.rubyonrails.org"), :position => "middle")).to eq('I have a link to Rails in the middle.') + I18n.backend.store_translations(:en, test4: "I have a %{link:link to Rails} in the %{position}.") + expect(@view.it("test4", link: It.link("http://www.rubyonrails.org"), position: "middle")).to eq('I have a link to Rails in the middle.') end it "should allow Integers as normal interpolation" do - I18n.backend.store_translations(:en, :test5 => "Hello %{name}.") - expect(@view.it("test5", :name => 2)).to eq('Hello 2.') + I18n.backend.store_translations(:en, test5: "Hello %{name}.") + expect(@view.it("test5", name: 2)).to eq('Hello 2.') end it "should escape the HTML in normal interpolations" do - I18n.backend.store_translations(:en, :test5 => "Hello %{name}.") - expect(@view.it("test5", :name => 'victim')).to eq('Hello <a href="http://evil.haxor.com">victim</a>.') + I18n.backend.store_translations(:en, test5: "Hello %{name}.") + expect(@view.it("test5", name: 'victim')).to eq('Hello <a href="http://evil.haxor.com">victim</a>.') end it "should not escape html_safe interpolations" do - I18n.backend.store_translations(:en, :test5 => "Hello %{name}.") - expect(@view.it("test5", :name => 'Rails'.html_safe)).to eq('Hello Rails.') + I18n.backend.store_translations(:en, test5: "Hello %{name}.") + expect(@view.it("test5", name: 'Rails'.html_safe)).to eq('Hello Rails.') end it "should allow interpolations inside of links" do - I18n.backend.store_translations(:en, :test6 => "Did you read our %{link:nice %{article}}?") - expect(@view.it("test6", :link => It.link("/article/2"), :article => "article")).to eq('Did you read our nice article?') + I18n.backend.store_translations(:en, test6: "Did you read our %{link:nice %{article}}?") + expect(@view.it("test6", link: It.link("/article/2"), article: "article")).to eq('Did you read our nice article?') end it "should raise a KeyError, if the key was not given" do - expect { @view.it("test1", :blubb => true) }.to raise_error(KeyError, "key{link} not found") + expect { @view.it("test1", blubb: true) }.to raise_error(KeyError, "key{link} not found") end it "should raise an ArgumentError, if a String was given for an interpolation with argument" do - I18n.backend.store_translations(:en, :test7 => "Sign up %{asdf:here}!") - expect { @view.it("test7", :asdf => "Heinz") }.to raise_error(ArgumentError, "key{asdf} has an argument, so it cannot resolved with a String") + I18n.backend.store_translations(:en, test7: "Sign up %{asdf:here}!") + expect { @view.it("test7", asdf: "Heinz") }.to raise_error(ArgumentError, "key{asdf} has an argument, so it cannot resolved with a String") end it "should allow Strings, if the interpolation name is link" do - I18n.backend.store_translations(:en, :test8 => "Sign up %{link:here}!") - expect(@view.it("test8", :link => "/register")).to eq('Sign up here!') + I18n.backend.store_translations(:en, test8: "Sign up %{link:here}!") + expect(@view.it("test8", link: "/register")).to eq('Sign up here!') end it "should allow Strings, if the interpolation name ends with _link" do - I18n.backend.store_translations(:en, :test8 => "Sign up %{register_link:here}!") - expect(@view.it("test8", :register_link => "/register")).to eq('Sign up here!') + I18n.backend.store_translations(:en, test8: "Sign up %{register_link:here}!") + expect(@view.it("test8", register_link: "/register")).to eq('Sign up here!') end it "should allow Strings, if the interpolation name starts with link_" do - I18n.backend.store_translations(:en, :test8 => "Sign up %{link_to_register:here}!") - expect(@view.it("test8", :link_to_register => "/register")).to eq('Sign up here!') + I18n.backend.store_translations(:en, test8: "Sign up %{link_to_register:here}!") + expect(@view.it("test8", link_to_register: "/register")).to eq('Sign up here!') end it "should work with tags without arguments" do - I18n.backend.store_translations(:en, :test9 => "We can %{br} do line breaks") - expect(@view.it("test9", :br => It.tag(:br))).to eq('We can
do line breaks') + I18n.backend.store_translations(:en, test9: "We can %{br} do line breaks") + expect(@view.it("test9", br: It.tag(:br))).to eq('We can
do line breaks') end it 'should support dot-prefixed keys' do - I18n.backend.store_translations(:en, :widgets => { :show => { :all_widgets => "See %{widgets_link:all widgets}" } }) + I18n.backend.store_translations(:en, widgets: { show: { all_widgets: "See %{widgets_link:all widgets}" } }) @view.instance_variable_set(:"@_virtual_path", "widgets/show") # For Rails 3.0 @view.instance_variable_set(:"@virtual_path", "widgets/show") # For Rails 3.1, 3.2 and probably 4.0 - expect(@view.it('.all_widgets', :widgets_link => '/widgets')).to eq('See all widgets') + expect(@view.it('.all_widgets', widgets_link: '/widgets')).to eq('See all widgets') end it 'should support the locale option' do - expect(@view.it('test1', :locale => "de", :link => It.link("http://www.rubyonrails.org"))).to eq('Ich habe einen Link zu Rails in der Mitte.') + expect(@view.it('test1', locale: "de", link: It.link("http://www.rubyonrails.org"))).to eq('Ich habe einen Link zu Rails in der Mitte.') end context "With a pluralized translation" do before do - I18n.backend.store_translations(:en, :test10 => {:zero => "You have zero messages.", :one => "You have %{link:one message}.", :other => "You have %{link:%{count} messages}."}) + I18n.backend.store_translations(:en, test10: {zero: "You have zero messages.", one: "You have %{link:one message}.", other: "You have %{link:%{count} messages}."}) end it 'should work with count = 0' do - expect(@view.it("test10", :count => 0, :link => "/messages")).to eq('You have zero messages.') + expect(@view.it("test10", count: 0, link: "/messages")).to eq('You have zero messages.') end it 'should work with count = 1' do - expect(@view.it("test10", :count => 1, :link => "/messages")).to eq('You have one message.') + expect(@view.it("test10", count: 1, link: "/messages")).to eq('You have one message.') end it 'should work with count > 1' do - expect(@view.it("test10", :count => 2, :link => "/messages")).to eq('You have 2 messages.') + expect(@view.it("test10", count: 2, link: "/messages")).to eq('You have 2 messages.') end end end diff --git a/spec/it/link_spec.rb b/spec/it/link_spec.rb index ac3620e..0661f06 100644 --- a/spec/it/link_spec.rb +++ b/spec/it/link_spec.rb @@ -9,7 +9,7 @@ end it "should accept a Hash as first param" do - expect { It::Link.new({:controller => "articles", :action => "index"}) }.not_to raise_error + expect { It::Link.new({controller: "articles", action: "index"}) }.not_to raise_error end it "should raise a TypeError if the first param is an Integer" do @@ -17,7 +17,7 @@ end it "should accept options as a Hash" do - expect { It::Link.new("http://www.rubyonrails.org/", {:id => "identity", :class => "classy"}) }.not_to raise_error + expect { It::Link.new("http://www.rubyonrails.org/", {id: "identity", class: "classy"}) }.not_to raise_error end it "should raise a TypeError, if the options are a String" do @@ -37,6 +37,6 @@ describe It::Link, '#process' do it "should return a link with the options set and the content as label" do - expect(It::Link.new("http://www.rubyonrails.org", :target => "_blank").process("Rails")).to eq('Rails') + expect(It::Link.new("http://www.rubyonrails.org", target: "_blank").process("Rails")).to eq('Rails') end end diff --git a/spec/it/parser_spec.rb b/spec/it/parser_spec.rb index ad3dcb4..df02307 100644 --- a/spec/it/parser_spec.rb +++ b/spec/it/parser_spec.rb @@ -7,10 +7,10 @@ values = {'b' => It.tag(:b), 'link' => '/messages'} parser = It::Parser.new('You have %{b:%{link:new messages}}!', values) - return1 = double('It::Interpolation', :process => 'new messages') + return1 = double('It::Interpolation', process: 'new messages') It::Interpolation.should_receive(:new).with('%{link:new messages}', values).and_return(return1) - return2 = double('It::Interpolation', :process => 'new messages') + return2 = double('It::Interpolation', process: 'new messages') It::Interpolation.should_receive(:new).with('%{b:new messages}', values).and_return(return2) expect(parser.process).to eq('You have new messages!') @@ -29,8 +29,8 @@ end it 'delegates pluralization to I18n' do - I18n.backend.stub(:pluralize).with('en', {:other => 'You have %{count} messages'}, 2) { 'This is the pluralized string' } - parser = It::Parser.new({:other => 'You have %{count} messages'}, 'locale' => 'en', 'count' => 2) + I18n.backend.stub(:pluralize).with('en', {other: 'You have %{count} messages'}, 2) { 'This is the pluralized string' } + parser = It::Parser.new({other: 'You have %{count} messages'}, 'locale' => 'en', 'count' => 2) expect(parser.process).to eq('This is the pluralized string') end diff --git a/spec/it/tag_spec.rb b/spec/it/tag_spec.rb index 860d5d9..f983e7a 100644 --- a/spec/it/tag_spec.rb +++ b/spec/it/tag_spec.rb @@ -7,23 +7,23 @@ it "should work with a parameter (Symbol)" do expect { It::Tag.new(:b) }.not_to raise_error end - + it "should work with a paramter (String)" do expect { It::Tag.new("b") }.not_to raise_error end - + it "should raise TypeError if called with an Integer" do expect { It::Tag.new(1) }.to raise_error(TypeError) end - + it "should accept an options Hash" do - expect { It::Tag.new(:b, :class => "very_bold") }.not_to raise_error + expect { It::Tag.new(:b, class: "very_bold") }.not_to raise_error end - + it "should raise a TypeError if called with a String" do expect { It::Tag.new(:b, "very_bold") }.to raise_error(TypeError) end - + it "should raise an ArgumentError if called with three params" do expect { It::Tag.new(:b, {}, :blubb) }.to raise_error(ArgumentError) end @@ -33,7 +33,7 @@ it "should return the tag as a Symbol if given as a Symbol" do expect(It::Tag.new(:i).tag_name).to eq(:i) end - + it "should return the tag_name as a Symbol if given as a String" do expect(It::Tag.new("i").tag_name).to eq(:i) end @@ -41,7 +41,7 @@ describe It::Tag, '#options' do it "should return the options with symbolized keys" do - expect(It::Tag.new(:i, "id" => "cool", :class => "classy").options).to eq({:id => "cool", :class => "classy"}) + expect(It::Tag.new(:i, "id" => "cool", class: "classy").options).to eq({id: "cool", class: "classy"}) end end @@ -49,19 +49,19 @@ it "should return a tag with the options as attributes and the param as content" do expect(It::Tag.new(:i, "id" => "cool", "class" => "classy").process("some text")).to eq('some text') end - + it "should be marked as html safe" do expect(It::Tag.new(:i).process("some text").html_safe).to be_true end - + it "should escape HTML" do expect(It::Tag.new(:i).process("some text & html")).to eq('some text & <b>html</b>') end - + it "should not escape strings marked as HTML safe" do expect(It::Tag.new(:i).process("some text & html".html_safe)).to eq('some text & html') end - + it "should return an empty tag, if no content is provided" do expect(It::Tag.new(:br, "id" => "cool").process).to eq('
') end diff --git a/spec/it_spec.rb b/spec/it_spec.rb index 482d6eb..7de7067 100644 --- a/spec/it_spec.rb +++ b/spec/it_spec.rb @@ -5,8 +5,8 @@ describe It, '.it' do it "should translate inside the controller as well" do - I18n.backend.store_translations(:en, :test1 => "I have a %{link:link to Rails} in the middle.") - expect(It.it("test1", :link => It.link("http://www.rubyonrails.org"))).to eq('I have a link to Rails in the middle.') + I18n.backend.store_translations(:en, test1: "I have a %{link:link to Rails} in the middle.") + expect(It.it("test1", link: It.link("http://www.rubyonrails.org"))).to eq('I have a link to Rails in the middle.') end end @@ -20,7 +20,7 @@ end it "should accept two params" do - expect { It.link("http://www.rubyonrails.org/", {:id => "identity", :class => "classy"}) }.not_to raise_error + expect { It.link("http://www.rubyonrails.org/", {id: "identity", class: "classy"}) }.not_to raise_error end it "should raise ArgumentError, if called with three params" do @@ -38,7 +38,7 @@ end it "should accept two params" do - expect { It.tag(:b, :class => "very_bold") }.not_to raise_error + expect { It.tag(:b, class: "very_bold") }.not_to raise_error end it "should raise an ArgumentError if called with three params" do