<commit_before>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<commit_msg>allow static host to be set by environment variable<commit_after>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
        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
{'fraction_non_alphanumeric': 0.08174097664543524, 'fraction_numerical': 0.008492569002123142, 'mean_word_length': 2.0256821829855536, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7531451', 'n_tokens_mistral': 576, 'n_tokens_neox': 541, 'n_words': 126}