Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for regexes containing angle brackets #1

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 19 additions & 17 deletions lib/yaml_to_tmlanguage_translator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@

class YamlToTmLanguageTranslator
def translate(yml, indent = -1)
xml = <<-EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
#{ load_and_dump(yml) }
</plist>
EOF
xml = REXML::Document.new(
<<~EOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
</plist>
EOF
)
xml.root << load_and_dump(yml)
output = ''
REXML::Document.new(xml).write output, indent
xml.write output, indent
output
end

Expand All @@ -25,25 +27,25 @@ def load_and_dump(yml)

def dump(obj)
if obj.class == Hash
output = "<dict>"
output = REXML::Element.new "dict"
obj.each do |key, value|
output << "<key>#{ key }</key>"
key_el = REXML::Element.new "key"
key_el.text = key
output << key_el
output << dump(value)
end
output << "</dict>"
elsif obj.class == String
output = "<string>#{ obj }</string>"
output = REXML::Element.new "string"
output.add_text obj
elsif obj.class == Array
output = "<array>"
output = REXML::Element.new "array"

obj.each do |value|
output << dump(value)
end

output << "</array>"
end

output || ''
output || REXML::Text.new("")
end

end
end