class SublimeDSL::TextMate::Snippet::PListReader

TextMate format importer

Public Instance Methods

load() click to toggle source
# File lib/sublime_dsl/textmate/snippet.rb, line 195
def load
  snippet.file_format = :textmate
  p = read_plist(file)
  snippet.tab_trigger = p.delete('tabTrigger')
  snippet.name = p.delete('name')
  snippet.content = p.delete('content')
  snippet.scope = p.delete('scope')
  snippet.key_equivalent = p.delete('keyEquivalent')
  snippet.semantic_class = p.delete('semanticClass')
  snippet.uuid = p.delete('uuid')
  snippet.bundle_uuid = p.delete('bundleUUID')
  p.empty? or warn "unexpected keys in #{file}: #{p.inspect}"
end
read_plist(file) click to toggle source
# File lib/sublime_dsl/textmate/snippet.rb, line 209
def read_plist(file)
  text = File.read(file, encoding: 'utf-8')

  # replace forbidden control characters (given in keyEquivalent)
  h = {}
  text.gsub!(Tools::XML::FORBIDDEN_CHARS_RE) do |c|
    h[c] = Tools::XML::FORBIDDEN_CHARS_MAP[c]
  end
  h.each_pair do |c, rep|
    snippet.warnings << "illegal XML character #{c.inspect} replaced by '#{rep}'"
  end

  PList.load(text)
end