<commit_before>module Nanoc
  class Page

    FILE_TYPES = {
      '.erb'    => :eruby,
      '.rhtml'  => :eruby,
      '.haml'   => :haml,
      '.mab'    => :markaby,
      '.liquid' => :liquid
    }

    BUILTIN_KEYS = [
      :content,
      :custom_path,
      :extension,
      :file,
      :filename,
      :filters,
      :filters_post,
      :filters_pre,
      :haml_options,
      :is_draft,
      :layout,
      :path,
      :skip_output
    ]

    PAGE_DEFAULTS = {
      :custom_path  => nil,
      :filename     => 'index',
      :extension    => 'html',
      :filters      => [],
      :is_draft     => false,
      :layout       => 'default'
    }

    attr_accessor :stage, :is_filtered, :content_filename

    def initialize(hash, path, compiler)
      @compiler   = compiler
      @stage      = nil
      @attributes = hash

      # Set path
      @attributes[:builtin] ||= {}
      @attributes[:builtin][:path] = path
    end

    # Proxy/Liquid support

    def to_proxy(params={})
      PageProxy.new(self, :filter => params[:filter])
    end

    def to_liquid
      nanoc_require 'liquid'
      PageDrop.new(self)
    end

    # Attributes

    def attributes
      @attributes
    end

    def custom_attribute_named(name)
      @attributes[name] || @compiler.default_attributes[name]
    end

    def builtin_attribute_named(name)
      @attributes[:builtin][name] || @attributes[name] || @compiler.default_attributes[name] || PAGE_DEFAULTS[name]
    end

    def has_builtin_attribute_named?(name)
      @attributes[:builtin].has_key?(name) || @attributes.has_key?(name) || @compiler.default_attributes.has_key?(name)
    end

    # Helper functions

    def content
      filter!
      builtin_attribute_named(:content)
    end

    def path=(path)
      @attributes[:builtin][:path] = path
    end

    def skip_output?
      builtin_attribute_named(:skip_output)
    end

    def is_draft?
      builtin_attribute_named(:is_draft)
    end

    def layout
      builtin_attribute_named(:layout)
    end

    def path_on_filesystem
      if builtin_attribute_named(:custom_path).nil?
        @compiler.config[:output_dir] + builtin_attribute_named(:path) +
          builtin_attribute_named(:filename) + '.' + builtin_attribute_named(:extension)
      else
        @compiler.config[:output_dir] + builtin_attribute_named(:custom_path)
      end
    end

    def file
      File.new(@content_filename)
    end

    def find_layout
      if has_builtin_attribute_named?(:layout)
        { :type => :eruby, :content => "<%= @page.content %>" }
      else
        # Find all layouts
        filenames = Dir["layouts/#{builtin_attribute_named(:layout)}.*"]

        # Reject backups
        filenames.reject! { |f| f =~ /~$/ }

        # Make sure there is only one content file
        filenames.ensure_single('layout files', builtin_attribute_named(:layout))
<commit_msg>fixed bug which would make all pages use no layout<commit_after>module Nanoc
  class Page

    FILE_TYPES = {
      '.erb'    => :eruby,
      '.rhtml'  => :eruby,
      '.haml'   => :haml,
      '.mab'    => :markaby,
      '.liquid' => :liquid
    }

    BUILTIN_KEYS = [
      :content,
      :custom_path,
      :extension,
      :file,
      :filename,
      :filters,
      :filters_post,
      :filters_pre,
      :haml_options,
      :is_draft,
      :layout,
      :path,
      :skip_output
    ]

    PAGE_DEFAULTS = {
      :custom_path  => nil,
      :filename     => 'index',
      :extension    => 'html',
      :filters      => [],
      :is_draft     => false,
      :layout       => 'default'
    }

    attr_accessor :stage, :is_filtered, :content_filename

    def initialize(hash, path, compiler)
      @compiler   = compiler
      @stage      = nil
      @attributes = hash

      # Set path
      @attributes[:builtin] ||= {}
      @attributes[:builtin][:path] = path
    end

    # Proxy/Liquid support

    def to_proxy(params={})
      PageProxy.new(self, :filter => params[:filter])
    end

    def to_liquid
      nanoc_require 'liquid'
      PageDrop.new(self)
    end

    # Attributes

    def attributes
      @attributes
    end

    def custom_attribute_named(name)
      @attributes[name] || @compiler.default_attributes[name]
    end

    def builtin_attribute_named(name)
      @attributes[:builtin][name] || @attributes[name] || @compiler.default_attributes[name] || PAGE_DEFAULTS[name]
    end

    def has_builtin_attribute_named?(name)
      @attributes[:builtin].has_key?(name) || @attributes.has_key?(name) || @compiler.default_attributes.has_key?(name)
    end

    # Helper functions

    def content
      filter!
      builtin_attribute_named(:content)
    end

    def path=(path)
      @attributes[:builtin][:path] = path
    end

    def skip_output?
      builtin_attribute_named(:skip_output)
    end

    def is_draft?
      builtin_attribute_named(:is_draft)
    end

    def layout
      builtin_attribute_named(:layout)
    end

    def path_on_filesystem
      if builtin_attribute_named(:custom_path).nil?
        @compiler.config[:output_dir] + builtin_attribute_named(:path) +
          builtin_attribute_named(:filename) + '.' + builtin_attribute_named(:extension)
      else
        @compiler.config[:output_dir] + builtin_attribute_named(:custom_path)
      end
    end

    def file
      File.new(@content_filename)
    end

    def find_layout
      if has_builtin_attribute_named?(:layout) and builtin_attribute_named(:layout) == nil
        { :type => :eruby, :content => "<%= @page.content %>" }
      else
        # Find all layouts
        filenames = Dir["layouts/#{builtin_attribute_named(:layout)}.*"]

        # Reject backups
        filenames.reject! { |f| f =~ /~$/ }

        # Make sure there is only one content file
        filenames.ensure_single('layout files', builtin_attribute_named(:layout))

{'fraction_non_alphanumeric': 0.11855757781935704, 'fraction_numerical': 0.0, 'mean_word_length': 2.4225844004656576, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, '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': '7613524', 'n_tokens_mistral': 1900, 'n_tokens_neox': 1853, 'n_words': 350}