Class: Bruter::Mustache
- Inherits:
-
Mustache
- Object
- Mustache
- Bruter::Mustache
- Defined in:
- lib/bruter/mustache.rb
Class Attribute Summary collapse
-
._directory ⇒ Object
Returns the value of attribute _directory.
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#response ⇒ Object
readonly
Returns the value of attribute response.
-
#router ⇒ Object
readonly
Returns the value of attribute router.
Class Method Summary collapse
-
.inherited(klass) ⇒ Object
Hack to set :_directory to the file location in which this class is subclassed.
-
.template_name ⇒ Object
Sets the default template name to an underscored version of the class name.
-
.template_path ⇒ Object
Sets the default template path to ‘../templates’ relative to where the this class is subclassed.
Instance Method Summary collapse
-
#env ⇒ Object
Retrieves the Rack request’s env.
-
#initialize(request, response, router) ⇒ Mustache
constructor
Sets the Rack request and response objects and the calling router object.
-
#params ⇒ Object
Retrieves the params from a name variable or globbed route.
-
#path(name, *args) ⇒ Object
Retrieves the path for a named route given the name and any arguments.
Constructor Details
#initialize(request, response, router) ⇒ Mustache
Sets the Rack request and response objects and the calling router object. Subclasses can define a :setup method that will be invoked after initialization is complete.
59 60 61 62 63 64 |
# File 'lib/bruter/mustache.rb', line 59 def initialize(request, response, router) @request = request @response = response @router = router send :setup if respond_to?(:setup) end |
Class Attribute Details
._directory ⇒ Object
Returns the value of attribute _directory.
5 6 7 |
# File 'lib/bruter/mustache.rb', line 5 def _directory @_directory end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
54 55 56 |
# File 'lib/bruter/mustache.rb', line 54 def request @request end |
#response ⇒ Object (readonly)
Returns the value of attribute response.
54 55 56 |
# File 'lib/bruter/mustache.rb', line 54 def response @response end |
#router ⇒ Object (readonly)
Returns the value of attribute router.
54 55 56 |
# File 'lib/bruter/mustache.rb', line 54 def router @router end |
Class Method Details
.inherited(klass) ⇒ Object
Hack to set :_directory to the file location in which this class is subclassed. Those not subclassing Bruter::Mustache in a file may want to explicitly set :_directory or the @template_path variable with :template_path=(path).
11 12 13 |
# File 'lib/bruter/mustache.rb', line 11 def inherited(klass) klass._directory = File.dirname(caller.first[/^[^:]+/]) end |
.template_name ⇒ Object
Sets the default template name to an underscored version of the class name.
Example:
# in '/path/to/app/views/tagged.rb'
module Views
class TaggedPosts < Bruter::Mustache
puts self.template_name
puts self.template_file
end
end
=> 'tagged_posts'
=> '/path/to/app/templates/tagged_posts.mustache'
49 50 51 |
# File 'lib/bruter/mustache.rb', line 49 def template_name @template_name ||= self.to_s.underscore.split('/').last end |
.template_path ⇒ Object
Sets the default template path to ‘../templates’ relative to where the this class is subclassed.
Example:
# in '/path/to/app/views/tagged.rb'
module Views
class TaggedPosts < Bruter::Mustache
puts self.template_path
end
end
=> '/path/to/app/templates'
27 28 29 30 31 32 33 |
# File 'lib/bruter/mustache.rb', line 27 def template_path if _directory @template_path ||= File.('../templates', _directory) else super end end |
Instance Method Details
#env ⇒ Object
Retrieves the Rack request’s env.
67 68 69 |
# File 'lib/bruter/mustache.rb', line 67 def env @request.env end |
#params ⇒ Object
Retrieves the params from a name variable or globbed route.
72 73 74 |
# File 'lib/bruter/mustache.rb', line 72 def params env['router.params'] end |
#path(name, *args) ⇒ Object
Retrieves the path for a named route given the name and any arguments.
77 78 79 |
# File 'lib/bruter/mustache.rb', line 77 def path(name, *args) args.any? ? router.url(name, *args) : router.url(name) end |