Class: Mack::Rendering::Type::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/mack/rendering/type/base.rb

Overview

Mack::Rendering::Type objects need to extend this class.

The method ‘render’ needs to be implemented as in all subclasses.

Direct Known Subclasses

FileBase, Inline, Public, Text, Url

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(view_template) ⇒ Base

Returns a new instance of Base.



12
13
14
# File 'lib/mack/rendering/type/base.rb', line 12

def initialize(view_template)
  @view_template = view_template
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object



40
41
42
# File 'lib/mack/rendering/type/base.rb', line 40

def method_missing(sym, *args)
  self.view_template.send(sym, *args)
end

Instance Attribute Details

#view_templateObject (readonly)

Returns the Mack::Rendering::ViewTemplate object associated with this render.



10
11
12
# File 'lib/mack/rendering/type/base.rb', line 10

def view_template
  @view_template
end

Instance Method Details

#allow_layout?Boolean

Can be overridden by subclasses to prevent layouts being used with the render.

Returns:

  • (Boolean)


32
33
34
# File 'lib/mack/rendering/type/base.rb', line 32

def allow_layout?
  true
end

#capture(*args, &block) ⇒ Object

See Mack::Rendering::ViewTemplate content_for for more details.



45
46
47
# File 'lib/mack/rendering/type/base.rb', line 45

def capture(*args, &block)
  @engine.capture(*args, &block)
end

#controller_view_pathObject

Returns the directory path for the current controller.



50
51
52
53
54
# File 'lib/mack/rendering/type/base.rb', line 50

def controller_view_path
  ivar_cache do
    Mack::Paths.views(self.controller.controller_name)
  end
end

#find_engine(e) ⇒ Object



36
37
38
# File 'lib/mack/rendering/type/base.rb', line 36

def find_engine(e)
  eval("Mack::Rendering::Engine::#{e.to_s.camelcase}")
end

#find_file(*path) ⇒ Object

If a file is found on disk it will be yielded up.

Example:

find_file("path", "to", "my", "file") do |f|
  puts File.open(f).read
end


24
25
26
27
28
29
# File 'lib/mack/rendering/type/base.rb', line 24

def find_file(*path)
  f = File.join(path)
  if File.exists?(f)
    yield f
  end
end