Class: Pod::Generator::InfoPlistFile

Inherits:
Object
  • Object
show all
Defined in:
lib/cocoapods/generator/info_plist_file.rb

Overview

Generates Info.plist files. A Info.plist file is generated for each Pod and for each Pod target definition, that requires to be built as framework. It states public attributes.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version, platform, bundle_package_type = :fmwk, additional_entries = {}) ⇒ InfoPlistFile

Initialize a new instance

Parameters:

  • version (String)

    @see #version

  • platform (Platform)

    @see #platform

  • bundle_package_type (Symbol) (defaults to: :fmwk)

    @see #bundle_package_type

  • additional_entries (Hash) (defaults to: {})

    @see #additional_entries


32
33
34
35
36
37
# File 'lib/cocoapods/generator/info_plist_file.rb', line 32

def initialize(version, platform, bundle_package_type = :fmwk, additional_entries = {})
  @version = version
  @platform = platform
  @bundle_package_type = bundle_package_type
  @additional_entries = additional_entries
end

Instance Attribute Details

#additional_entriesHash (readonly)

Returns any additional entries to include in this Info.plist.

Returns:

  • (Hash)

    any additional entries to include in this Info.plist


23
24
25
# File 'lib/cocoapods/generator/info_plist_file.rb', line 23

def additional_entries
  @additional_entries
end

#bundle_package_typeSymbol (readonly)

Returns the CFBundlePackageType of the target this Info.plist file is for.

Returns:

  • (Symbol)

    the CFBundlePackageType of the target this Info.plist file is for.


19
20
21
# File 'lib/cocoapods/generator/info_plist_file.rb', line 19

def bundle_package_type
  @bundle_package_type
end

#platformPlatform (readonly)

Returns The platform to use for when generating this Info.plist file.

Returns:

  • (Platform)

    The platform to use for when generating this Info.plist file.


14
15
16
# File 'lib/cocoapods/generator/info_plist_file.rb', line 14

def platform
  @platform
end

#versionString (readonly)

Returns version The version to use for when generating this Info.plist file.

Returns:

  • (String)

    version The version to use for when generating this Info.plist file.


10
11
12
# File 'lib/cocoapods/generator/info_plist_file.rb', line 10

def version
  @version
end

Instance Method Details


71
72
73
74
75
# File 'lib/cocoapods/generator/info_plist_file.rb', line 71

def footer
  <<-PLIST
</plist>
  PLIST
end

#generateString

Generates the contents of the Info.plist

Returns:

  • (String)

57
58
59
# File 'lib/cocoapods/generator/info_plist_file.rb', line 57

def generate
  to_plist(info)
end

#headerObject (private)


63
64
65
66
67
68
69
# File 'lib/cocoapods/generator/info_plist_file.rb', line 63

def header
  <<-PLIST
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
  PLIST
end

#infoObject (private)


105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/cocoapods/generator/info_plist_file.rb', line 105

def info
  info = {
    'CFBundleIdentifier' => '${PRODUCT_BUNDLE_IDENTIFIER}',
    'CFBundleInfoDictionaryVersion' => '6.0',
    'CFBundleName' => '${PRODUCT_NAME}',
    'CFBundlePackageType' => bundle_package_type.to_s.upcase,
    'CFBundleShortVersionString' => version,
    'CFBundleSignature' => '????',
    'CFBundleVersion' => '${CURRENT_PROJECT_VERSION}',
    'NSPrincipalClass' => '',
    'CFBundleDevelopmentRegion' => 'en',
  }

  info['CFBundleExecutable'] = '${EXECUTABLE_NAME}' if bundle_package_type != :bndl
  info['CFBundleVersion'] = '1' if bundle_package_type == :bndl
  info['NSPrincipalClass'] = 'NSApplication' if bundle_package_type == :appl && platform == :osx

  info.merge!(additional_entries)

  info
end

#save_as(path) ⇒ void

This method returns an undefined value.

Generates and saves the Info.plist to the given path.

Parameters:

  • path (Pathname)

    the path where the prefix header should be stored.


46
47
48
49
50
51
# File 'lib/cocoapods/generator/info_plist_file.rb', line 46

def save_as(path)
  contents = generate
  path.open('w') do |f|
    f.write(contents)
  end
end

#serialize(value, output, indentation = 0) ⇒ Object (private)


81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# File 'lib/cocoapods/generator/info_plist_file.rb', line 81

def serialize(value, output, indentation = 0)
  indent = ' ' * indentation
  case value
  when Array
    output << indent << "<array>\n"
    value.each { |v| serialize(v, output, indentation + 2) }
    output << indent << "</array>\n"
  when Hash
    output << indent << "<dict>\n"
    value.to_a.sort_by(&:first).each do |key, v|
      output << indent << '  ' << "<key>#{key}</key>\n"
      serialize(v, output, indentation + 2)
    end
    output << indent << "</dict>\n"
  when String
    output << indent << "<string>#{value}</string>\n"
  when true
    output << indent << "<true/>\n"
  when false
    output << indent << "<false/>\n"
  end
  output
end

#to_plist(root) ⇒ Object (private)


77
78
79
# File 'lib/cocoapods/generator/info_plist_file.rb', line 77

def to_plist(root)
  serialize(root, header) << footer
end