Sha256: c4f701d84ecc2656e44ad6be53ad3274b2d83437c3382a8b173054fc3701335f

Contents?: true

Size: 1.63 KB

Versions: 5

Compression:

Stored size: 1.63 KB

Contents

module Mack
  module Rendering # :nodoc:
    module Type # :nodoc:
      # Mack::Rendering::Type objects need to extend this class.
      # 
      # The method 'render' needs to be implemented as in all subclasses.
      class Base
        
        # Returns the Mack::Rendering::ViewTemplate object associated with this render.
        attr_reader :view_template
        
        def initialize(view_template)
          @view_template = view_template
        end
        
        needs_method :render
        
        # 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
        def find_file(*path)
          f = File.join(path)
          if File.exists?(f)
            yield f
          end
        end
        
        # Can be overridden by subclasses to prevent layouts being used with the render.
        def allow_layout?
          true
        end
        
        def find_engine(e)
          eval("Mack::Rendering::Engine::#{e.to_s.camelcase}")
        end
        
        def method_missing(sym, *args)
          self.view_template.send(sym, *args)
        end
        
        # See Mack::Rendering::ViewTemplate content_for for more details.
        def capture(*args, &block)
          @engine.capture(*args, &block)
        end
        
        # Returns the directory path for the current controller.
        def controller_view_path
          ivar_cache do
            File.join(Mack::Configuration.views_directory, self.controller.controller_name)
          end
        end
        
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
mack-0.5.5.1 lib/rendering/type/base.rb
mack-0.5.5.2 lib/rendering/type/base.rb
mack-0.5.5.4 lib/rendering/type/base.rb
mack-0.5.5.3 lib/rendering/type/base.rb
mack-0.5.5 lib/rendering/type/base.rb