better_pluralize 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: af70f4fe7e19c895c5b3235d391ffd468ab26896
4
+ data.tar.gz: b4dbd7bed624701248c542b06a59818e8a42c6f8
5
+ SHA512:
6
+ metadata.gz: 729ba20e4f87607f51c25e6e74942c23c34eedadf2f5838e28a2c0652b7300968baca79ccb6a08a1ec649d263f7cf022122cf33751461b0bcb44375db4eda010
7
+ data.tar.gz: 3d040fc32e200f37b75a22d96de905dd021c29bcf8cc64a519619761d29d99aa09e23167ea187ad3c552305c0b7f4c7e0605e153e5f104d6257518677bfef5a4
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
@@ -0,0 +1,3 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in better_pluralize.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Jiri Pospisil
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,34 @@
1
+ # BetterPluralize
2
+
3
+ Adds block support to the Rails' pluralize view helper so you can customize its
4
+ output.
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ gem "better_pluralize"
11
+
12
+ And then execute:
13
+
14
+ $ bundle
15
+
16
+ Or install it yourself as:
17
+
18
+ $ gem install better_pluralize
19
+
20
+ ## Usage
21
+
22
+ ```
23
+ <%= pluralize @parts.size, "part" do |count, word| %>
24
+ <strong><%= count %></strong> <%= word %> found!
25
+ <% end %>
26
+ ```
27
+
28
+ ## Contributing
29
+
30
+ 1. Fork it
31
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
32
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
33
+ 4. Push to the branch (`git push origin my-new-feature`)
34
+ 5. Create new Pull Request
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.pattern = "test/test_*.rb"
7
+ end
8
+
9
+ task :default => :test
10
+
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "better_pluralize/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "better_pluralize"
8
+ spec.version = BetterPluralize::VERSION
9
+ spec.authors = ["Jiri Pospisil"]
10
+ spec.email = ["mekishizufu@gmail.com"]
11
+ spec.description = "Adds block support to the Rails' pluralize view helper so you can further customize its output"
12
+ spec.summary = "Adds block support to the Rails' pluralize view helper"
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files`.split($/)
17
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_development_dependency "bundler", "~> 1.3"
22
+ spec.add_development_dependency "rake"
23
+
24
+ spec.add_dependency "rails", "> 3"
25
+ end
@@ -0,0 +1,11 @@
1
+ require "better_pluralize/version"
2
+
3
+ module BetterPluralize
4
+ class Railtie < ::Rails::Railtie
5
+ initializer "better_pluralize" do |app|
6
+ ActiveSupport.on_load(:action_view) do
7
+ require "better_pluralize/helpers"
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ module BetterPluralize
2
+ module ::ActionView
3
+ module Helpers
4
+ module TextHelper
5
+ # Behaves exactly as the official `pluralize` helper except it allows you
6
+ # to pass an optional block that receives the current count and the
7
+ # pluralized word.
8
+ #
9
+ # pluralize(2, 'person') do |count, word|
10
+ # "Yay #{count} #{word}"
11
+ # end
12
+ #
13
+ def pluralize(count, singular, plural = nil, &block)
14
+ word = if (count == 1 || count =~ /^1(\.0+)?$/)
15
+ singular
16
+ else
17
+ plural || singular.pluralize
18
+ end
19
+
20
+ safe_count = count || 0
21
+
22
+ if block_given?
23
+ capture safe_count, word, &block
24
+ else
25
+ "#{safe_count} #{word}"
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,3 @@
1
+ module BetterPluralize
2
+ VERSION = "1.0.0"
3
+ end
@@ -0,0 +1,42 @@
1
+ require "minitest/autorun"
2
+ require "rails"
3
+
4
+ require "action_view/buffers"
5
+ require "action_view/helpers/capture_helper"
6
+ require "better_pluralize/helpers"
7
+
8
+ class TestBetterPluralize < MiniTest::Unit::TestCase
9
+ attr_accessor :output_buffer
10
+
11
+ include ActionView::Helpers::CaptureHelper
12
+ include ActionView::Helpers::TextHelper
13
+
14
+ def test_backwards_compatibility
15
+ text_0 = pluralize nil, "person"
16
+ assert_equal "0 people", text_0
17
+
18
+ text_1 = pluralize 0, "person"
19
+ assert_equal "0 people", text_1
20
+
21
+ text_2 = pluralize 1, "person"
22
+ assert_equal "1 person", text_2
23
+
24
+ text_3 = pluralize 2, "person"
25
+ assert_equal "2 people", text_3
26
+
27
+ text_4 = pluralize 2, "person", "users"
28
+ assert_equal "2 users", text_4
29
+ end
30
+
31
+ def test_passing_blocks
32
+ text_0 = pluralize 1, "person", "users" do |count, word|
33
+ "From block: #{count} #{word}"
34
+ end
35
+ assert_equal "From block: 1 person", text_0
36
+
37
+ text_1 = pluralize 2, "person", "users" do |count, word|
38
+ "From block: #{count} #{word}"
39
+ end
40
+ assert_equal "From block: 2 users", text_1
41
+ end
42
+ end
metadata ADDED
@@ -0,0 +1,99 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: better_pluralize
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jiri Pospisil
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-08-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.3'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.3'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>'
46
+ - !ruby/object:Gem::Version
47
+ version: '3'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>'
53
+ - !ruby/object:Gem::Version
54
+ version: '3'
55
+ description: Adds block support to the Rails' pluralize view helper so you can further
56
+ customize its output
57
+ email:
58
+ - mekishizufu@gmail.com
59
+ executables: []
60
+ extensions: []
61
+ extra_rdoc_files: []
62
+ files:
63
+ - .gitignore
64
+ - .travis.yml
65
+ - Gemfile
66
+ - LICENSE.txt
67
+ - README.md
68
+ - Rakefile
69
+ - better_pluralize.gemspec
70
+ - lib/better_pluralize.rb
71
+ - lib/better_pluralize/helpers.rb
72
+ - lib/better_pluralize/version.rb
73
+ - test/test_better_pluralize.rb
74
+ homepage: ''
75
+ licenses:
76
+ - MIT
77
+ metadata: {}
78
+ post_install_message:
79
+ rdoc_options: []
80
+ require_paths:
81
+ - lib
82
+ required_ruby_version: !ruby/object:Gem::Requirement
83
+ requirements:
84
+ - - '>='
85
+ - !ruby/object:Gem::Version
86
+ version: '0'
87
+ required_rubygems_version: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - '>='
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ requirements: []
93
+ rubyforge_project:
94
+ rubygems_version: 2.0.3
95
+ signing_key:
96
+ specification_version: 4
97
+ summary: Adds block support to the Rails' pluralize view helper
98
+ test_files:
99
+ - test/test_better_pluralize.rb