klipp 0.0.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (73) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/.travis.yml +5 -0
  4. data/README.md +13 -26
  5. data/bin/klipp +1 -1
  6. data/klipp.gemspec +11 -6
  7. data/lib/klipp/configuration.rb +0 -4
  8. data/lib/klipp/creator.rb +78 -0
  9. data/lib/klipp/parameter_list.rb +3 -3
  10. data/lib/klipp/version.rb +1 -1
  11. data/lib/klipp.rb +148 -92
  12. data/lib/template/spec.rb +231 -0
  13. data/lib/template/token.rb +81 -0
  14. data/lib/template.rb +59 -0
  15. data/spec/fixtures/ambiguous-repo/Ambiguous/Ambiguous.klippspec +5 -0
  16. data/spec/fixtures/projects/Klippfile +26 -0
  17. data/spec/fixtures/projects/Klippfile-after-prepare +27 -0
  18. data/spec/fixtures/projects/Klippfile-ambiguous +1 -0
  19. data/spec/fixtures/projects/Klippfile-bad-ruby +3 -0
  20. data/spec/fixtures/projects/Klippfile-minimal +1 -0
  21. data/spec/fixtures/projects/Klippfile-unambiguous +1 -0
  22. data/spec/fixtures/template-repository/Ambiguous/Ambiguous.klippspec +5 -0
  23. data/spec/fixtures/template-repository/Another-Template/Another-Template.klippspec +20 -0
  24. data/spec/fixtures/template-repository/BadExample/BadExample.klippspec +35 -0
  25. data/spec/fixtures/template-repository/Empty/Empty.klippspec +20 -0
  26. data/spec/fixtures/template-repository/Example/.gitignore +10 -0
  27. data/spec/fixtures/template-repository/Example/Example.klippspec +40 -0
  28. data/spec/fixtures/template-repository/Example/Podfile +10 -0
  29. data/spec/fixtures/template-repository/Example/XXBLANKXX.hidden +10 -0
  30. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Config/Base.xcconfig +8 -0
  31. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Images/Default-568h@2x.png +0 -0
  32. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Images/Default.png +0 -0
  33. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Images/Default@2x.png +0 -0
  34. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXAppDelegate.h +13 -0
  35. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXAppDelegate.m +30 -0
  36. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXRootViewController.h +11 -0
  37. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXRootViewController.m +30 -0
  38. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/XXPROJECT_TITLEXX-Info.plist +38 -0
  39. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/XXPROJECT_TITLEXX-Prefix.pch +14 -0
  40. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/en.lproj/Localizable.strings +1 -0
  41. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/main.m +17 -0
  42. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX/nl.lproj/Localizable.strings +1 -0
  43. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX.xcodeproj/project.pbxproj +466 -0
  44. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXX.xcodeproj/project.xcworkspace/contents.xcworkspacedata +7 -0
  45. data/spec/fixtures/template-repository/Example/XXPROJECT_IDXXTests/XXPROJECT_TITLEXXTests.m +22 -0
  46. data/spec/fixtures/template-repository/Interactive/Interactive.klippspec +15 -0
  47. data/spec/fixtures/template-repository/Interactive/XXSUBJECT_UNDER_TESTXXTests.m +15 -0
  48. data/spec/klipp/configuration_spec.rb +8 -0
  49. data/spec/klipp/creator_spec.rb +120 -0
  50. data/spec/klipp_spec.rb +80 -85
  51. data/spec/spec_helper.rb +8 -2
  52. data/spec/template/spec_spec.rb +225 -0
  53. data/spec/template/token_spec.rb +100 -0
  54. data/spec/template_spec.rb +82 -0
  55. metadata +118 -43
  56. data/lib/klipp/buffered_output.rb +0 -17
  57. data/lib/klipp/project.rb +0 -46
  58. data/lib/klipp/template.rb +0 -50
  59. data/lib/klipp/token.rb +0 -35
  60. data/spec/fixtures/klipps/Example.klippfile +0 -4
  61. data/spec/fixtures/klipps/ExcessiveExample.klippfile +0 -5
  62. data/spec/fixtures/klipps/Generated.klippfile +0 -11
  63. data/spec/fixtures/klipps/LackingExample.klippfile +0 -3
  64. data/spec/fixtures/klipps/MalformedExample.klippfile +0 -4
  65. data/spec/fixtures/klipps/single-token.yml +0 -5
  66. data/spec/fixtures/templates/Example/RegularFileWithContents.txt +0 -3
  67. data/spec/fixtures/templates/Example/XXCLASS_PREFIXXXPrefixedFile.txt +0 -3
  68. data/spec/fixtures/templates/Example/XXPROJECT_IDXX/BinaryFile.png +0 -0
  69. data/spec/fixtures/templates/Example/XXPROJECT_IDXX/XXCLASS_PREFIXXXPrefixedFileInDirectory.txt +0 -3
  70. data/spec/fixtures/templates/Example.yml +0 -29
  71. data/spec/klipp/project_spec.rb +0 -46
  72. data/spec/klipp/template_spec.rb +0 -80
  73. data/spec/klipp/token_spec.rb +0 -86
@@ -0,0 +1,82 @@
1
+ # coding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe Template do
5
+
6
+ context 'route' do
7
+
8
+ it 'raises a hint when not supplying any commands' do
9
+ expect { Template.route(*%w[]) }.to raise_error Klipp::Hint
10
+ end
11
+
12
+ it 'raises an error when supplying an unknown command' do
13
+ expect { Template.route(*%w[magic]) }.to raise_error RuntimeError
14
+ end
15
+
16
+ it 'routes list' do
17
+ Template.expects(:cli_list)
18
+ Template.route(*%w[list])
19
+ end
20
+
21
+ it 'routes spec' do
22
+ Template.expects(:cli_spec)
23
+ Template.route(*%w[spec])
24
+ end
25
+
26
+ end
27
+
28
+ context 'list' do
29
+
30
+ before do
31
+ Klipp::Configuration.stubs(:root_dir).returns(File.join(__dir__, 'fixtures'))
32
+ end
33
+
34
+ it 'lists the available templates, like Example' do
35
+ capture_stdout {
36
+ Template.cli_list
37
+ }.should include 'Example', 'template-repository'
38
+ end
39
+
40
+ end
41
+
42
+ context 'spec' do
43
+
44
+ before do
45
+ Klipp::Configuration.stubs(:root_dir).returns(File.join(__dir__, 'fixtures'))
46
+ end
47
+
48
+ it 'raises a hint without a template name' do
49
+ expect { Template.cli_spec(%w[]) }.to raise_error Klipp::Hint
50
+ end
51
+
52
+ it 'raises an error if the template name is malformed' do
53
+ expect { Template.cli_spec(['No.dots']) }.to raise_error RuntimeError
54
+ expect { Template.cli_spec(['No w&ird characters']) }.to raise_error RuntimeError
55
+ expect { Template.cli_spec(['No w&ird characters!']) }.to raise_error RuntimeError
56
+ end
57
+
58
+ it 'specs a .klippspec, like Empty.klippspec' do
59
+ File.expects(:write).with(File.join(Dir.pwd, 'Empty.klippspec'), read_fixture('Empty.klippspec'))
60
+ Template.cli_spec(%w[Empty])
61
+ end
62
+
63
+ it 'specs another .klippspec, like Another-Template.klippspec' do
64
+ File.expects(:write).with(File.join(Dir.pwd, 'Another-Template.klippspec'), read_fixture('Another-Template.klippspec'))
65
+ Template.cli_spec(%w[Another-Template])
66
+ end
67
+
68
+ it 'does not overwrite klippspecs' do
69
+ File.expects(:write).never
70
+ File.stubs(:exists?).returns(true)
71
+ Template.cli_spec(%w[Empty])
72
+ end
73
+
74
+ it 'will overwrite klippspecs when forced' do
75
+ File.expects(:write).with(File.join(Dir.pwd, 'Empty.klippspec'), read_fixture('Empty.klippspec'))
76
+ File.stubs(:exists?).returns(true)
77
+ Template.cli_spec(%w[Empty -f])
78
+ end
79
+
80
+ end
81
+
82
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: klipp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Eric-Paul Lecluse
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-09-04 00:00:00.000000000 Z
11
+ date: 2013-11-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -17,7 +17,7 @@ dependencies:
17
17
  - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.3'
20
- type: :development
20
+ type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
@@ -31,7 +31,7 @@ dependencies:
31
31
  - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
- type: :development
34
+ type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
@@ -39,13 +39,13 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: highline
42
+ name: ptools
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
- type: :development
48
+ type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
@@ -53,13 +53,41 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: ptools
56
+ name: formatador
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: colorize
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: grit
57
85
  requirement: !ruby/object:Gem::Requirement
58
86
  requirements:
59
87
  - - '>='
60
88
  - !ruby/object:Gem::Version
61
89
  version: '0'
62
- type: :development
90
+ type: :runtime
63
91
  prerelease: false
64
92
  version_requirements: !ruby/object:Gem::Requirement
65
93
  requirements:
@@ -67,13 +95,13 @@ dependencies:
67
95
  - !ruby/object:Gem::Version
68
96
  version: '0'
69
97
  - !ruby/object:Gem::Dependency
70
- name: colored
98
+ name: highline
71
99
  requirement: !ruby/object:Gem::Requirement
72
100
  requirements:
73
101
  - - '>='
74
102
  - !ruby/object:Gem::Version
75
103
  version: '0'
76
- type: :development
104
+ type: :runtime
77
105
  prerelease: false
78
106
  version_requirements: !ruby/object:Gem::Requirement
79
107
  requirements:
@@ -89,6 +117,7 @@ extensions: []
89
117
  extra_rdoc_files: []
90
118
  files:
91
119
  - .gitignore
120
+ - .travis.yml
92
121
  - Gemfile
93
122
  - LICENSE.txt
94
123
  - README.md
@@ -97,30 +126,53 @@ files:
97
126
  - build_klipp.sh
98
127
  - klipp.gemspec
99
128
  - lib/klipp.rb
100
- - lib/klipp/buffered_output.rb
101
129
  - lib/klipp/configuration.rb
130
+ - lib/klipp/creator.rb
102
131
  - lib/klipp/parameter_list.rb
103
- - lib/klipp/project.rb
104
- - lib/klipp/template.rb
105
- - lib/klipp/token.rb
106
132
  - lib/klipp/version.rb
107
- - spec/fixtures/klipps/Example.klippfile
108
- - spec/fixtures/klipps/ExcessiveExample.klippfile
109
- - spec/fixtures/klipps/Generated.klippfile
110
- - spec/fixtures/klipps/LackingExample.klippfile
111
- - spec/fixtures/klipps/MalformedExample.klippfile
112
- - spec/fixtures/klipps/single-token.yml
113
- - spec/fixtures/templates/Example.yml
114
- - spec/fixtures/templates/Example/RegularFileWithContents.txt
115
- - spec/fixtures/templates/Example/XXCLASS_PREFIXXXPrefixedFile.txt
116
- - spec/fixtures/templates/Example/XXPROJECT_IDXX/BinaryFile.png
117
- - spec/fixtures/templates/Example/XXPROJECT_IDXX/XXCLASS_PREFIXXXPrefixedFileInDirectory.txt
133
+ - lib/template.rb
134
+ - lib/template/spec.rb
135
+ - lib/template/token.rb
136
+ - spec/fixtures/ambiguous-repo/Ambiguous/Ambiguous.klippspec
137
+ - spec/fixtures/projects/Klippfile
138
+ - spec/fixtures/projects/Klippfile-after-prepare
139
+ - spec/fixtures/projects/Klippfile-ambiguous
140
+ - spec/fixtures/projects/Klippfile-bad-ruby
141
+ - spec/fixtures/projects/Klippfile-minimal
142
+ - spec/fixtures/projects/Klippfile-unambiguous
143
+ - spec/fixtures/template-repository/Ambiguous/Ambiguous.klippspec
144
+ - spec/fixtures/template-repository/Another-Template/Another-Template.klippspec
145
+ - spec/fixtures/template-repository/BadExample/BadExample.klippspec
146
+ - spec/fixtures/template-repository/Empty/Empty.klippspec
147
+ - spec/fixtures/template-repository/Example/.gitignore
148
+ - spec/fixtures/template-repository/Example/Example.klippspec
149
+ - spec/fixtures/template-repository/Example/Podfile
150
+ - spec/fixtures/template-repository/Example/XXBLANKXX.hidden
151
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX.xcodeproj/project.pbxproj
152
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX.xcodeproj/project.xcworkspace/contents.xcworkspacedata
153
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Config/Base.xcconfig
154
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Images/Default-568h@2x.png
155
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Images/Default.png
156
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Images/Default@2x.png
157
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXAppDelegate.h
158
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXAppDelegate.m
159
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXRootViewController.h
160
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXRootViewController.m
161
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/XXPROJECT_TITLEXX-Info.plist
162
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/XXPROJECT_TITLEXX-Prefix.pch
163
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/en.lproj/Localizable.strings
164
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/main.m
165
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/nl.lproj/Localizable.strings
166
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXXTests/XXPROJECT_TITLEXXTests.m
167
+ - spec/fixtures/template-repository/Interactive/Interactive.klippspec
168
+ - spec/fixtures/template-repository/Interactive/XXSUBJECT_UNDER_TESTXXTests.m
118
169
  - spec/klipp/configuration_spec.rb
119
- - spec/klipp/project_spec.rb
120
- - spec/klipp/template_spec.rb
121
- - spec/klipp/token_spec.rb
170
+ - spec/klipp/creator_spec.rb
122
171
  - spec/klipp_spec.rb
123
172
  - spec/spec_helper.rb
173
+ - spec/template/spec_spec.rb
174
+ - spec/template/token_spec.rb
175
+ - spec/template_spec.rb
124
176
  homepage: https://github.com/epologee/klipp
125
177
  licenses:
126
178
  - MIT
@@ -141,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
141
193
  version: '0'
142
194
  requirements: []
143
195
  rubyforge_project:
144
- rubygems_version: 2.0.2
196
+ rubygems_version: 2.0.3
145
197
  signing_key:
146
198
  specification_version: 4
147
199
  summary: Klipp is a command line gem for creating new (Xcode) projects from existing
@@ -149,20 +201,43 @@ summary: Klipp is a command line gem for creating new (Xcode) projects from exis
149
201
  existing Xcode project and creates a new project by copying and modifying an existing
150
202
  template project by your own specifications.
151
203
  test_files:
152
- - spec/fixtures/klipps/Example.klippfile
153
- - spec/fixtures/klipps/ExcessiveExample.klippfile
154
- - spec/fixtures/klipps/Generated.klippfile
155
- - spec/fixtures/klipps/LackingExample.klippfile
156
- - spec/fixtures/klipps/MalformedExample.klippfile
157
- - spec/fixtures/klipps/single-token.yml
158
- - spec/fixtures/templates/Example.yml
159
- - spec/fixtures/templates/Example/RegularFileWithContents.txt
160
- - spec/fixtures/templates/Example/XXCLASS_PREFIXXXPrefixedFile.txt
161
- - spec/fixtures/templates/Example/XXPROJECT_IDXX/BinaryFile.png
162
- - spec/fixtures/templates/Example/XXPROJECT_IDXX/XXCLASS_PREFIXXXPrefixedFileInDirectory.txt
204
+ - spec/fixtures/ambiguous-repo/Ambiguous/Ambiguous.klippspec
205
+ - spec/fixtures/projects/Klippfile
206
+ - spec/fixtures/projects/Klippfile-after-prepare
207
+ - spec/fixtures/projects/Klippfile-ambiguous
208
+ - spec/fixtures/projects/Klippfile-bad-ruby
209
+ - spec/fixtures/projects/Klippfile-minimal
210
+ - spec/fixtures/projects/Klippfile-unambiguous
211
+ - spec/fixtures/template-repository/Ambiguous/Ambiguous.klippspec
212
+ - spec/fixtures/template-repository/Another-Template/Another-Template.klippspec
213
+ - spec/fixtures/template-repository/BadExample/BadExample.klippspec
214
+ - spec/fixtures/template-repository/Empty/Empty.klippspec
215
+ - spec/fixtures/template-repository/Example/.gitignore
216
+ - spec/fixtures/template-repository/Example/Example.klippspec
217
+ - spec/fixtures/template-repository/Example/Podfile
218
+ - spec/fixtures/template-repository/Example/XXBLANKXX.hidden
219
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX.xcodeproj/project.pbxproj
220
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX.xcodeproj/project.xcworkspace/contents.xcworkspacedata
221
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Config/Base.xcconfig
222
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Images/Default-568h@2x.png
223
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Images/Default.png
224
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Images/Default@2x.png
225
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXAppDelegate.h
226
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXAppDelegate.m
227
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXRootViewController.h
228
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/Source/XXCLASS_PREFIXXXRootViewController.m
229
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/XXPROJECT_TITLEXX-Info.plist
230
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/XXPROJECT_TITLEXX-Prefix.pch
231
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/en.lproj/Localizable.strings
232
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/main.m
233
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXX/nl.lproj/Localizable.strings
234
+ - spec/fixtures/template-repository/Example/XXPROJECT_IDXXTests/XXPROJECT_TITLEXXTests.m
235
+ - spec/fixtures/template-repository/Interactive/Interactive.klippspec
236
+ - spec/fixtures/template-repository/Interactive/XXSUBJECT_UNDER_TESTXXTests.m
163
237
  - spec/klipp/configuration_spec.rb
164
- - spec/klipp/project_spec.rb
165
- - spec/klipp/template_spec.rb
166
- - spec/klipp/token_spec.rb
238
+ - spec/klipp/creator_spec.rb
167
239
  - spec/klipp_spec.rb
168
240
  - spec/spec_helper.rb
241
+ - spec/template/spec_spec.rb
242
+ - spec/template/token_spec.rb
243
+ - spec/template_spec.rb
@@ -1,17 +0,0 @@
1
- module BufferedOutput
2
- module ClassMethods
3
- @@output = nil
4
-
5
- def output=(output)
6
- @@output = output
7
- end
8
-
9
- def output
10
- @@output || $stdout
11
- end
12
-
13
- def buffer_puts(output)
14
- self.output.puts output
15
- end
16
- end
17
- end
data/lib/klipp/project.rb DELETED
@@ -1,46 +0,0 @@
1
- require 'ptools'
2
- require 'fileutils'
3
-
4
- module Klipp
5
-
6
- class Project
7
-
8
- def initialize(template)
9
- @template = template
10
- end
11
-
12
- def create
13
- # Check template directory exists
14
- # Copy all files while adjusting paths
15
- source_template_dir = File.join(Klipp::Configuration.templates_dir, @template.name)
16
- target_template_dir = File.join(Dir.pwd, @template.name)
17
-
18
- raise "Target directory already exists. Klipp will not overwrite your project: #{target_template_dir}" if File.exists? target_template_dir
19
-
20
- @source_files = Dir.glob(File.join(source_template_dir, '**', '*'))
21
- @source_files.each do |source_file|
22
- transfer_file source_file, target_file(source_template_dir, source_file, target_template_dir)
23
- end
24
- end
25
-
26
- def target_file(source_template_dir, source_file, target_template_dir)
27
- stripped_path = source_file.gsub(source_template_dir, '')
28
- customizable_path = @template.replace_tokens(stripped_path)
29
- File.join(target_template_dir, customizable_path)
30
- end
31
-
32
- def transfer_file(source_file, target_file)
33
- FileUtils.mkdir_p File.dirname(target_file)
34
-
35
- if File.directory? source_file
36
- FileUtils.mkdir_p target_file
37
- elsif File.binary? source_file
38
- FileUtils.cp(source_file, target_file)
39
- else
40
- IO.write target_file, @template.replace_tokens(File.read(source_file))
41
- end
42
- end
43
-
44
- end
45
-
46
- end
@@ -1,50 +0,0 @@
1
- require 'yaml'
2
- require 'erb'
3
-
4
- module Klipp
5
-
6
- class Template
7
- attr_reader :tokens, :name
8
-
9
- def initialize path, name
10
- @name = name
11
- raise 'Attempted to initialize template without name' unless name
12
-
13
- full_path = File.join(path, "#{name}.yml")
14
- raise "Unknown template name: #{name} (in template directory #{path})" unless File.exists?(full_path)
15
- yaml_tokens = YAML.load(File.read(full_path))
16
-
17
- @tokens = Hash[yaml_tokens.map { |token_name, values| [token_name, Klipp::Token.new(values)] }]
18
- end
19
-
20
- def [](name)
21
- @tokens[name].value
22
- end
23
-
24
- def []=(name, value)
25
- @tokens[name].value=value
26
- end
27
-
28
- def load_klippfile(klippfile)
29
- yaml = YAML.load(File.read(klippfile))
30
- raise 'Tokens not matching' unless yaml.keys == @tokens.keys
31
- yaml.each { |name, value| self[name] = value }
32
- end
33
-
34
- def klippfile
35
- "#{@name}.klippfile"
36
- end
37
-
38
- def generated_klippfile
39
- @tokens.map { |name, t| "#{name}:\n# #{t.subtitle}" }.join("\n\n")
40
- end
41
-
42
- def replace_tokens(string_with_tokens, delimiter='XX')
43
- replaced = string_with_tokens
44
- @tokens.each { |name, t| replaced.gsub!(delimiter+name+delimiter, t.value ? t.value.to_s : '') }
45
- replaced
46
- end
47
-
48
- end
49
-
50
- end
data/lib/klipp/token.rb DELETED
@@ -1,35 +0,0 @@
1
- require 'yaml'
2
-
3
- module Klipp
4
-
5
- class Token
6
- attr_accessor :value
7
- attr_reader :title, :subtitle, :default, :validate, :not_valid_response
8
-
9
- def initialize(token_yml)
10
- if token_yml.is_a? String
11
- parsed = YAML.load token_yml
12
- else
13
- parsed = token_yml
14
- end
15
-
16
- @title = parsed['title']
17
- @subtitle = parsed['subtitle']
18
- @default = parsed['default']
19
- @validate = parsed['validate']
20
- @not_valid_response = parsed['not_valid_response']
21
-
22
- rescue Exception => e
23
- p token_yml
24
- end
25
-
26
- def ask_for_input(terminal = nil)
27
- @value = (terminal || HighLine.new).ask("\n<%= color('#{@title}', BOLD) %> #{"(#{@subtitle})" if @subtitle})?") do |q|
28
- q.default = @default if @default
29
- q.validate = @validate if @validate
30
- q.responses[:not_valid] = @not_valid_response if @not_valid_response
31
- end
32
- end
33
-
34
- end
35
- end
@@ -1,4 +0,0 @@
1
- PARTNER: The Prestigeous Partner
2
- PROJECT_TITLE: Project X
3
- PROJECT_ID: ProjectX
4
- CLASS_PREFIX: PJX
@@ -1,5 +0,0 @@
1
- PARTNER: The Prestigeous Partner
2
- PROJECT_TITLE: Project X
3
- PROJECT_ID: ProjectX
4
- CLASS_PREFIX: PJX
5
- EXTRA_TOKEN: Bad Token
@@ -1,11 +0,0 @@
1
- PARTNER:
2
- # e.g. 'FC Utrecht'
3
-
4
- PROJECT_TITLE:
5
- # e.g. 'FC Utrecht Agenda'
6
-
7
- PROJECT_ID:
8
- # e.g. 'FCUtrechtAgenda'
9
-
10
- CLASS_PREFIX:
11
- # e.g. 'FCU'
@@ -1,3 +0,0 @@
1
- PARTNER: The Prestigeous Partner
2
- PROJECT_TITLE: Project X
3
- PROJECT_ID: ProjectX
@@ -1,4 +0,0 @@
1
- PARTNERSSSSSS: The Prestigeous Partner
2
- PROJECT_TITLE: Project X
3
- PROJECT_ID: ProjectX
4
- CLASS_PREFIX: PJX
@@ -1,5 +0,0 @@
1
- title: Partner name
2
- subtitle: e.g. 'FC Utrecht'
3
- default: Qwerty
4
- validate: !ruby/regexp '/^[A-Z][A-Za-z0-9 ]{2,}$/'
5
- not_valid_response: Should be at least three characters long and start with a capital character
@@ -1,3 +0,0 @@
1
- Regular content stays untouched
2
- Tokens are replaced: XXPROJECT_IDXX
3
- Even if it's in the middle of something else BlablablaXXPROJECT_IDXXBlabla
@@ -1,3 +0,0 @@
1
- Regular content stays untouched
2
- Tokens are replaced: XXPROJECT_IDXX
3
- Even if it's in the middle of something else BlablablaXXPROJECT_IDXXBlabla
@@ -1,3 +0,0 @@
1
- Regular content stays untouched
2
- Tokens are replaced: XXPROJECT_IDXX
3
- Even if it's in the middle of something else BlablablaXXPROJECT_IDXXBlabla
@@ -1,29 +0,0 @@
1
- PARTNER:
2
- title: Partner name
3
- subtitle: e.g. 'FC Utrecht'
4
- default: Qwerty
5
- validate: !ruby/regexp '/^[A-Z][A-Za-z0-9 ]{2,}$/'
6
- not_valid_response: Should be at least three characters long and start with a capital character
7
-
8
- PROJECT_TITLE:
9
- title: Project title
10
- subtitle: e.g. 'FC Utrecht Agenda'
11
- default: #PARTNER# Agenda
12
- validate: !ruby/regexp '/^[A-Z][A-Za-z0-9 ]{2,}$/'
13
- not_valid_response: Should be at least three characters long and start with a capital character
14
-
15
- PROJECT_ID:
16
- title: Project id
17
- subtitle: e.g. 'FCUtrechtAgenda'
18
- default: #PROJECT_ID#
19
- whitespace: :strip_and_collapse
20
- validate: !ruby/regexp '/^[A-Z][A-Za-z0-9 ]{2,}$/'
21
- not_valid_response: Should be at least three characters long and start with a capital character
22
-
23
- CLASS_PREFIX:
24
- title: Class prefix
25
- subtitle: e.g. 'FCU'
26
- default: #PROJECT_ID#
27
- whitespace: :strip_and_collapse
28
- validate: !ruby/regexp '/^[A-Z][A-Za-z0-9 ]{2,}$/'
29
- not_valid_response: Should be at least three characters long and start with a capital character
@@ -1,46 +0,0 @@
1
- require 'spec_helper'
2
- require 'tmpdir'
3
-
4
- describe Klipp::Project do
5
-
6
- context 'with a template' do
7
-
8
- before do
9
- fixtures_dir = File.join(File.dirname(__dir__), 'fixtures')
10
- Klipp::Configuration.stubs(:root_dir).returns fixtures_dir
11
- @template = Klipp::Template.new(Klipp::Configuration.templates_dir, 'Example')
12
- @template.load_klippfile File.join(fixtures_dir, 'klipps', 'Example.klippfile')
13
- @project = Klipp::Project.new(@template)
14
- Dir.stubs(:pwd).returns(Dir.mktmpdir)
15
- end
16
-
17
- it 'copies files while replacing paths' do
18
- @project.create
19
- File.exists?(File.join Dir.pwd, 'Example', 'ProjectX').should be true
20
- File.exists?(File.join Dir.pwd, 'Example', 'PJXPrefixedFile.txt').should be true
21
- File.exists?(File.join Dir.pwd, 'Example', 'ProjectX', 'BinaryFile.png').should be true
22
- File.exists?(File.join Dir.pwd, 'Example', 'ProjectX', 'PJXPrefixedFileInDirectory.txt').should be true
23
- end
24
-
25
- it 'replaces file contens while transferring' do
26
- @project.create
27
- File.read(File.join Dir.pwd, 'Example', 'PJXPrefixedFile.txt').should include 'Regular content stays untouched'
28
- File.read(File.join Dir.pwd, 'Example', 'PJXPrefixedFile.txt').should include 'Tokens are replaced: ProjectX'
29
- File.read(File.join Dir.pwd, 'Example', 'PJXPrefixedFile.txt').should include 'Even if it\'s in the middle of something else BlablablaProjectXBlabla'
30
- end
31
-
32
- it 'copies binary files without replacing contents' do
33
- @project.create
34
- template_png = File.join(Klipp::Configuration.templates_dir, 'Example', 'XXPROJECT_IDXX', 'BinaryFile.png')
35
- transferred_png = File.join(Dir.pwd, 'Example', 'ProjectX', 'BinaryFile.png')
36
- FileUtils.compare_file(template_png, transferred_png).should be true
37
- end
38
-
39
- it 'halts transfer if the directory already exists' do
40
- FileUtils.mkdir_p File.join(Dir.pwd, 'Example')
41
- expect { @project.create }.to raise_error RuntimeError
42
- end
43
-
44
- end
45
-
46
- end