Skip to content

Instantly share code, notes, and snippets.

@mkhl
Created May 29, 2009 12:34
Show Gist options
  • Save mkhl/119929 to your computer and use it in GitHub Desktop.
Save mkhl/119929 to your computer and use it in GitHub Desktop.
Reads a file containing Espresso snippets and turns them into TEA snippets
#!/usr/bin/env ruby -wKU -rubygems
require "nokogiri"
def to_action(text)
doc = Nokogiri::XML(text)
doc.xpath('/action-recipes/snippet').each do |node|
txt = node.at('text')
txt.remove
snippet = txt.content
node.fragment('<class>TEAforEspresso</class>').parent = node
Nokogiri::XML::Builder.new do |xml|
xml.setup {
xml.action "insert_snippet"
xml.options {
xml.dict {
xml.key "default"
xml.string {
xml.cdata snippet
}
}
}
}
xml.doc.root.parent = node
end
ctx = node.at('syntax-context')
ctx.remove
ctx.dup.parent = node.at('setup')
node.name = 'action'
end
doc.serialize
end
if __FILE__ == $PROGRAM_NAME
puts to_action(ARGF.read)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment