Sha256: 52f5b650c64243a44e817e18cc356efeec7c822b95028cb8a529e5669f1378e5

Contents?: true

Size: 1006 Bytes

Versions: 22

Compression:

Stored size: 1006 Bytes

Contents

require 'mustache'

module Alephant
  module Preview
    module Template

      class Base < Mustache
        attr_accessor :regions

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

        def static_host
          ENV['STATIC_HOST'] || 'localhost:8000'
        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)
          if components.kind_of?(Array)
            components.join
          else
            components
          end
        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
  end
end

Version data entries

22 entries across 22 versions & 1 rubygems

Version Path
alephant-preview-0.3.9 lib/alephant/preview/template/base.rb
alephant-preview-0.3.8 lib/alephant/preview/template/base.rb
alephant-preview-0.3.7 lib/alephant/preview/template/base.rb
alephant-preview-0.3.6 lib/alephant/preview/template/base.rb
alephant-preview-0.3.5 lib/alephant/preview/template/base.rb
alephant-preview-0.3.4 lib/alephant/preview/template/base.rb
alephant-preview-0.3.3 lib/alephant/preview/template/base.rb
alephant-preview-0.3.2 lib/alephant/preview/template/base.rb
alephant-preview-0.3.1 lib/alephant/preview/template/base.rb
alephant-preview-0.3.0 lib/alephant/preview/template/base.rb
alephant-preview-0.2.0 lib/alephant/preview/template/base.rb
alephant-preview-0.1.2 lib/alephant/preview/template/base.rb
alephant-preview-0.1.1 lib/alephant/preview/template/base.rb
alephant-preview-0.1.0 lib/alephant/preview/template/base.rb
alephant-preview-0.0.7 lib/alephant/preview/template/base.rb
alephant-preview-0.0.6 lib/alephant/preview/template/base.rb
alephant-preview-0.0.5.4 lib/alephant/preview/template/base.rb
alephant-preview-0.0.5.3 lib/alephant/preview/template/base.rb
alephant-preview-0.0.5.2 lib/alephant/preview/template/base.rb
alephant-preview-0.0.5.1 lib/alephant/preview/template/base.rb