Module: TmlRails::ActionControllerExtension::InstanceMethods
- Defined in:
- lib/tml_rails/extensions/action_controller_extension.rb
Instance Method Summary collapse
- #tml_access_token ⇒ Object
-
#tml_browser_accepted_locales ⇒ Object
Returns all browser accepted locales.
-
#tml_cookie ⇒ Object
Returns data from cookie set by the agent.
- #tml_filter_init ⇒ Object
- #tml_filter_reset ⇒ Object
- #tml_init ⇒ Object
-
#tml_locale ⇒ Object
Locale is retrieved from method => params => cookie => subdomain => browser accepted locales Alternatively, this method can be overwritten.
- #tml_reset ⇒ Object
-
#tml_source ⇒ Object
Overwrite this method in a controller to assign a custom source for all views.
- #tml_translator ⇒ Object
- #tml_viewing_user ⇒ Object
Instance Method Details
#tml_access_token ⇒ Object
140 141 142 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 140 def tml_access_token [:oauth] ? [:oauth][:token] : nil end |
#tml_browser_accepted_locales ⇒ Object
Returns all browser accepted locales
56 57 58 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 56 def tml_browser_accepted_locales @tml_browser_accepted_locales ||= Tml::Utils.browser_accepted_locales(request.env['HTTP_ACCEPT_LANGUAGE']).join(',') end |
#tml_cookie ⇒ Object
Returns data from cookie set by the agent
68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 68 def @tml_cookie ||= begin = [Tml::Utils.(Tml.config.application[:key])] if .blank? {} else HashWithIndifferentAccess.new(Tml::Utils.decode(, Tml.config.application[:token])) end end rescue Exception => ex Tml.logger.error("Failed to parse tml cookie: #{ex.}") {} end |
#tml_filter_init ⇒ Object
169 170 171 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 169 def tml_filter_init tml_init if Tml.config.auto_init end |
#tml_filter_reset ⇒ Object
183 184 185 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 183 def tml_filter_reset tml_reset if Tml.config.auto_init end |
#tml_init ⇒ Object
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 144 def tml_init return if Tml.config.disabled? # Tml.logger.info(tml_cookie.inspect) @tml_started_at = Time.now Tml.session.init( :source => tml_source, :locale => tml_locale, :user => tml_viewing_user, :translator => tml_translator, :access_token => tml_access_token ) if defined? I18n.enforce_available_locales I18n.enforce_available_locales = false end I18n.locale = Tml.session.current_language.locale if tml_current_translator and tml_current_translator.inline? I18n.reload! end end |
#tml_locale ⇒ Object
Locale is retrieved from method => params => cookie => subdomain => browser accepted locales Alternatively, this method can be overwritten
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 84 def tml_locale @tml_locale ||= begin locale = nil unless Tml.config.current_locale_method.blank? begin locale = self.send(Tml.config.current_locale_method) rescue locale = nil end end if locale.nil? if params[:locale].blank? locale = [:locale] if locale.nil? if Tml.config.locale[:subdomain] locale = request.subdomains.first elsif Tml.config.locale[:tld] locale = request.host.split('.').last else locale = tml_browser_accepted_locales end end else locale = [:locale] = params[:locale] [Tml::Utils.(Tml.config.application[:key])] = Tml::Utils.encode(, Tml.config.application[:token]) end end locale end end |
#tml_reset ⇒ Object
173 174 175 176 177 178 179 180 181 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 173 def tml_reset return if Tml.config.disabled? @tml_finished_at = Time.now Tml.session.application.submit_missing_keys if Tml.session.application Tml.session.reset Tml.cache.reset_version Tml.logger.info("Request took #{@tml_finished_at - @tml_started_at} mls") if @tml_started_at Tml.logger.info('-----------------------------------------------------------') end |
#tml_source ⇒ Object
Overwrite this method in a controller to assign a custom source for all views
61 62 63 64 65 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 61 def tml_source "/#{controller_name}/#{action_name}" rescue self.class.name end |
#tml_translator ⇒ Object
130 131 132 133 134 135 136 137 138 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 130 def tml_translator @tml_translator ||= begin if [:translator] Tml::Translator.new([:translator]) else nil end end end |
#tml_viewing_user ⇒ Object
118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 118 def tml_viewing_user @tml_viewing_user ||= begin unless Tml.config.current_user_method.blank? begin self.send(Tml.config.current_user_method) rescue {} end end end end |