Sha256: 72d966754e57a6df3779550637ba5d82b1517abb6ee9b76e0f8359449207a06d

Contents?: true

Size: 654 Bytes

Versions: 18

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

    alias append= append

    def join
      @buffer.join
    end
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
opal-1.3.2 stdlib/template.rb
opal-1.3.1 stdlib/template.rb
opal-1.3.0 stdlib/template.rb
opal-1.3.0.rc1 stdlib/template.rb
opal-1.3.0.alpha1 stdlib/template.rb
opal-1.2.0 stdlib/template.rb
opal-1.2.0.beta1 stdlib/template.rb
opal-1.1.1 stdlib/template.rb
opal-1.1.1.rc1 stdlib/template.rb
opal-1.1.0 stdlib/template.rb
opal-1.1.0.rc1 stdlib/template.rb
opal-1.0.5 stdlib/template.rb
opal-1.0.4 stdlib/template.rb
opal-1.0.3 stdlib/template.rb
opal-1.0.2 stdlib/template.rb
opal-1.0.1 stdlib/template.rb
opal-1.0.0 stdlib/template.rb
opal-1.0.0.beta1 stdlib/template.rb