/
plist.rb
80 lines (68 loc) · 1.95 KB
/
plist.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
module Pod
module Generator
class Plist < Acknowledgements
def self.path_from_basepath(path)
Pathname.new(path.dirname + "#{path.basename}.plist")
end
def save_as(path)
Xcodeproj::PlistHelper.write(plist, path)
end
def plist
{
:Title => plist_title,
:StringsTable => plist_title,
:PreferenceSpecifiers => licenses,
}
end
def plist_title
'Acknowledgements'
end
def licenses
licences_array = [header_hash]
specs.each do |spec|
if (hash = hash_for_spec(spec))
licences_array << hash
end
end
licences_array << footnote_hash
end
def hash_for_spec(spec)
if (license = license_text(spec))
{
:Type => 'PSGroupSpecifier',
:Title => sanitize_encoding(spec.name),
:FooterText => sanitize_encoding(license),
}
end
end
def header_hash
{
:Type => 'PSGroupSpecifier',
:Title => sanitize_encoding(header_title),
:FooterText => sanitize_encoding(header_text),
}
end
def footnote_hash
{
:Type => 'PSGroupSpecifier',
:Title => sanitize_encoding(footnote_title),
:FooterText => sanitize_encoding(footnote_text),
}
end
#-----------------------------------------------------------------------#
private
# !@group Private methods
# Returns the sanitized text with UTF-8 invalid characters eliminated.
#
# @param [String] text
# the text we want to sanitize.
#
# @return [String] The sanitized UTF-8 text.
#
def sanitize_encoding(text)
text.encode('UTF-8', :invalid => :replace, :undef => :replace, :replace => '')
end
#-----------------------------------------------------------------------#
end
end
end