Class: Gluttonberg::Middleware::Locales
- Inherits:
-
Object
- Object
- Gluttonberg::Middleware::Locales
- Defined in:
- lib/gluttonberg/middleware/locales.rb
Overview
This middleware is used to extract locale info from current path. This helps gluttonberg pages and other controllers to access locale information easily.
Class Method Summary collapse
-
.bypass_path?(path, env) ⇒ Boolean
Checks if we need to skip current path from analysing it for locales or gluttonberg pages.
Instance Method Summary collapse
- #call(env) ⇒ Object
-
#initialize(app) ⇒ Locales
constructor
A new instance of Locales.
Constructor Details
#initialize(app) ⇒ Locales
Returns a new instance of Locales.
6 7 8 |
# File 'lib/gluttonberg/middleware/locales.rb', line 6 def initialize(app) @app = app end |
Class Method Details
.bypass_path?(path, env) ⇒ Boolean
Checks if we need to skip current path from analysing it for locales or gluttonberg pages
36 37 38 39 40 41 42 |
# File 'lib/gluttonberg/middleware/locales.rb', line 36 def self.bypass_path?(path, env) if path.blank? false else path =~ /^\/admin/ || path.start_with?("/stylesheets") || path.start_with?("/javascripts") || path.start_with?("/images") || path.start_with?("/gluttonberg") || path.start_with?("/assets") || path.start_with?("/user_asset") end end |
Instance Method Details
#call(env) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/gluttonberg/middleware/locales.rb', line 15 def call(env) env['PATH_INFO'] = '' if env['PATH_INFO'].nil? path = env['PATH_INFO'] unless Gluttonberg::Middleware::Locales.bypass_path?(path, env) case Gluttonberg::Engine.config.identify_locale when :subdomain # return the sub-domain when :prefix handle_prefix(path, env) when :domain env['SERVER_NAME'] end end @app.call(env) end |