Entries Tagged as 'Ruby'

Updating tons of git repositories made easy

With git being the awesome version control system that it is, I switched to using git-svn for all our Web-Empowered Church extensions. That way I get the easy branching and merging while still being compatible with Subversion and everyone else who’s using it (and who hasn’t seen the light yet…).

Now I have a directory that contains all our wec_* extensions. With Subversion, I could do a simple “svn up *” and it would update all the working copies inside the subdirectories. Unfortunately, git doesn’t do that.

Ruby to the rescue:

#!/usr/bin/env ruby
def rebase(dir)
  Dir.chdir(dir) do |path|
      puts "Rebasing #{path}...."
      `git svn rebase`
      puts "done!\n\n"
  end
end

if ARGV[0].nil?
  dirs = Dir["*/"]
  dirs.each do |dir|
    rebase(dir)
  end
else
  rebase ARGV[0]
end

Just stuck this into the directory above all the extensions. Now I can rebase all extensions automatically with one little command, or just one by giving an optional argument.

How to update 100 templates…

…the Ruby way. We have a ton of templates for the Web-Empowered Church Starter Package, so you can imagine the work of having to make a change to it that goes beyond simple updates. We decided to replace chc_forum with mm_forum because it’s newer and better maintained, which meant to update all those templates with new styles for the new forum. Not only that, but each added style needs to match the template, so color schemes have to be different depending on the current template.

Us programmers are very lazy, so I decided to write a script that does all that for us instead of wasting hours and hours on brainless work. It’s available on the WEC SVN server. In a nutshell, there are two file to edit: template.css, and config.yaml.

The template.css file contains the new content that will be appended to the existing styles files. It contains placeholders %1-%3 that will be dynamically filled in with the right colors for this template.

The config.yaml file contains the meat of the application. Check out the inline comments for more details, but you basically give it a regular expression to apply to the existing template styles and tell it which capturing group to use as a substitute. You can give as many regular expressions/arguments as you want, but the number has to match the number of markers in the template file.
The second part of the yaml config is a list of paths and files that tell the script which file to append and parse for the substitute styles.

It was fun writing and can be used to append pretty much anything to any file you want, so it may be helpful to you!