<commit_before># encoding: utf-8

require "yaml"
require "ostruct"
require "fileutils"

require_relative "../simple-templater"
require_relative "main"

# yes? etc
require "cli"

# - Find possible location and take first one
# - If type of the location is full, then copy it's content directory to the desired name
# - If type of the location is diff, then take another location, copy it and then copy files from the first one
# - Run init.rb

# === Hooks ===

# == preprocessing.rb ==
# @foo = "bar"
# <%= %> a <%% %%>

# models/%model%.rb
# model.rb.rbt, posts.html.erb.rbt

# content/foo
# xxx/bar
# => simple-templater project blog --models=post,tag --controllers=posts,tags
module SimpleTemplater
  class Generator
    attr_reader :name, :path
    def initialize(name, path)
      raise GeneratorNotFound unless File.directory?(path)
      @name, @path = name.to_sym, path
    end

    # @param location ... ./blog
    # @param args Array --git-repository --no-github
    def run(location, *args)
      self.load_setup
      SimpleTemplater.logger.info("Creating #{self.config.type} #{self.name} from stubs in #{location}")
      FileUtils.mkdir_p(self.name)
      Dir.chdir(self.name) do
        ARGV.clear.push(*[self.content_dir(location), @args].flatten.compact)
        if File.exist?(hook = File.join(@stubs_dir, "preprocess.rb"))
          load hook
        else
          SimpleTemplater::Templater.create(self.content_dir)
        end
      end
      self.run_postprocess_hook
    end

    def load_setup
      if File.exist?(hook = file("preprocess.rb"))
        load(hook) && SimpleTemplater.logger.inspect("Running preprocess.rb hook")
      end
    end

    def run_postprocess_hook
      Dir.chdir(@name) do
        if File.exist?(hook = File.join(@stubs_dir, "postprocess.rb"))
          load(hook) && SimpleTemplater.logger.inspect("Running postprocess.rb hook")
        end
      end
    end

    def file(path)
      File.join(self.path, path)
    end

    # Metadata options
    # :type: full|diff<commit_msg>Generator#full? and Generator#diff?<commit_after># encoding: utf-8

require "yaml"
require "ostruct"
require "fileutils"

require_relative "../simple-templater"
require_relative "main"

# yes? etc
require "cli"

# - Find possible location and take first one
# - If type of the location is full, then copy it's content directory to the desired name
# - If type of the location is diff, then take another location, copy it and then copy files from the first one
# - Run init.rb

# === Hooks ===

# == preprocessing.rb ==
# @foo = "bar"
# <%= %> a <%% %%>

# models/%model%.rb
# model.rb.rbt, posts.html.erb.rbt

# content/foo
# xxx/bar
# => simple-templater project blog --models=post,tag --controllers=posts,tags
module SimpleTemplater
  class Generator
    attr_reader :name, :path
    def initialize(name, path)
      raise GeneratorNotFound unless File.directory?(path)
      @name, @path = name.to_sym, path
    end

    # @param location ... ./blog
    # @param args Array --git-repository --no-github
    def run(location, *args)
      self.load_setup
      SimpleTemplater.logger.info("Creating #{self.config.type} #{self.name} from stubs in #{location}")
      FileUtils.mkdir_p(self.name)
      Dir.chdir(self.name) do
        ARGV.clear.push(*[self.content_dir(location), @args].flatten.compact)
        if File.exist?(hook = File.join(@stubs_dir, "preprocess.rb"))
          load hook
        else
          SimpleTemplater::Templater.create(self.content_dir)
        end
      end
      self.run_postprocess_hook
    end

    def load_setup
      if File.exist?(hook = file("preprocess.rb"))
        load(hook) && SimpleTemplater.logger.inspect("Running preprocess.rb hook")
      end
    end

    def run_postprocess_hook
      Dir.chdir(@name) do
        if File.exist?(hook = File.join(@stubs_dir, "postprocess.rb"))
          load(hook) && SimpleTemplater.logger.inspect("Running postprocess.rb hook")
        end
      end
    end

    def file(path)
      File.join(self.path, path)
    end

    def full?
      self.config.type.eql?("full")
    end

    def diff?
      self.config.type.eql?("diff")
    end

    # Metadata options
    # :type: full|diff
{'fraction_non_alphanumeric': 0.12511893434823979, 'fraction_numerical': 0.0004757373929590866, 'mean_word_length': 2.8827331486611265, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, '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': '952047', 'n_tokens_mistral': 1362, 'n_tokens_neox': 1339, 'n_words': 345}