Sha256: d54ead7a994609b3ff3473ab615e0af558b9c961509a0f67dd0a942938b0c083

Contents?: true

Size: 809 Bytes

Versions: 1

Compression:

Stored size: 809 Bytes

Contents

# frozen_string_literal: true

module PageMeta
  class Translator
    include ::ActionView::Helpers::TranslationHelper

    attr_reader :scope, :naming, :options, :html

    def initialize(scope, naming, options = {})
      @scope = scope
      @naming = naming
      @html = options[:html]
      @options = options
    end

    def to_s
      return "" if simple.blank?
      t("page_meta.#{scope}.base", value: simple, default: simple)
    end

    def translation_scope
      "page_meta.#{scope}.#{naming.controller}.#{naming.action}"
    end

    def simple
      override_options = options.merge(default: "")

      translation = t("#{translation_scope}_html", override_options) if html
      translation = t(translation_scope, override_options) if translation.blank?
      translation
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
page_meta-0.2.0 lib/page_meta/translator.rb