Sha256: ab209e38850add211d5e8bdc7acbe6258b65ef62b28f6a763ba10b2cdd5e31a6

Contents?: true

Size: 905 Bytes

Versions: 6

Compression:

Stored size: 905 Bytes

Contents

require 'alephant/views/base'

module Alephant
  module Views
    class Preview < Mustache
      attr_accessor :regions

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

      def 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

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
alephant-0.0.9.2-java lib/alephant/views/preview.rb
alephant-0.0.9.1-java lib/alephant/views/preview.rb
alephant-0.0.9-java lib/alephant/views/preview.rb
alephant-0.0.8.2-java lib/alephant/views/preview.rb
alephant-0.0.8.1-java lib/alephant/views/preview.rb
alephant-0.0.8-java lib/alephant/views/preview.rb