class Tilt::StaticTemplate

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

Public Class Methods

subclass(mime_type: 'text/html', &block) click to toggle source
    # File lib/tilt/template.rb
564 def self.subclass(mime_type: 'text/html', &block)
565   Class.new(self) do
566     self.default_mime_type = mime_type
567 
568     private
569 
570     define_method(:_prepare_output, &block)
571   end
572 end

Public Instance Methods

allows_script?() click to toggle source

Static templates never allow script.

    # File lib/tilt/template.rb
586 def allows_script?
587   false
588 end
compiled_method(locals_keys, scope_class=nil) click to toggle source

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

    # File lib/tilt/template.rb
581 def compiled_method(locals_keys, scope_class=nil)
582   raise NotImplementedError
583 end
render(scope=nil, locals=nil) click to toggle source

Static templates always return the prepared output.

    # File lib/tilt/template.rb
575 def render(scope=nil, locals=nil)
576   @output
577 end

Protected Instance Methods

prepare() click to toggle source
    # File lib/tilt/template.rb
592 def prepare
593   @output = _prepare_output
594 end

Private Instance Methods

set_compiled_method_cache() click to toggle source

Do nothing, since compiled method cache is not used.

    # File lib/tilt/template.rb
599 def set_compiled_method_cache
600 end
set_fixed_locals() click to toggle source

Do nothing, since fixed locals are not used.

    # File lib/tilt/template.rb
603 def set_fixed_locals
604 end