Sha256: 11a6e793c02f8be5018582a14276fd356ede49d2af5762d9a0d92a6be7d09707

Contents?: true

Size: 1.5 KB

Versions: 31

Compression:

Stored size: 1.5 KB

Contents

# @Opulent
module Opulent
  # @OpulentTemplate
  class OpulentTemplate < ::Tilt::Template
    self.default_mime_type = 'text/html'

    # Do whatever preparation is necessary to setup the underlying template
    # engine. Called immediately after template data is loaded. Instance
    # variables set in this method are available when #evaluate is called.
    #
    # Subclasses must provide an implementation of this method.
    #
    def prepare
      @engine = ::Opulent::Opulent.new
      @engine.update_options @options
    end

    # Execute the compiled template and return the result string. Template
    # evaluation is guaranteed to be performed in the scope object with the
    # locals specified and with support for yielding to the block.
    #
    # This method is only used by source generating templates. Subclasses that
    # override render() may not support all features.
    #
    def evaluate(scope, locals, &block)
      locals[:scope] = scope
      @output = @engine.render_file @file, locals, &block
    end


    # A string containing the (Ruby) source code for the template. The
    # default Template#evaluate implementation requires either this
    # method or the #precompiled method be overridden. When defined,
    # the base Template guarantees correct file/line handling, locals
    # support, custom scopes, proper encoding, and support for template
    # compilation.
    def precompiled_template(locals)
      @output
    end
  end

  ::Tilt.register OpulentTemplate, 'op', 'opl', 'opulent'
end

Version data entries

31 entries across 31 versions & 1 rubygems

Version Path
opulent-1.5.5 .libold/opulent/template.rb
opulent-1.5.4 .libold/opulent/template.rb
opulent-1.5.3 .libold/opulent/template.rb
opulent-1.5.2 .libold/opulent/template.rb
opulent-1.5.1 .libold/opulent/template.rb
opulent-1.5.0 .libold/opulent/template.rb
opulent-1.4.8 .libold/opulent/template.rb
opulent-1.4.7 .libold/opulent/template.rb
opulent-1.4.6 .libold/opulent/template.rb
opulent-1.4.5 .libold/opulent/template.rb
opulent-1.4.3 .libold/opulent/template.rb
opulent-1.4.2 .libold/opulent/template.rb
opulent-1.4.1 .libold/opulent/template.rb
opulent-1.4.0 .libold/opulent/template.rb
opulent-1.3.3 .libold/opulent/template.rb
opulent-1.3.2 .libold/opulent/template.rb
opulent-1.3.1 .libold/opulent/template.rb
opulent-1.3.0 .libold/opulent/template.rb
opulent-1.2.1 .libold/opulent/template.rb
opulent-1.2.0 .libold/opulent/template.rb