Sha256: ac3bcf5323347eab7db7a8b7712302d4b0d3c1c7f7a9f30300a2c87cbb4564ab

Contents?: true

Size: 654 Bytes

Versions: 22

Compression:

Stored size: 654 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

    def join
      @buffer.join
    end

    alias append= append
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
opal-1.8.3.rc1 stdlib/template.rb
opal-1.8.2 stdlib/template.rb
opal-1.8.1 stdlib/template.rb
opal-1.8.0 stdlib/template.rb
opal-1.8.0.beta1 stdlib/template.rb
opal-1.7.4 stdlib/template.rb
opal-1.8.0.alpha1 stdlib/template.rb
opal-1.7.3 stdlib/template.rb
opal-1.7.2 stdlib/template.rb
opal-1.7.1 stdlib/template.rb
opal-1.7.0 stdlib/template.rb
opal-1.7.0.rc1 stdlib/template.rb
opal-1.6.1 stdlib/template.rb
opal-1.6.0 stdlib/template.rb
opal-1.6.0.rc1 stdlib/template.rb
opal-1.6.0.alpha1 stdlib/template.rb
opal-1.5.1 stdlib/template.rb
opal-1.5.0 stdlib/template.rb
opal-1.5.0.rc1 stdlib/template.rb
opal-1.4.1 stdlib/template.rb