Class: LocaleSchema::Translation
- Inherits:
-
Object
- Object
- LocaleSchema::Translation
- Defined in:
- lib/locale_schema/translation.rb
Constant Summary collapse
- HTML_SAFE_LEAF_NAMES =
%w{markdown textile html}
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#key ⇒ Object
readonly
Returns the value of attribute key.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#scope ⇒ Object
readonly
Returns the value of attribute scope.
Instance Method Summary collapse
- #defaults ⇒ Object
- #html_safe? ⇒ Boolean
-
#initialize(args = {}) ⇒ Translation
constructor
A new instance of Translation.
- #leaf_name ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ Translation
Returns a new instance of Translation.
7 8 9 10 11 12 |
# File 'lib/locale_schema/translation.rb', line 7 def initialize(args={}) @key = args[:key] @options = args[:options] || {} @context = args[:context] @scope = args[:scope].split('/') || [] end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
3 4 5 |
# File 'lib/locale_schema/translation.rb', line 3 def context @context end |
#key ⇒ Object (readonly)
Returns the value of attribute key.
3 4 5 |
# File 'lib/locale_schema/translation.rb', line 3 def key @key end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
3 4 5 |
# File 'lib/locale_schema/translation.rb', line 3 def @options end |
#scope ⇒ Object (readonly)
Returns the value of attribute scope.
3 4 5 |
# File 'lib/locale_schema/translation.rb', line 3 def scope @scope end |
Instance Method Details
#defaults ⇒ Object
22 23 24 25 26 27 |
# File 'lib/locale_schema/translation.rb', line 22 def defaults [ :"#{context}.#{scope.join('.')}.#{key}", :"#{context}.application.#{key}" ] end |
#html_safe? ⇒ Boolean
18 19 20 |
# File 'lib/locale_schema/translation.rb', line 18 def html_safe? HTML_SAFE_LEAF_NAMES.include?(leaf_name) end |
#leaf_name ⇒ Object
14 15 16 |
# File 'lib/locale_schema/translation.rb', line 14 def leaf_name key.to_s.split('.').last end |
#to_s ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/locale_schema/translation.rb', line 29 def to_s s = I18n.t(defaults[0], .merge(:default => defaults[1..-1])) if leaf_name == 'markdown' s = ::Redcarpet::Markdown.new(Redcarpet::Render::HTML).render(s) end s end |