<commit_before># **Stasis** is a dynamic framework for static sites.

### Prerequisites

require 'fileutils'
require 'rubygems'

# [Slim][sl] ships with its own [Tilt][ti] integration. If the user has [Slim][sl]
# installed, require it, otherwise don't worry about it.
#
# [sl]: http://slim-lang.com/
# [ti]: https://github.com/rtomayko/tilt

begin
  require 'slim'
rescue Exception => e
end

# Activate the [Tilt][ti] gem.

gem "tilt", "~> 1.3.3"

# Add the project directory to the load paths.

$:.unshift File.dirname(__FILE__)

# Require all Stasis library files.

require 'stasis/dev_mode'
require 'stasis/options'
require 'stasis/plugin'
require 'stasis/server'

require 'stasis/scope'
require 'stasis/scope/action'
require 'stasis/scope/controller'

require 'stasis/plugins/before'
require 'stasis/plugins/helpers'
require 'stasis/plugins/ignore'
require 'stasis/plugins/instead'
require 'stasis/plugins/layout'
require 'stasis/plugins/priority'
require 'stasis/plugins/render'

### Public Interface

class Stasis
  
  # `Action` -- changes with each iteration of the main loop within `Stasis#render`.
  attr_accessor :action

  # `Controller` -- set to the same instance for the lifetime of the `Stasis` instance.
  attr_accessor :controller

  # `String` -- the destination path passed to `Stasis.new`.
  attr_accessor :destination

  # `String` -- changes with each iteration of the main loop within `Stasis#render`.
  attr_accessor :path

  # `Array` -- all paths in the project that Stasis will act upon.
  attr_accessor :paths

  # `Options` -- options passed to `Stasis.new`.
  attr_accessor :options

  # `Array` -- `Plugin` instances.
  attr_accessor :plugins

  # `String` -- the root path passed to `Stasis.new`.
  attr_accessor :root
  
  def initialize(root, *args)
    @options = {}
    @options = args.pop if args.last.is_a?(::Hash)
    
    @root = File.expand_path(root)
    @destination = args[0] || @root + '/public'
    @destination = File.expand_path(@destination, @root)

    load_paths unless options[:development]

    # Create plugin instances.
    @plugins = find_plugins.collect { |klass| klass.new(self) }

    @controller = Controller.new(self)
    load_controllers unless options[:development]
  end

  def load_paths
    # Create an `Array` of paths that Stasis will act upon.
    @paths = Dir["#{@root}/**/*"]

    # Reject paths that are directories or within the destination directory.
    @paths.reject! do |path|
      !File.file?(path) || path[0..@destination.length-1] == @destination
    end

    # Reject paths that are controllers.
    @paths.reject! do |path|
      if File.basename(path) == 'controller.rb'
        true
      else
        false
      end
    end
  end

  def load_controllers
    # Create a controller instance.
    @controller = Controller.new(self)

    # Reload controllers
    Dir["#{@root}/**/controller.rb"].each do |path|
      @controller._add(path)
    end
  end

  def render(*only)
    collect = {}
    render_options = {}

    if only.last.is_a?(::Hash)
      render_options = only.pop
    end

    # Resolve paths given via the `only` parameter.
    only = only.inject([]) do |array, path|
      # If `path` is a regular expression...
      if path.is_a?(::Regexp)
        array << path
      # If `root + path` exists...
      elsif (path = File.expand_path(path, root)) && File.exists?(path)
        array << path
      # If `path` exists...
      elsif File.exists?(path)
        array << path
      end
      array
    end

    if only.empty?<commit_msg>Make sure no files in the destination directory is evaluated as a controller.<commit_after># **Stasis** is a dynamic framework for static sites.

### Prerequisites

require 'fileutils'
require 'rubygems'

# [Slim][sl] ships with its own [Tilt][ti] integration. If the user has [Slim][sl]
# installed, require it, otherwise don't worry about it.
#
# [sl]: http://slim-lang.com/
# [ti]: https://github.com/rtomayko/tilt

begin
  require 'slim'
rescue Exception => e
end

# Activate the [Tilt][ti] gem.

gem "tilt", "~> 1.3.3"

# Add the project directory to the load paths.

$:.unshift File.dirname(__FILE__)

# Require all Stasis library files.

require 'stasis/dev_mode'
require 'stasis/options'
require 'stasis/plugin'
require 'stasis/server'

require 'stasis/scope'
require 'stasis/scope/action'
require 'stasis/scope/controller'

require 'stasis/plugins/before'
require 'stasis/plugins/helpers'
require 'stasis/plugins/ignore'
require 'stasis/plugins/instead'
require 'stasis/plugins/layout'
require 'stasis/plugins/priority'
require 'stasis/plugins/render'

### Public Interface

class Stasis
  
  # `Action` -- changes with each iteration of the main loop within `Stasis#render`.
  attr_accessor :action

  # `Controller` -- set to the same instance for the lifetime of the `Stasis` instance.
  attr_accessor :controller

  # `String` -- the destination path passed to `Stasis.new`.
  attr_accessor :destination

  # `String` -- changes with each iteration of the main loop within `Stasis#render`.
  attr_accessor :path

  # `Array` -- all paths in the project that Stasis will act upon.
  attr_accessor :paths

  # `Options` -- options passed to `Stasis.new`.
  attr_accessor :options

  # `Array` -- `Plugin` instances.
  attr_accessor :plugins

  # `String` -- the root path passed to `Stasis.new`.
  attr_accessor :root
  
  def initialize(root, *args)
    @options = {}
    @options = args.pop if args.last.is_a?(::Hash)
    
    @root = File.expand_path(root)
    @destination = args[0] || @root + '/public'
    @destination = File.expand_path(@destination, @root)

    load_paths unless options[:development]

    # Create plugin instances.
    @plugins = find_plugins.collect { |klass| klass.new(self) }

    @controller = Controller.new(self)
    load_controllers unless options[:development]
  end

  def load_paths
    # Create an `Array` of paths that Stasis will act upon.
    @paths = Dir["#{@root}/**/*"]

    # Reject paths that are directories or within the destination directory.
    @paths.reject! do |path|
      !File.file?(path) || path[0..@destination.length-1] == @destination
    end

    # Reject paths that are controllers.
    @paths.reject! do |path|
      if File.basename(path) == 'controller.rb'
        true
      else
        false
      end
    end
  end

  def load_controllers
    # Create a controller instance.
    @controller = Controller.new(self)

    # Reload controllers
    Dir["#{@root}/**/controller.rb"].each do |path|
      @controller._add(path) unless path[0..@destination.length-1] == @destination
    end
  end

  def render(*only)
    collect = {}
    render_options = {}

    if only.last.is_a?(::Hash)
      render_options = only.pop
    end

    # Resolve paths given via the `only` parameter.
    only = only.inject([]) do |array, path|
      # If `path` is a regular expression...
      if path.is_a?(::Regexp)
        array << path
      # If `root + path` exists...
      elsif (path = File.expand_path(path, root)) && File.exists?(path)
        array << path
      # If `path` exists...
      elsif File.exists?(path)
        array << path
      end
      array
    end

    if only.empty?
{'fraction_non_alphanumeric': 0.1255212677231026, 'fraction_numerical': 0.0019460661662496525, 'mean_word_length': 3.1303099885189436, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 3, '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': '599444', 'n_tokens_mistral': 2300, 'n_tokens_neox': 2259, 'n_words': 682}