xfabricator 0.1.2 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 645a21806994d33b4928c8ff917164bd7ee10e0f
4
- data.tar.gz: 675a34495eba71982d963f6c0125d691852e747c
3
+ metadata.gz: 322079b7d1a85c7ba769423c3ff5c12599a10a96
4
+ data.tar.gz: 20318c1f5fab4b69061d3350898d8aba4314aa6d
5
5
  SHA512:
6
- metadata.gz: 98352f3416adb271fc9bd3d73379cdb018670e3072e6d7a1050cfb7e8108e18dddb7c129054bc0734c1599a3e74d5c41cc238a0cc964bcbfe605a022dfe765d8
7
- data.tar.gz: 725e357afccdf7fa7e87495108454cc5c15e0b2d7baa09752319add13fd86aa60039147c1807275833e02b145e2140f6b11a50d1f7492d3575b5914f42554268
6
+ metadata.gz: 662d9432e58fc435fe18618d01604299e8336b9f66256e3b1e34fe9161bffc2b934aaaa1b2434b888024c22eba302df22b2426f9babc14bf50be0840c8500807
7
+ data.tar.gz: 21b5944af780542391faf214450cf0a20fbe8590bb68f68c66656f492f4c4f213c814cf7425c3a65b099d4fd2c6a11ab82867fe90775ff48141b1701a10a1092
data/bin/xfabricate CHANGED
@@ -95,7 +95,7 @@ OptionParser.new do |opts|
95
95
  options[:group] = group_name
96
96
  end
97
97
 
98
- opts.on("-p path_name", "--path=path_name", "specify path to generate created files") do |path|
98
+ opts.on("-p path_name", "--path=path_name", "specify search path to find the current group") do |path|
99
99
  options[:path] = path
100
100
  end
101
101
 
@@ -1,14 +1,16 @@
1
1
  require "xfabricator/version"
2
2
  require 'xcodeproj'
3
3
  require 'xfabricator/x_code_file_template'
4
+ require 'fileutils'
5
+ require 'xfabricator/xcodeproj_additions'
4
6
 
5
7
  module Xfabricator
6
8
 
7
9
  class Fabricator
8
10
 
9
- def initialize(config, fabrication_path)
11
+ def initialize(config, search_path)
10
12
  @config = config
11
- @fabrication_path = fabrication_path
13
+ @search_path = search_path
12
14
  end
13
15
 
14
16
  def fabricate(template, variables, target_name)
@@ -30,7 +32,8 @@ module Xfabricator
30
32
  raise ArgumentError, "target_name not specified"
31
33
  end
32
34
 
33
- target = @config.project.targets.find { |target| target.name == target_name }
35
+ project = @config.project
36
+ target = project.targets.find { |target| target.name == target_name }
34
37
 
35
38
  unless target
36
39
  raise ArgumentError, "Couldn't find target with name: #{target_name}"
@@ -46,25 +49,36 @@ module Xfabricator
46
49
  if Pathname.new(template_file_path).exist?
47
50
  name_template = Mustache.new
48
51
  output_name = name_template.render template_file.output_name_template, variables
49
- output_file = fabricate_file(output_name, template_file_path, variables)
50
- ref = group.new_reference output_file
52
+
53
+ current_group = group
54
+
55
+ if template_file.sub_path.length > 0
56
+ groups = group.xfab_create_subpath(template_file.sub_path)
57
+ current_group = groups.last
58
+ end
59
+
60
+ output_file = fabricate_file(output_name, template_file_path, variables, current_group.real_path)
61
+
62
+ ref = current_group.new_reference output_file
51
63
  target.add_file_references [ref]
52
64
  else
53
65
  raise RuntimeError, "template file was not found: #{template_file_path}"
54
66
  end
55
67
 
56
- @config.project.save
57
68
  end
58
69
 
70
+ project.save
71
+
59
72
  end
60
73
 
61
- def fabricate_file(output_name, template_file_path, variables)
62
- output_file = "#{@fabrication_path}/#{output_name}"
74
+ def fabricate_file(output_name, template_file_path, variables, output_dir)
75
+ FileUtils.mkdir_p output_dir
63
76
 
64
77
  template = XCodeFileTemplate.new @config.project, variables
65
78
  template.template_file = template_file_path
66
79
  rendered_content = template.render
67
80
 
81
+ output_file = "#{output_dir}/#{output_name}"
68
82
  File.open(output_file, 'w') { |file| file.write(rendered_content) }
69
83
  output_file
70
84
  end
@@ -73,13 +87,11 @@ module Xfabricator
73
87
  project = @config.project
74
88
  main_group = project.main_group
75
89
 
76
- main_group_path = "#{project.path.parent.to_s}#{main_group.hierarchy_path}"
77
- puts "#{main_group_path} == #{@fabrication_path.to_s}"
78
- if main_group_path == @fabrication_path.to_s
90
+ if main_group.real_path == @search_path.to_s
79
91
  return main_group
80
92
  end
81
93
 
82
- find_group_for_directory(main_group, @fabrication_path, project)
94
+ find_group_for_directory(main_group, @search_path, project)
83
95
  end
84
96
 
85
97
  def find_group_for_directory(current_group, directory, project)
@@ -44,10 +44,12 @@ module Xfabricator
44
44
 
45
45
  attr_reader :output_name_template
46
46
  attr_reader :template_file
47
+ attr_reader :sub_path
47
48
 
48
- def initialize(template_file, output_name_template)
49
+ def initialize(template_file, output_name_template, sub_path = '')
49
50
  @output_name_template = output_name_template
50
51
  @template_file = template_file
52
+ @sub_path = sub_path
51
53
  end
52
54
 
53
55
  end
@@ -1,3 +1,3 @@
1
1
  module Xfabricator
2
- VERSION = "0.1.2"
2
+ VERSION = "1.0.0"
3
3
  end
@@ -0,0 +1,29 @@
1
+ require 'xcodeproj'
2
+
3
+ module Xfabricator
4
+
5
+ module PBXGroupAdditions
6
+
7
+ def xfab_create_subpath(path)
8
+ return self unless path
9
+
10
+ path = path.split('/') unless path.is_a?(Array)
11
+ child_name = path.shift
12
+ child = children.find { |c| c.display_name == child_name }
13
+
14
+ if child.nil?
15
+ child = new_group(nil, child_name)
16
+ end
17
+
18
+ if path.empty?
19
+ [ child ]
20
+ else
21
+ [ child ].concat child.xfab_create_subpath(path)
22
+ end
23
+ end
24
+
25
+ end
26
+
27
+ Xcodeproj::Project::Object::PBXGroup.include PBXGroupAdditions
28
+
29
+ end
data/xfabricator.gemspec CHANGED
@@ -25,6 +25,6 @@ Gem::Specification.new do |spec|
25
25
  spec.add_development_dependency "rake", "~> 10.0"
26
26
  spec.add_development_dependency "xcodeproj", "~> 1.4"
27
27
  spec.add_development_dependency "mustache", "~> 1.0"
28
- spec.add_development_dependency "inquirer"
28
+ spec.add_development_dependency "inquirer", "~> 0"
29
29
 
30
30
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: xfabricator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nicholas Cross
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-18 00:00:00.000000000 Z
11
+ date: 2017-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -70,14 +70,14 @@ dependencies:
70
70
  name: inquirer
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  description: Generate file templates and add them to XCode project...
@@ -100,6 +100,7 @@ files:
100
100
  - lib/xfabricator/template_definition.rb
101
101
  - lib/xfabricator/version.rb
102
102
  - lib/xfabricator/x_code_file_template.rb
103
+ - lib/xfabricator/xcodeproj_additions.rb
103
104
  - xfabricator.gemspec
104
105
  homepage: https://github.com/nicholascross/xfabricator
105
106
  licenses: