text_helpers 0.6.1 → 0.7.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +24 -63
- data/lib/text_helpers/contexts.rb +3 -3
- data/lib/text_helpers/railtie.rb +5 -0
- data/lib/text_helpers/version.rb +1 -1
- 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: 903554bdd7d36e4e370e3ee49c9b4fea2ce583c0
|
4
|
+
data.tar.gz: a44bc31df0e1ee330828bc7fce8c744cef1b851a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cd7cbf44933933fde4fef80f20346ce5f69acef7c5faf5842f73397db143ec3a13b59b2ada6ced119fc9500b76f0a1ff832d81d3bce9cf8f4054168c8f712a1b
|
7
|
+
data.tar.gz: ce8278cd00a6b9ec4df5e4aaaf9ae6486fb5a4e7212b9f4d0528647f05a32104958b01df0fe2e333ef0350130070f41357f8ec011c8e0a6b7094e94077c3b74d
|
data/README.md
CHANGED
@@ -1,7 +1,6 @@
|
|
1
1
|
# TextHelpers
|
2
2
|
|
3
|
-
`TextHelpers` is a library intended to make working with static text in Rails
|
4
|
-
projects as painless as possible.
|
3
|
+
`TextHelpers` is a library intended to make working with static text in Rails projects as painless as possible.
|
5
4
|
|
6
5
|
Include it in your `Gemfile` with:
|
7
6
|
|
@@ -11,50 +10,23 @@ gem "text_helpers"
|
|
11
10
|
|
12
11
|
## Suggested Use
|
13
12
|
|
14
|
-
All static text should be placed in locale files, in a directory
|
15
|
-
structure mirroring the app directory structure. The text for
|
16
|
-
`app/views/some/_partial.html.haml` would go in
|
17
|
-
`config/locales/views/some/partial.en.yml`, for example. This is not a strict
|
18
|
-
requirement, but will go a long way toward keeping your locales easily
|
19
|
-
maintainable.
|
13
|
+
All static text should be placed in locale files, in a directory structure mirroring the app directory structure. The text for `app/views/some/_partial.html.haml` would go in `config/locales/views/some/partial.en.yml`, for example. This is not a strict requirement, but will go a long way toward keeping your locales easily maintainable.
|
20
14
|
|
21
|
-
|
22
|
-
following line to your application.rb to ensure that Rails loads any locale
|
23
|
-
files organized this way:
|
24
|
-
|
25
|
-
```ruby
|
26
|
-
config.i18n.load_path += Dir[Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s]
|
27
|
-
```
|
28
|
-
|
29
|
-
In any locale file entry, you can reference another key in the locale file by
|
30
|
-
using the syntax `!scope.to.key!`. For the sake of maintainability, I
|
31
|
-
recommend restricting the use of this feature to small, highly-recycled
|
32
|
-
fragments of static text. `I18n`'s built-in `%{value}` interpolation can be
|
33
|
-
used for variable text.
|
15
|
+
In any locale file entry, you can reference another key in the locale file by using the syntax `!scope.to.key!`. For the sake of maintainability, I recommend restricting the use of this feature to small, highly-recycled fragments of static text. `I18n`'s built-in `%{value}` interpolation can be used for variable text.
|
34
16
|
|
35
17
|
### In Views
|
36
18
|
|
37
|
-
To access this text in views, two helpers are available, `text` and `html`.
|
38
|
-
Both helpers take a lookup key, used to identify the desired piece of text,
|
39
|
-
and an argument hash, which is forwarded to the `I18n.t` call.
|
19
|
+
To access this text in views, two helpers are available, `text` and `html`. Both helpers take a lookup key, used to identify the desired piece of text, and an argument hash, which is forwarded to the `I18n.t` call.
|
40
20
|
|
41
|
-
`text` returns the requested text, with special values interpolated, and made
|
42
|
-
html_safe (so HTML can be used here, when absolutely necessary).
|
21
|
+
`text` returns the requested text, with special values interpolated, and made html_safe (so HTML can be used here, when absolutely necessary).
|
43
22
|
|
44
|
-
`html` parses the requested text using Markdown, making it useful for rendering
|
45
|
-
larger pieces of text involving multiple paragraphs, list items or links.
|
23
|
+
`html` parses the requested text using Markdown, making it useful for rendering larger pieces of text involving multiple paragraphs, list items or links.
|
46
24
|
|
47
|
-
`html` automatically parses Markdown using
|
48
|
-
[`SmartyPants`-style](http://daringfireball.net/projects/smartypants/)
|
49
|
-
character conversions, so you can write plain text and have the proper
|
50
|
-
typographical elements generated for you without having to explicitly insert
|
51
|
-
HTML entities for common cases.
|
25
|
+
`html` automatically parses Markdown using [`SmartyPants`-style](http://daringfireball.net/projects/smartypants/) character conversions, so you can write plain text and have the proper typographical elements generated for you without having to explicitly insert HTML entities for common cases.
|
52
26
|
|
53
|
-
If you want to render a small fragment of Markdown without `p` tag wrappers,
|
54
|
-
you can pass `inline: true` as an option to `html`.
|
27
|
+
If you want to render a small fragment of Markdown without `p` tag wrappers, you can pass `inline: true` as an option to `html`.
|
55
28
|
|
56
|
-
`text` and `html` will escape all arguments passed to it in order to prevent XSS
|
57
|
-
attacks. If you want to pass html content, you should ensure you mark it as .html_safe
|
29
|
+
`text` and `html` will escape all arguments passed to it in order to prevent XSS attacks. If you want to pass html content, you should ensure you mark it as .html_safe
|
58
30
|
|
59
31
|
Example: `text('welcome_user', username)` will escape html characters in username
|
60
32
|
```ruby
|
@@ -68,14 +40,11 @@ Welcome <b>Bob</b>
|
|
68
40
|
|
69
41
|
### In Controllers
|
70
42
|
|
71
|
-
The same helpers are available in controllers, with the translation scope based
|
72
|
-
on the controller name rather than the view directory. This will typically be
|
73
|
-
used for flash messages or alerts of some kind.
|
43
|
+
The same helpers are available in controllers, with the translation scope based on the controller name rather than the view directory. This will typically be used for flash messages or alerts of some kind.
|
74
44
|
|
75
45
|
## Testing
|
76
46
|
|
77
|
-
Some shared `RSpec` contexts are available to allow the same locale
|
78
|
-
abstractions for testing. You can include these contexts with:
|
47
|
+
Some shared `RSpec` contexts are available to allow the same locale abstractions for testing. You can include these contexts with:
|
79
48
|
|
80
49
|
```
|
81
50
|
require "text_helpers/contexts"
|
@@ -83,18 +52,15 @@ require "text_helpers/contexts"
|
|
83
52
|
|
84
53
|
### Views
|
85
54
|
|
86
|
-
The view text helpers described above can be accessed in view
|
87
|
-
specs by adding `view: true` to the spec metadata.
|
55
|
+
The view text helpers described above can be accessed in view specs by adding `view: true` to the spec metadata.
|
88
56
|
|
89
57
|
### Controllers
|
90
58
|
|
91
|
-
The controller text helpers described above can be accessed in controller
|
92
|
-
specs by adding `controller: true` to your spec metadata.
|
59
|
+
The controller text helpers described above can be accessed in controller specs by adding `controller: true` to your spec metadata.
|
93
60
|
|
94
61
|
### Temporary/Stub Localizations
|
95
62
|
|
96
|
-
`text_helpers/rspec.rb` contains some helpers for setting up a test localization
|
97
|
-
environment during your test runs.
|
63
|
+
`text_helpers/rspec.rb` contains some helpers for setting up a test localization environment during your test runs.
|
98
64
|
|
99
65
|
To configure it, `require "text_helpers/rspec"` and configure the `before` and
|
100
66
|
`after` hooks appropriately:
|
@@ -124,35 +90,30 @@ set_translation('models.user.attributes.name', 'Name')
|
|
124
90
|
|
125
91
|
### Initialization
|
126
92
|
|
127
|
-
`TextHelpers` performs some setup during your application's initialization.
|
128
|
-
initializers are installed:
|
93
|
+
`TextHelpers` performs some setup during your application's initialization. Five initializers are installed:
|
129
94
|
|
130
95
|
#### `text_helpers.action_view.extend_base`
|
131
96
|
|
132
|
-
This initializer includes the `TextHelpers::Translation` module into
|
133
|
-
`ActionView::Base` and adds an appropriate `#translation_scope` method.
|
97
|
+
This initializer includes the `TextHelpers::Translation` module into `ActionView::Base` and adds an appropriate `#translation_scope` method.
|
134
98
|
|
135
99
|
#### `text_helpers.action_mailer.extend_base`
|
136
100
|
|
137
|
-
This initializer includes the `TextHelpers::Translation` module into
|
138
|
-
`ActionMailer::Base` and adds an appropriate `#translation_scope` method.
|
101
|
+
This initializer includes the `TextHelpers::Translation` module into `ActionMailer::Base` and adds an appropriate `#translation_scope` method.
|
139
102
|
|
140
103
|
#### `text_helpers.action_controller.extend_base`
|
141
104
|
|
142
|
-
This initializer includes the `TextHelpers::Translation` module into
|
143
|
-
|
105
|
+
This initializer includes the `TextHelpers::Translation` module into `ActionController::Base` and adds an appropriate `#translation_scope` method.
|
106
|
+
|
107
|
+
#### `text_helpers.i18n.add_load_paths`
|
108
|
+
|
109
|
+
This initializer updates the default I18n locale file load paths for your Rails application to recursively include files within directories and subdirectories. This enables a more hierarchical organization of your locale files.
|
144
110
|
|
145
111
|
#### `text_helpers.setup_exception_handling`
|
146
112
|
|
147
|
-
This initializer configures exception handling so that exceptions are raised
|
148
|
-
if `config.text_helpers.raise_on_missing_translations` is set to `true`, which
|
149
|
-
it is by default in the `test` or `development` environments.
|
113
|
+
This initializer configures exception handling so that exceptions are raised if `config.text_helpers.raise_on_missing_translations` is set to `true`, which it is by default in the `test` or `development` environments.
|
150
114
|
|
151
115
|
### Configuration
|
152
116
|
|
153
117
|
#### `config.text_helpers.raise_on_missing_translations`
|
154
118
|
|
155
|
-
This configuration value defaults to `true` in `test` or `development`
|
156
|
-
environments. If set to `false`, your own exception handling can be configured
|
157
|
-
by setting `config.action_view.raise_on_missing_translations` and
|
158
|
-
`I18n.exception_handler` as appropriate.
|
119
|
+
This configuration value defaults to `true` in `test` or `development` environments. If set to `false`, your own exception handling can be configured by setting `config.action_view.raise_on_missing_translations` and `I18n.exception_handler` as appropriate.
|
@@ -1,4 +1,4 @@
|
|
1
|
-
shared_context "a controller spec", controller: true do
|
1
|
+
RSpec.shared_context "a controller spec", controller: true do
|
2
2
|
include TextHelpers::Translation
|
3
3
|
|
4
4
|
def translation_scope
|
@@ -7,7 +7,7 @@ shared_context "a controller spec", controller: true do
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
-
shared_context "a mailer spec", mailer: true do
|
10
|
+
RSpec.shared_context "a mailer spec", mailer: true do
|
11
11
|
include TextHelpers::Translation
|
12
12
|
|
13
13
|
def translation_scope
|
@@ -16,7 +16,7 @@ shared_context "a mailer spec", mailer: true do
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
shared_context "a view spec", view: true do
|
19
|
+
RSpec.shared_context "a view spec", view: true do
|
20
20
|
include TextHelpers::Translation
|
21
21
|
|
22
22
|
def translation_scope
|
data/lib/text_helpers/railtie.rb
CHANGED
@@ -57,6 +57,11 @@ module TextHelpers
|
|
57
57
|
end
|
58
58
|
end
|
59
59
|
|
60
|
+
initializer "text_helpers.i18n.add_load_paths" do |app|
|
61
|
+
locales = Rails.root.join('config', 'locales', '**', '*.{rb,yml}').to_s
|
62
|
+
app.config.i18n.load_path += Dir[locales]
|
63
|
+
end
|
64
|
+
|
60
65
|
initializer "text_helpers.setup_exception_handling", after: 'after_initialize' do
|
61
66
|
next unless config.text_helpers.raise_on_missing_translations
|
62
67
|
|
data/lib/text_helpers/version.rb
CHANGED
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.
|
4
|
+
version: 0.7.0
|
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: 2016-05-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|