Sha256: 142b804b6cec3fb6c3060c5eaa97f348162f765a679bc4b0f3ea67951d22b609

Contents?: true

Size: 739 Bytes

Versions: 1

Compression:

Stored size: 739 Bytes

Contents

require 'mustache'
require 'alephant/views'
require 'hashie'
require 'json'
require 'i18n'

module Alephant::Views
  class Base < Mustache
    attr_accessor :data

    LOCALE = :en

    def initialize(data = {})
      @data = Hashie::Mash.new data
    end

    def t(*args)
      I18n.locale = self.class::LOCALE
      lambda do |comma_delimited_args|
        args   = comma_delimited_args.strip.split ','
        key    = args.shift
        params = args.empty? ? {} : JSON.parse(args.first).with_indifferent_access
        prefix = /\/([^\/]+)\./.match(template_file)[1]

        I18n.translate("#{prefix}.#{key}", params)
      end
    end

    def self.inherited(subclass)
      ::Alephant::Views.register(subclass)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alephant-renderer-0.0.6 lib/alephant/views/base.rb