Sha256: e7f65d0bf129576994fabb4044fd6fd19103870254d6588267d37bceda6bc55d

Contents?: true

Size: 1.55 KB

Versions: 9

Compression:

Stored size: 1.55 KB

Contents

module Spontaneous::Output::Template
  class PublishEngine
    # Should be initialized with the Site template roots
    def initialize(template_roots, cache = Spontaneous::Output.cache_templates?)
      @engine = template_engine_class(cache).new(template_roots, syntax)
      self.write_compiled_scripts = Spontaneous::Output.write_compiled_scripts?
    end

    def write_compiled_scripts=(state)
      @engine.write_compiled_scripts = state if @engine.respond_to?(:write_compiled_scripts=)
    end

    def syntax
      PublishSyntax
    end

    def roots
      @engine.roots
    end

    def render(content, context, format = "html")
      render_template(template_path(content, format), context, format)
    end

    def render_template(template_path, context, format = "html")
      @engine.render(template_path, context, format)
    end

    def render_string(template_string, context, format = "html")
      @engine.render_string(template_string, context, format)
    end

    def template_path(content, format)
      content.template(format)
    end

    def template_exists?(root, template, format)
      @engine.template_exists?(root, template, format)
    end

    def template_engine_class(cache)
      ::Spontaneous::Output.template_engine_class(cache)
    end
  end

  # Should be initialized with the path to the current rendered revision
  class RequestEngine < PublishEngine
    def syntax
      RequestSyntax
    end

    def template_path(content, format)
      path = content.path.gsub(%r{^/}, "")
      path = "index" if path.empty?
      path
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
spontaneous-0.2.0.beta4 lib/spontaneous/output/template/engine.rb
spontaneous-0.2.0.beta3 lib/spontaneous/output/template/engine.rb
spontaneous-0.2.0.beta2 lib/spontaneous/output/template/engine.rb
spontaneous-0.2.0.beta1 lib/spontaneous/output/template/engine.rb
spontaneous-0.2.0.alpha7 lib/spontaneous/output/template/engine.rb
spontaneous-0.2.0.alpha6 lib/spontaneous/output/template/engine.rb
spontaneous-0.2.0.alpha5 lib/spontaneous/output/template/engine.rb
spontaneous-0.2.0.alpha4 lib/spontaneous/output/template/engine.rb
spontaneous-0.2.0.alpha3 lib/spontaneous/output/template/engine.rb