class Stasis::Extensions::I18n

Public Class Methods

new(stasis) click to toggle source
# File lib/stasis/extensions/i18n.rb, line 9
def initialize(stasis)
  @stasis = stasis
  reset
end

Public Instance Methods

before_all() click to toggle source
# File lib/stasis/extensions/i18n.rb, line 14
def before_all
  ::I18n.locale = ENV['LOCALE'] || ::I18n.default_locale
  define_helpers
end
reset() click to toggle source
# File lib/stasis/extensions/i18n.rb, line 19
def reset
  ::I18n.load_path = Dir[File.expand_path('config/locales/*.yml', @stasis.root)]
  ::I18n.default_locale = :en
  ::I18n.reload!
end

Protected Instance Methods

body_class() click to toggle source
# File lib/stasis/extensions/i18n.rb, line 29
def body_class
  [::I18n.locale, scope.last]
end
define_helpers() click to toggle source
# File lib/stasis/extensions/i18n.rb, line 27
def define_helpers
  @stasis.controller.helpers do
    def body_class
      [::I18n.locale, scope.last]
    end

    def relative_path
      @asset_path || _stasis.path.sub("#{_stasis.root}/", '')
    end

    def root_url
      "http://#{t('hostname', :scope => '')}"
    end

    def scope
      relative_path.sub(/\.\w+(\.(?:erb|haml|scss))?$/, '').split('/')
    end

    def translate(*args)
      options = args.last.is_a?(Hash) ? args.pop : {}
      options[:scope] ||= scope
      ::I18n.translate(*args, options)
    end

    alias_method :t, :translate
  end
end
relative_path() click to toggle source
# File lib/stasis/extensions/i18n.rb, line 33
def relative_path
  @asset_path || _stasis.path.sub("#{_stasis.root}/", '')
end
root_url() click to toggle source
# File lib/stasis/extensions/i18n.rb, line 37
def root_url
  "http://#{t('hostname', :scope => '')}"
end
scope() click to toggle source
# File lib/stasis/extensions/i18n.rb, line 41
def scope
  relative_path.sub(/\.\w+(\.(?:erb|haml|scss))?$/, '').split('/')
end
translate(*args) click to toggle source
# File lib/stasis/extensions/i18n.rb, line 45
def translate(*args)
  options = args.last.is_a?(Hash) ? args.pop : {}
  options[:scope] ||= scope
  ::I18n.translate(*args, options)
end