Commit cdad6fe4 authored by Will Pragnell's avatar Will Pragnell

Added Plist Acknowledgements sub-class

parent 908327e6
...@@ -31,6 +31,7 @@ module Pod ...@@ -31,6 +31,7 @@ module Pod
autoload :CopyResourcesScript, 'cocoapods/generator/copy_resources_script' autoload :CopyResourcesScript, 'cocoapods/generator/copy_resources_script'
autoload :Documentation, 'cocoapods/generator/documentation' autoload :Documentation, 'cocoapods/generator/documentation'
autoload :Acknowledgements, 'cocoapods/generator/acknowledgements' autoload :Acknowledgements, 'cocoapods/generator/acknowledgements'
autoload :Plist, 'cocoapods/generator/acknowledgements/plist'
end end
end end
......
...@@ -2,60 +2,19 @@ module Pod ...@@ -2,60 +2,19 @@ module Pod
module Generator module Generator
class Acknowledgements class Acknowledgements
require "xcodeproj/xcodeproj_ext"
def self.generators
[Plist]
end
def initialize(target_definition, pods) def initialize(target_definition, pods)
@target_definition, @pods = target_definition, pods @target_definition, @pods = target_definition, pods
end end
def save_as(path) def save_as(path)
Xcodeproj.write_plist(plist, path) Acknowledgements.generators.each do |generator|
end generator.new(@target_definition, @pods).save_as(path)
def plist
{
:Title => "Acknowledgements",
:StringsTable => "Acknowledgements",
:PreferenceSpecifiers => licenses
}
end
def licenses
licences_array = [header]
@pods.each do |pod|
if (hash = hash_for_pod(pod))
licences_array << hash
end
end end
licences_array << footnote
end
def hash_for_pod(pod)
if (license = pod.license_text)
{
:Type => "PSGroupSpecifier",
:Title => pod.name,
:FooterText => license
}
else
puts "[!] No license for #{pod.name}"
end
end
def header
{
:Type => "PSGroupSpecifier",
:Title => header_title,
:FooterText => header_text
}
end
def footnote
{
:Type => "PSGroupSpecifier",
:Title => footnote_title,
:FooterText => footnote_text
}
end end
def header_title def header_title
......
module Pod
module Generator
class Plist < Acknowledgements
require "xcodeproj/xcodeproj_ext"
def save_as(path)
Xcodeproj.write_plist(plist, path)
end
def plist
{
:Title => "Acknowledgements",
:StringsTable => "Acknowledgements",
:PreferenceSpecifiers => licenses
}
end
def licenses
licences_array = [header_hash]
@pods.each do |pod|
if (hash = hash_for_pod(pod))
licences_array << hash
end
end
licences_array << footnote_hash
end
def hash_for_pod(pod)
if (license = pod.license_text)
{
:Type => "PSGroupSpecifier",
:Title => pod.name,
:FooterText => license
}
else
puts "[!] No license for #{pod.name}"
end
end
def header_hash
{
:Type => "PSGroupSpecifier",
:Title => header_title,
:FooterText => header_text
}
end
def footnote_hash
{
:Type => "PSGroupSpecifier",
:Title => footnote_title,
:FooterText => footnote_text
}
end
end
end
end
require File.expand_path("../../../../spec_helper", __FILE__)
describe Pod::Generator::Plist do
before do
@podfile = Pod::Podfile.new do
platform :ios
xcodeproj "dummy"
end
@target_definition = @podfile.target_definitions[:default]
@sandbox = temporary_sandbox
@pods = [Pod::LocalPod.new(fixture_spec("banana-lib/BananaLib.podspec"), @sandbox, Pod::Platform.ios)]
copy_fixture_to_pod("banana-lib", @pods[0])
@plist = Pod::Generator::Plist.new(@target_definition, @pods)
end
it "returns the correct number of licenses (including header and footnote)" do
@plist.licenses.count.should == 3
end
# TODO Test with a pod that has no licence
it "returns a correctly formed license hash for each pod" do
@plist.hash_for_pod(@pods[0]).should == {
:Type => "PSGroupSpecifier",
:Title => "BananaLib",
:FooterText => "Permission is hereby granted ..."
}
end
it "returns a plist containg the licenses" do
@plist.plist.should == {
:Title => "Acknowledgements",
:StringsTable => "Acknowledgements",
:PreferenceSpecifiers => @plist.licenses
}
end
it "writes a plist to disk" do
path = @sandbox.root + "#{@target_definition.label}-Acknowledgements.plist"
@plist.save_as(path).should.be.true
end
end
...@@ -14,29 +14,16 @@ describe Pod::Generator::Acknowledgements do ...@@ -14,29 +14,16 @@ describe Pod::Generator::Acknowledgements do
@acknowledgements = Pod::Generator::Acknowledgements.new(@target_definition, @pods) @acknowledgements = Pod::Generator::Acknowledgements.new(@target_definition, @pods)
end end
it "returns the correct number of licenses (including header and footnote)" do it "calls save_as on a Plist generator" do
@acknowledgements.licenses.count.should == 3 Pod::Generator::Plist.any_instance.expects(:save_as)
end path = @sandbox.root + "#{@target_definition.label}-Acknowledgements.plist"
@acknowledgements.save_as(path)
# TODO Test with a pod that has no licence
it "returns a correctly formed license hash for each pod" do
@acknowledgements.hash_for_pod(@pods[0]).should == {
:Type => "PSGroupSpecifier",
:Title => "BananaLib",
:FooterText => "Permission is hereby granted ..."
}
end
it "returns a plist containg the licenses" do
@acknowledgements.plist.should == {
:Title => "Acknowledgements",
:StringsTable => "Acknowledgements",
:PreferenceSpecifiers => @acknowledgements.licenses
}
end end
it "writes a plist to disk" do it "returns a string for each header and footnote text method" do
path = @sandbox.root + "#{@target_definition.label}-Acknowledgements.plist" @acknowledgements.header_title.should.be.kind_of(String)
@acknowledgements.save_as(path).should.be.true @acknowledgements.header_text.should.be.kind_of(String)
@acknowledgements.footnote_title.should.be.kind_of(String)
@acknowledgements.footnote_text.should.be.kind_of(String)
end end
end end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment