it 0.8.0 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +8 -1
- data/README.md +2 -2
- data/Rakefile +1 -1
- data/it.gemspec +2 -2
- data/lib/it/interpolation.rb +29 -14
- data/lib/it/link.rb +4 -2
- data/lib/it/parser.rb +7 -7
- data/lib/it/plain.rb +1 -1
- data/lib/it/tag.rb +2 -2
- data/lib/it/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3afe5b083028e03d2498a736e5a7755b8729e5ed
|
4
|
+
data.tar.gz: 4f787ab01e824e5cf59864aa1b8ca7f9e4483a24
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faaf1c0d1ac146c4ac6f78d1ef77a3604d749eada8886ffac8908d812a322f1496fe9f0b521d83eb1563ae39701d71cf3e875f4beda9e5403f2dd9ea65fc9498
|
7
|
+
data.tar.gz: 003d59a65094af75ccb9ffb6703bbd2373232c8668dddc4a14a11156adb37a658cff1b8fdf3fe550635cc2593a54de498560f9a6bdf3bc08e3d5d7ea4a0d92da
|
data/CHANGELOG.md
CHANGED
@@ -1,4 +1,11 @@
|
|
1
|
-
#
|
1
|
+
# 1.0.0 (2017-06-03)
|
2
|
+
|
3
|
+
* Allow whitespace after the colon without considering it part of the value [#20](https://github.com/iGEL/it/pull/20)
|
4
|
+
*Russell Norris*
|
5
|
+
* Run specs with warnings enabled
|
6
|
+
* 1.0.0 Release to conform with semver 2.0
|
7
|
+
|
8
|
+
# 0.8.0 (2015-06-12)
|
2
9
|
|
3
10
|
* Make `It.plain` work with empty content [#14](https://github.com/iGEL/it/pull/14)
|
4
11
|
*Emil Sågfors*
|
data/README.md
CHANGED
@@ -2,10 +2,10 @@
|
|
2
2
|
[![Build Status](http://img.shields.io/travis/iGEL/it/master.svg?style=flat)](https://travis-ci.org/iGEL/it)
|
3
3
|
[![Coverage](http://img.shields.io/coveralls/iGEL/it/master.svg?style=flat)](https://coveralls.io/r/iGEL/it)
|
4
4
|
[![Rubygems](http://img.shields.io/gem/v/it.svg?style=flat)](http://rubygems.org/gems/it)
|
5
|
-
[![Github Issues](http://img.shields.io/github/issues/iGEL/it.svg?style=flat)](https://
|
5
|
+
[![Github Issues](http://img.shields.io/github/issues/iGEL/it.svg?style=flat)](https://github.com/iGEL/it/issues)
|
6
6
|
[![Dependency Status](http://img.shields.io/gemnasium/iGEL/it.svg?style=flat)](https://gemnasium.com/iGEL/it)
|
7
7
|
|
8
|
-
Tested against Ruby 2.
|
8
|
+
Tested against Ruby 2.4, 2.3, 2.2, head, and jruby 9.1.10.0 and Rails 5.1, 5.0, and 4.2
|
9
9
|
|
10
10
|
What is **it**?
|
11
11
|
=============
|
data/Rakefile
CHANGED
data/it.gemspec
CHANGED
@@ -12,13 +12,13 @@ Gem::Specification.new do |spec|
|
|
12
12
|
spec.homepage = 'https://github.com/igel/it'
|
13
13
|
spec.license = 'MIT'
|
14
14
|
|
15
|
-
spec.files = %w
|
15
|
+
spec.files = %w[MIT-LICENSE README.md Rakefile Gemfile CHANGELOG.md it.gemspec] + Dir['lib/**/*.rb']
|
16
16
|
spec.require_paths = ['lib']
|
17
17
|
|
18
18
|
spec.add_dependency 'actionpack', '>= 3.0.0'
|
19
19
|
|
20
20
|
spec.add_development_dependency 'bundler', '~> 1.7'
|
21
|
-
spec.add_development_dependency 'rake', '~>
|
21
|
+
spec.add_development_dependency 'rake', '~> 12'
|
22
22
|
spec.add_development_dependency 'rspec', '~> 3.2'
|
23
23
|
spec.add_development_dependency 'coveralls'
|
24
24
|
spec.add_development_dependency 'nokogiri'
|
data/lib/it/interpolation.rb
CHANGED
@@ -2,20 +2,37 @@ module It
|
|
2
2
|
# Contains one interpolation and will delegate the work to the It::Tag (or subclass) or
|
3
3
|
# ERB::Util.h
|
4
4
|
class Interpolation
|
5
|
-
|
5
|
+
class << self
|
6
|
+
def call(string, values)
|
7
|
+
key, label = extract_key_and_label_from(string)
|
8
|
+
value = values[key]
|
6
9
|
|
7
|
-
|
8
|
-
self.key, self.label = string[2..-2].split(':', 2)
|
9
|
-
validate_key_presence(values)
|
10
|
+
raise KeyError, "key{#{key}} not found" unless values.key?(key)
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
new(key, value, label).process
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
# This is a :reek:UtilityFunction, but it's not an instance method
|
18
|
+
def extract_key_and_label_from(string)
|
19
|
+
# eg: %{key:label} or %{key} or %{key: label}
|
20
|
+
string[2..-2].split(/:\s*/, 2)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
def initialize(key, value, label)
|
25
|
+
@key = key
|
26
|
+
@value = value
|
27
|
+
@label = label
|
13
28
|
end
|
14
29
|
|
15
30
|
def process
|
31
|
+
convert_link
|
32
|
+
|
16
33
|
validate_value_for_arguments
|
17
34
|
|
18
|
-
if value.is_a?(It::Tag)
|
35
|
+
if value.is_a?(It::Tag)
|
19
36
|
process_it_tag
|
20
37
|
else # Normal interpolations, as I18n.t would do it.
|
21
38
|
ERB::Util.h(value)
|
@@ -24,10 +41,12 @@ module It
|
|
24
41
|
|
25
42
|
private
|
26
43
|
|
44
|
+
attr_reader :key, :value, :label
|
45
|
+
|
27
46
|
# Convert keys with String arguments into It::Links, if they are named link, link_* or *_link
|
28
|
-
def
|
47
|
+
def convert_link
|
29
48
|
if key =~ /(\Alink\z|_link\z|\Alink_)/ && value.is_a?(String)
|
30
|
-
|
49
|
+
@value = It::Link.new(value)
|
31
50
|
end
|
32
51
|
end
|
33
52
|
|
@@ -39,13 +58,9 @@ module It
|
|
39
58
|
end
|
40
59
|
end
|
41
60
|
|
42
|
-
def validate_key_presence(values)
|
43
|
-
fail KeyError, "key{#{key}} not found" unless values.key?(key)
|
44
|
-
end
|
45
|
-
|
46
61
|
def validate_value_for_arguments
|
47
62
|
if label && !value.is_a?(It::Tag)
|
48
|
-
|
63
|
+
raise ArgumentError, "key{#{key}} has an argument, so it cannot resolved with a #{value.class}"
|
49
64
|
end
|
50
65
|
end
|
51
66
|
end
|
data/lib/it/link.rb
CHANGED
@@ -3,9 +3,11 @@ module It
|
|
3
3
|
class Link < Tag
|
4
4
|
include ActionView::Helpers::UrlHelper
|
5
5
|
|
6
|
+
attr_reader :href
|
7
|
+
|
6
8
|
# See It.link for details. You can do everything there and save 6 characters.
|
7
9
|
def initialize(href, options = {})
|
8
|
-
|
10
|
+
raise TypeError, 'Invalid href given' unless [Hash, String].include?(href.class)
|
9
11
|
|
10
12
|
super(:a, options)
|
11
13
|
@href = href
|
@@ -13,7 +15,7 @@ module It
|
|
13
15
|
|
14
16
|
# Will be called from inside the helper to return the tag with the given content.
|
15
17
|
def process(content)
|
16
|
-
link_to(content,
|
18
|
+
link_to(content, href, options)
|
17
19
|
end
|
18
20
|
end
|
19
21
|
end
|
data/lib/it/parser.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
module It
|
2
2
|
# Parses the string and replaces all interpolations accordingly.
|
3
3
|
class Parser
|
4
|
-
|
4
|
+
attr_reader :string, :options
|
5
5
|
|
6
|
-
INTERPOLATION_REGEXP = /%\{[^{}
|
6
|
+
INTERPOLATION_REGEXP = /%\{[^{}]+\}/
|
7
7
|
|
8
8
|
def self.backend_options(options)
|
9
9
|
options.with_indifferent_access.slice(:default, :locale, :scope)
|
10
10
|
end
|
11
11
|
|
12
12
|
def initialize(string, options)
|
13
|
-
|
14
|
-
|
13
|
+
@string = string
|
14
|
+
@options = options
|
15
15
|
end
|
16
16
|
|
17
17
|
def process
|
@@ -21,7 +21,7 @@ module It
|
|
21
21
|
# For deep nesting, we repeat the process until we have no interpolations anymore
|
22
22
|
while contains_interpolation?
|
23
23
|
string.gsub!(INTERPOLATION_REGEXP) do |interpolation|
|
24
|
-
Interpolation.
|
24
|
+
Interpolation.call(interpolation, options)
|
25
25
|
end
|
26
26
|
end
|
27
27
|
string.html_safe
|
@@ -36,7 +36,7 @@ module It
|
|
36
36
|
def handle_pluralization
|
37
37
|
return if !string.is_a?(Hash) || !options.key?('count')
|
38
38
|
|
39
|
-
|
39
|
+
@string = I18n.backend.send(:pluralize, locale, string, options['count'])
|
40
40
|
end
|
41
41
|
|
42
42
|
def locale
|
@@ -44,7 +44,7 @@ module It
|
|
44
44
|
end
|
45
45
|
|
46
46
|
def escape_string
|
47
|
-
|
47
|
+
@string = String.new(ERB::Util.h(string))
|
48
48
|
end
|
49
49
|
end
|
50
50
|
end
|
data/lib/it/plain.rb
CHANGED
@@ -2,7 +2,7 @@ module It
|
|
2
2
|
# Handles replacements in non HTML templates (e.g. mails)
|
3
3
|
class Plain < Tag
|
4
4
|
def initialize(template = '%s')
|
5
|
-
|
5
|
+
raise TypeError, "expected a String, got #{template.class}" unless template.is_a?(String)
|
6
6
|
|
7
7
|
@template = template
|
8
8
|
end
|
data/lib/it/tag.rb
CHANGED
@@ -7,8 +7,8 @@ module It
|
|
7
7
|
|
8
8
|
# See It.tag for details. You can do everything there and save 6 characters.
|
9
9
|
def initialize(tag_name, options = {})
|
10
|
-
|
11
|
-
|
10
|
+
raise TypeError, 'tag_name must be a String or Symbol' unless [String, Symbol].include?(tag_name.class)
|
11
|
+
raise TypeError, 'options must be a Hash' unless options.is_a?(Hash)
|
12
12
|
|
13
13
|
@tag_name = tag_name.to_sym
|
14
14
|
@options = options.symbolize_keys
|
data/lib/it/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: it
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Johannes Barre
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-06-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - "~>"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '12'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - "~>"
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '12'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -163,7 +163,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
163
163
|
version: '0'
|
164
164
|
requirements: []
|
165
165
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
166
|
+
rubygems_version: 2.6.10
|
167
167
|
signing_key:
|
168
168
|
specification_version: 4
|
169
169
|
summary: A helper for links and other html tags in your translations
|