Sha256: e929eb7438e570c8fb525ec69acc3ece7eba7e17f8e65e051dc8336c24cc4ec7

Contents?: true

Size: 653 Bytes

Versions: 46

Compression:

Stored size: 653 Bytes

Contents

class Template
  @_cache = {}
  def self.[](name)
    @_cache[name] || @_cache["templates/#{name}"]
  end

  def self.[]=(name, instance)
    @_cache[name] = instance
  end

  def self.paths
    @_cache.keys
  end

  attr_reader :body

  def initialize(name, &body)
    @name, @body = name, body
    Template[name] = self
  end

  def inspect
    "#<Template: '#@name'>"
  end

  def render(ctx = self)
    ctx.instance_exec(OutputBuffer.new, &@body)
  end

  class OutputBuffer
    def initialize
      @buffer = []
    end

    def append(str)
      @buffer << str
    end

    alias append= append

    def join
      @buffer.join
    end
  end
end

Version data entries

46 entries across 46 versions & 3 rubygems

Version Path
opal-0.11.4 stdlib/template.rb
opal-0.11.3 stdlib/template.rb
opal-0.11.2 stdlib/template.rb
opal-0.11.1 stdlib/template.rb
opal-0.11.1.pre stdlib/template.rb
opal-0.10.6 stdlib/template.rb
opal-0.10.6.beta stdlib/template.rb
opal-0.11.0 stdlib/template.rb
opal-0.10.5 stdlib/template.rb
opal-0.10.4 stdlib/template.rb
opal-0.11.0.rc1 stdlib/template.rb
opal-0.10.3 stdlib/template.rb
opal-0.10.2 stdlib/template.rb
opal-0.10.1 stdlib/template.rb
opal-0.10.0 stdlib/template.rb
opal-0.10.0.rc2 stdlib/template.rb
opal-0.9.4 stdlib/template.rb
opal-0.9.3 stdlib/template.rb
opal-0.10.0.rc1 stdlib/template.rb
opal-0.10.0.beta5 stdlib/template.rb