page_meta 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: '098f9bb6d6f41562f414f69b57cb0e5ca6c77034'
4
- data.tar.gz: 19a6825dbf0a33b5bdb2cd26b098f80230885ebe
3
+ metadata.gz: e9c07868edd3c003b06253874a088a2ea0bb00bd
4
+ data.tar.gz: d228a7a77ef36d2312c03bb0d7b2245872f44448
5
5
  SHA512:
6
- metadata.gz: b4ca261f7b9ce10155844b32b1d77d470f5f8cce17b71678a114ebc7bdb074d56b8e3b5b2c2f8e6dff7e2d28a4e758028d46e5d33d469d1d0f19ba7658d46ea1
7
- data.tar.gz: c330695fe010a45597362f7b26b4b7c16cf6fb5e1f2858296b19b510c637f4f31888fe67e59349c6457f83f09eb4068737f722c9927bd1f8552221295ade3d42
6
+ metadata.gz: 51d00356fd9df12fcd14867e5bf158f9fa04cf1dbd66d1b20105a8fdeac5e8692fb765c3dc84bd319b8d246aa073345749cf5a7d490fc36dad78c23e05faddae
7
+ data.tar.gz: 181ead8af4434898b10f609784abecd295f5f098fcf333647997d556ce6b236473e7000bdf8e1bc0d4e2fbe5b661c207470041a3b406fb8fc488c2338479d4d1
data/README.md CHANGED
@@ -180,6 +180,17 @@ To render all tags, just do something like this:
180
180
  </html>
181
181
  ```
182
182
 
183
+ #### Rendering titles and descriptions
184
+
185
+ You may want to render title and description on your page. In this case, you may use something like this:
186
+
187
+ ```erb
188
+ <h1><%= page_meta.title.simple %></h1>
189
+ <p><%= page_meta.description.simple %></p>
190
+ ```
191
+
192
+ If your description contains HTML, you can use `page_meta.description(html: true).simple` instead. It will use Rails' `html_safe` helpers to safely retrieve the translation, just like regular Rails would do. [Please read Rails docs](http://guides.rubyonrails.org/i18n.html#using-safe-html-translations) for more info.
193
+
183
194
  ## Development
184
195
 
185
196
  After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
@@ -10,6 +10,7 @@ module PageMeta
10
10
 
11
11
  def initialize(controller)
12
12
  @controller = controller
13
+ @description = {}
13
14
  @store = {}
14
15
  end
15
16
 
@@ -33,8 +34,8 @@ module PageMeta
33
34
  @title ||= Translator.new(:titles, naming, store)
34
35
  end
35
36
 
36
- def description
37
- @description ||= Translator.new(:descriptions, naming, store)
37
+ def description(html: false)
38
+ @description[html] ||= Translator.new(:descriptions, naming, store.merge(html: html))
38
39
  end
39
40
 
40
41
  def keywords
@@ -2,24 +2,32 @@
2
2
 
3
3
  module PageMeta
4
4
  class Translator
5
- attr_reader :scope, :naming, :options
5
+ include ::ActionView::Helpers::TranslationHelper
6
+
7
+ attr_reader :scope, :naming, :options, :html
6
8
 
7
9
  def initialize(scope, naming, options = {})
8
10
  @scope = scope
9
11
  @naming = naming
12
+ @html = options[:html]
10
13
  @options = options
11
14
  end
12
15
 
13
16
  def to_s
14
17
  return "" if simple.blank?
15
- I18n.t("page_meta.#{scope}.base", value: simple, default: simple)
18
+ t("page_meta.#{scope}.base", value: simple, default: simple)
19
+ end
20
+
21
+ def translation_scope
22
+ "page_meta.#{scope}.#{naming.controller}.#{naming.action}"
16
23
  end
17
24
 
18
25
  def simple
19
- I18n.t(
20
- "page_meta.#{scope}.#{naming.controller}.#{naming.action}",
21
- options.merge(default: "")
22
- )
26
+ override_options = options.merge(default: "")
27
+
28
+ translation = t("#{translation_scope}_html", override_options) if html
29
+ translation = t(translation_scope, override_options) if translation.blank?
30
+ translation
23
31
  end
24
32
  end
25
33
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PageMeta
4
- VERSION = "0.1.3"
4
+ VERSION = "0.2.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: page_meta
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nando Vieira
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-10-21 00:00:00.000000000 Z
11
+ date: 2017-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails