Module: TmlRails::ActionControllerExtension::InstanceMethods
- Defined in:
- lib/tml_rails/extensions/action_controller_extension.rb
Instance Method Summary collapse
-
#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_browser_accepted_locales ⇒ Object
Returns all browser accepted locales
55 56 57 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 55 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
67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 67 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
159 160 161 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 159 def tml_filter_init tml_init if Tml.config.auto_init end |
#tml_filter_reset ⇒ Object
172 173 174 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 172 def tml_filter_reset tml_reset if Tml.config.auto_init end |
#tml_init ⇒ Object
137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 137 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 ) if I18n.backend.class.name == 'I18n::Backend::Tml' if defined? I18n.enforce_available_locales I18n.enforce_available_locales = false end I18n.locale = Tml.session.current_language.locale end end |
#tml_locale ⇒ Object
Locale is retrieved from method => params => cookie => subdomain => browser accepted locales Alternatively, this method can be overwritten
83 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 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 83 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.subdomain 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
163 164 165 166 167 168 169 170 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 163 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 end |
#tml_source ⇒ Object
Overwrite this method in a controller to assign a custom source for all views
60 61 62 63 64 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 60 def tml_source "/#{controller_name}/#{action_name}" rescue self.class.name end |
#tml_translator ⇒ Object
127 128 129 130 131 132 133 134 135 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 127 def tml_translator @tml_translator ||= begin if [:translator] Tml::Translator.new([:translator]) else nil end end end |
#tml_viewing_user ⇒ Object
115 116 117 118 119 120 121 122 123 124 125 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 115 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 |