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
441 def self.subclass(mime_type: 'text/html', &block)
442   Class.new(self) do
443     self.default_mime_type = mime_type
444 
445     private
446 
447     define_method(:_prepare_output, &block)
448   end
449 end

Public Instance Methods

allows_script?() click to toggle source

Static templates never allow script.

    # File lib/tilt/template.rb
463 def allows_script?
464   false
465 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
458 def compiled_method(locals_keys, scope_class=nil)
459   raise NotImplementedError
460 end
render(scope=nil, locals=nil) click to toggle source

Static templates always return the prepared output.

    # File lib/tilt/template.rb
452 def render(scope=nil, locals=nil)
453   @output
454 end

Protected Instance Methods

prepare() click to toggle source
    # File lib/tilt/template.rb
469 def prepare
470   @output = _prepare_output
471 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
476 def set_compiled_method_cache
477 end