Skip to content

Instantly share code, notes, and snippets.

@82times
Last active December 17, 2015 11:09
Show Gist options
  • Save 82times/5600155 to your computer and use it in GitHub Desktop.
Save 82times/5600155 to your computer and use it in GitHub Desktop.
CocoaPods Acknowledgements helper helper Generates output suitable for a non-centered Acknowledgements.plist from Pods-acknowledgements.markdown.
#! /usr/bin/ruby
# This script generates standard output suitable for writing to an
# Acknowledgements.plist file to be included in the Settings.bundle
# of an iOS app. Call it from a post_install hook in your Podfile.
#
# Feel free to improve--this is not the classiest way of doing this.
# Better would be to add this functionality into CocoaPods itself.
#
# It relies on the Pods-acknowledgements.markdown file generated by
# CocoaPods 0.19.1 Make addjustments to that path here if necessary.
FILEPATH="Pods/Pods-acknowledgements.markdown"
def plist_chunk(string, type)
string.strip!
chunk = " <dict>\n"
chunk << " <key>Type</key>\n"
chunk << " <string>PSGroupSpecifier</string>\n"
chunk << " <key>#{type}</key>\n"
chunk << " <string>#{string}</string>\n"
chunk << " </dict>"
return chunk
end
# Title chunks are left-aligned and bold.
def title_chunk(string)
return plist_chunk(string, 'Title')
end
# Footer chunks are centered and not bold.
def footer_chunk(string)
return plist_chunk(string, 'FooterText')
end
preamble = %{
<?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">
<dict>
<key>PreferenceSpecifiers</key>
<array>
}
conclusion = %{
</array>
<key>StringsTable</key>
<string>Acknowledgements</string>
<key>Title</key>
<string>Acknowledgements</string>
</dict>
</plist>
}
file = File.open(FILEPATH, "rb")
contents = file.read
licenses = contents.split(/^##/)
cocoapods_footer = licenses[-1].to_a[-2,2].join
licenses[-1] = licenses[-1].to_a[0..-2].join # The last two lines aren't part of the actual licenses.
# We'll add it as a footer at the bottom.
puts preamble
puts footer_chunk('This application makes use of the following third party libraries:')
licenses[1..-1].each do |license|
paragraphs = license.split("\n\n")
paragraphs.each do |paragraph|
# get rid of line breaks inside paragraphs. Many license files are hard-wrapped at n characters.
paragraph.gsub!(/\s*\n\s*/," ")
chunk = title_chunk(paragraph)
puts chunk
end
# Add some space between licenses. You could use some symbol here, too.
puts footer_chunk('')
end
puts footer_chunk(cocoapods_footer)
puts conclusion
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment