Repta

SYNOPSIS

This command uses rules to do a global search and replace on a target directory. By default, it will look for a "rules" directory where the command is executed. The rule files must be in the rules directory.

Get it now on GitHub

MOTIVATION

A website had certain JavaScript code snippets, such as Google Analytics, that needed to be present only in the production environment and not the development environment. An easy way to achieve this separation was needed, regardless of framework or lack of one. This tool was written to perform a global search and replace of a "tag" across all the project files as one of the steps during the deployment of the website.

EXAMPLE RULE FILE

module YourRuleName
  def filetypes  # any regex
    /.*\.(html|php|erb)$/
  end
  def tag  # any regex
    /<--.*\[WHATEVER TAG\].*-->/
  end
  def replacement  # any string
    <<EOS
This is the replacement text.
Using a 'here document' in this example.
EOS
  end
end