text_helpers 1.0.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +102 -0
- data/lib/text_helpers/railtie.rb +8 -2
- data/lib/text_helpers/translation.rb +5 -5
- data/lib/text_helpers/version.rb +1 -1
- data/test/lib/text_helpers/translation_test.rb +12 -4
- data/text_helpers.gemspec +1 -1
- metadata +9 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 196566e88af14d22f2703223fcb8a334f44d0bc6162b2a90e92ea722840da6a6
|
4
|
+
data.tar.gz: bdf313faa479139cac2acf301b8c80e28f83448de3da1d1e8145b1408c91cdaa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 95e9ff9a22f917aa08ff7b227c922abc56f0285d29ef581e0b43402a26777c98979737364da42cf015f1719f64f992e8b48caa6f3f7d9dd58468c689a8801285
|
7
|
+
data.tar.gz: 4346400f3ffb3a02404d899fe28ebea2b57e3481afd65a13321215e91e16a04a6d788141486a7893c37c3f9d38993312ed9b67363c2b45e4c16bc96e9a6e23ee
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
# Change Log
|
2
|
+
|
3
|
+
## [1.2.0] - 2022-01-05
|
4
|
+
|
5
|
+
### Changes
|
6
|
+
|
7
|
+
- Add support for Rails 7 (thanks to @boatrite)
|
8
|
+
|
9
|
+
## [1.1.1] - 2021-02-02
|
10
|
+
|
11
|
+
### Changes
|
12
|
+
|
13
|
+
- Bump minimum redcarpet version for security (thanks to @n00dle)
|
14
|
+
|
15
|
+
## [1.1.0] - 2020-12-02
|
16
|
+
|
17
|
+
### New Features
|
18
|
+
|
19
|
+
- Add `rel=noopener` to external links (thanks to @n00dle)
|
20
|
+
|
21
|
+
## [1.0.1] - 2020-12-02
|
22
|
+
|
23
|
+
### Changes
|
24
|
+
|
25
|
+
- Support cascading backends by default
|
26
|
+
|
27
|
+
## [1.0.0] - 2020-03-27
|
28
|
+
|
29
|
+
### Changes
|
30
|
+
|
31
|
+
- **(Breaking)** Drop explicit support for Ruby versions below 2.6
|
32
|
+
|
33
|
+
### Bug Fixes
|
34
|
+
|
35
|
+
- Properly support translations using I18n::Pluralization backend (thanks to @jhanggi)
|
36
|
+
|
37
|
+
## [0.7.2] - 2019-07-06
|
38
|
+
|
39
|
+
### Bug Fixes
|
40
|
+
|
41
|
+
- Improve orphaned text matcher targeting
|
42
|
+
|
43
|
+
## [0.7.1] - 2019-07-05
|
44
|
+
|
45
|
+
### Bug Fixes
|
46
|
+
|
47
|
+
- Prevent unnecessary non-breaking spaces in generated HTML
|
48
|
+
|
49
|
+
### Changes
|
50
|
+
|
51
|
+
- Improve `NotImplementedError` messaging (thanks to @stephen-puiszis)
|
52
|
+
- Update README with spec setup instructions (thanks to @jhanggi)
|
53
|
+
|
54
|
+
## [0.7.0] - 2016-05-06
|
55
|
+
|
56
|
+
### New features
|
57
|
+
|
58
|
+
- Automatically load entire locale directory via Railtie
|
59
|
+
|
60
|
+
## [0.6.1] - 2015-10-01
|
61
|
+
|
62
|
+
### Changes
|
63
|
+
|
64
|
+
- Bump version requirement for Redcarpet gem to address memory leaks
|
65
|
+
|
66
|
+
## [0.6.0] - 2015-06-15
|
67
|
+
|
68
|
+
### New Features
|
69
|
+
|
70
|
+
- Apply `target=_blank` attribute to anchor tags pointed at external URLs
|
71
|
+
|
72
|
+
## [0.5.3] - 2015-02-25
|
73
|
+
|
74
|
+
### Changes
|
75
|
+
|
76
|
+
- Update spec helpers for compatibility with RSpec 3 (thanks to @gabrielg)
|
77
|
+
|
78
|
+
## [0.5.2] - 2015-02-03
|
79
|
+
|
80
|
+
### Changes
|
81
|
+
|
82
|
+
- Support cascading backends for interpolated keys (thanks to @gabrielg)
|
83
|
+
|
84
|
+
## [0.5.1] - 2015-01-23
|
85
|
+
|
86
|
+
### New Features
|
87
|
+
|
88
|
+
- Add RSpec helpers (thanks to @gabrielg)
|
89
|
+
|
90
|
+
[1.2.0]: https://github.com/ahorner/text-helpers/compare/v1.1.1...v1.2.0
|
91
|
+
[1.1.1]: https://github.com/ahorner/text-helpers/compare/v1.1.0...v1.1.1
|
92
|
+
[1.1.0]: https://github.com/ahorner/text-helpers/compare/v1.0.1...v1.1.0
|
93
|
+
[1.0.1]: https://github.com/ahorner/text-helpers/compare/v1.0.0...v1.0.1
|
94
|
+
[1.0.0]: https://github.com/ahorner/text-helpers/compare/v0.7.2...v1.0.0
|
95
|
+
[0.7.2]: https://github.com/ahorner/text-helpers/compare/v0.7.1...v0.7.2
|
96
|
+
[0.7.1]: https://github.com/ahorner/text-helpers/compare/v0.7.0...v0.7.1
|
97
|
+
[0.7.0]: https://github.com/ahorner/text-helpers/compare/v0.6.1...v0.7.0
|
98
|
+
[0.6.1]: https://github.com/ahorner/text-helpers/compare/v0.6.0...v0.6.1
|
99
|
+
[0.6.0]: https://github.com/ahorner/text-helpers/compare/v0.5.3...v0.6.0
|
100
|
+
[0.5.3]: https://github.com/ahorner/text-helpers/compare/v0.5.2...v0.5.3
|
101
|
+
[0.5.2]: https://github.com/ahorner/text-helpers/compare/v0.5.1...v0.5.2
|
102
|
+
[0.5.1]: https://github.com/ahorner/text-helpers/compare/v0.5.0...v0.5.1
|
data/lib/text_helpers/railtie.rb
CHANGED
@@ -65,8 +65,14 @@ module TextHelpers
|
|
65
65
|
initializer "text_helpers.setup_exception_handling", after: 'after_initialize' do
|
66
66
|
next unless config.text_helpers.raise_on_missing_translations
|
67
67
|
|
68
|
-
if
|
69
|
-
config.
|
68
|
+
if Rails::VERSION::MAJOR >= 7
|
69
|
+
if config.respond_to?(:i18n)
|
70
|
+
config.i18n.raise_on_missing_translations = true
|
71
|
+
end
|
72
|
+
else
|
73
|
+
if config.respond_to?(:action_view)
|
74
|
+
config.action_view.raise_on_missing_translations = true
|
75
|
+
end
|
70
76
|
end
|
71
77
|
|
72
78
|
TextHelpers.install_i18n_exception_handler
|
@@ -12,7 +12,7 @@ module TextHelpers
|
|
12
12
|
attributes = [
|
13
13
|
("href=\"#{link}\"" if link),
|
14
14
|
("title=\"#{title}\"" if title),
|
15
|
-
("target=\"_blank\"" if link
|
15
|
+
("target=\"_blank\" rel=\"noopener\"" if link.match?(PROTOCOL_MATCHER)),
|
16
16
|
]
|
17
17
|
|
18
18
|
"<a #{attributes.compact.join(" ")}>#{content}</a>"
|
@@ -37,14 +37,14 @@ module TextHelpers
|
|
37
37
|
options = html_safe_options(options)
|
38
38
|
text = I18n.t(key, **{
|
39
39
|
scope: self.translation_scope,
|
40
|
-
default: "!#{key}!"
|
40
|
+
default: "!#{key}!",
|
41
|
+
cascade: true,
|
41
42
|
}.merge(options)).strip
|
42
43
|
|
43
|
-
interpolation_options = options
|
44
|
-
interpolation_options[:cascade] = true unless interpolation_options.has_key?(:cascade)
|
44
|
+
interpolation_options = { cascade: true }.merge(options)
|
45
45
|
|
46
46
|
# Interpolate any keypaths (e.g., `!some.lookup.path/key!`) found in the text.
|
47
|
-
while text
|
47
|
+
while text.match?(KEYPATH_MATCHER) do
|
48
48
|
text = text.gsub(KEYPATH_MATCHER) { |match| I18n.t($1, **interpolation_options) }
|
49
49
|
end
|
50
50
|
|
data/lib/text_helpers/version.rb
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
require_relative
|
1
|
+
require_relative "../../test_helper"
|
2
2
|
|
3
3
|
describe TextHelpers::Translation do
|
4
4
|
before do
|
@@ -119,12 +119,12 @@ describe TextHelpers::Translation do
|
|
119
119
|
assert_equal "<em>#{@scoped_text}</em>\n", @helper.html(:test_key, inline: true, orphans: true)
|
120
120
|
end
|
121
121
|
|
122
|
-
it "renders internal links without a target" do
|
122
|
+
it "renders internal links without a target or rel" do
|
123
123
|
assert_equal "<a href=\"/internal/path\">Internal link</a>\n", @helper.html(:internal_link, inline: true)
|
124
124
|
end
|
125
125
|
|
126
|
-
it "renders external links with target='_blank'" do
|
127
|
-
assert_equal "<a href=\"http://external.com\" target=\"_blank\">External link</a>\n", @helper.html(:external_link, inline: true)
|
126
|
+
it "renders external links with target='_blank' and rel='noopener'" do
|
127
|
+
assert_equal "<a href=\"http://external.com\" target=\"_blank\" rel=\"noopener\">External link</a>\n", @helper.html(:external_link, inline: true)
|
128
128
|
end
|
129
129
|
|
130
130
|
it "interpolates values wrapped in !!" do
|
@@ -242,6 +242,14 @@ describe TextHelpers::Translation do
|
|
242
242
|
I18n.backend = @original_backend
|
243
243
|
end
|
244
244
|
|
245
|
+
it "cascades the requested key by default" do
|
246
|
+
I18n.backend.store_translations(:en, {test_scoped_key: "a translation"})
|
247
|
+
assert_equal "a translation", @helper.text(:test_scoped_key, scope: "some.unnecessary.scope")
|
248
|
+
|
249
|
+
I18n.backend.store_translations(:en, {some: {test_scoped_key: "a scoped translation"}})
|
250
|
+
assert_equal "a scoped translation", @helper.text(:test_scoped_key, scope: "some.unnecessary.scope")
|
251
|
+
end
|
252
|
+
|
245
253
|
it "cascades the interpolated key by default" do
|
246
254
|
I18n.backend.store_translations(:en, {test_scoped_key: "a translation"})
|
247
255
|
|
data/text_helpers.gemspec
CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
|
|
24
24
|
|
25
25
|
gem.add_dependency("activesupport")
|
26
26
|
gem.add_dependency("i18n", ">=0.6.8")
|
27
|
-
gem.add_dependency("redcarpet", ">=3.
|
27
|
+
gem.add_dependency("redcarpet", ">=3.5.1")
|
28
28
|
|
29
29
|
gem.add_development_dependency("rake")
|
30
30
|
gem.add_development_dependency("railties")
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: text_helpers
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-01-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -44,14 +44,14 @@ dependencies:
|
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: 3.
|
47
|
+
version: 3.5.1
|
48
48
|
type: :runtime
|
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: 3.
|
54
|
+
version: 3.5.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rake
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,6 +89,7 @@ extra_rdoc_files: []
|
|
89
89
|
files:
|
90
90
|
- ".gitignore"
|
91
91
|
- ".travis.yml"
|
92
|
+
- CHANGELOG.md
|
92
93
|
- Gemfile
|
93
94
|
- LICENSE
|
94
95
|
- README.md
|
@@ -108,7 +109,7 @@ homepage: https://github.com/ahorner/text-helpers
|
|
108
109
|
licenses:
|
109
110
|
- MIT
|
110
111
|
metadata: {}
|
111
|
-
post_install_message:
|
112
|
+
post_install_message:
|
112
113
|
rdoc_options: []
|
113
114
|
require_paths:
|
114
115
|
- lib
|
@@ -123,8 +124,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
123
124
|
- !ruby/object:Gem::Version
|
124
125
|
version: '0'
|
125
126
|
requirements: []
|
126
|
-
rubygems_version: 3.
|
127
|
-
signing_key:
|
127
|
+
rubygems_version: 3.2.32
|
128
|
+
signing_key:
|
128
129
|
specification_version: 4
|
129
130
|
summary: TextHelpers is a gem which supplies some basic utilities for text localization
|
130
131
|
in Rails projects. The library is intended to make it simple to keep your application's
|