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
39f80935
Commit
39f80935
authored
Nov 14, 2012
by
Fabio Pelosin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Genenrator::PrefixHeader] Added.
parent
066aac5d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
146 additions
and
0 deletions
+146
-0
prefix_header.rb
lib/cocoapods/generator/prefix_header.rb
+73
-0
prefix_header_spec.rb
spec/unit/generator/prefix_header_spec.rb
+73
-0
No files found.
lib/cocoapods/generator/prefix_header.rb
0 → 100644
View file @
39f80935
module
Pod
module
Generator
# Generates a prefix header file for a Pods library. The prefix header is
# generated according to the platform of the target and the pods.
#
# According to the platform the prefix header imports `UIKit/UIKit.h` or
# `Cocoa/Cocoa.h`.
#
class
PrefixHeader
# @return [Platform] the platform for which the prefix header will be
# generated.
#
attr_reader
:platform
# @return [Array<LocalPod>] the LocalPod for the target for which the
# prefix header needs to be generated.
#
attr_reader
:pods
# @param [Platform] platform @see platform
#
# @param [Array<LocalPod>] @see pods
#
def
initialize
(
platform
,
pods
)
@platform
=
platform
@pods
=
pods
end
#--------------------------------------#
# Generates the contents of the prefix header according to the platform
# and the pods.
#
# @note If the platform is iOS an import call to `UIKit/UIKit.h` is
# added to the top of the prefix header. For OS X `Cocoa/Cocoa.h`
# is imported.
#
# @return [String]
#
# TODO: Subspecs can specify prefix header information too.
#
def
generate
result
=
"#ifdef __OBJC__
\n
"
result
<<
"#import
#{
platform
==
:ios
?
'<UIKit/UIKit.h>'
:
'<Cocoa/Cocoa.h>'
}
\n
"
result
<<
"#endif
\n
"
pods
.
each
do
|
pod
|
result
<<
"
\n
"
if
prefix_header_contents
=
pod
.
top_specification
.
prefix_header_contents
result
<<
prefix_header_contents
result
<<
"
\n
"
elsif
prefix_header
=
pod
.
prefix_header_file
result
<<
prefix_header
.
read
end
end
result
end
# Generates and saves the prefix header to the given path.
#
# @param [Pathname] path
# the path where the prefix header should be stored.
#
# @return [void]
#
def
save_as
(
path
)
path
.
open
(
'w'
)
{
|
header
|
header
.
write
(
generate
)
}
end
end
end
end
spec/unit/generator/prefix_header_spec.rb
0 → 100644
View file @
39f80935
require
File
.
expand_path
(
'../../../spec_helper'
,
__FILE__
)
describe
PrefixHeader
=
Pod
::
Generator
::
PrefixHeader
do
before
do
platform
=
Pod
::
Platform
.
ios
specification
=
fixture_spec
(
'banana-lib/BananaLib.podspec'
)
@pod
=
Pod
::
LocalPod
.
new
(
specification
,
nil
,
platform
)
pods
=
[
@pod
]
@gen
=
PrefixHeader
.
new
(
platform
,
pods
)
@pod
.
stubs
(
:root
).
returns
(
Pathname
.
new
(
fixture
(
'banana-lib'
)))
end
it
"includes the contents of the specification's prefix header"
do
spec
=
@pod
.
top_specification
spec
.
prefix_header_contents
=
'#import "BlocksKit.h"'
@gen
.
generate
.
should
==
<<-
EOS
.
strip_heredoc
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import "BlocksKit.h"
EOS
end
it
"includes the contents of the specification's prefix header file"
do
@gen
.
generate
.
should
==
<<-
EOS
.
strip_heredoc
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import <BananaTree/BananaTree.h>
EOS
end
it
"prefers the inline specification of the prefix header contents"
do
spec
=
@pod
.
top_specification
spec
.
prefix_header_contents
=
'#import "BlocksKit.h"'
@pod
.
prefix_header_file
.
should
.
be
.
not
.
nil
@gen
.
generate
.
should
==
<<-
EOS
.
strip_heredoc
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import "BlocksKit.h"
EOS
end
it
"imports UIKit in iOS platforms"
do
@gen
.
stubs
(
:platform
).
returns
(
Pod
::
Platform
.
ios
)
@gen
.
generate
.
should
.
include?
(
'#import <UIKit/UIKit.h>'
)
end
it
"imports Cocoa for OS X platforms"
do
@gen
.
stubs
(
:platform
).
returns
(
Pod
::
Platform
.
osx
)
@gen
.
generate
.
should
.
include?
(
'#import <Cocoa/Cocoa.h>'
)
end
extend
SpecHelper
::
TemporaryDirectory
it
"writes the prefix header file to the disk"
do
path
=
temporary_directory
+
'Test.pch'
@gen
.
save_as
(
path
)
path
.
read
.
should
==
<<-
EOS
.
strip_heredoc
#ifdef __OBJC__
#import <UIKit/UIKit.h>
#endif
#import <BananaTree/BananaTree.h>
EOS
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