stevenson 1.0.1 → 2.0.0

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.
Files changed (49) hide show
  1. checksums.yaml +4 -4
  2. data/.travis.yml +2 -0
  3. data/assets/stevenson_dotfile.yml +29 -0
  4. data/lib/stevenson/application.rb +34 -29
  5. data/lib/stevenson/dotfile.rb +26 -0
  6. data/lib/stevenson/output_filter/generator.rb +30 -0
  7. data/lib/stevenson/output_filter.rb +42 -0
  8. data/lib/stevenson/output_filters/jekyll.rb +6 -13
  9. data/lib/stevenson/output_filters/zip.rb +12 -14
  10. data/lib/stevenson/template/loader.rb +36 -0
  11. data/lib/stevenson/template.rb +35 -0
  12. data/lib/stevenson/templates/git.rb +16 -17
  13. data/lib/stevenson/templates/local.rb +21 -0
  14. data/lib/stevenson/version.rb +1 -1
  15. data/lib/stevenson.rb +9 -7
  16. data/spec/bin/.gitkeep +0 -0
  17. data/spec/lib/output_filter/generator_spec.rb +37 -0
  18. data/spec/lib/output_filter_spec.rb +57 -0
  19. data/spec/lib/output_filters/jekyll_spec.rb +23 -0
  20. data/spec/lib/output_filters/zip_spec.rb +19 -0
  21. data/spec/lib/template/loader_spec.rb +35 -0
  22. data/spec/lib/template_spec.rb +20 -0
  23. data/spec/lib/templates/git_spec.rb +43 -0
  24. data/spec/lib/templates/local_spec.rb +42 -0
  25. data/stevenson.gemspec +3 -2
  26. metadata +44 -40
  27. data/assets/template_aliases.yml +0 -36
  28. data/lib/stevenson/configurators/yaml_configurator.rb +0 -79
  29. data/lib/stevenson/input/email.rb +0 -19
  30. data/lib/stevenson/input/password.rb +0 -19
  31. data/lib/stevenson/input/select.rb +0 -69
  32. data/lib/stevenson/input/text.rb +0 -28
  33. data/lib/stevenson/input/url.rb +0 -19
  34. data/lib/stevenson/input.rb +0 -51
  35. data/lib/stevenson/template_loader.rb +0 -50
  36. data/lib/stevenson/templates/base.rb +0 -45
  37. data/lib/stevenson/templates/invalid_template_exception.rb +0 -6
  38. data/spec/configurators/yaml_configurator_spec.rb +0 -12
  39. data/spec/input/email_spec.rb +0 -12
  40. data/spec/input/password_spec.rb +0 -12
  41. data/spec/input/select_spec.rb +0 -12
  42. data/spec/input/text_spec.rb +0 -12
  43. data/spec/input/url_spec.rb +0 -12
  44. data/spec/input_spec.rb +0 -38
  45. data/spec/output_filters/jekyll_spec.rb +0 -17
  46. data/spec/output_filters/zip_spec.rb +0 -17
  47. data/spec/template_loader_spec.rb +0 -51
  48. data/spec/templates/base_spec.rb +0 -83
  49. data/spec/templates/git_spec.rb +0 -37
@@ -0,0 +1,20 @@
1
+ describe Stevenson::Template do
2
+ let(:template_name) { 'template' }
3
+ let(:options) { Hash.new }
4
+
5
+ describe ".load(template, options)" do
6
+ let(:template) { double(:template) }
7
+ let(:loader) { double(:loader, template: template) }
8
+ subject { described_class.load(template_name, options) }
9
+
10
+ it "should call Loader.new with template_name and options" do
11
+ expect(Stevenson::Template::Loader).to receive(:new).with(template_name, options).and_return(loader)
12
+ subject
13
+ end
14
+
15
+ it "should return Loader's template response" do
16
+ allow(Stevenson::Template::Loader).to receive(:new).and_return(loader)
17
+ expect(subject).to eq template
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,43 @@
1
+ describe Stevenson::Template::Git do
2
+ let(:template_url) { 'http://www.github.com/Org/repo.git' }
3
+ let(:options) { Hash.new }
4
+ subject { described_class.new(template_url, options) }
5
+
6
+ describe '#local_directory' do
7
+ let(:tmp_dir) { '/tmp/dir/to/template' }
8
+ before { allow(Dir).to receive(:mktmpdir).and_return(tmp_dir) }
9
+
10
+ context 'when template_url is a valid URL' do
11
+ let(:git_repo) { double(:git_repo) }
12
+ before { allow(::Git).to receive(:clone).and_return(git_repo) }
13
+
14
+ it 'returns a temp directory' do
15
+ expect(subject.local_directory).to eq tmp_dir
16
+ end
17
+
18
+ it 'clones the given repository to the working template path' do
19
+ expect(::Git).to receive(:clone).with(template_url, tmp_dir)
20
+ subject.local_directory
21
+ end
22
+
23
+ context "when the :branch option is set" do
24
+ let(:branch) { 'test-branch' }
25
+ let(:options) { { branch: branch } }
26
+
27
+ it "should check out the related branch" do
28
+ expect(git_repo).to receive(:checkout).with(branch).and_return(true)
29
+ subject.local_directory
30
+ end
31
+ end
32
+ end
33
+
34
+ context 'when template_url is an invalid URL' do
35
+ let(:template_url) { 'not/a/repo' }
36
+ before { allow(::Git).to receive(:clone).and_raise(::Git::GitExecuteError) }
37
+
38
+ it 'raises an invalid template exception' do
39
+ expect { subject.local_directory }.to raise_exception(Stevenson::Template::InvalidTemplateException)
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,42 @@
1
+ describe Stevenson::Template::Local do
2
+ let(:template_path) { '/path/to/local/template' }
3
+ let(:options) { Hash.new }
4
+ subject { described_class.new(template_path, options) }
5
+
6
+ describe '#local_directory' do
7
+ let(:tmp_dir) { '/tmp/dir/to/template' }
8
+ before { allow(Dir).to receive(:mktmpdir).and_return(tmp_dir) }
9
+
10
+ context 'when template_path is a valid path' do
11
+ before { allow(File).to receive(:directory?).and_return(true) }
12
+
13
+ it 'returns a temp directory' do
14
+ allow(FileUtils).to receive(:cp_r).and_return(true)
15
+ expect(subject.local_directory).to eq tmp_dir
16
+ end
17
+
18
+ it "copies the template_path's contents to the temp directory" do
19
+ expect(FileUtils).to receive(:cp_r).with("#{template_path}/.", tmp_dir).and_return(true)
20
+ expect(subject.local_directory).to eq tmp_dir
21
+ end
22
+
23
+ context "when the :subdirectory option is set" do
24
+ let(:subdirectory) { 'subdirectory' }
25
+ let(:options) { { subdirectory: subdirectory } }
26
+
27
+ it "should copy the template_path's subdirectory" do
28
+ expect(FileUtils).to receive(:cp_r).with("#{template_path}/#{subdirectory}/.", tmp_dir).and_return(true)
29
+ subject.local_directory
30
+ end
31
+ end
32
+ end
33
+
34
+ context 'when template_path is an invalid path' do
35
+ before { allow(File).to receive(:directory?).and_return(false) }
36
+
37
+ it 'raises an invalid template exception' do
38
+ expect { subject.local_directory }.to raise_exception(Stevenson::Template::InvalidTemplateException)
39
+ end
40
+ end
41
+ end
42
+ end
data/stevenson.gemspec CHANGED
@@ -6,8 +6,8 @@ require 'stevenson/version'
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "stevenson"
8
8
  spec.version = Stevenson::VERSION
9
- spec.authors = ["Dylan Karr"]
10
- spec.email = ["dylan@RootsRated.com"]
9
+ spec.authors = ["RootsRated"]
10
+ spec.email = ["developers@rootsrated.com"]
11
11
  spec.summary = "Stevenson is a generator for Jekyll microsites created by RootsRated.com"
12
12
  spec.description = "Stevenson is a simple generator for microsites using Jekyll"
13
13
  spec.homepage = ""
@@ -23,6 +23,7 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "rspec"
24
24
 
25
25
  spec.add_dependency "git"
26
+ spec.add_dependency "hashie"
26
27
  spec.add_dependency "highline"
27
28
  spec.add_dependency "jekyll"
28
29
  spec.add_dependency "rubyzip", ">= 1.0.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stevenson
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
- - Dylan Karr
7
+ - RootsRated
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-14 00:00:00.000000000 Z
11
+ date: 2015-09-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: hashie
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'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: highline
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -124,7 +138,7 @@ dependencies:
124
138
  version: '0'
125
139
  description: Stevenson is a simple generator for microsites using Jekyll
126
140
  email:
127
- - dylan@RootsRated.com
141
+ - developers@rootsrated.com
128
142
  executables:
129
143
  - stevenson
130
144
  extensions: []
@@ -137,38 +151,31 @@ files:
137
151
  - LICENSE.txt
138
152
  - README.md
139
153
  - Rakefile
140
- - assets/template_aliases.yml
154
+ - assets/stevenson_dotfile.yml
141
155
  - bin/stevenson
142
156
  - lib/stevenson.rb
143
157
  - lib/stevenson/application.rb
144
- - lib/stevenson/configurators/yaml_configurator.rb
145
- - lib/stevenson/input.rb
146
- - lib/stevenson/input/email.rb
147
- - lib/stevenson/input/password.rb
148
- - lib/stevenson/input/select.rb
149
- - lib/stevenson/input/text.rb
150
- - lib/stevenson/input/url.rb
158
+ - lib/stevenson/dotfile.rb
159
+ - lib/stevenson/output_filter.rb
160
+ - lib/stevenson/output_filter/generator.rb
151
161
  - lib/stevenson/output_filters/jekyll.rb
152
162
  - lib/stevenson/output_filters/zip.rb
153
- - lib/stevenson/template_loader.rb
154
- - lib/stevenson/templates/base.rb
163
+ - lib/stevenson/template.rb
164
+ - lib/stevenson/template/loader.rb
155
165
  - lib/stevenson/templates/git.rb
156
- - lib/stevenson/templates/invalid_template_exception.rb
166
+ - lib/stevenson/templates/local.rb
157
167
  - lib/stevenson/version.rb
158
- - spec/configurators/yaml_configurator_spec.rb
168
+ - spec/bin/.gitkeep
159
169
  - spec/helpers.rb
160
- - spec/input/email_spec.rb
161
- - spec/input/password_spec.rb
162
- - spec/input/select_spec.rb
163
- - spec/input/text_spec.rb
164
- - spec/input/url_spec.rb
165
- - spec/input_spec.rb
166
- - spec/output_filters/jekyll_spec.rb
167
- - spec/output_filters/zip_spec.rb
170
+ - spec/lib/output_filter/generator_spec.rb
171
+ - spec/lib/output_filter_spec.rb
172
+ - spec/lib/output_filters/jekyll_spec.rb
173
+ - spec/lib/output_filters/zip_spec.rb
174
+ - spec/lib/template/loader_spec.rb
175
+ - spec/lib/template_spec.rb
176
+ - spec/lib/templates/git_spec.rb
177
+ - spec/lib/templates/local_spec.rb
168
178
  - spec/spec_helper.rb
169
- - spec/template_loader_spec.rb
170
- - spec/templates/base_spec.rb
171
- - spec/templates/git_spec.rb
172
179
  - stevenson.gemspec
173
180
  homepage: ''
174
181
  licenses:
@@ -190,22 +197,19 @@ required_rubygems_version: !ruby/object:Gem::Requirement
190
197
  version: '0'
191
198
  requirements: []
192
199
  rubyforge_project:
193
- rubygems_version: 2.4.6
200
+ rubygems_version: 2.4.3
194
201
  signing_key:
195
202
  specification_version: 4
196
203
  summary: Stevenson is a generator for Jekyll microsites created by RootsRated.com
197
204
  test_files:
198
- - spec/configurators/yaml_configurator_spec.rb
205
+ - spec/bin/.gitkeep
199
206
  - spec/helpers.rb
200
- - spec/input/email_spec.rb
201
- - spec/input/password_spec.rb
202
- - spec/input/select_spec.rb
203
- - spec/input/text_spec.rb
204
- - spec/input/url_spec.rb
205
- - spec/input_spec.rb
206
- - spec/output_filters/jekyll_spec.rb
207
- - spec/output_filters/zip_spec.rb
207
+ - spec/lib/output_filter/generator_spec.rb
208
+ - spec/lib/output_filter_spec.rb
209
+ - spec/lib/output_filters/jekyll_spec.rb
210
+ - spec/lib/output_filters/zip_spec.rb
211
+ - spec/lib/template/loader_spec.rb
212
+ - spec/lib/template_spec.rb
213
+ - spec/lib/templates/git_spec.rb
214
+ - spec/lib/templates/local_spec.rb
208
215
  - spec/spec_helper.rb
209
- - spec/template_loader_spec.rb
210
- - spec/templates/base_spec.rb
211
- - spec/templates/git_spec.rb
@@ -1,36 +0,0 @@
1
- hyde-base:
2
- git: https://github.com/RootsRated/hyde.git
3
- subdirectory: base
4
- templatedco-exmachina:
5
- git: https://github.com/RootsRated/hyde.git
6
- subdirectory: exmachina
7
- templatedco-horizons:
8
- git: https://github.com/RootsRated/hyde.git
9
- subdirectory: horizons
10
- templatedco-ion:
11
- git: https://github.com/RootsRated/hyde.git
12
- subdirectory: ion
13
- templatedco-linear:
14
- git: https://github.com/RootsRated/hyde.git
15
- subdirectory: linear
16
- templatedco-phaseshift:
17
- git: https://github.com/RootsRated/hyde.git
18
- subdirectory: phaseshift
19
- templatedco-solarize:
20
- git: https://github.com/RootsRated/hyde.git
21
- subdirectory: solarize
22
- rr-base:
23
- git: https://github.com/RootsRated/rootsrated_hyde.git
24
- subdirectory: base
25
- rr-ironman:
26
- git: https://github.com/RootsRated/rootsrated_hyde.git
27
- subdirectory: ironman
28
- rr-graphite:
29
- git: https://github.com/RootsRated/rootsrated_hyde.git
30
- subdirectory: graphite
31
- rr-new-balance:
32
- git: https://github.com/RootsRated/rootsrated_hyde.git
33
- subdirectory: new-balance
34
- rr-ski:
35
- git: https://github.com/RootsRated/rootsrated_hyde.git
36
- subdirectory: ski
@@ -1,79 +0,0 @@
1
- require 'yaml'
2
-
3
- module Stevenson
4
- module Configurator
5
- class YAMLConfigurator
6
- def initialize(config_path)
7
- # Save the config path for later use
8
- @config_path = config_path
9
-
10
- # Load options from the template
11
- @root_options = load_yaml File.join(config_path, '_stevenson.yml')
12
- end
13
-
14
- def configure(path=nil, options=nil)
15
- # If no options are provided, use the root_options
16
- options ||= @root_options
17
-
18
- # If no path is provided, use the config_path
19
- path ||= @config_path
20
-
21
- # If the path is a directory, recursively configure that directory
22
- if File.directory? path
23
- # Iterate through each option provided
24
- options.each do |key, value|
25
- configure "#{path}/#{key}", value
26
- end
27
- else
28
- # If path is a file, load the YAML from that file
29
- config = load_yaml path
30
-
31
- # Collect answers for the config in the file
32
- config = collect_answers options, config
33
-
34
- # And save the config back to YAML file.
35
- save_yaml path, config
36
- end
37
- end
38
-
39
- private
40
-
41
- def collect_answers(options, config)
42
- if !options['type'] || options['type'].is_a?(Hash)
43
- # If the current option is not a leaf, iterate over its values
44
- options.each do |key, value|
45
- # If no key is present in the config, assign one
46
- config[key] = {} unless config[key]
47
-
48
- # Recursively collect answers for the current key in the config and
49
- # options
50
- config[key] = collect_answers value, config[key]
51
- end
52
-
53
- # Return the new config
54
- config
55
- else
56
- # Collect the appropriate answer for the given question
57
- Input.input_for(options).collect!
58
- end
59
- end
60
-
61
- def load_yaml(path)
62
- # If a YAML file is present, load it
63
- if File.file? path
64
- YAML.load_file(path) || {}
65
- else
66
- # Otherwise, return an empty hash
67
- {}
68
- end
69
- end
70
-
71
- def save_yaml(path, config)
72
- # Write config to path as YAML
73
- File.open(path, 'w') do |f|
74
- f.write config.to_yaml
75
- end
76
- end
77
- end
78
- end
79
- end
@@ -1,19 +0,0 @@
1
- module Stevenson
2
- module Input
3
- class Email < Text
4
- include Base
5
-
6
- def collect!
7
- # Ask the user the question and apply the appropriate options
8
- answer = ask(@prompt) do |q|
9
- q.default = default
10
- q.validate = /\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i
11
- q.limit = @limit if @limit
12
- end
13
-
14
- # Return the user's answer
15
- answer.to_s
16
- end
17
- end
18
- end
19
- end
@@ -1,19 +0,0 @@
1
- module Stevenson
2
- module Input
3
- class Password < Text
4
- include Base
5
-
6
- def collect!
7
- # Ask the user the question and apply the appropriate options
8
- answer = ask(@prompt) do |q|
9
- q.default = default
10
- q.echo = @is_secret
11
- q.limit = @limit if @limit
12
- end
13
-
14
- # Return the user's answer
15
- answer.to_s
16
- end
17
- end
18
- end
19
- end
@@ -1,69 +0,0 @@
1
- require 'highline/import'
2
- require 'json'
3
- require 'net/http'
4
-
5
- module Stevenson
6
- module Input
7
- class Select
8
- include Base
9
-
10
- def initialize(options)
11
- super
12
-
13
- # Save the basic settings for the prompt
14
- @prompt = options['prompt'] || ''
15
-
16
- # Load settings from remote sources, if any
17
- load_remote_options options['url'], options if options['url']
18
- end
19
-
20
- def collect!
21
- # Prompt the user with a menu using the provided settings
22
- choose do |menu|
23
- menu.prompt = @prompt
24
-
25
- options.each do |key, value|
26
- menu.choice(key) { value }
27
- end
28
- end
29
- end
30
-
31
- private
32
-
33
- def load_remote_options(url, options)
34
- # Download and parse the JSON to use for options
35
- uri = URI(url)
36
- raw_json = Net::HTTP.get uri
37
- json = JSON.parse raw_json
38
-
39
- # Get the appropriate keys for processing the JSON
40
- list_key = options['list_key'] || ''
41
- name_key = options['name_key'] || ''
42
- value_key = options['value_key'] || options['name_key'] || ''
43
-
44
- # Get the array of items to generate options for
45
- list_items = get_value_from_selector json, list_key
46
-
47
- # For each item, fetch the name and value for each option and assign them
48
- list_items.each do |list_item|
49
- name = get_value_from_selector list_item, name_key
50
- value = get_value_from_selector list_item, value_key
51
- options[name] = value
52
- end
53
- end
54
-
55
- def get_value_from_selector(hash, selector_string)
56
- # Split the provided selector into an array of selectors
57
- selectors = selector_string.split '.'
58
-
59
- # For each one, get the associated subhash from the hash
60
- selectors.each do |selector|
61
- hash = hash[selector] if hash
62
- end
63
-
64
- # Return the resulting hash
65
- hash
66
- end
67
- end
68
- end
69
- end
@@ -1,28 +0,0 @@
1
- require 'highline/import'
2
-
3
- module Stevenson
4
- module Input
5
- class Text
6
- include Input::Base
7
-
8
- def initialize(options)
9
- super
10
-
11
- # Save the basic settings for the prompt
12
- @prompt = options['prompt'] || ''
13
- @limit = options['limit'] || false
14
- end
15
-
16
- def collect!
17
- # Ask the user the question and apply the appropriate options
18
- answer = ask(@prompt) do |q|
19
- q.default = default
20
- q.limit = @limit if @limit
21
- end
22
-
23
- # Return the user's answer
24
- answer.to_s
25
- end
26
- end
27
- end
28
- end
@@ -1,19 +0,0 @@
1
- module Stevenson
2
- module Input
3
- class Url < Text
4
- include Base
5
-
6
- def collect!
7
- # Ask the user the question and apply the appropriate options
8
- answer = ask(@prompt) do |q|
9
- q.default = default
10
- q.validate = /https?:\/\/[\S]+/
11
- q.limit = @limit if @limit
12
- end
13
-
14
- # Return the user's answer
15
- answer.to_s
16
- end
17
- end
18
- end
19
- end
@@ -1,51 +0,0 @@
1
- module Stevenson
2
- module Input
3
- autoload :Email, 'stevenson/input/email'
4
- autoload :Password, 'stevenson/input/password'
5
- autoload :Select, 'stevenson/input/select'
6
- autoload :Text, 'stevenson/input/text'
7
- autoload :Url, 'stevenson/input/url'
8
-
9
- module Base
10
- attr_reader :options
11
-
12
- def self.included(input)
13
- input.extend ClassMethods
14
-
15
- Stevenson.inputs[input.input_name] = input
16
- end
17
-
18
- module ClassMethods
19
- def input_name
20
- name.gsub(/^.*::/, '').downcase.to_sym
21
- end
22
- end
23
-
24
- def initialize(options, default=nil)
25
- @options, @default = options, default
26
- end
27
-
28
- def collect!
29
- raise NotImplementedError
30
- end
31
-
32
- def default
33
- @default ||= options['default'] if options['default']
34
- @default ||= ''
35
- end
36
- end
37
-
38
- def self.input_for(options)
39
- input_klass = input_klass_for(options['type'])
40
- input_klass.new(options)
41
- end
42
-
43
- private
44
-
45
- def self.input_klass_for(type)
46
- Stevenson.inputs[type] || const_get(type.to_s.capitalize)
47
- rescue NameError => e
48
- raise NameError.new "Type '#{type}' is not a valid input type.", e
49
- end
50
- end
51
- end
@@ -1,50 +0,0 @@
1
- require 'stevenson/templates/base'
2
- require 'stevenson/templates/git'
3
- require 'yaml'
4
-
5
- module Stevenson
6
- class TemplateLoader
7
- TEMPLATE_ALIASES_PATH = File.join('..', '..', 'assets', 'template_aliases.yml')
8
-
9
- def self.load(template_name)
10
- # If a template alias exists with the key template
11
- if template_aliases[template_name]
12
- # Load a template and return it
13
- load_template template_aliases[template_name]
14
- elsif template_name =~ /^.*\.git$/
15
- # If the given string is a git url, load the git template and return it
16
- Templates::GitTemplate.new template_name
17
- else
18
- # Otherwise, return a new template using the name as a path
19
- Templates::Base.new template_name
20
- end
21
- end
22
-
23
- def self.template_aliases
24
- # Get the path to the template aliases file
25
- template_aliases_path = File.join(File.dirname(__FILE__), TEMPLATE_ALIASES_PATH)
26
-
27
- # Load the template aliases
28
- template_aliases = YAML.load_file template_aliases_path
29
- end
30
-
31
- def self.load_template(template_options)
32
- # If the template options contain a git url, load the git template and return it
33
- if template_options['git']
34
- template = Templates::GitTemplate.new template_options['git']
35
-
36
- # If the alias provides a branch, switch to it
37
- template.switch_branch template_options['branch'] if template_options['branch']
38
-
39
- # If the alias provides a subdirectory, switch to it
40
- template.select_subdirectory template_options['subdirectory'] if template_options['subdirectory']
41
-
42
- # Return the template
43
- template
44
- else
45
- # Otherwise, return false
46
- false
47
- end
48
- end
49
- end
50
- end
@@ -1,45 +0,0 @@
1
- require 'stevenson/templates/invalid_template_exception'
2
-
3
- module Stevenson
4
- module Templates
5
- class Base
6
- def initialize(path)
7
- if !File.directory?(path)
8
- # If the given path is not a directory, raise an invalid template exception
9
- raise InvalidTemplateException.new('The given path is not a directory')
10
- else
11
- # Otherwise, copy the template to a temporary directory to work with
12
- @path = Dir.mktmpdir
13
- FileUtils.cp_r File.join(path, '.'), @path
14
- end
15
- end
16
-
17
- def path
18
- # Return the path to the repo
19
- @path
20
- end
21
-
22
- def select_subdirectory(directory)
23
- # Create a new temporary directory to work from
24
- new_path = Dir.mktmpdir
25
-
26
- # Copy files from the subdirectory to the new temp dir
27
- FileUtils.cp_r File.join(@path, directory, '.'), new_path
28
-
29
- # Remove the old temporary directory
30
- FileUtils.remove_entry_secure @path
31
-
32
- # Set the path to the new path
33
- @path = new_path
34
- end
35
-
36
- def output(directory)
37
- # Copy the configured template to the output_directory
38
- FileUtils.copy_entry @path, directory
39
-
40
- # Cleanup the temporary directory
41
- FileUtils.remove_entry_secure @path
42
- end
43
- end
44
- end
45
- end