<commit_before>module Typus

  def self.generator

    logger = Logger.new("#{Rails.root}/log/#{Rails.env}.log")

    # Create app/controllers/admin if doesn't exist.
    admin_controllers_folder = "#{Rails.root}/app/controllers/admin"
    Dir.mkdir(admin_controllers_folder) unless File.directory?(admin_controllers_folder)

    # Get a list of all available app/controllers/admin
    admin_controllers = Dir["#{Rails.root}/vendor/plugins/*/app/controllers/admin/*.rb", "#{admin_controllers_folder}/*.rb"]
    admin_controllers = admin_controllers.map { |i| File.basename(i) }

    # Create app/views/admin if doesn't exist.
    admin_views_folder = "#{Rails.root}/app/views/admin"
    Dir.mkdir(admin_views_folder) unless File.directory?(admin_views_folder)

    # Create test/functional/admin if doesn't exist.
    admin_controller_tests_folder = "#{Rails.root}/test/functional/admin"
    if File.directory?("#{Rails.root}/test")
      Dir.mkdir(admin_controller_tests_folder) unless File.directory?(admin_controller_tests_folder)
    end

    # Get a list of all available functional test for admin.
    admin_controller_tests = Dir["#{Rails.root}/vendor/plugins/*/test/functional/admin/*.rb", "#{admin_controller_tests_folder}/*.rb"]
    admin_controller_tests = admin_controller_tests.map { |i| File.basename(i) }

    # Generate unexisting controllers for resources which are not tied to
    # a model.
    resources.each do |resource|

      controller_filename = "#{resource.underscore}_controller.rb"
      controller_location = "#{admin_controllers_folder}/#{controller_filename}"

      if !admin_controllers.include?(controller_filename)

        content = <<-RAW
# Controller generated by Typus, use it to extend admin functionality.
class Admin::#{resource}Controller < TypusController

  ##
  # This controller was generated because you have defined a resource 
  # on <tt>config/typus/XXXXXX_roles.yml</tt> which is a tableless model.<commit_msg>Updated comments.<commit_after>module Typus

  def self.generator

    logger = Logger.new("#{Rails.root}/log/#{Rails.env}.log")

    # Create app/controllers/admin if doesn't exist.
    admin_controllers_folder = "#{Rails.root}/app/controllers/admin"
    Dir.mkdir(admin_controllers_folder) unless File.directory?(admin_controllers_folder)

    # Get a list of controllers under `app/controllers/admin`.
    admin_controllers = Dir["#{Rails.root}/vendor/plugins/*/app/controllers/admin/*.rb", "#{admin_controllers_folder}/*.rb"]
    admin_controllers = admin_controllers.map { |i| File.basename(i) }

    # Create app/views/admin if doesn't exist.
    admin_views_folder = "#{Rails.root}/app/views/admin"
    Dir.mkdir(admin_views_folder) unless File.directory?(admin_views_folder)

    # Create test/functional/admin if doesn't exist.
    admin_controller_tests_folder = "#{Rails.root}/test/functional/admin"
    if File.directory?("#{Rails.root}/test")
      Dir.mkdir(admin_controller_tests_folder) unless File.directory?(admin_controller_tests_folder)
    end

    # Get a list of functional tests under `test/functional/admin`.
    admin_controller_tests = Dir["#{Rails.root}/vendor/plugins/*/test/functional/admin/*.rb", "#{admin_controller_tests_folder}/*.rb"]
    admin_controller_tests = admin_controller_tests.map { |i| File.basename(i) }

    # Generate controllers for tableless models.
    resources.each do |resource|

      controller_filename = "#{resource.underscore}_controller.rb"
      controller_location = "#{admin_controllers_folder}/#{controller_filename}"

      if !admin_controllers.include?(controller_filename)

        content = <<-RAW
# Controller generated by Typus, use it to extend admin functionality.
class Admin::#{resource}Controller < TypusController

  ##
  # This controller was generated because you have defined a resource 
  # on <tt>config/typus/XXXXXX_roles.yml</tt> which is a tableless model.
{'fraction_non_alphanumeric': 0.12064549180327869, 'fraction_numerical': 0.0, 'mean_word_length': 4.469187675070028, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 7, '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': '1643100', 'n_tokens_mistral': 1197, 'n_tokens_neox': 1157, 'n_words': 237}