class Tilt::StaticTemplate

  1. lib/tilt/template.rb
Superclass: Template

Static templates are templates that return the same output for every render

Instead of inheriting from the StaticTemplate class, you will use the .subclass method with a block which processes @data and returns the transformed value.

Basic example which transforms the template to uppercase:

UppercaseTemplate = Tilt::StaticTemplate.subclass do
  @data.upcase
end

Methods

Public Class

  1. subclass

Public Instance

  1. allows_script?
  2. compiled_method
  3. render

Protected Instance

  1. prepare

Public Class methods

subclass(mime_type: 'text/html', &block)
[show source]
    # File lib/tilt/template.rb
569 def self.subclass(mime_type: 'text/html', &block)
570   Class.new(self) do
571     self.default_mime_type = mime_type
572 
573     private
574 
575     define_method(:_prepare_output, &block)
576   end
577 end

Public Instance methods

allows_script?()

Static templates never allow script.

[show source]
    # File lib/tilt/template.rb
591 def allows_script?
592   false
593 end
compiled_method(locals_keys, scope_class=nil)

Raise NotImplementedError, since static templates do not support compiled methods.

[show source]
    # File lib/tilt/template.rb
586 def compiled_method(locals_keys, scope_class=nil)
587   raise NotImplementedError
588 end
render(scope=nil, locals=nil)

Static templates always return the prepared output.

[show source]
    # File lib/tilt/template.rb
580 def render(scope=nil, locals=nil)
581   @output
582 end

Protected Instance methods

prepare()
[show source]
    # File lib/tilt/template.rb
597 def prepare
598   @output = _prepare_output
599 end