Class: PodBuilder::Licenses
- Inherits:
-
Object
- Object
- PodBuilder::Licenses
- Defined in:
- lib/pod_builder/licenses.rb
Class Method Summary collapse
Class Method Details
.write(licenses, all_buildable_items) ⇒ Object
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 |
# File 'lib/pod_builder/licenses.rb', line 3 def self.write(licenses, all_buildable_items) puts "Writing licenses".yellow license_file_path = PodBuilder::project_path(Configuration.license_filename) + ".plist" current_licenses = [] if File.exist?(license_file_path) plist = CFPropertyList::List.new(:file => license_file_path) dict = CFPropertyList.native_types(plist.value) current_licenses = dict["PreferenceSpecifiers"] if current_licenses.count > 0 licenses_header = current_licenses.shift raise "\n\nUnexpected license found in header\n".red if licenses_header.has_key?("License") end if current_licenses.count > 0 = current_licenses.pop raise "\n\nUnexpected license found in footer\n".red if .has_key?("License") end end if licenses.count > 0 licenses_header = licenses.shift raise "\n\nUnexpected license found in header\n".red if licenses_header.has_key?("License") = licenses.pop raise "\n\nUnexpected license found in footer\n".red if .has_key?("License") lincenses_titles = licenses.map { |x| x["Title"] } current_licenses.select! { |x| !lincenses_titles.include?(x["Title"]) } end licenses += current_licenses # merge with existing license licenses.uniq! { |x| x["Title"] } licenses.sort_by! { |x| x["Title"] } licenses.select! { |x| !Configuration.skip_licenses.include?(x["Title"]) } licenses.select! { |x| all_buildable_items.map(&:root_name).include?(x["Title"]) } # Remove items that are no longer included license_dict = {} license_dict["PreferenceSpecifiers"] = [licenses_header, licenses, ].compact.flatten license_dict["StringsTable"] = "Acknowledgements" license_dict["Title"] = license_dict["StringsTable"] plist = CFPropertyList::List.new plist.value = CFPropertyList.guess(license_dict) plist.save(license_file_path, CFPropertyList::List::FORMAT_BINARY) if licenses.count > 0 write_markdown(license_file_path) end end |
.write_markdown(plist_path) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/pod_builder/licenses.rb', line 55 def self.write_markdown(plist_path) plist = CFPropertyList::List.new(:file => plist_path) dict = CFPropertyList.native_types(plist.value) licenses = dict["PreferenceSpecifiers"] header = licenses.shift markdown = [] markdown += ["# #{header["Title"]}", header["FooterText"], ""] markdown += licenses.map { |x| ["## #{x["Title"]}", x["FooterText"], ""] } markdown.flatten! markdown_path = plist_path.chomp(File.extname(plist_path)) + ".md" File.write(markdown_path, markdown.join("\n")) end |