text_helpers 0.7.0 → 0.7.1
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/README.md +13 -3
- 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 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: aab61ab2ec51e7a9457ad3fc762341ecc59862b7
|
4
|
+
data.tar.gz: 687b06a1b1ee2447c5fb29248307f74726550589
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c03051dbfce0714ee802493eb44ecabeeb669b9eef87a847b5a21c3a03380832f247ed9192032b804dd8363046fe8c474600fbd3bc16c221587d7337bf380f2a
|
7
|
+
data.tar.gz: 800a199fde5ee931a01078e1a08f2587952b577c9852b30dae3ea726f24cd3d6740edd96d1277871718df97f815b72bb80f16bc1cb1dd1c65d09ce2dbfbe7438
|
data/README.md
CHANGED
@@ -60,7 +60,9 @@ The controller text helpers described above can be accessed in controller specs
|
|
60
60
|
|
61
61
|
### Temporary/Stub Localizations
|
62
62
|
|
63
|
-
`text_helpers/rspec.rb` contains some helpers for setting up a test localization
|
63
|
+
`text_helpers/rspec.rb` contains some helpers for setting up a test localization
|
64
|
+
environment during your test runs. You can enable the helper methods by adding
|
65
|
+
the `:text_helpers` tag to the examples that require them.
|
64
66
|
|
65
67
|
To configure it, `require "text_helpers/rspec"` and configure the `before` and
|
66
68
|
`after` hooks appropriately:
|
@@ -69,11 +71,13 @@ To configure it, `require "text_helpers/rspec"` and configure the `before` and
|
|
69
71
|
require 'text_helpers/rspec'
|
70
72
|
|
71
73
|
RSpec.configure do |config|
|
74
|
+
config.include TextHelpers::RSpec::TestHelpers, text_helpers: true
|
75
|
+
|
72
76
|
config.before(:suite) do
|
73
77
|
TextHelpers::RSpec.setup_spec_translations
|
74
78
|
end
|
75
79
|
|
76
|
-
config.after(:each) do
|
80
|
+
config.after(:each, :text_helpers) do
|
77
81
|
TextHelpers::RSpec.reset_spec_translations
|
78
82
|
end
|
79
83
|
end
|
@@ -83,7 +87,13 @@ Temporary localizations can then be defined within your examples via the
|
|
83
87
|
`#set_translation` method, like so:
|
84
88
|
|
85
89
|
```
|
86
|
-
|
90
|
+
describe "with a translation set", :text_helpers do
|
91
|
+
before do
|
92
|
+
set_translation('models.user.attributes.name', 'Name')
|
93
|
+
end
|
94
|
+
|
95
|
+
it { ... }
|
96
|
+
end
|
87
97
|
```
|
88
98
|
|
89
99
|
## Configuration & Initialization
|
@@ -22,7 +22,7 @@ module TextHelpers
|
|
22
22
|
|
23
23
|
module Translation
|
24
24
|
|
25
|
-
ORPHAN_MATCHER =
|
25
|
+
ORPHAN_MATCHER = /[ \t](?![^<]*>)(\S+\s*<\/(?:p|li)>)/.freeze
|
26
26
|
|
27
27
|
# Public: Get the I18n localized text for the passed key.
|
28
28
|
#
|
@@ -82,7 +82,7 @@ module TextHelpers
|
|
82
82
|
smartify(@renderer.render(text))
|
83
83
|
end
|
84
84
|
|
85
|
-
#
|
85
|
+
# Internal: Auto-apply smart quotes to the passed text.
|
86
86
|
#
|
87
87
|
# text - A String which should be passed through the SmartyPants renderer.
|
88
88
|
#
|
@@ -91,16 +91,16 @@ module TextHelpers
|
|
91
91
|
Redcarpet::Render::SmartyPants.render(text)
|
92
92
|
end
|
93
93
|
|
94
|
-
#
|
94
|
+
# Internal: The proper scope for I18n translation.
|
95
95
|
#
|
96
96
|
# Must be implemented by any classes which include this module.
|
97
97
|
#
|
98
98
|
# Raises NotImplementedError.
|
99
99
|
def translation_scope
|
100
|
-
raise NotImplementedError
|
100
|
+
raise NotImplementedError, "must implement a public method `translation_scope` to determine I18n scope"
|
101
101
|
end
|
102
102
|
|
103
|
-
#
|
103
|
+
# Internal: Convert all passed in arguments into html-safe strings
|
104
104
|
#
|
105
105
|
# hash - a set of key-value pairs, which converts the second argument into an html-safe string
|
106
106
|
#
|
data/lib/text_helpers/version.rb
CHANGED
@@ -9,6 +9,7 @@ describe TextHelpers::Translation do
|
|
9
9
|
before do
|
10
10
|
@scoped_text = "Scoped lookup"
|
11
11
|
@global_text = "Global lookup"
|
12
|
+
@single_word_text = "Single"
|
12
13
|
@email_address = "user@example.org"
|
13
14
|
@multiline_text = <<-MULTI.gsub(/^[ \t]+/, '')
|
14
15
|
This is some multiline text.
|
@@ -30,6 +31,7 @@ describe TextHelpers::Translation do
|
|
30
31
|
email_key: "<#{@email_address}>",
|
31
32
|
test_key: "*#{@scoped_text}*",
|
32
33
|
list_key: "* #{@scoped_text}",
|
34
|
+
single_word_list_key: "* #{@single_word_text}",
|
33
35
|
interpolated_key: "Global? (!test_key!)",
|
34
36
|
interpolated_scoped_key: "Global? (!test_scoped_key!)",
|
35
37
|
interpol_arg_key: "Interpolate global? (!interpolated_key!)",
|
@@ -74,6 +76,16 @@ describe TextHelpers::Translation do
|
|
74
76
|
assert_equal expected, @helper.html(:list_key)
|
75
77
|
end
|
76
78
|
|
79
|
+
it "does not inject ` ` entities in HTML list items unnecessarily" do
|
80
|
+
expected = <<-EXPECTED.gsub(/^[ \t]+/, '')
|
81
|
+
<ul>
|
82
|
+
<li>#{@single_word_text}</li>
|
83
|
+
</ul>
|
84
|
+
EXPECTED
|
85
|
+
|
86
|
+
assert_equal expected, @helper.html(:single_word_list_key)
|
87
|
+
end
|
88
|
+
|
77
89
|
it "does not modify HTML tags" do
|
78
90
|
expected = "<p><a href=\"mailto:#{@email_address}\">#{@email_address}</a></p>\n"
|
79
91
|
assert_equal expected, @helper.html(:email_key)
|
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: 0.7.
|
4
|
+
version: 0.7.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Horner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|