Created
May 29, 2009 12:34
-
-
Save mkhl/119929 to your computer and use it in GitHub Desktop.
Reads a file containing Espresso snippets and turns them into TEA snippets
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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