module PropertyList
Constants
- VERSION
Public Class Methods
Util method for extracting data from smime/mobileprovision envelope. Example:
data = File.binread 'foo.mobileprovision' plist = PropertyList.load PropertyList.data_from_smime data
# File lib/property-list.rb, line 43 def self.data_from_smime data require 'openssl' asn1 = OpenSSL::ASN1.decode data asn1.value[1].value[0].value[2].value[1].value.first.value end
Generate ASCII (Plain) plist.
Options:
-
`indent_unit:` the indent unit, default value is `“t”`, set to `''` if you don't need indent.
-
`initial_indent:` initial indent space, default is `''`, the indentation per line equals to `initial_indent + indent * current_indent_level`.
-
`wrap:` wrap the top level output with `{…}` when obj is a Hash, default is `true`.
-
`encoding_comment:` add encoding comment `// !$UTF8$!` on top of file, default is `false`.
-
`sort_keys:` sort dict keys, default is `true`.
-
`gnu_extension` whether allow GNUStep extensions for ASCII plist to support serializing more types, default is `true`.
# File lib/property-list/ascii_generator.rb, line 13 def self.dump_ascii obj, indent_unit: "\t", initial_indent: '', wrap: true, encoding_comment: false, sort_keys: true, gnu_extension: true generator = AsciiGenerator.new indent_unit: indent_unit, initial_indent: initial_indent, sort_keys: sort_keys, gnu_extension: gnu_extension generator.output << "// !$*UTF8*$!\n" if encoding_comment generator.generate obj, wrap generator.output << "\n" if wrap and obj.is_a?(Hash) generator.output.join end
Generate binary plist, the version is auto detected
# File lib/property-list/binary_generator.rb, line 5 def self.dump_binary obj, options=nil generator = BinaryGenerator.new options generator.generate obj binding.pry if $test generator.output.join end
Generate ASCII (Plain) plist.
Options:
-
`segment:` whether output an XML segment (not wrapped with `<?xml>, <DOCTYPE>, <plist>` tags), default is `false`.
-
`xml_version:` you can also specify `“1.1”` for www.w3.org/TR/xml11/, default is `“1.0”`, no effect if `:segment` is set to `true`.
-
`gnu_dtd:` use GNUStep DTD instead (which is a bit different in string escaping), default is `false`.
-
`indent_unit:` the indent unit, default value is `“t”`, set to or `''` if you don't need indent.
-
`initial_indent:` initial indent space, default is `''`, the indentation per line equals to `initial_indent + indent * current_indent_level`.
-
`base64_width:` the width of characters per line when serializing data with Base64, default value is `68`, must be multiple of `4`.
-
`base64_indent:` whether indent the Base64 encoded data, you can use `false` for compatibility to generate same output for other frameworks, default value is `true`.
# File lib/property-list/xml_generator.rb, line 15 def self.dump_xml obj, segment: false, xml_version: '1.0', gnu_dtd: false, base64_width: 68, base64_indent: true, indent_unit: "\t", initial_indent: '' if !base64_width.is_a?(Integer) or base64_width <= 0 or base64_width % 4 != 0 raise ArgumentError, "option :base64_width must be a positive integer and a multiple of 4" end generator = XmlGenerator.new gnu_dtd: gnu_dtd, base64_width: base64_width, base64_indent: base64_indent, indent_unit: indent_unit, initial_indent: initial_indent if segment generator.generate obj else generator.output << %|<?xml version="#{xml_version}" encoding="UTF-8"?>\n| if gnu_dtd generator.output << %|<!DOCTYPE plist PUBLIC "-//GNUstep//DTD plist 0.9//EN" "http://www.gnustep.org/plist-0_9.xml">\n| generator.output << %|<plist>\n| else generator.output << %|<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">\n| generator.output << %|<plist version="1.0">\n| end generator.generate obj generator.output << %|</plist>\n| end generator.output.join end
Load plist (binary or xml or ascii) into a ruby object.
Auto detects format.
# File lib/property-list.rb, line 28 def self.load data case data.byteslice(0, 8) when /\Abplist\d\d/n load_binary data.force_encoding('binary') when /\A<\?xml\ /n load_xml data.force_encoding('utf-8') else load_ascii data.force_encoding('utf-8') end end
Parse ASCII plist into a Ruby object
# File lib/property-list/ascii_parser.rb, line 3 def self.load_ascii text AsciiParser.new(text).parse end
Parse binary plist into a Ruby object
# File lib/property-list/binary_parser.rb, line 3 def self.load_binary data BinaryParser.new(data).parse end
Load plist from file
Auto detects format
# File lib/property-list.rb, line 21 def self.load_file file_name load File.binread file_name end
Parse XML plist into a Ruby object
# File lib/property-list/xml_parser.rb, line 3 def self.load_xml xml XmlParser.new(xml).parse end