Class: Flex::Template
- Inherits:
-
Object
- Object
- Flex::Template
- Defined in:
- lib/flex/template.rb,
lib/flex/template/tags.rb,
lib/flex/template/common.rb,
lib/flex/template/logger.rb,
lib/flex/template/search.rb,
lib/flex/template/partial.rb,
lib/flex/template/slim_search.rb
Overview
Generic Flex::Template object. This class represents a generic Flex::Template object. It is used as the base class by all the more specific Flex::Template::* classes. You usually don’t need to instantiate this class manually, since it is usually used internally. For more details about templates, see the documentation.
Direct Known Subclasses
Defined Under Namespace
Modules: Common, Logger Classes: Partial, Search, SlimSearch, Tag, Tags
Instance Attribute Summary collapse
-
#method ⇒ Object
readonly
Returns the value of attribute method.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Attributes included from Common
#data, #name, #partials, #tags
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(method, path, data = nil, *vars) ⇒ Template
constructor
A new instance of Template.
- #render(*vars) ⇒ Object
- #to_a(*vars) ⇒ Object
- #to_source ⇒ Object
Methods included from Common
Methods included from Logger
Constructor Details
#initialize(method, path, data = nil, *vars) ⇒ Template
Returns a new instance of Template.
19 20 21 22 23 24 25 26 |
# File 'lib/flex/template.rb', line 19 def initialize(method, path, data=nil, *vars) @method = method.to_s.upcase raise ArgumentError, "#@method method not supported" \ unless %w[HEAD GET PUT POST DELETE].include?(@method) @path = path =~ /^\// ? path : "/#{path}" @data = Utils.parse_source(data) @instance_vars = Vars.new(*vars) end |
Instance Attribute Details
#method ⇒ Object (readonly)
Returns the value of attribute method.
17 18 19 |
# File 'lib/flex/template.rb', line 17 def method @method end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
17 18 19 |
# File 'lib/flex/template.rb', line 17 def path @path end |
Class Method Details
.variables ⇒ Object
13 14 15 |
# File 'lib/flex/template.rb', line 13 def self.variables Vars.new end |
Instance Method Details
#render(*vars) ⇒ Object
28 29 30 31 32 |
# File 'lib/flex/template.rb', line 28 def render(*vars) do_render(*vars) do |response, int| Result.new(self, int[:vars], response).to_flex_result end end |
#to_a(*vars) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/flex/template.rb', line 34 def to_a(*vars) vars = Vars.new(*vars) int = interpolate(vars) a = [method, int[:path], Utils.keyfy(:to_s, int[:data]), Utils.keyfy(:to_s, @instance_vars)] 2.times { a.pop if a.last.nil? || a.last.empty? } a end |
#to_source ⇒ Object
42 43 44 |
# File 'lib/flex/template.rb', line 42 def to_source {@name.to_s => to_a}.to_yaml end |