Module: TmlRails::ActionControllerExtension::InstanceMethods
- Defined in:
- lib/tml_rails/extensions/action_controller_extension.rb
Instance Method Summary collapse
- #tml_browser_accepted_locales ⇒ Object
-
#tml_component ⇒ Object
Overwrite this method in a controller to assign a custom component for all views.
- #tml_init_client_sdk ⇒ Object
- #tml_reset_client_sdk ⇒ Object
-
#tml_source ⇒ Object
Overwrite this method in a controller to assign a custom source for all views.
- #tml_toggle_tools(flag) ⇒ Object
- #tml_tools_enabled? ⇒ Boolean
- #tml_user_preferred_locale ⇒ Object
Instance Method Details
#tml_browser_accepted_locales ⇒ Object
52 53 54 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 52 def tml_browser_accepted_locales @tml_browser_accepted_locales ||= Tml::Utils.browser_accepted_locales(request) end |
#tml_component ⇒ Object
Overwrite this method in a controller to assign a custom component for all views
72 73 74 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 72 def tml_component nil end |
#tml_init_client_sdk ⇒ Object
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 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 84 def tml_init_client_sdk return if Tml.config.disabled? @tml_started_at = Time.now if params[:tml] tml_toggle_tools(params[:tml] == 'on') end tml_session_params = { :tools_enabled => tml_tools_enabled?, :source => tml_source, :component => tml_component } if Tml.config.current_user_method begin tml_session_params.merge!(:user => self.send(Tml.config.current_user_method)) rescue # Tml.logger.error('Current user method is specified but not provided') end end if Tml.config.current_locale_method begin tml_session_params.merge!(:locale => self.send(Tml.config.current_locale_method)) rescue # Tml.logger.error('Current locale method is specified but not provided') end end unless tml_session_params[:locale] tml_session_params.merge!(:cookies => ) tml_session_params.merge!(:change_locale => true) if params[:locale] tml_session_params.merge!(:locale => params[:locale] || tml_user_preferred_locale) end Tml.session.init(tml_session_params) # if user sets locale manually, update the cookie for future use if tml_session_params[:change_locale] [Tml.session.] = Tml::Utils.encode(Tml.session.) end if defined? I18n.enforce_available_locales I18n.enforce_available_locales = false end I18n.locale = Tml.session.current_language.locale end |
#tml_reset_client_sdk ⇒ Object
134 135 136 137 138 139 140 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 134 def tml_reset_client_sdk return if Tml.config.disabled? @tml_finished_at = Time.now tml_application.submit_missing_keys Tml.session.reset 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
65 66 67 68 69 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 65 def tml_source "/#{controller_name}/#{action_name}" rescue self.class.name end |
#tml_toggle_tools(flag) ⇒ Object
76 77 78 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 76 def tml_toggle_tools(flag) session[:tml_tools_disabled] = !flag end |
#tml_tools_enabled? ⇒ Boolean
80 81 82 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 80 def tml_tools_enabled? not session[:tml_tools_disabled] end |
#tml_user_preferred_locale ⇒ Object
56 57 58 59 60 61 62 |
# File 'lib/tml_rails/extensions/action_controller_extension.rb', line 56 def tml_user_preferred_locale tml_browser_accepted_locales.each do |locale| next unless Tml.session.application and Tml.session.application.locales.include?(locale) return locale end Tml.config.default_locale end |