<commit_before>require 'rails/generators/active_record'

module LiquidCms
  class InstallGenerator < Rails::Generators::Base
    include Rails::Generators::Migration

    desc "Install Liquid CMS files"
    source_root File.expand_path('templates', File.dirname(__FILE__))

    def copy_migration_file
      migration_template 'migration.rb', File.join('db', 'migrate', 'create_liquid_cms_setup')
    end

    def self.next_migration_number(migration_dir)
      ActiveRecord::Generators::Base.next_migration_number migration_dir
    end

    def add_unreleased_gem_dependencies
      append_file 'Gemfile', %q(gem 'vestal_versions', '~> 1.2.1', :git => 'git://github.com/adamcooper/vestal_versions.git')
    end

    def copy_setup_controller
      copy_file 'setup_controller.rb', File.join('app', 'controllers', 'cms', 'setup_controller.rb')
    end

    def create_asset_directories
      %w(assets components).each do |asset_dir|
        empty_directory File.join('public', 'cms', asset_dir)
      end
    end

    def copy_cms_plugins<commit_msg>allow the generator to continue even if the migration file is found<commit_after>require 'rails/generators/active_record'

module LiquidCms
  class InstallGenerator < Rails::Generators::Base
    include Rails::Generators::Migration

    desc "Install Liquid CMS files"
    source_root File.expand_path('templates', File.dirname(__FILE__))

    def copy_migration_file
      name = 'create_liquid_cms_setup'
      if self.class.migration_exists?(File.join('db', 'migrate'), name).blank?
        migration_template 'migration.rb', File.join('db', 'migrate', name) if self.class.migration_exists?(File.join('db', 'migrate'), name).blank?
      else
        puts "Migration '#{name}' already exists... skipping"
      end
    end

    def self.next_migration_number(migration_dir)
      ActiveRecord::Generators::Base.next_migration_number migration_dir
    end

    def add_unreleased_gem_dependencies
      append_file 'Gemfile', %q(gem 'vestal_versions', '~> 1.2.1', :git => 'git://github.com/adamcooper/vestal_versions.git')
    end

    def copy_setup_controller
      copy_file 'setup_controller.rb', File.join('app', 'controllers', 'cms', 'setup_controller.rb')
    end

    def create_asset_directories
      %w(assets components).each do |asset_dir|
        empty_directory File.join('public', 'cms', asset_dir)
      end
    end

    def copy_cms_plugins
{'fraction_non_alphanumeric': 0.11074243052675238, 'fraction_numerical': 0.002488593944421402, 'mean_word_length': 4.153846153846154, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3238', 'n_tokens_mistral': 777, 'n_tokens_neox': 737, 'n_words': 154}