vito / chyrp

The ultra-lightweight ultra-flexible blogging engine with a fetish for birds and misspellings.

chyrp / triggers.rb
100755 35 lines (35 sloc) 0.902 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
require "find"
excludes = [".svn"]
exclude_files = []
triggers = []
output = ""
msgstr = ""
basedir = ARGV[0] || "."
Find.find(basedir) do |path|
  if FileTest.directory?(path)
    if excludes.include?(File.basename(path))
      Find.prune
    else
      next
    end
  else
    filename = File.basename(path)
    if filename =~ /\.php/ and not exclude_files.include?(filename)
      cleaned = path.sub("./", "")
      contents = File.read(path)
      if contents =~ /(\$trigger|Twigger::current\(\))->call\("[^"]+"(.*?)\)/
        counter = 1
        File.open(path, "r") do |infile|
          while (line = infile.gets)
            line.gsub(/(\$trigger|Twigger::current\(\))->call\("([^"]+)"(, (.+))?\)/) do
              args = $4 || ""
              output << $2 + ":\n\t" + args + "\n"
              triggers << $2
            end
          end
        end
      end
    end
  end
end
puts output