Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
C
cocoapods
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gengmeiios
cocoapods
Commits
ae9e56a8
Commit
ae9e56a8
authored
Feb 02, 2013
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Generator::Acknowledgements] Adapt for new architecture.
parent
e5e2498c
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
164 additions
and
63 deletions
+164
-63
acknowledgements.rb
lib/cocoapods/generator/acknowledgements.rb
+72
-2
markdown.rb
lib/cocoapods/generator/acknowledgements/markdown.rb
+5
-5
plist.rb
lib/cocoapods/generator/acknowledgements/plist.rb
+5
-5
spec_helper.rb
spec/spec_helper.rb
+8
-0
markdown_spec.rb
spec/unit/generator/acknowledgements/markdown_spec.rb
+18
-20
plist_spec.rb
spec/unit/generator/acknowledgements/plist_spec.rb
+10
-15
acknowledgements_spec.rb
spec/unit/generator/acknowledgements_spec.rb
+46
-16
No files found.
lib/cocoapods/generator/acknowledgements.rb
View file @
ae9e56a8
...
@@ -3,29 +3,99 @@ module Pod
...
@@ -3,29 +3,99 @@ module Pod
class
Acknowledgements
class
Acknowledgements
# @return [Array<Class>] The classes of the acknowledgements generator
# subclasses.
#
def
self
.
generators
def
self
.
generators
[
Plist
,
Markdown
]
[
Plist
,
Markdown
]
end
end
def
initialize
(
target_definition
,
pods
)
# @return [Array<Sandbox::FileAccessor>] the list of the file accessors
@target_definition
,
@pods
=
target_definition
,
pods
# for the specs of the target that needs to generate the
# acknowledgements.
#
attr_reader
:file_accessors
# @param [Array<Sandbox::FileAccessor>] @see file_accessors.
#
def
initialize
(
file_accessors
)
@file_accessors
=
file_accessors
end
end
#-----------------------------------------------------------------------#
# !@group Configuration
# @return [String] The title of the acknowledgements file.
#
def
header_title
def
header_title
"Acknowledgements"
"Acknowledgements"
end
end
# @return [String] A text to present before listing the acknowledgements.
#
def
header_text
def
header_text
"This application makes use of the following third party libraries:"
"This application makes use of the following third party libraries:"
end
end
# @return [String] The title of the foot notes.
#
def
footnote_title
def
footnote_title
""
""
end
end
# @return [String] the foot notes.
#
def
footnote_text
def
footnote_text
"Generated by CocoaPods - http://cocoapods.org"
"Generated by CocoaPods - http://cocoapods.org"
end
end
#-----------------------------------------------------------------------#
private
# !@group Private methods
# @return [Array<Specification>] The root specifications for which the
# acknowledgements should be generated.
#
def
specs
file_accessors
.
map
{
|
accessor
|
accessor
.
spec
.
root
}.
uniq
end
# Returns the text of the license for the given spec.
#
# @param [Specification] spec
# the specification for which license is needed.
#
# @return [String] The text of the license.
# @return [Nil] If not license text could be found.
#
def
license_text
(
spec
)
if
spec
.
license
if
text
=
spec
.
license
[
:text
]
text
elsif
license_file
=
file_accessor
(
spec
).
license
text
=
IO
.
read
(
license_file
)
end
end
end
protected
# Returns the file accessor for the given spec.
#
# @param [Specification] spec
# the specification for which the file accessor is needed.
#
# @return [Sandbox::FileAccessor] The file accessor.
#
def
file_accessor
(
spec
)
file_accessors
.
find
{
|
accessor
|
accessor
.
spec
.
root
==
spec
}
end
#-----------------------------------------------------------------------#
end
end
end
end
end
end
lib/cocoapods/generator/acknowledgements/markdown.rb
View file @
ae9e56a8
...
@@ -19,16 +19,16 @@ module Pod
...
@@ -19,16 +19,16 @@ module Pod
end
end
end
end
def
string_for_
pod
(
pod
)
def
string_for_
spec
(
spec
)
if
(
license_text
=
pod
.
license_text
)
if
(
license_text
=
license_text
(
spec
)
)
"
\n
"
<<
title_from_string
(
pod
.
name
,
2
)
<<
"
\n\n
"
<<
license_text
<<
"
\n
"
"
\n
"
<<
title_from_string
(
spec
.
name
,
2
)
<<
"
\n\n
"
<<
license_text
<<
"
\n
"
end
end
end
end
def
licenses
def
licenses
licenses_string
=
"
#{
title_from_string
(
header_title
,
1
)
}
\n
#{
header_text
}
\n
"
licenses_string
=
"
#{
title_from_string
(
header_title
,
1
)
}
\n
#{
header_text
}
\n
"
@pods
.
each
do
|
pod
|
specs
.
each
do
|
spec
|
if
(
license
=
string_for_
pod
(
pod
))
if
(
license
=
string_for_
spec
(
spec
))
license
=
license
.
force_encoding
(
"UTF-8"
)
if
license
.
respond_to?
(
:force_encoding
)
license
=
license
.
force_encoding
(
"UTF-8"
)
if
license
.
respond_to?
(
:force_encoding
)
licenses_string
+=
license
licenses_string
+=
license
end
end
...
...
lib/cocoapods/generator/acknowledgements/plist.rb
View file @
ae9e56a8
...
@@ -26,19 +26,19 @@ module Pod
...
@@ -26,19 +26,19 @@ module Pod
def
licenses
def
licenses
licences_array
=
[
header_hash
]
licences_array
=
[
header_hash
]
@pods
.
each
do
|
pod
|
specs
.
each
do
|
spec
|
if
(
hash
=
hash_for_
pod
(
pod
))
if
(
hash
=
hash_for_
spec
(
spec
))
licences_array
<<
hash
licences_array
<<
hash
end
end
end
end
licences_array
<<
footnote_hash
licences_array
<<
footnote_hash
end
end
def
hash_for_
pod
(
pod
)
def
hash_for_
spec
(
spec
)
if
(
license
=
pod
.
license_text
)
if
(
license
=
license_text
(
spec
)
)
{
{
:Type
=>
"PSGroupSpecifier"
,
:Type
=>
"PSGroupSpecifier"
,
:Title
=>
pod
.
name
,
:Title
=>
spec
.
name
,
:FooterText
=>
license
:FooterText
=>
license
}
}
end
end
...
...
spec/spec_helper.rb
View file @
ae9e56a8
...
@@ -84,6 +84,14 @@ def fixture_spec(name)
...
@@ -84,6 +84,14 @@ def fixture_spec(name)
Pod
::
Specification
.
from_file
(
file
)
Pod
::
Specification
.
from_file
(
file
)
end
end
def
fixture_file_accessor
(
name
,
platform
=
:ios
)
file
=
SpecHelper
::
Fixture
.
fixture
(
name
)
spec
=
Pod
::
Specification
.
from_file
(
file
)
path_list
=
Pod
::
Sandbox
::
PathList
.
new
(
file
.
dirname
)
file_accessor
=
Pod
::
Sandbox
::
FileAccessor
.
new
(
path_list
,
spec
.
consumer
(
platform
))
end
# TODO This should not be needed anymore
def
copy_fixture_to_pod
(
name
,
pod
)
def
copy_fixture_to_pod
(
name
,
pod
)
path
=
SpecHelper
::
Fixture
.
fixture
(
name
)
path
=
SpecHelper
::
Fixture
.
fixture
(
name
)
FileUtils
.
cp_r
(
path
,
pod
.
root
)
FileUtils
.
cp_r
(
path
,
pod
.
root
)
...
...
spec/unit/generator/acknowledgements/markdown_spec.rb
View file @
ae9e56a8
...
@@ -2,40 +2,38 @@ require File.expand_path("../../../../spec_helper", __FILE__)
...
@@ -2,40 +2,38 @@ require File.expand_path("../../../../spec_helper", __FILE__)
describe
Pod
::
Generator
::
Markdown
do
describe
Pod
::
Generator
::
Markdown
do
before
do
before
do
@sandbox
=
temporary_sandbox
@file_accessor
=
fixture_file_accessor
(
'banana-lib/BananaLib.podspec'
)
@target_definition
=
mock
@spec
=
@file_accessor
.
spec
@pods
=
[
mock
]
@generator
=
Pod
::
Generator
::
Markdown
.
new
([
@file_accessor
])
@pods
[
0
].
expects
(
:license_text
).
returns
(
"LICENSE_TEXT"
).
at_least_once
@spec
.
stubs
(
:name
).
returns
(
"POD_NAME"
)
@pods
[
0
].
expects
(
:name
).
returns
(
"POD_NAME"
).
at_least_once
@generator
.
stubs
(
:license_text
).
returns
(
"LICENSE_TEXT"
)
@markdown
=
Pod
::
Generator
::
Markdown
.
new
(
@target_definition
,
@pods
)
end
end
it
"returns a correctly formatted title string"
do
it
"returns a correctly formatted title string"
do
@pods
[
0
].
unstub
(
:license_text
)
@generator
.
title_from_string
(
"A Title"
,
2
).
should
.
equal
"## A Title"
@pods
[
0
].
unstub
(
:name
)
@markdown
.
title_from_string
(
"A Title"
,
2
).
should
.
equal
"## A Title"
end
end
it
"returns a correctly formatted license string for each pod"
do
it
"returns a correctly formatted license string for each pod"
do
@
markdown
.
string_for_pod
(
@pods
[
0
]
).
should
.
equal
"
\n
## POD_NAME
\n\n
LICENSE_TEXT
\n
"
@
generator
.
string_for_spec
(
@spec
).
should
.
equal
"
\n
## POD_NAME
\n\n
LICENSE_TEXT
\n
"
end
end
it
"returns a correctly formatted markdown string for the target"
do
it
"returns a correctly formatted markdown string for the target"
do
@
markdown
.
stubs
(
:header_title
).
returns
(
"HEADER_TITLE"
)
@
generator
.
stubs
(
:header_title
).
returns
(
"HEADER_TITLE"
)
@
markdown
.
stubs
(
:header_text
).
returns
(
"HEADER_TEXT"
)
@
generator
.
stubs
(
:header_text
).
returns
(
"HEADER_TEXT"
)
@
markdown
.
stubs
(
:footnote_title
).
returns
(
""
)
# Test that extra \n isn't added for empty strings
@
generator
.
stubs
(
:footnote_title
).
returns
(
""
)
# Test that extra \n isn't added for empty strings
@
markdown
.
stubs
(
:footnote_text
).
returns
(
"FOOTNOTE_TEXT"
)
@
generator
.
stubs
(
:footnote_text
).
returns
(
"FOOTNOTE_TEXT"
)
@
markdown
.
licenses
.
should
.
equal
"# HEADER_TITLE
\n
HEADER_TEXT
\n\n
## POD_NAME
\n\n
LICENSE_TEXT
\n
FOOTNOTE_TEXT
\n
"
@
generator
.
licenses
.
should
.
equal
"# HEADER_TITLE
\n
HEADER_TEXT
\n\n
## POD_NAME
\n\n
LICENSE_TEXT
\n
FOOTNOTE_TEXT
\n
"
end
end
it
"writes a markdown file to disk"
do
it
"writes a markdown file to disk"
do
basepath
=
@sandbox
.
root
+
"Pods-acknowledgements"
basepath
=
config
.
sandbox
.
root
+
"Pods-acknowledgements"
given_path
=
@markdown
.
class
.
path_from_basepath
(
basepath
)
given_path
=
@generator
.
class
.
path_from_basepath
(
basepath
)
expected_path
=
@sandbox
.
root
+
"Pods-acknowledgements.markdown"
expected_path
=
config
.
sandbox
.
root
+
"Pods-acknowledgements.markdown"
mockFile
=
mock
mockFile
=
mock
mockFile
.
expects
(
:write
).
with
(
equals
(
@
markdown
.
licenses
))
mockFile
.
expects
(
:write
).
with
(
equals
(
@
generator
.
licenses
))
mockFile
.
expects
(
:close
)
mockFile
.
expects
(
:close
)
File
.
expects
(
:new
).
with
(
equals
(
expected_path
),
equals
(
"w"
)).
returns
(
mockFile
)
File
.
expects
(
:new
).
with
(
equals
(
expected_path
),
equals
(
"w"
)).
returns
(
mockFile
)
@
markdown
.
save_as
(
given_path
)
@
generator
.
save_as
(
given_path
)
end
end
end
end
spec/unit/generator/acknowledgements/plist_spec.rb
View file @
ae9e56a8
...
@@ -2,12 +2,11 @@ require File.expand_path("../../../../spec_helper", __FILE__)
...
@@ -2,12 +2,11 @@ require File.expand_path("../../../../spec_helper", __FILE__)
describe
Pod
::
Generator
::
Plist
do
describe
Pod
::
Generator
::
Plist
do
before
do
before
do
@sandbox
=
temporary_sandbox
@file_accessor
=
fixture_file_accessor
(
'banana-lib/BananaLib.podspec'
)
@target_definition
=
mock
@spec
=
@file_accessor
.
spec
@pods
=
[
mock
]
@plist
=
Pod
::
Generator
::
Plist
.
new
([
@file_accessor
])
@pods
[
0
].
expects
(
:license_text
).
returns
(
"LICENSE_TEXT"
).
at_least_once
@spec
.
stubs
(
:name
).
returns
(
"POD_NAME"
)
@pods
[
0
].
expects
(
:name
).
returns
(
"POD_NAME"
).
at_least_once
@plist
.
stubs
(
:license_text
).
returns
(
"LICENSE_TEXT"
)
@plist
=
Pod
::
Generator
::
Plist
.
new
(
@target_definition
,
@pods
)
end
end
it
"returns the correct number of licenses (including header and footnote)"
do
it
"returns the correct number of licenses (including header and footnote)"
do
...
@@ -15,13 +14,11 @@ describe Pod::Generator::Plist do
...
@@ -15,13 +14,11 @@ describe Pod::Generator::Plist do
end
end
it
"returns a string for the plist title"
do
it
"returns a string for the plist title"
do
@pods
[
0
].
unstub
(
:license_text
)
@pods
[
0
].
unstub
(
:name
)
@plist
.
plist_title
.
should
.
be
.
kind_of
(
String
)
@plist
.
plist_title
.
should
.
be
.
kind_of
(
String
)
end
end
it
"returns a correctly formed license hash for each pod"
do
it
"returns a correctly formed license hash for each pod"
do
@plist
.
hash_for_
pod
(
@pods
[
0
]
).
should
==
{
@plist
.
hash_for_
spec
(
@spec
).
should
==
{
:Type
=>
"PSGroupSpecifier"
,
:Type
=>
"PSGroupSpecifier"
,
:Title
=>
"POD_NAME"
,
:Title
=>
"POD_NAME"
,
:FooterText
=>
"LICENSE_TEXT"
:FooterText
=>
"LICENSE_TEXT"
...
@@ -29,10 +26,8 @@ describe Pod::Generator::Plist do
...
@@ -29,10 +26,8 @@ describe Pod::Generator::Plist do
end
end
it
"returns nil for a pod with no license text"
do
it
"returns nil for a pod with no license text"
do
@pods
[
0
].
unstub
(
:license_text
)
@plist
.
expects
(
:license_text
).
returns
(
nil
)
@pods
[
0
].
unstub
(
:name
)
@plist
.
hash_for_spec
(
@spec
).
should
.
be
.
nil
@pods
[
0
].
expects
(
:license_text
).
returns
(
nil
)
@plist
.
hash_for_pod
(
@pods
[
0
]).
should
.
be
.
nil
end
end
it
"returns a plist containg the licenses"
do
it
"returns a plist containg the licenses"
do
...
@@ -44,9 +39,9 @@ describe Pod::Generator::Plist do
...
@@ -44,9 +39,9 @@ describe Pod::Generator::Plist do
end
end
it
"writes a plist to disk at the given path"
do
it
"writes a plist to disk at the given path"
do
basepath
=
@
sandbox
.
root
+
"Pods-acknowledgements"
basepath
=
config
.
sandbox
.
root
+
"Pods-acknowledgements"
given_path
=
@plist
.
class
.
path_from_basepath
(
basepath
)
given_path
=
@plist
.
class
.
path_from_basepath
(
basepath
)
expected_path
=
@
sandbox
.
root
+
"Pods-acknowledgements.plist"
expected_path
=
config
.
sandbox
.
root
+
"Pods-acknowledgements.plist"
Xcodeproj
.
expects
(
:write_plist
).
with
(
equals
(
@plist
.
plist
),
equals
(
expected_path
))
Xcodeproj
.
expects
(
:write_plist
).
with
(
equals
(
@plist
.
plist
),
equals
(
expected_path
))
@plist
.
save_as
(
given_path
)
@plist
.
save_as
(
given_path
)
end
end
...
...
spec/unit/generator/acknowledgements_spec.rb
View file @
ae9e56a8
require
File
.
expand_path
(
"../../../spec_helper"
,
__FILE__
)
require
File
.
expand_path
(
"../../../spec_helper"
,
__FILE__
)
describe
Pod
::
Generator
::
Acknowledgements
do
module
Pod
before
do
describe
Generator
::
Acknowledgements
do
@sandbox
=
temporary_sandbox
before
do
@target_definition
=
mock
@file_accessor
=
fixture_file_accessor
(
'banana-lib/BananaLib.podspec'
)
@pods
=
[
mock
]
@spec
=
@file_accessor
.
spec
@acknowledgements
=
Pod
::
Generator
::
Acknowledgements
.
new
(
@target_definition
,
@pods
)
@generator
=
Pod
::
Generator
::
Acknowledgements
.
new
([
@file_accessor
]
)
end
end
it
"the the generators"
do
describe
"In general"
do
generators
=
Pod
::
Generator
::
Acknowledgements
.
generators
generators
.
map
{
|
g
|
g
.
name
.
split
(
'::'
).
last
}.
should
==
[
'Plist'
,
'Markdown'
]
it
"returns the classes of the concrete generators generators"
do
end
generators
=
Pod
::
Generator
::
Acknowledgements
.
generators
generators
.
map
{
|
g
|
g
.
name
.
split
(
'::'
).
last
}.
should
==
[
'Plist'
,
'Markdown'
]
end
it
"returns a string for each header and footnote text method"
do
@generator
.
header_title
.
should
.
be
.
kind_of
(
String
)
@generator
.
header_text
.
should
.
be
.
kind_of
(
String
)
@generator
.
footnote_title
.
should
.
be
.
kind_of
(
String
)
@generator
.
footnote_text
.
should
.
be
.
kind_of
(
String
)
end
end
#-----------------------------------------------------------------------#
describe
"Private methods"
do
it
"returns the root specifications"
do
generator
=
Pod
::
Generator
::
Acknowledgements
.
new
([
@file_accessor
,
@file_accessor
])
generator
.
send
(
:specs
).
should
==
[
@file_accessor
.
spec
]
end
it
"returns the license"
do
text_from_spec
=
@generator
.
send
(
:license_text
,
@spec
)
text_from_spec
.
should
==
"Permission is hereby granted ..."
end
it
"returns the license from the file"
do
@spec
.
stubs
(
:license
).
returns
({
:type
=>
'MIT'
,
:file
=>
'README'
})
text_from_spec
=
@generator
.
send
(
:license_text
,
@spec
)
text_from_spec
.
should
==
"post v1.0
\n
"
end
end
#-----------------------------------------------------------------------#
it
"returns a string for each header and footnote text method"
do
@acknowledgements
.
header_title
.
should
.
be
.
kind_of
(
String
)
@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
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment