xcode_template_maker 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/empty_template.rb +10 -0
- data/lib/empty_templates/file_definition.xml +10 -0
- data/lib/empty_templates/file_template.xml +19 -0
- data/lib/file_definition.rb +25 -0
- data/lib/file_template.rb +25 -0
- data/lib/file_template_exporter.rb +50 -0
- data/lib/yaml_file_template.rb +18 -0
- metadata +52 -0
@@ -0,0 +1,10 @@
|
|
1
|
+
class EmptyTemplate
|
2
|
+
@@empty_template_dir = File.expand_path(File.join(File.dirname(__FILE__), "empty_templates"))
|
3
|
+
def self.empty_template_dir=(value)
|
4
|
+
@@empty_template_dir = value
|
5
|
+
end
|
6
|
+
|
7
|
+
def self.read(template_name)
|
8
|
+
File.read(File.join(@@empty_template_dir, "#{template_name}.xml"))
|
9
|
+
end
|
10
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
2
|
+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
3
|
+
<plist version="1.0">
|
4
|
+
<dict>
|
5
|
+
<key>Identifier</key>
|
6
|
+
<string>{{IDENTIFIER}}</string>
|
7
|
+
<key>Kind</key>
|
8
|
+
<string>Xcode.Xcode3.ProjectTemplateUnitKind</string>
|
9
|
+
<key>Definitions</key>
|
10
|
+
<dict>
|
11
|
+
{{FILE_DEFINITIONS}}
|
12
|
+
</dict>
|
13
|
+
|
14
|
+
<key>Nodes</key>
|
15
|
+
<array>
|
16
|
+
{{FILE_DEFINITIONS_LIST}}
|
17
|
+
</array>
|
18
|
+
</dict>
|
19
|
+
</plist>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class FileDefinition
|
2
|
+
attr_accessor :input_path, :group_path, :output_path, :include_in_target
|
3
|
+
|
4
|
+
def self.build(project_root, file_path)
|
5
|
+
relative_file_path = file_path.gsub("#{File.expand_path(project_root)}/", "")
|
6
|
+
include_in_target = !relative_file_path.match(/\.[cm]$/).nil?
|
7
|
+
FileDefinition.new({
|
8
|
+
:input_path => relative_file_path,
|
9
|
+
:group_path => File.dirname(relative_file_path),
|
10
|
+
:output_path => relative_file_path,
|
11
|
+
:include_in_target => include_in_target
|
12
|
+
})
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize(options)
|
16
|
+
@input_path = options[:input_path]
|
17
|
+
@group_path = options[:group_path]
|
18
|
+
@output_path = options[:output_path]
|
19
|
+
@include_in_target = options[:include_in_target]
|
20
|
+
end
|
21
|
+
|
22
|
+
def include_in_target?
|
23
|
+
@include_in_target
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require "file_definition"
|
2
|
+
|
3
|
+
class FileTemplate
|
4
|
+
attr_reader :identifier, :project_root, :kind, :file_definitions
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@identifier = options[:identifier]
|
8
|
+
@project_root = options[:project_root]
|
9
|
+
@kind = "Xcode.Xcode3.ProjectTemplateUnitKind"
|
10
|
+
@file_definitions = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def include_dir(path)
|
14
|
+
files_in_dir(path).each do |path|
|
15
|
+
@file_definitions << FileDefinition.build(project_root, path)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def files_in_dir(path)
|
22
|
+
full_path = path.match(/^\//) ? path : File.join(project_root, path)
|
23
|
+
Dir.glob(File.join(full_path, "**/*")).reject { |path| File.directory? path }
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,50 @@
|
|
1
|
+
require "empty_template"
|
2
|
+
|
3
|
+
class FileTemplateExporter
|
4
|
+
attr_reader :filename
|
5
|
+
|
6
|
+
def initialize(file_template)
|
7
|
+
@file_template = file_template
|
8
|
+
@filename = "TemplateInfo.plist"
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_xml
|
12
|
+
file_template = EmptyTemplate.read("file_template")
|
13
|
+
file_template.gsub!("{{IDENTIFIER}}", @file_template.identifier)
|
14
|
+
file_definitions_to_xml = file_definitions.collect do |file_definition|
|
15
|
+
file_definition_to_xml(file_definition)
|
16
|
+
end.join("\n")
|
17
|
+
file_template.gsub!("{{FILE_DEFINITIONS}}", file_definitions_to_xml)
|
18
|
+
file_template.gsub!("{{FILE_DEFINITIONS_LIST}}", file_definition_list_as_xml)
|
19
|
+
file_template
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
def file_definition_list_as_xml
|
25
|
+
file_definitions.collect do |file_definition|
|
26
|
+
"<string>#{file_definition.input_path}</string>"
|
27
|
+
end.join("\n")
|
28
|
+
end
|
29
|
+
|
30
|
+
def file_definition_to_xml(file_definition)
|
31
|
+
file_definition_template = EmptyTemplate.read("file_definition")
|
32
|
+
file_definition_template.gsub!("{{INPUT_PATH}}", file_definition.input_path)
|
33
|
+
file_definition_template.gsub!("{{OUTPUT_PATH}}", file_definition.output_path)
|
34
|
+
file_definition_template.gsub!("{{GROUP_PATH}}", group_path_to_xml(file_definition.group_path))
|
35
|
+
file_definition_template.gsub!("{{EXCLUDE_FROM_TARGET}}", include_in_target_string(file_definition))
|
36
|
+
return file_definition_template
|
37
|
+
end
|
38
|
+
|
39
|
+
def include_in_target_string(file_definition)
|
40
|
+
file_definition.include_in_target? ? "" : "<key>TargetIndices</key>\n<array/>\n"
|
41
|
+
end
|
42
|
+
|
43
|
+
def group_path_to_xml(group_path)
|
44
|
+
group_path.split("/").collect {|part| "<string>#{part}</string>"}.join("\n")
|
45
|
+
end
|
46
|
+
|
47
|
+
def file_definitions
|
48
|
+
@file_template.file_definitions
|
49
|
+
end
|
50
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "file_template"
|
2
|
+
require "yaml"
|
3
|
+
|
4
|
+
class YAMLFileTemplate
|
5
|
+
|
6
|
+
def self.load_from_yaml(yaml)
|
7
|
+
parsed_options = YAML.load(yaml)
|
8
|
+
file_template = FileTemplate.new({
|
9
|
+
:identifier => parsed_options["identifier"],
|
10
|
+
:project_root => parsed_options["project_root"]
|
11
|
+
})
|
12
|
+
parsed_options["included_dirs"].each do |dir|
|
13
|
+
file_template.include_dir(dir)
|
14
|
+
end
|
15
|
+
return file_template
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
metadata
ADDED
@@ -0,0 +1,52 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: xcode_template_maker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Eric Meyer
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-02-13 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Much easier way to create templates for Xcode than editing the xml
|
15
|
+
email:
|
16
|
+
- emeyer@8thlight.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/empty_template.rb
|
22
|
+
- lib/empty_templates/file_definition.xml
|
23
|
+
- lib/empty_templates/file_template.xml
|
24
|
+
- lib/file_definition.rb
|
25
|
+
- lib/file_template.rb
|
26
|
+
- lib/file_template_exporter.rb
|
27
|
+
- lib/yaml_file_template.rb
|
28
|
+
homepage: https://github.com/ericmeyer/xcode_template_maker
|
29
|
+
licenses: []
|
30
|
+
post_install_message:
|
31
|
+
rdoc_options: []
|
32
|
+
require_paths:
|
33
|
+
- lib
|
34
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
35
|
+
none: false
|
36
|
+
requirements:
|
37
|
+
- - ! '>='
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
requirements: []
|
47
|
+
rubyforge_project: xcode_template_maker
|
48
|
+
rubygems_version: 1.8.16
|
49
|
+
signing_key:
|
50
|
+
specification_version: 3
|
51
|
+
summary: Much easier way to create templates for Xcode than editing the xml
|
52
|
+
test_files: []
|