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
fdfca014
Commit
fdfca014
authored
Sep 08, 2014
by
Marius Rackwitz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
[Refactor] Extracted Generator::Header from PrefixHeader
Fixed wrong documented types drive-by.
parent
6555d4e0
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
129 additions
and
43 deletions
+129
-43
cocoapods.rb
lib/cocoapods.rb
+1
-0
header.rb
lib/cocoapods/generator/header.rb
+75
-0
prefix_header.rb
lib/cocoapods/generator/prefix_header.rb
+16
-33
header_spec.rb
spec/unit/generator/header_spec.rb
+37
-0
prefix_header_spec.rb
spec/unit/generator/prefix_header_spec.rb
+0
-10
No files found.
lib/cocoapods.rb
View file @
fdfca014
...
@@ -56,6 +56,7 @@ module Pod
...
@@ -56,6 +56,7 @@ module Pod
autoload
:BridgeSupport
,
'cocoapods/generator/bridge_support'
autoload
:BridgeSupport
,
'cocoapods/generator/bridge_support'
autoload
:CopyResourcesScript
,
'cocoapods/generator/copy_resources_script'
autoload
:CopyResourcesScript
,
'cocoapods/generator/copy_resources_script'
autoload
:DummySource
,
'cocoapods/generator/dummy_source'
autoload
:DummySource
,
'cocoapods/generator/dummy_source'
autoload
:Header
,
'cocoapods/generator/header'
autoload
:PrefixHeader
,
'cocoapods/generator/prefix_header'
autoload
:PrefixHeader
,
'cocoapods/generator/prefix_header'
autoload
:TargetEnvironmentHeader
,
'cocoapods/generator/target_environment_header'
autoload
:TargetEnvironmentHeader
,
'cocoapods/generator/target_environment_header'
autoload
:XCConfig
,
'cocoapods/generator/xcconfig'
autoload
:XCConfig
,
'cocoapods/generator/xcconfig'
...
...
lib/cocoapods/generator/header.rb
0 → 100644
View file @
fdfca014
module
Pod
module
Generator
# Generates a header file.
#
# According to the platform the header imports `UIKit/UIKit.h` or
# `Cocoa/Cocoa.h`.
#
class
Header
# @return [Symbol] the platform for which the prefix header will be
# generated.
#
attr_reader
:platform
# @return [Array<String>] The list of the headers to import.
#
attr_reader
:imports
# @param [Symbol] platform
# @see platform
#
def
initialize
(
platform
)
@platform
=
platform
@imports
=
[]
end
# Generates the contents of the header according to the platform.
#
# @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]
#
def
generate
result
=
""
result
<<
generate_platform_import_header
unless
imports
.
empty?
imports
.
each
do
|
import
|
result
<<
%|\n#import "#{import}"|
end
end
result
end
# Generates and saves the header to the given path.
#
# @param [Pathname] path
# the path where the header should be stored.
#
# @return [void]
#
def
save_as
(
path
)
path
.
open
(
'w'
)
{
|
header
|
header
.
write
(
generate
)
}
end
#-----------------------------------------------------------------------#
protected
# Generates the contents of the header according to the platform.
#
# @note If the platform is iOS an import call to `UIKit/UIKit.h` is
# added to the top of the header. For OS X `Cocoa/Cocoa.h` is
# imported.
#
# @return [String]
#
def
generate_platform_import_header
"#import
#{
platform
==
:ios
?
'<UIKit/UIKit.h>'
:
'<Cocoa/Cocoa.h>'
}
\n
"
end
end
end
end
lib/cocoapods/generator/prefix_header.rb
View file @
fdfca014
...
@@ -6,38 +6,26 @@ module Pod
...
@@ -6,38 +6,26 @@ module Pod
# According to the platform the prefix header imports `UIKit/UIKit.h` or
# According to the platform the prefix header imports `UIKit/UIKit.h` or
# `Cocoa/Cocoa.h`.
# `Cocoa/Cocoa.h`.
#
#
class
PrefixHeader
class
PrefixHeader
<
Header
# @return [Array<FileAccessor>] The file accessors for which to generate
# @return [Array<FileAccessor>] The file accessors for which to generate
# the prefix header.
# the prefix header.
#
#
attr_reader
:file_accessors
attr_reader
:file_accessors
# @
return [Platform] the platform for which the prefix header will be
# @
param [Array<FileAccessor>] file_accessors
#
generated.
#
@see file_accessors
#
#
attr_reader
:platform
# @param [Platform] platform
# @see platform
# @return [Array<String>] The list of the headers to import (with
# quotes).
#
attr_reader
:imports
# @param [Platform] platform @see platform
# @param [Array<LocalPod>] consumers @see consumers
#
#
def
initialize
(
file_accessors
,
platform
)
def
initialize
(
file_accessors
,
platform
)
@file_accessors
=
file_accessors
@file_accessors
=
file_accessors
@platform
=
platform
super
platform
@imports
=
[]
end
end
# Generates the contents of the prefix header according to the platform
# Generates the contents of the prefix header according to the platform
# and the pods.
# 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.
#
# @note Only unique prefix_header_contents are added to the prefix
# @note Only unique prefix_header_contents are added to the prefix
# header.
# header.
#
#
...
@@ -48,20 +36,14 @@ module Pod
...
@@ -48,20 +36,14 @@ module Pod
# file_accessor.prefix_header.
# file_accessor.prefix_header.
#
#
def
generate
def
generate
result
=
"#ifdef __OBJC__
\n
"
result
=
super
result
<<
"#import
#{
platform
==
:ios
?
'<UIKit/UIKit.h>'
:
'<Cocoa/Cocoa.h>'
}
\n
"
result
<<
"#endif
\n
"
imports
.
each
do
|
import
|
result
<<
"
\n
"
result
<<
%(\n#import "#{import}")
end
unique_prefix_header_contents
=
file_accessors
.
map
do
|
file_accessor
|
unique_prefix_header_contents
=
file_accessors
.
map
do
|
file_accessor
|
file_accessor
.
spec_consumer
.
prefix_header_contents
file_accessor
.
spec_consumer
.
prefix_header_contents
end
.
compact
.
uniq
end
.
compact
.
uniq
result
<<
"
\n
"
unique_prefix_header_contents
.
each
do
|
prefix_header_contents
|
unique_prefix_header_contents
.
each
do
|
prefix_header_contents
|
result
<<
prefix_header_contents
result
<<
prefix_header_contents
result
<<
"
\n
"
result
<<
"
\n
"
...
@@ -75,15 +57,16 @@ module Pod
...
@@ -75,15 +57,16 @@ module Pod
result
result
end
end
# Generates and saves the prefix header to the given path.
protected
#
# @param [Pathname] path
# Generates the contents of the header according to the platform.
# the path where the prefix header should be stored.
#
#
# @return [
void
]
# @return [
String
]
#
#
def
save_as
(
path
)
def
generate_platform_import_header
path
.
open
(
'w'
)
{
|
header
|
header
.
write
(
generate
)
}
result
=
"#ifdef __OBJC__
\n
"
result
<<
super
result
<<
"#endif
\n
"
end
end
end
end
end
end
...
...
spec/unit/generator/header_spec.rb
0 → 100644
View file @
fdfca014
require
File
.
expand_path
(
'../../../spec_helper'
,
__FILE__
)
module
Pod
describe
Header
=
Generator
::
Header
do
before
do
@gen
=
Header
.
new
(
Pod
::
Platform
.
ios
)
end
it
'includes the imports'
do
@gen
.
imports
<<
'header.h'
@gen
.
generate
.
should
==
<<-
EOS
.
strip_heredoc
.
chomp
#import <UIKit/UIKit.h>
#import "header.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
it
'writes the header file to the disk'
do
path
=
temporary_directory
+
'Test.h'
@gen
.
save_as
(
path
)
path
.
read
.
should
==
<<-
EOS
.
strip_heredoc
#import <UIKit/UIKit.h>
EOS
end
end
end
spec/unit/generator/prefix_header_spec.rb
View file @
fdfca014
...
@@ -80,16 +80,6 @@ module Pod
...
@@ -80,16 +80,6 @@ module Pod
EOS
EOS
end
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
it
'writes the prefix header file to the disk'
do
it
'writes the prefix header file to the disk'
do
path
=
temporary_directory
+
'Test.pch'
path
=
temporary_directory
+
'Test.pch'
@gen
.
save_as
(
path
)
@gen
.
save_as
(
path
)
...
...
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