Class: Trimmer::Controller
- Inherits:
-
Object
- Object
- Trimmer::Controller
- Defined in:
- lib/trimmer/controller.rb
Instance Attribute Summary collapse
-
#allowed_keys ⇒ Object
Returns the value of attribute allowed_keys.
-
#renderer_scope ⇒ Object
Returns the value of attribute renderer_scope.
-
#templates_path ⇒ Object
Returns the value of attribute templates_path.
Instance Method Summary collapse
-
#call(env) ⇒ Object
Handle trimmer routes else call the next middleware with the environment.
-
#initialize(app, opts = {}) ⇒ Controller
constructor
A new instance of Controller.
Constructor Details
#initialize(app, opts = {}) ⇒ Controller
Returns a new instance of Controller.
13 14 15 16 17 18 19 |
# File 'lib/trimmer/controller.rb', line 13 def initialize(app, opts={}) @app = app @templates_path = opts[:templates_path] || File.(File.dirname(__FILE__)) @allowed_keys = opts[:allowed_keys] || "*" @renderer_scope = opts[:renderer_scope] || Object.new end |
Instance Attribute Details
#allowed_keys ⇒ Object
Returns the value of attribute allowed_keys.
11 12 13 |
# File 'lib/trimmer/controller.rb', line 11 def allowed_keys @allowed_keys end |
#renderer_scope ⇒ Object
Returns the value of attribute renderer_scope.
11 12 13 |
# File 'lib/trimmer/controller.rb', line 11 def renderer_scope @renderer_scope end |
#templates_path ⇒ Object
Returns the value of attribute templates_path.
11 12 13 |
# File 'lib/trimmer/controller.rb', line 11 def templates_path @templates_path end |
Instance Method Details
#call(env) ⇒ Object
Handle trimmer routes else call the next middleware with the environment.
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/trimmer/controller.rb', line 23 def call(env) request = Rack::Request.new(env) response = nil case request.path when /\/trimmer(\/([^\/]+))*\/translations\.([js]+)$/ validate_locale($2) if $2 || ($2 && $2.empty?) response = translations($2, $3, request.params) when /\/trimmer\/([^\/]+)\/templates\.([js]+)$/ validate_locale($1) response = templates($1, $2) when /\/trimmer\/([^\.|\/]+)\.([js]+)$/ validate_locale($1) response = resources($1, $2, request.params) else response = @app.call(env) end response end |