class Tr8n::Session
Attributes
Public Class Methods
access_token()
click to toggle source
# File lib/tr8n/session.rb, line 44 def self.access_token @access_token end
access_token=(token)
click to toggle source
# File lib/tr8n/session.rb, line 48 def self.access_token=(token) @access_token = token end
Public Instance Methods
current_component_from_block_options()
click to toggle source
# File lib/tr8n/session.rb, line 190 def current_component_from_block_options arr = @block_options || [] arr.reverse.each do |opts| return application.component_by_key(opts[:component]) unless opts[:component].blank? end Tr8n.config.current_component end
current_source_from_block_options()
click to toggle source
# File lib/tr8n/session.rb, line 182 def current_source_from_block_options arr = @block_options || [] arr.reverse.each do |opts| return application.source_by_key(opts[:source]) unless opts[:source].blank? end nil end
init(opts = {})
click to toggle source
# File lib/tr8n/session.rb, line 52 def init(opts = {}) return unless Tr8n.config.enabled? and Tr8n.config.application key = opts[:key] || Tr8n.config.application[:key] secret = opts[:secret] || Tr8n.config.application[:secret] host = opts[:host] || Tr8n.config.application[:host] Tr8n::Session.access_token ||= begin self.access_token = opts[:token] || Tr8n.config.application[:token] self.access_token ||= opts[:access_token] || Tr8n.config.application[:access_token] end Tr8n.cache.reset_version self.application = Tr8n.memory.fetch(Tr8n::Application.cache_key) do Tr8n::Application.new(:host => host, :key => key, :secret => secret, :access_token => Tr8n::Session.access_token).fetch end if Tr8n.cache.read_only? self.class.access_token = self.application.access_token end # Tr8n.logger.info(self.cookie_params.inspect) self.cookie_params = begin cookie_name = "tr8n_#{self.application.key}" if opts[:cookies] and opts[:cookies][cookie_name] begin HashWithIndifferentAccess.new(Tr8n::Utils.decode_and_verify_params(opts[:cookies][cookie_name], secret)) rescue Exception => ex Tr8n.logger.error("Failed to parse tr8n cookie: #{ex.message}") {} end else {} end end self.tools_enabled = opts[:tools_enabled] self.current_user = opts[:user] self.current_source = opts[:source] || '/tr8n/core' self.current_component = opts[:component] self.current_locale = opts[:locale] || self.cookie_params[:locale] || Tr8n.config.default_locale if self.cookie_params['translator'] self.current_translator = Tr8n::Translator.new(self.cookie_params['translator']) end # if inline mode don't use any app cache if inline_mode? self.application = self.application.dup self.application.reset_translation_cache end if self.current_translator self.current_translator.application = self.application end self.current_language = self.application.language(self.current_locale) end
inline_mode?()
click to toggle source
# File lib/tr8n/session.rb, line 152 def inline_mode? current_translator and current_translator.inline? end
pop_block_options()
click to toggle source
# File lib/tr8n/session.rb, line 164 def pop_block_options return unless @block_options @block_options.pop end
push_block_options(opts)
click to toggle source
Block Options
# File lib/tr8n/session.rb, line 160 def push_block_options(opts) (@block_options ||= []).push(opts) end
reset()
click to toggle source
# File lib/tr8n/session.rb, line 117 def reset self.application= nil self.current_user= nil self.current_language= nil self.current_translator= nil self.current_source= nil self.current_component= nil self.tools_enabled= nil self.block_options= nil end
source_language()
click to toggle source
# File lib/tr8n/session.rb, line 136 def source_language arr = @block_options || [] arr.reverse.each do |opts| return application.language(opts[:locale]) unless opts[:locale].blank? end application.language end
target_language()
click to toggle source
# File lib/tr8n/session.rb, line 144 def target_language arr = @block_options || [] arr.reverse.each do |opts| return application.language(opts[:target_locale]) unless opts[:target_locale].nil? end current_language end
tools_enabled?()
click to toggle source
# File lib/tr8n/session.rb, line 113 def tools_enabled? self.tools_enabled end
with_block_options(opts) { || ... }
click to toggle source
# File lib/tr8n/session.rb, line 173 def with_block_options(opts) push_block_options(opts) if block_given? ret = yield end pop_block_options ret end