Class: Bartender::Partial
- Inherits:
-
Object
- Object
- Bartender::Partial
- Includes:
- ViewHelpers
- Defined in:
- lib/bartender/partial.rb
Instance Method Summary collapse
-
#initialize(partial, sprockets_env, variables = {}) ⇒ Partial
constructor
A new instance of Partial.
- #method_missing(m, *args) ⇒ Object
-
#to_s ⇒ Object
Function init.
Methods included from ViewHelpers
#asset_url, #link_image, #link_script, #link_stylesheet, #partial
Constructor Details
#initialize(partial, sprockets_env, variables = {}) ⇒ Partial
Returns a new instance of Partial.
6 7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/bartender/partial.rb', line 6 def initialize(partial, sprockets_env, variables={}) @tempalte = "" @sprockets_env = sprockets_env variables.each {|k,v| instance_variable_set "@#{k}", v} search_string = File.join(Bartender::DEFAULTS['pages'], '_' + partial + "*") file = Dir.glob(search_string)[0] if file && File.exists?(file) @template = Tilt.new(file).render(self) else $stderr.puts "ERROR: Could not find partial file '#{partial}' in #{Bartender::DEFAULTS['pages']} for page #{self.page}" exit 0 end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args) ⇒ Object
25 26 27 28 29 30 31 |
# File 'lib/bartender/partial.rb', line 25 def method_missing(m, *args) if m =~ /^(\w+)=$/ instance_variable_set "@#{$1}", args[0] else instance_variable_get "@#{m}" end end |
Instance Method Details
#to_s ⇒ Object
Function init
20 21 22 |
# File 'lib/bartender/partial.rb', line 20 def to_s @template.to_s end |