class PageMeta::Translator

Attributes

html[R]
naming[R]
options[R]
scope[R]

Public Class Methods

new(scope, naming, options = {}) click to toggle source
# File lib/page_meta/translator.rb, line 9
def initialize(scope, naming, options = {})
  @scope = scope
  @naming = naming
  @html = options[:html]
  @options = options
end

Public Instance Methods

simple() click to toggle source
# File lib/page_meta/translator.rb, line 36
def simple
  override_options = options.merge(default: "")

  translation = ""

  translation_scope.each do |scope|
    translation = t("#{scope}_html", **override_options) if html
    translation = t(scope, **override_options) if translation.blank?

    break if translation.present?
  end

  translation
end
singular_scope() click to toggle source
# File lib/page_meta/translator.rb, line 16
def singular_scope
  @singular_scope ||= scope == :keywords ? "keywords" : scope.to_s.singularize
end
to_s() click to toggle source
# File lib/page_meta/translator.rb, line 20
def to_s
  return "" if simple.blank?

  [
    t("page_meta.#{scope}.base", value: simple, default: ""),
    t("page_meta.#{singular_scope}_base", value: simple, default: simple)
  ].reject(&:blank?).first || ""
end
translation_scope() click to toggle source
# File lib/page_meta/translator.rb, line 29
def translation_scope
  [
    "page_meta.#{scope}.#{naming.controller}.#{naming.action}",
    "page_meta.#{naming.controller}.#{naming.action}.#{singular_scope}"
  ]
end