Sha256: ff256b819bc993c77d2df9a0afbfcd80db50a38d57e9fda60a9c15bd5bba5126

Contents?: true

Size: 709 Bytes

Versions: 1

Compression:

Stored size: 709 Bytes

Contents

require 'mustache'

module Juggalo
  class Layout < Mustache
    attr_accessor :regions

    def initialize(template_location)
      @regions={}
      self.template_file = template_location
    end

    def method_missing(name, *args, &block)
      return super unless respond_to? name.to_s
      region @regions[name.to_s]
    end

    def respond_to?(method)
      valid_regions.include? method.to_s
    end

    def region(components)
      components.map { |c| c.render }.join unless components.nil?
    end

    def valid_regions
      self.template.tokens.find_all { |token|
        token.is_a?(Array) && token[0] == :mustache
      }.map{ |token|
        token[2][2][0].to_s
      }
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
juggalo-0.0.1 lib/juggalo/layout.rb