### Home Classes Methods

### In Files

- lib/merb-core/controller/template.rb

### Namespace

- CLASS Merb::Template::Erubis

### Methods

- ::engine_for
- ::inline_template
- ::load_template_io
- ::needs_compilation?
- ::register_extensions
- ::template_extensions
- ::template_for
- ::template_name

### Files

- CHANGELOG
- LICENSE
- README
- TODO

### Class/Module Index

Quicksearch

- Merb
- Merb::AbstractController
- Merb::AcceptType
- Merb::AuthenticationMixin
- Merb::AuthenticationMixin::BasicAuthentication
- Merb::BootLoader
- Merb::BootLoader::AfterAppLoads
- Merb::BootLoader::BackgroundServices
- Merb::BootLoader::BeforeAppLoads
- Merb::BootLoader::BuildFramework
- Merb::BootLoader::ChooseAdapter
- Merb::BootLoader::Cookies
- Merb::BootLoader::Defaults
- Merb::BootLoader::Dependencies
- Merb::BootLoader::DropPidFile
- Merb::BootLoader::LoadClasses
- Merb::BootLoader::Logger
- Merb::BootLoader::MimeTypes
- Merb::BootLoader::MixinSession
- Merb::BootLoader::RackUpApplication
- Merb::BootLoader::ReloadClasses
- Merb::BootLoader::ReloadClasses::TimedExecutor
- Merb::BootLoader::Router
- Merb::BootLoader::SetupSession
- Merb::BootLoader::SetupStubClasses
- Merb::BootLoader::Templates
- Merb::ConditionalGetMixin
- Merb::Config
- Merb::Config::ConfigBlock
- Merb::Const
- Merb::Controller
- Merb::ControllerExceptions
- Merb::ControllerExceptions::Accepted
- Merb::ControllerExceptions::ActionNotFound
- Merb::ControllerExceptions::BadGateway
- Merb::ControllerExceptions::BadRequest
- Merb::ControllerExceptions::Base
- Merb::ControllerExceptions::ClientError
- Merb::ControllerExceptions::Conflict
- Merb::ControllerExceptions::Continue
- Merb::ControllerExceptions::Created
- Merb::ControllerExceptions::ExpectationFailed
- Merb::ControllerExceptions::Forbidden
- Merb::ControllerExceptions::GatewayTimeout
- Merb::ControllerExceptions::Gone
- Merb::ControllerExceptions::HTTPVersionNotSupported
- Merb::ControllerExceptions::Informational
- Merb::ControllerExceptions::InternalServerError
- Merb::ControllerExceptions::LayoutNotFound
- Merb::ControllerExceptions::LengthRequired
- Merb::ControllerExceptions::MethodNotAllowed
- Merb::ControllerExceptions::MovedPermanently
- Merb::ControllerExceptions::MovedTemporarily
- Merb::ControllerExceptions::MultiPartParseError
- Merb::ControllerExceptions::MultipleChoices
- Merb::ControllerExceptions::NoContent
- Merb::ControllerExceptions::NonAuthoritativeInformation
- Merb::ControllerExceptions::NotAcceptable
- Merb::ControllerExceptions::NotFound
- Merb::ControllerExceptions::NotImplemented
- Merb::ControllerExceptions::NotModified
- Merb::ControllerExceptions::OK
- Merb::ControllerExceptions::PartialContent
- Merb::ControllerExceptions::PaymentRequired
- Merb::ControllerExceptions::PreconditionFailed
- Merb::ControllerExceptions::ProxyAuthenticationRequired
- Merb::ControllerExceptions::Redirection
- Merb::ControllerExceptions::RequestEntityTooLarge
- Merb::ControllerExceptions::RequestRangeNotSatisfiable
- Merb::ControllerExceptions::RequestTimeout
- Merb::ControllerExceptions::RequestURITooLarge
- Merb::ControllerExceptions::ResetContent
- Merb::ControllerExceptions::SeeOther
- Merb::ControllerExceptions::ServerError
- Merb::ControllerExceptions::ServiceUnavailable
- Merb::ControllerExceptions::Successful
- Merb::ControllerExceptions::SwitchingProtocols
- Merb::ControllerExceptions::TemplateNotFound
- Merb::ControllerExceptions::TemporaryRedirect
- Merb::ControllerExceptions::Unauthorized
- Merb::ControllerExceptions::UnsupportedMediaType
- Merb::ControllerExceptions::UseProxy
- Merb::ControllerMixin
- Merb::CookieSession
- Merb::CookieSession::CookieOverflow
- Merb::CookieSession::TamperedWithCookie
- Merb::Cookies
- Merb::CookiesMixin
- Merb::CookiesMixin::RequestMixin
- Merb::Counter
- Merb::Dispatcher
- Merb::Dispatcher::DefaultException
- Merb::Dispatcher::DefaultExceptionHelper
- Merb::GlobalHelpers
- Merb::InlineTemplates
- Merb::Logger
- Merb::MemcacheSession
- Merb::MemcacheStore
- Merb::MemorySession
- Merb::MemorySessionStore
- Merb::Parse
- Merb::Plugins
- Merb::Rack
- Merb::Rack::AbstractAdapter
- Merb::Rack::Adapter
- Merb::Rack::Application
- Merb::Rack::ConditionalGet
- Merb::Rack::Console
- Merb::Rack::ContentLength
- Merb::Rack::DeferrableMiddleware
- Merb::Rack::Ebb
- Merb::Rack::EventedMongrel
- Merb::Rack::FastCGI
- Merb::Rack::Handler
- Merb::Rack::Handler::Mongrel
- Merb::Rack::Head
- Merb::Rack::Helpers
- Merb::Rack::Irb
- Merb::Rack::Middleware
- Merb::Rack::Mongrel
- Merb::Rack::PathPrefix
- Merb::Rack::Profiler
- Merb::Rack::Runner
- Merb::Rack::Static
- Merb::Rack::StreamWrapper
- Merb::Rack::SwiftipliedMongrel
- Merb::Rack::Thin
- Merb::Rack::ThinTurbo
- Merb::Rack::Tracer
- Merb::Rack::WEBrick
- Merb::RenderMixin
- Merb::RenderMixin::ClassMethods
- Merb::Request
- Merb::ReservedError
- Merb::Responder
- Merb::ResponderMixin
- Merb::ResponderMixin::ClassMethods
- Merb::ResponderMixin::ContentTypeAlreadySet
- Merb::Router
- Merb::Router::Behavior
- Merb::Router::Behavior::Error
- Merb::Router::Behavior::Proxy
- Merb::Router::CachedProc
- Merb::Router::GenerationError
- Merb::Router::NotCompiledError
- Merb::Router::Resources
- Merb::Router::RouteNotFound
- Merb::Server
- Merb::Session
- Merb::SessionContainer
- Merb::SessionMixin
- Merb::SessionMixin::NoSessionContainer
- Merb::SessionMixin::RequestMixin
- Merb::SessionMixin::RequestMixin::ClassMethods
- Merb::SessionMixin::SessionOverflow
- Merb::SessionStoreContainer
- Merb::System
- Merb::System::PortablePoller
- Merb::Template
- Merb::Template::Erubis
- Merb::Template::Erubis::Mixin
- Merb::Test
- Merb::Test::ControllerHelper
- Merb::Test::Cookie
- Merb::Test::CookieJar
- Merb::Test::ExampleGroup
- Merb::Test::Helpers
- Merb::Test::MakeRequest
- Merb::Test::Matchers
- Merb::Test::MultipartRequestHelper
- Merb::Test::MultipartRequestHelper::FileParam
- Merb::Test::MultipartRequestHelper::Param
- Merb::Test::MultipartRequestHelper::Post
- Merb::Test::RequestHelper
- Merb::Test::RequestHelper::CookieJar
- Merb::Test::RequestHelper::FakeRequest
- Merb::Test::RouteHelper
- Merb::Test::Rspec
- Merb::Test::Rspec::ControllerMatchers
- Merb::Test::Rspec::ControllerMatchers::BeError
- Merb::Test::Rspec::ControllerMatchers::BeRedirect
- Merb::Test::Rspec::ControllerMatchers::Provide
- Merb::Test::Rspec::RouteMatchers
- Merb::Test::Rspec::RouteMatchers::ParameterMatcher
- Merb::Test::Rspec::RouteMatchers::RouteToMatcher
- Merb::Test::ViewHelper
- Merb::Test::WebratHelper
- Merb::Worker
- Erubis
- Erubis::Basic
- Erubis::Basic::Converter
- Erubis::BlockAwareEnhancer
- Erubis::BlockAwareEruby
- Erubis::MEruby
- Spec
- Spec::Matchers
- Spec::Matchers::MatcherDSL
- Spec::Runner
- Spec::Runner::Formatter
- Spec::Runner::Formatter::BaseTextFormatter
- Gem
- Gem::Dependency
- Hpricot
- Hpricot::Elem
- Mongrel
- Mongrel::HttpResponse
- Class
- Exception
- Hash
- Kernel
- MemCache
- Memcached
- Object
- String
- Time

No matching classes.

# Merb::Template

### Constants

EXTENSIONS
METHOD_LIST
MTIMES
SUPPORTED_LOCALS_LIST

### Public Class Methods

engine_for(path) click to toggle source

Finds the engine for a particular path.

#### Parameters

path<String> | The path of the file to find an engine for.

#### Returns

Class | The engine.

:api: private

    # File lib/merb-core/controller/template.rb, line 153
    def engine_for(path)
      path = File.expand_path(path)
      EXTENSIONS[path.match(/\.([^\.]*)$/)[1]]
    end

inline_template(io, locals=[], mod = Merb::InlineTemplates) click to toggle source

Takes a template at a particular path and inlines it into a module and adds it to the METHOD_LIST table to speed lookup later.

#### Parameters

io<path> | An IO that responds to path (File or VirtualFile)
locals> | A list of local names that should be assigned in the template method from the arguments hash. Defaults to [].
mod<Module> | The module to put the compiled method into. Defaults to Merb::InlineTemplates

#### Returns

Symbol | The name of the method that the template was compiled into.

#### Notes

Even though this method supports inlining into any module, the method must be available to instances of AbstractController that will use it.

:api: private

    # File lib/merb-core/controller/template.rb, line 131
    def inline_template(io, locals=[], mod = Merb::InlineTemplates)
      full_file_path = File.expand_path(io.path)
      engine_neutral_path = full_file_path.gsub(/\.[^\.]*$/, "")

      local_list = (SUPPORTED_LOCALS_LIST[engine_neutral_path] |= locals)
      ret = METHOD_LIST[engine_neutral_path] =
        engine_for(full_file_path).compile_template(io,
        template_name(full_file_path), local_list, mod)

      io.close
      ret
    end

load_template_io(path) click to toggle source

For a given path, get an IO object that responds to path.

This is so that plugins can override this if they provide mechanisms for specifying templates that are not just simple files. The plugin is responsible for ensuring that the fake path provided will work with template_for, and thus the RenderMixin in general.

#### Parameters

path<String> | A full path to find a template for. This is the

    path that the RenderMixin assumes it should find the template
    in.

#### Returns

IO#path | An IO object that responds to path (File or VirtualFile).

:api: plugin @overridable

    # File lib/merb-core/controller/template.rb, line 54
    def load_template_io(path)
      file = Dir["#{path}.{#{template_extensions.join(',')}}"].first
      File.open(file, "r") if file
    end

needs_compilation?(path, locals) click to toggle source

Decide if a template needs to be re/compiled.

#### Parameters

path<String> | The full path of the template to check support for.
locals> | The list of locals that need to be supported

#### Returns

Boolean | Whether or not the template for the provided path needs to be recompiled

:api: private

    # File lib/merb-core/controller/template.rb, line 92
    def needs_compilation?(path, locals)
      return true if Merb::Config[:reload_templates] || !METHOD_LIST[path]

      current_locals = SUPPORTED_LOCALS_LIST[path]
      current_locals != locals &&
        !(locals - current_locals).empty?
    end

register_extensions(engine, extensions) click to toggle source

Registers the extensions that will trigger a particular templating engine.

#### Parameters

engine<Class> | The class of the engine that is being registered
extensions> | The list of extensions that will be registered with this templating language

#### Raises

ArgumentError | engine does not have a compile_template method.

#### Returns

nil

#### Example

    Merb::Template.register_extensions(Merb::Template::Erubis, ["erb"])

:api: plugin

    # File lib/merb-core/controller/template.rb, line 177
    def register_extensions(engine, extensions)
      raise ArgumentError, "The class you are registering does not have a compile_template method" unless
        engine.respond_to?(:compile_template)
      extensions.each{|ext| EXTENSIONS[ext] = engine }
      Merb::AbstractController.class_eval         include #{engine}::Mixin
    end

template_extensions() click to toggle source

Get all known template extensions

#### Returns

    Array:: Extension strings.

:api: plugin

    # File lib/merb-core/controller/template.rb, line 106
    def template_extensions
      EXTENSIONS.keys
    end

template_for(path, template_stack = [], locals=[]) click to toggle source

Get the name of the template method for a particular path.

#### Parameters

path<String> | A full path to find a template method for.
template_stack<Array> | The template stack. Not used.
locals> | The names of local variables

#### Returns

<String> | name of the method that inlines the template.

:api: private

    # File lib/merb-core/controller/template.rb, line 71
    def template_for(path, template_stack = [], locals=[])
      path = File.expand_path(path)

      if needs_compilation?(path, locals)
        template_io = load_template_io(path)
        METHOD_LIST[path] = inline_template(template_io, locals) if template_io
      end

      METHOD_LIST[path]
    end

template_name(path) click to toggle source

Get the template's method name from a full path. This replaces non-alphanumeric characters with __ and "." with "_"

Collisions are potentially possible with something like: ~foo.bar and __foo.bar or !foo.bar.

#### Parameters

path<String> | A full path to convert to a valid Ruby method name

#### Returns

String | The template name.

We might want to replace this with something that varies the character replaced based on the non-alphanumeric character to avoid edge-case collisions.

:api: private

    # File lib/merb-core/controller/template.rb, line 30
    def template_name(path)
      path = File.expand_path(path)
      path.gsub(/[^\.a-zA-Z0-9]/, "__").gsub(/\./, "_")
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.