<commit_before>require 'rails/generators'
require File.expand_path('../utils', __FILE__)

module Cms
  class InstallGenerator < Rails::Generators::Base
    source_root File.expand_path('../templates', __FILE__)
    include Rails::Generators::Migration
    include Generators::Utils::InstanceMethods
    extend Generators::Utils::ClassMethods

    def install
      locales_string = ask_for('Locales(space-separated list)', 'en uk ru')
      @locales = locales_string.split(" ")
      @use_translations = @locales.length > 1

      @pages = ask_for("Pages(space-separated list)", "home about_us contacts articles").split(" ")
      @form_keys = ask_for("Forms(space-separated list)", "contact_request").split(" ")
      @form_keys = [] if @form_keys.first == "skip"
      @forms = {}
      @form_keys.each do |form|
        @forms[form.underscore.to_sym] = ask_for("Form `#{form}` fields: ", "name email phone comment:text")
      end
      @rails_admin_menu_sections = ask_for("RailsAdmin menu sections(space-separated list) ", "feedbacks home about_us blog news contacts terms_of_use tags users settings pages assets").split(" ")
      @rails_admin_menu_sections_formatted = "[#{@rails_admin_menu_sections.map { |section| ":#{section}" }.join(', ')}]"
      @database_engine = ask_for("Database engine: 1. postgres; 2. sqlite", "1")
      @database_engine = @database_engine == "1" ? "postgres" : "sqlite"
      if @database_engine == "sqlite"
        @database_name = Rails.env.to_s
      else
        @database_name = ""
      end

      @database_name = ask_for("Database name: ", @database_name)


      add_gems
      add_routes
      add_initializers
      add_models
      init_application_rb
      init_application_yml
      init_application_controller
      add_controllers
      add_forms
      add_migrations


      #template 'initializer.erb', 'config/initializers/rails_admin.rb'
    end

    private
    def add_gems
      gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
      gem 'attachable', github: "VoroninNick/attachable"

      gem 'slim-rails', '3.1.1'
      gem "html2slim"
      gem 'bower-rails'
      gem "protected_attributes"

      gem 'rails_admin'
      gem 'rails_admin_nestable'

      gem 'figaro'

      gem 'devise'

      gem 'enumerize'

      gem 'ckeditor'

      gem 'paperclip'
      gem 'paperclip-tinify'

      gem 'pluck_to_hash'

      gem 'yaml_db'

      gem 'quiet_assets'
<commit_msg>disable protected_attributes gem for rails 5+<commit_after>require 'rails/generators'
require File.expand_path('../utils', __FILE__)

module Cms
  class InstallGenerator < Rails::Generators::Base
    source_root File.expand_path('../templates', __FILE__)
    include Rails::Generators::Migration
    include Generators::Utils::InstanceMethods
    extend Generators::Utils::ClassMethods

    def install
      locales_string = ask_for('Locales(space-separated list)', 'en uk ru')
      @locales = locales_string.split(" ")
      @use_translations = @locales.length > 1

      @pages = ask_for("Pages(space-separated list)", "home about_us contacts articles").split(" ")
      @form_keys = ask_for("Forms(space-separated list)", "contact_request").split(" ")
      @form_keys = [] if @form_keys.first == "skip"
      @forms = {}
      @form_keys.each do |form|
        @forms[form.underscore.to_sym] = ask_for("Form `#{form}` fields: ", "name email phone comment:text")
      end
      @rails_admin_menu_sections = ask_for("RailsAdmin menu sections(space-separated list) ", "feedbacks home about_us blog news contacts terms_of_use tags users settings pages assets").split(" ")
      @rails_admin_menu_sections_formatted = "[#{@rails_admin_menu_sections.map { |section| ":#{section}" }.join(', ')}]"
      @database_engine = ask_for("Database engine: 1. postgres; 2. sqlite", "1")
      @database_engine = @database_engine == "1" ? "postgres" : "sqlite"
      if @database_engine == "sqlite"
        @database_name = Rails.env.to_s
      else
        @database_name = ""
      end

      @database_name = ask_for("Database name: ", @database_name)


      add_gems
      add_routes
      add_initializers
      add_models
      init_application_rb
      init_application_yml
      init_application_controller
      add_controllers
      add_forms
      add_migrations


      #template 'initializer.erb', 'config/initializers/rails_admin.rb'
    end

    private
    def add_gems
      gem 'tzinfo-data', platforms: [:mingw, :mswin, :x64_mingw, :jruby]
      gem 'attachable', github: "VoroninNick/attachable"

      gem 'slim-rails', '3.1.1'
      gem "html2slim"
      gem 'bower-rails'
      gem "protected_attributes" if Rails::VERSION::MAJOR < 5

      gem 'rails_admin'
      gem 'rails_admin_nestable'

      gem 'figaro'

      gem 'devise'

      gem 'enumerize'

      gem 'ckeditor'

      gem 'paperclip'
      gem 'paperclip-tinify'

      gem 'pluck_to_hash'

      gem 'yaml_db'

      gem 'quiet_assets'

{'fraction_non_alphanumeric': 0.12065151819827066, 'fraction_numerical': 0.004826060727930827, 'mean_word_length': 3.2081218274111674, 'pattern_counts': {'":': 2, '<': 6, '<?xml version=': 0, '>': 5, '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': '1675077', 'n_tokens_mistral': 1643, 'n_tokens_neox': 1550, 'n_words': 340}