<commit_before>module Paloma
  #
  # Setup:
  #   rails g paloma:setup
  #     - Generates the following:
  #         - 'paloma' folder under app/assets/javascripts/paloma
  #         - index.js and paloma.js under the 'paloma' folder
  #
  #
  # Usage: 
  #   rails g paloma:add <controller_name>
  #     - Generates the following:
  #         - a folder under app/assets/javascripts/paloma named as <controller_name>
  #         - callbacks.js inside the folder just made
  #     - Updates index.js under the 'paloma' folder
  #         - adds a line in order to require the callbacks to be made under the recently made folder
  #
  #
  #   rails g paloma:add <controller_name>/<action_name>
  #     - Generates the following:
  #         - <action_name>.js file inside the <controller_name> folder
  #
  #
  # Generated Files:
  #  index.js
  #    - contains code for requiring all callbacks of all folders
  #    - always updated when new folders and callback.js files are created
  #
  #  paloma.js
  #    - declaration of namespace used in all callbacks
  #
  #  <controller_name>/callbacks.js
  #    - contains code for requiring all callbacks under the same folder <controller_name> 
  #
  #  <controller_name>/<action_name>.js
  #    - actual code to be executed when callback is called
  #
    
  PARENT  = 'app/assets/javascripts/paloma/'
  INDEX = PARENT + 'index.js'
  PALOMA = PARENT + 'paloma.js'
  
  class SetupGenerator < ::Rails::Generators::Base
    source_root File.expand_path('../templates', __FILE__)
    
    def setup_paloma
      #index.js on callbacks folder
      has_index = File.exists? INDEX
      copy_file 'index.js', INDEX unless has_index  
      
      has_paloma = File.exists? PALOMA
      copy_file 'paloma.js', PALOMA unless has_paloma
    end
    
  end
  
  
  class AddGenerator < ::Rails::Generators::NamedBase
    source_root File.expand_path('../templates', __FILE__)
    
    def create_callback_file
      file = file_path.split('/')
      controller = file[0]
      action = file[1]
      
      callbacks = PARENT + "#{controller}/_callbacks.js"
      templates = "#{Paloma.root}/lib/paloma/templates/"
      local = PARENT + "#{controller}/_local.js"
      action_file = PARENT + "#{controller}/#{action}.js"
      
      #_callbacks.js per folder(controller)
      has_callbacks = File.exists? callbacks
      unless has_callbacks
        content = File.read(templates + '_callbacks.js').gsub('controller', "#{controller}")
        File.open(callbacks, 'w'){ |f| f.write(content) }
        File.open(INDEX, 'a+'){|f| f << "\n//= require ./" + controller + '/_callbacks' }
      end
      
      #_local.js per folder(controller)
      has_local =File.exists? local
      unless has_local
        content = File.read(templates + '_local.js').gsub('controller', "#{controller}")
        File.open(local, 'w'){ |f| f.write(content) }
      end
      
      #<action>.js on folder(controller) - code for callback<commit_msg>Fix generators - mkdir<commit_after>module Paloma
  #
  # Setup:
  #   rails g paloma:setup
  #     - Generates the following:
  #         - 'paloma' folder under app/assets/javascripts/paloma
  #         - index.js and paloma.js under the 'paloma' folder
  #
  #
  # Usage: 
  #   rails g paloma:add <controller_name>
  #     - Generates the following:
  #         - a folder under app/assets/javascripts/paloma named as <controller_name>
  #         - callbacks.js inside the folder just made
  #     - Updates index.js under the 'paloma' folder
  #         - adds a line in order to require the callbacks to be made under the recently made folder
  #
  #
  #   rails g paloma:add <controller_name>/<action_name>
  #     - Generates the following:
  #         - <action_name>.js file inside the <controller_name> folder
  #
  #
  # Generated Files:
  #  index.js
  #    - contains code for requiring all callbacks of all folders
  #    - always updated when new folders and callback.js files are created
  #
  #  paloma.js
  #    - declaration of namespace used in all callbacks
  #
  #  <controller_name>/callbacks.js
  #    - contains code for requiring all callbacks under the same folder <controller_name> 
  #
  #  <controller_name>/<action_name>.js
  #    - actual code to be executed when callback is called
  #
    
  PARENT  = 'app/assets/javascripts/paloma/'
  INDEX = PARENT + 'index.js'
  PALOMA = PARENT + 'paloma.js'
  
  class SetupGenerator < ::Rails::Generators::Base
    source_root File.expand_path('../templates', __FILE__)
    
    def setup_paloma
      #index.js on callbacks folder
      has_index = File.exists? INDEX
      copy_file 'index.js', INDEX unless has_index  
      
      has_paloma = File.exists? PALOMA
      copy_file 'paloma.js', PALOMA unless has_paloma
    end
    
  end
  
  
  class AddGenerator < ::Rails::Generators::NamedBase
    source_root File.expand_path('../templates', __FILE__)
    
    def create_callback_file
      file = file_path.split('/')
      controller = file[0]
      action = file[1]
      
      callbacks = PARENT + "#{controller}/_callbacks.js"
      templates = "#{Paloma.root}/lib/paloma/templates/"
      local = PARENT + "#{controller}/_local.js"
      action_file = PARENT + "#{controller}/#{action}.js"
      
      #_callbacks.js per folder(controller)
      has_callbacks = File.exists? callbacks
      unless has_callbacks
        Dir.mkdir(PARENT + "#{controller}")
        content = File.read(templates + '_callbacks.js').gsub('controller', "#{controller}")
        File.open(callbacks, 'w'){ |f| f.write(content) }
        File.open(INDEX, 'a+'){ |f| f << "\n//= require ./" + controller + '/_callbacks' }
      end
      
      #_local.js per folder(controller)
      has_local =File.exists? local
      unless has_local
        content = File.read(templates + '_local.js').gsub('controller', "#{controller}")
        File.open(local, 'w'){ |f| f.write(content) }
      end
      
      #<action>.js on folder(controller) - code for callback
{'fraction_non_alphanumeric': 0.11433333333333333, 'fraction_numerical': 0.0006666666666666666, 'mean_word_length': 2.542502951593861, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 25, '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': '4415533', 'n_tokens_mistral': 1917, 'n_tokens_neox': 1878, 'n_words': 482}