Skip to content

Instantly share code, notes, and snippets.

Created February 18, 2013 19:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/4980029 to your computer and use it in GitHub Desktop.
Save anonymous/4980029 to your computer and use it in GitHub Desktop.
Detect variables used in Mustache templates.
#!/usr/bin/env ruby
fn = ARGV[0]
if !fn
puts "Usage: #{$0} file.mustache"
puts
exit
end
fields = []
File.read(fn).split("\n").each do |l|
if l =~ /{{{(.+?)}}}/ || l =~ /{{(.+?)}}/
next if $1[0,1] == '/'
field = $1
field = field[1..-1] if field[0,1] == '#'
field = field[1..-1] if field[0,1] == '^'
fields << field
end
end
puts fields.sort.uniq.join("\n")
puts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment