Module: Padrino::Rendering::ClassMethods

### Home Classes Methods

### In Files

- lib/padrino/rendering.rb

### Methods

- #cache_layout_path
- #cache_template_file!
- #cache_template_path
- #fetch_layout_path
- #fetch_template_file
- #layout

### Files

- README.rdoc

### Class/Module Index

Quicksearch

- Padrino
- Padrino::Helpers
- Padrino::Helpers::AssetTagHelpers
- Padrino::Helpers::FormBuilder
- Padrino::Helpers::FormBuilder::AbstractFormBuilder
- Padrino::Helpers::FormBuilder::DeprecatedBuilderMethods
- Padrino::Helpers::FormBuilder::StandardFormBuilder
- Padrino::Helpers::FormHelpers
- Padrino::Helpers::FormHelpers::Errors
- Padrino::Helpers::FormHelpers::Options
- Padrino::Helpers::FormHelpers::Security
- Padrino::Helpers::NumberHelpers
- Padrino::Helpers::OutputHelpers
- Padrino::Helpers::OutputHelpers::AbstractHandler
- Padrino::Helpers::OutputHelpers::ErbHandler
- Padrino::Helpers::OutputHelpers::HamlHandler
- Padrino::Helpers::OutputHelpers::SinatraCurrentEngine
- Padrino::Helpers::OutputHelpers::SlimHandler
- Padrino::Helpers::RenderHelpers
- Padrino::Helpers::TagHelpers
- Padrino::Helpers::TranslationHelpers
- Padrino::Rendering
- Padrino::Rendering::ClassMethods
- Padrino::Rendering::ErubisTemplate
- Padrino::Rendering::HamlTemplate
- Padrino::Rendering::InstanceMethods
- Padrino::Rendering::SafeBufferEnhancer
- Padrino::Rendering::SafeEruby
- Padrino::Rendering::SafeTemplate
- Padrino::Rendering::SlimTemplate
- Padrino::Rendering::TemplateNotFound
- Haml
- Haml::Helpers
- Haml::Util

No matching classes.

# Padrino::Rendering::ClassMethods

Class methods responsible for rendering templates as part of a request.

### Public Instance Methods

cache_layout_path(name) click to toggle source

    # File lib/padrino/rendering.rb, line 139
    def cache_layout_path(name)
      @_cached_layout ||= {}
      if !reload_templates? && path = @_cached_layout[name]
        path
      else
        @_cached_layout[name] = yield(name)
      end
    end

cache_template_file!(template_file, render_options) click to toggle source

Caches the template file for the given rendering options. Deprecated since 0.12.1

@param [String] template_file

    The path of the template file.

@param [Array<template_path, content_type, locale>] render_options

    # File lib/padrino/rendering.rb, line 115
    def cache_template_file!(template_file, render_options)
      logger.warn "##{__method__} is deprecated"
      (@_cached_templates ||= {})[render_options] = template_file || []
    end

cache_template_path(options) click to toggle source

    # File lib/padrino/rendering.rb, line 148
    def cache_template_path(options)
      began_at = Time.now
      @_cached_templates ||= {}
      logging = defined?(settings) && settings.logging? && defined?(logger)
      if !reload_templates? && path = @_cached_templates[options]
        logger.debug :cached, began_at, path[0] if logging
      else
        path = @_cached_templates[options] = yield(name)
        logger.debug :template, began_at, path[0] if path && logging
      end
      path
    end

fetch_layout_path(given_layout, layouts_path=views) click to toggle source

Returns the cached layout path.

@param [String, nil] given_layout

    The requested layout.

@param [String, nil] layouts_path

    The directory where the layouts are located. Defaults to #views.

    # File lib/padrino/rendering.rb, line 128
    def fetch_layout_path(given_layout, layouts_path=views)
      layout_name = (given_layout || @layout || :application).to_s
      cache_layout_path(layout_name) do
        if Pathname.new(layout_name).absolute? && Dir["#{layout_name}.*"].any? || Dir["#{layouts_path}/#{layout_name}.*"].any?
          layout_name
        else
          File.join('layouts', layout_name)
        end
      end
    end

fetch_template_file(render_options) click to toggle source

Returns the cached template file to render for a given url, content_type and locale. Deprecated since 0.12.1

@param [Array<template_path, content_type, locale>] render_options

    # File lib/padrino/rendering.rb, line 102
    def fetch_template_file(render_options)
      logger.warn "##{__method__} is deprecated"
      (@_cached_templates ||= {})[render_options]
    end

layout(name=:layout, &block) click to toggle source

Use layout like rails does or if a block given then like sinatra. If used without a block, sets the current layout for the route.

By default, searches in your:

`app`/`views`/`layouts`/`application`.(`haml`|`erb`|`xxx`) `app`/`views`/`layout_name`.(`haml`|`erb`|`xxx`)

If you define `layout` :`custom` then searches for your layouts in `app`/`views`/`layouts`/`custom`.(`haml`|`erb`|`xxx`) `app`/`views`/`custom`.(`haml`|`erb`|`xxx`)

@param [Symbol] name (:layout)

    The layout to use.

@yield []

    # File lib/padrino/rendering.rb, line 91
    def layout(name=:layout, &block)
      return super(name, &block) if block_given?
      @layout = name
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.