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.
- checksums.yaml +4 -4
- data/.travis.yml +2 -0
- data/assets/stevenson_dotfile.yml +29 -0
- data/lib/stevenson/application.rb +34 -29
- data/lib/stevenson/dotfile.rb +26 -0
- data/lib/stevenson/output_filter/generator.rb +30 -0
- data/lib/stevenson/output_filter.rb +42 -0
- data/lib/stevenson/output_filters/jekyll.rb +6 -13
- data/lib/stevenson/output_filters/zip.rb +12 -14
- data/lib/stevenson/template/loader.rb +36 -0
- data/lib/stevenson/template.rb +35 -0
- data/lib/stevenson/templates/git.rb +16 -17
- data/lib/stevenson/templates/local.rb +21 -0
- data/lib/stevenson/version.rb +1 -1
- data/lib/stevenson.rb +9 -7
- data/spec/bin/.gitkeep +0 -0
- data/spec/lib/output_filter/generator_spec.rb +37 -0
- data/spec/lib/output_filter_spec.rb +57 -0
- data/spec/lib/output_filters/jekyll_spec.rb +23 -0
- data/spec/lib/output_filters/zip_spec.rb +19 -0
- data/spec/lib/template/loader_spec.rb +35 -0
- data/spec/lib/template_spec.rb +20 -0
- data/spec/lib/templates/git_spec.rb +43 -0
- data/spec/lib/templates/local_spec.rb +42 -0
- data/stevenson.gemspec +3 -2
- metadata +44 -40
- data/assets/template_aliases.yml +0 -36
- data/lib/stevenson/configurators/yaml_configurator.rb +0 -79
- data/lib/stevenson/input/email.rb +0 -19
- data/lib/stevenson/input/password.rb +0 -19
- data/lib/stevenson/input/select.rb +0 -69
- data/lib/stevenson/input/text.rb +0 -28
- data/lib/stevenson/input/url.rb +0 -19
- data/lib/stevenson/input.rb +0 -51
- data/lib/stevenson/template_loader.rb +0 -50
- data/lib/stevenson/templates/base.rb +0 -45
- data/lib/stevenson/templates/invalid_template_exception.rb +0 -6
- data/spec/configurators/yaml_configurator_spec.rb +0 -12
- data/spec/input/email_spec.rb +0 -12
- data/spec/input/password_spec.rb +0 -12
- data/spec/input/select_spec.rb +0 -12
- data/spec/input/text_spec.rb +0 -12
- data/spec/input/url_spec.rb +0 -12
- data/spec/input_spec.rb +0 -38
- data/spec/output_filters/jekyll_spec.rb +0 -17
- data/spec/output_filters/zip_spec.rb +0 -17
- data/spec/template_loader_spec.rb +0 -51
- data/spec/templates/base_spec.rb +0 -83
- data/spec/templates/git_spec.rb +0 -37
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4bbb1c5387f8971d634dbab92d275947b481e6a
|
4
|
+
data.tar.gz: 8944fee22ba3f747259246c6512c9b13860a6b2f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a06819996cd37937b72e2d6e000336a867af6723402b41e353654c913a739b8cc9f87bad2e25a27cdb0d051e65e2593cbd87f1d14c38251d8d7c37f3b7734029
|
7
|
+
data.tar.gz: a91025832a88cf33489e40a6360c6ee78c6c1f91b70f392f88564966b6e9ad1fd6491df3ece4827b555a5257e6ad80b6a4b13384b7ff859d3b127008088300c4
|
data/.travis.yml
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
template_aliases:
|
2
|
+
hyde-base:
|
3
|
+
name: https://github.com/RootsRated/hyde.git
|
4
|
+
options:
|
5
|
+
subdirectory: base
|
6
|
+
templatedco-exmachina:
|
7
|
+
name: https://github.com/RootsRated/hyde.git
|
8
|
+
options:
|
9
|
+
subdirectory: exmachina
|
10
|
+
templatedco-horizons:
|
11
|
+
name: https://github.com/RootsRated/hyde.git
|
12
|
+
options:
|
13
|
+
subdirectory: horizons
|
14
|
+
templatedco-ion:
|
15
|
+
name: https://github.com/RootsRated/hyde.git
|
16
|
+
options:
|
17
|
+
subdirectory: ion
|
18
|
+
templatedco-linear:
|
19
|
+
name: https://github.com/RootsRated/hyde.git
|
20
|
+
options:
|
21
|
+
subdirectory: linear
|
22
|
+
templatedco-phaseshift:
|
23
|
+
name: https://github.com/RootsRated/hyde.git
|
24
|
+
options:
|
25
|
+
subdirectory: phaseshift
|
26
|
+
templatedco-solarize:
|
27
|
+
name: https://github.com/RootsRated/hyde.git
|
28
|
+
options:
|
29
|
+
subdirectory: solarize
|
@@ -2,52 +2,57 @@ require 'thor'
|
|
2
2
|
|
3
3
|
module Stevenson
|
4
4
|
class Application < Thor
|
5
|
-
desc '
|
5
|
+
desc 'new PROJECT_NAME CONFIG_PATH', 'generates a Jekyll at PROJECT_NAME with a config file at CONFIG_PATH'
|
6
6
|
|
7
|
+
method_option :template,
|
8
|
+
aliases: '-t',
|
9
|
+
default: 'hyde-base',
|
10
|
+
desc: 'The template to use'
|
11
|
+
|
12
|
+
# Template Options
|
7
13
|
method_option :branch,
|
8
14
|
aliases: '-b',
|
9
15
|
desc: 'The git branch you would like to use from your template'
|
10
|
-
method_option :jekyll,
|
11
|
-
type: :boolean,
|
12
|
-
aliases: '-j',
|
13
|
-
desc: 'Jekyll compiles the output directory'
|
14
16
|
method_option :subdirectory,
|
15
17
|
aliases: '-s',
|
16
18
|
desc: 'The subdirectory to use from the template, if any'
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
|
20
|
+
# Data Options
|
21
|
+
method_option :data,
|
22
|
+
aliases: "-d",
|
23
|
+
desc: 'The path to related data yml files'
|
24
|
+
|
25
|
+
# Output Options
|
26
|
+
method_option :output,
|
27
|
+
type: :array,
|
28
|
+
aliases: "-o",
|
29
|
+
desc: 'Array of output filters to be applied in order'
|
21
30
|
method_option :zip,
|
22
31
|
type: :boolean,
|
23
32
|
aliases: "-z",
|
24
33
|
desc: 'Zip compresses the output directory'
|
25
34
|
|
26
|
-
def new(output_directory)
|
35
|
+
def new(output_directory, config_path)
|
27
36
|
# Load the template using the template loader
|
28
|
-
template = Stevenson::
|
29
|
-
|
30
|
-
# If a branch is provided, switch to that branch
|
31
|
-
template.switch_branch options[:branch] if options[:branch]
|
32
|
-
|
33
|
-
# If a subdirectory is provided, switch to that directory
|
34
|
-
template.select_subdirectory options[:subdirectory] if options[:subdirectory]
|
37
|
+
template = Stevenson::Template.load(options[:template], options)
|
35
38
|
|
36
|
-
#
|
37
|
-
|
38
|
-
|
39
|
+
# Place yml files
|
40
|
+
template.place_config(config_path)
|
41
|
+
template.place_files(options[:data], '_data') if options[:data]
|
39
42
|
|
40
|
-
#
|
41
|
-
|
43
|
+
# Run output filters, in order, against the template
|
44
|
+
puts Stevenson::OutputFilter.generate!(template, options)
|
42
45
|
|
43
|
-
|
44
|
-
template.extend(Stevenson::OutputFilters::ZipFilter) if options[:zip]
|
45
|
-
|
46
|
-
# Save the repo to the output directory
|
47
|
-
template.output output_directory
|
48
|
-
|
49
|
-
rescue Templates::InvalidTemplateException => e
|
46
|
+
rescue StandardError => e
|
50
47
|
say e.message
|
48
|
+
ensure
|
49
|
+
template.close
|
50
|
+
end
|
51
|
+
|
52
|
+
desc 'generate_dotfile', 'Generates a Stevenson configuration dotfile'
|
53
|
+
def generate_dotfile
|
54
|
+
Dotfile.install
|
55
|
+
puts "Generated dotfile at #{Dotfile.path}"
|
51
56
|
end
|
52
57
|
end
|
53
58
|
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'delegate'
|
2
|
+
require 'hashie/mash'
|
3
|
+
require 'yaml'
|
4
|
+
|
5
|
+
module Stevenson
|
6
|
+
class Dotfile < SimpleDelegator
|
7
|
+
|
8
|
+
TEMPLATE_PATH = File.join(File.dirname(__FILE__), '..', '..', 'assets', 'stevenson_dotfile.yml')
|
9
|
+
DOTFILE_PATH = File.join(Dir.home, ".stevenson")
|
10
|
+
|
11
|
+
class << self
|
12
|
+
def install
|
13
|
+
FileUtils.copy TEMPLATE_PATH, DOTFILE_PATH
|
14
|
+
end
|
15
|
+
|
16
|
+
def path
|
17
|
+
DOTFILE_PATH
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize
|
22
|
+
dotfile_path = File.exist?(self.class.path) ? self.class.path : TEMPLATE_PATH
|
23
|
+
super Hashie::Mash.new YAML.load_file(dotfile_path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Stevenson
|
2
|
+
module OutputFilter
|
3
|
+
class Generator
|
4
|
+
attr_reader :options
|
5
|
+
|
6
|
+
def initialize(options)
|
7
|
+
@options = options
|
8
|
+
end
|
9
|
+
|
10
|
+
def generate!(template)
|
11
|
+
filters.inject(template.local_directory) do |rendered, filter|
|
12
|
+
OutputFilter.filter_for(filter).new(rendered).output
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def filters
|
19
|
+
@_filters ||= begin
|
20
|
+
filters = [:jekyll]
|
21
|
+
filters.concat options[:output] if options[:output]
|
22
|
+
filters << :zip if options[:zip]
|
23
|
+
filters.uniq
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module Stevenson
|
2
|
+
module OutputFilter
|
3
|
+
autoload :Jekyll, 'stevenson/output_filters/jekyll'
|
4
|
+
autoload :Zip, 'stevenson/output_filters/zip'
|
5
|
+
|
6
|
+
autoload :Generator, 'stevenson/output_filter/generator'
|
7
|
+
|
8
|
+
class Base
|
9
|
+
attr_reader :directory
|
10
|
+
|
11
|
+
def self.included(filter)
|
12
|
+
filter.extend ClassMethods
|
13
|
+
|
14
|
+
Stevenson.output_filters[filter.filter_name] = filter
|
15
|
+
end
|
16
|
+
|
17
|
+
module ClassMethods
|
18
|
+
def filter_name
|
19
|
+
name.gsub(/^.*::/, '').downcase.to_sym
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def initialize(directory)
|
24
|
+
@directory = directory
|
25
|
+
end
|
26
|
+
|
27
|
+
def output
|
28
|
+
raise NotImplementedError
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.generate!(template, options)
|
33
|
+
Generator.new(options).generate!(template)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.filter_for(type)
|
37
|
+
Stevenson.output_filters[type] || const_get(type.to_s.capitalize)
|
38
|
+
rescue NameError => e
|
39
|
+
raise NameError.new "Type '#{type}' is not a valid output type.", e
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -1,21 +1,14 @@
|
|
1
1
|
module Stevenson
|
2
|
-
module
|
3
|
-
|
4
|
-
|
2
|
+
module OutputFilter
|
3
|
+
class Jekyll < Base
|
4
|
+
|
5
|
+
def output
|
5
6
|
# Jekyll Build the Directory
|
6
|
-
Dir.chdir(
|
7
|
+
Dir.chdir(directory) do
|
7
8
|
`jekyll b`
|
8
9
|
end
|
9
10
|
|
10
|
-
|
11
|
-
Dir.mktmpdir do |dir|
|
12
|
-
FileUtils.cp_r File.join(path, '_site', '.'), dir
|
13
|
-
FileUtils.rm_r path
|
14
|
-
FileUtils.cp_r dir, path
|
15
|
-
end
|
16
|
-
|
17
|
-
# Call the parent method
|
18
|
-
super directory
|
11
|
+
File.join(directory, '_site', '.')
|
19
12
|
end
|
20
13
|
end
|
21
14
|
end
|
@@ -1,15 +1,13 @@
|
|
1
1
|
require 'zip'
|
2
2
|
|
3
3
|
module Stevenson
|
4
|
-
module
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
super dir
|
10
|
-
|
4
|
+
module OutputFilter
|
5
|
+
class Zip < Base
|
6
|
+
|
7
|
+
def output
|
8
|
+
"#{directory}.zip".tap do |dir|
|
11
9
|
# Zip up the output directory
|
12
|
-
write
|
10
|
+
write directory, dir
|
13
11
|
end
|
14
12
|
end
|
15
13
|
|
@@ -22,24 +20,24 @@ module Stevenson
|
|
22
20
|
entries = Dir.entries(@inputDir)
|
23
21
|
entries.delete(".")
|
24
22
|
entries.delete("..")
|
25
|
-
io = Zip::File.open(@outputFile, Zip::File::CREATE)
|
23
|
+
io = ::Zip::File.open(@outputFile, ::Zip::File::CREATE)
|
26
24
|
|
27
25
|
writeEntries(entries, "", io)
|
28
26
|
io.close()
|
29
27
|
end
|
30
28
|
|
31
29
|
def writeEntries(entries, path, io)
|
32
|
-
entries.each
|
33
|
-
zipFilePath = path == "" ?
|
30
|
+
entries.each do |entry|
|
31
|
+
zipFilePath = path == "" ? entry : File.join(path, entry)
|
34
32
|
diskFilePath = File.join(@inputDir, zipFilePath)
|
35
33
|
if File.directory?(diskFilePath)
|
36
34
|
io.mkdir(zipFilePath)
|
37
|
-
subdir =Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..")
|
35
|
+
subdir = Dir.entries(diskFilePath); subdir.delete("."); subdir.delete("..")
|
38
36
|
writeEntries(subdir, zipFilePath, io)
|
39
37
|
else
|
40
|
-
io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read())}
|
38
|
+
io.get_output_stream(zipFilePath) { |f| f.puts(File.open(diskFilePath, "rb").read()) }
|
41
39
|
end
|
42
|
-
|
40
|
+
end
|
43
41
|
end
|
44
42
|
end
|
45
43
|
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Stevenson
|
2
|
+
module Template
|
3
|
+
class Loader
|
4
|
+
attr_reader :template_name, :options
|
5
|
+
|
6
|
+
def initialize(template_name, options)
|
7
|
+
@template_name, @options = template_name, options
|
8
|
+
end
|
9
|
+
|
10
|
+
def template
|
11
|
+
return Template.load(matching_alias.name, matching_alias.options) if matching_alias?
|
12
|
+
|
13
|
+
template_klass.new template_name, options
|
14
|
+
end
|
15
|
+
|
16
|
+
def template_klass
|
17
|
+
case template_name
|
18
|
+
when /^.*\.git$/
|
19
|
+
Template::Git
|
20
|
+
else
|
21
|
+
Template::Local
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def matching_alias
|
28
|
+
Stevenson.dotfile.template_aliases.fetch(template_name, nil)
|
29
|
+
end
|
30
|
+
|
31
|
+
def matching_alias?
|
32
|
+
!!matching_alias
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Stevenson
|
2
|
+
module Template
|
3
|
+
autoload :Git, 'stevenson/templates/git'
|
4
|
+
autoload :Local, 'stevenson/templates/local'
|
5
|
+
|
6
|
+
autoload :Loader, 'stevenson/template/loader'
|
7
|
+
|
8
|
+
def self.load(template, options)
|
9
|
+
Loader.new(template, options).template
|
10
|
+
end
|
11
|
+
|
12
|
+
class Base
|
13
|
+
attr_reader :name, :options
|
14
|
+
|
15
|
+
def initialize(name, options = {})
|
16
|
+
@name, @options = name, options
|
17
|
+
end
|
18
|
+
|
19
|
+
def place_config(config_file)
|
20
|
+
place_files(config_file, 'config.yml')
|
21
|
+
end
|
22
|
+
|
23
|
+
def place_files(files, directory)
|
24
|
+
action = File.directory?(files) ? :cp_r : :cp
|
25
|
+
FileUtils.send(action, files, File.join(local_directory, directory))
|
26
|
+
end
|
27
|
+
|
28
|
+
def close
|
29
|
+
FileUtils.rm_rf local_directory if local_directory
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
class InvalidTemplateException < StandardError; end
|
34
|
+
end
|
35
|
+
end
|
@@ -1,26 +1,25 @@
|
|
1
1
|
require 'git'
|
2
|
-
require 'stevenson/templates/base'
|
3
2
|
|
4
3
|
module Stevenson
|
5
|
-
module
|
6
|
-
class
|
7
|
-
|
8
|
-
# Create a temporary directory to clone the repo at
|
9
|
-
Dir.mktmpdir do |dir|
|
10
|
-
# Clone the repo to a temporary directory for later use
|
11
|
-
Git.clone template_url, File.join(dir, 'repo')
|
4
|
+
module Template
|
5
|
+
class Git < Base
|
6
|
+
attr_reader :template_url, :options
|
12
7
|
|
13
|
-
|
14
|
-
|
15
|
-
end
|
16
|
-
rescue Git::GitExecuteError => e
|
17
|
-
# If the given URL is not valid, raise an exception and cleanup
|
18
|
-
raise InvalidTemplateException.new('Failed to clone the repository')
|
8
|
+
def initialize(template_url, options)
|
9
|
+
@template_url, @options = template_url, options
|
19
10
|
end
|
20
11
|
|
21
|
-
def
|
22
|
-
|
23
|
-
|
12
|
+
def local_directory
|
13
|
+
@_local_directory ||= Dir.mktmpdir.tap do |dir|
|
14
|
+
# Clone the repo to a temporary directory for later use
|
15
|
+
::Git.clone(template_url, dir).tap do |repo|
|
16
|
+
# Switch_branch if set
|
17
|
+
repo.checkout(options[:branch]) if options.has_key?(:branch)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
rescue ::Git::GitExecuteError
|
21
|
+
# If the given repo URL is not valid, raise an exception
|
22
|
+
raise InvalidTemplateException.new('Failed to clone the repository')
|
24
23
|
end
|
25
24
|
end
|
26
25
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module Stevenson
|
2
|
+
module Template
|
3
|
+
class Local < Base
|
4
|
+
attr_reader :template_path, :options
|
5
|
+
|
6
|
+
def initialize(template_path, options)
|
7
|
+
@template_path, @options = template_path, options
|
8
|
+
end
|
9
|
+
|
10
|
+
def local_directory
|
11
|
+
raise InvalidTemplateException.new('The given path is not a directory') unless File.directory?(template_path)
|
12
|
+
|
13
|
+
@_local_directory ||= Dir.mktmpdir.tap do |dir|
|
14
|
+
directories = [template_path, options[:subdirectory], '.'].compact
|
15
|
+
|
16
|
+
FileUtils.cp_r File.join(*directories), dir
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/stevenson/version.rb
CHANGED
data/lib/stevenson.rb
CHANGED
@@ -1,14 +1,16 @@
|
|
1
|
-
require 'stevenson/configurators/yaml_configurator'
|
2
|
-
require 'stevenson/output_filters/jekyll'
|
3
|
-
require 'stevenson/output_filters/zip'
|
4
|
-
require 'stevenson/template_loader'
|
5
1
|
require 'stevenson/version'
|
6
2
|
|
7
3
|
module Stevenson
|
8
4
|
autoload :Application, 'stevenson/application'
|
9
|
-
autoload :
|
5
|
+
autoload :Dotfile, 'stevenson/dotfile'
|
6
|
+
autoload :Template, 'stevenson/template'
|
7
|
+
autoload :OutputFilter, 'stevenson/output_filter'
|
10
8
|
|
11
|
-
def self.
|
12
|
-
@
|
9
|
+
def self.dotfile
|
10
|
+
@_dotfile ||= Dotfile.new
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.output_filters
|
14
|
+
@_output_filters ||= {}
|
13
15
|
end
|
14
16
|
end
|
data/spec/bin/.gitkeep
ADDED
File without changes
|
@@ -0,0 +1,37 @@
|
|
1
|
+
describe Stevenson::OutputFilter::Generator do
|
2
|
+
let(:options) { Hash.new }
|
3
|
+
subject { described_class.new(options) }
|
4
|
+
|
5
|
+
describe "#generate!(template)" do
|
6
|
+
let(:template) { double(:template, local_directory: '/tmp/path/to/template') }
|
7
|
+
let(:jekyll_output) { double(:jekyll_output) }
|
8
|
+
let(:zip_output) { double(:zip_output) }
|
9
|
+
before do
|
10
|
+
allow_any_instance_of(Stevenson::OutputFilter::Jekyll).to receive(:output).and_return(jekyll_output)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should create a new filter for the jekyll filter's output" do
|
14
|
+
expect(Stevenson::OutputFilter::Jekyll).to receive(:new).with(template.local_directory).and_call_original
|
15
|
+
subject.generate!(template)
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should return the filter's output result" do
|
19
|
+
expect(subject.generate!(template)).to eq jekyll_output
|
20
|
+
end
|
21
|
+
|
22
|
+
context "when more than one filter exists" do
|
23
|
+
let(:options) { { zip: true } }
|
24
|
+
let(:zip_filter) { double(:zip_filter, output: zip_output) }
|
25
|
+
|
26
|
+
it "should build subsequent filters with the previous' output" do
|
27
|
+
expect(Stevenson::OutputFilter::Zip).to receive(:new).with(jekyll_output).and_return(zip_filter)
|
28
|
+
subject.generate!(template)
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return the subsequent filter's output" do
|
32
|
+
allow(Stevenson::OutputFilter::Zip).to receive(:new).with(jekyll_output).and_return(zip_filter)
|
33
|
+
expect(subject.generate!(template)).to eq zip_output
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Stevenson::OutputFilter
|
2
|
+
class Test < Base
|
3
|
+
end
|
4
|
+
end
|
5
|
+
|
6
|
+
describe Stevenson::OutputFilter do
|
7
|
+
let(:filter) { Stevenson::OutputFilter::Test }
|
8
|
+
|
9
|
+
describe ".generate!(template, options)" do
|
10
|
+
let(:template) { double(:template) }
|
11
|
+
let(:options) { Hash.new }
|
12
|
+
let(:output) { double(:output) }
|
13
|
+
let(:generator) { double(:generator, generate!: output) }
|
14
|
+
subject { described_class.generate!(template, options) }
|
15
|
+
|
16
|
+
it "should call Generator.new with options" do
|
17
|
+
expect(Stevenson::OutputFilter::Generator).to receive(:new).with(options).and_return(generator)
|
18
|
+
subject
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should call generator's generate! with template" do
|
22
|
+
allow(Stevenson::OutputFilter::Generator).to receive(:new).and_return(generator)
|
23
|
+
expect(generator).to receive(:generate!).with(template)
|
24
|
+
subject
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should return generate!er's output response" do
|
28
|
+
allow(Stevenson::OutputFilter::Generator).to receive(:new).and_return(generator)
|
29
|
+
expect(subject).to eq output
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
describe ".filter_for()" do
|
34
|
+
context "when the filter has been registered previously" do
|
35
|
+
it "should return the filter class from Stevenson.output_filters" do
|
36
|
+
expect(Stevenson::OutputFilter.filter_for(:test)).to eq(filter)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "when the filter has not been registered previously" do
|
41
|
+
it "should return the filter class from Stevenson.output_filters" do
|
42
|
+
allow(Stevenson).to receive(:output_filters).and_return({})
|
43
|
+
expect(Stevenson::OutputFilter.filter_for(:test)).to eq(filter)
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "when the filter doesn't exist" do
|
48
|
+
it "should raise a NameError with a descriptive error message" do
|
49
|
+
expect { Stevenson::OutputFilter.filter_for(:bad_filter) }.to raise_error do |error|
|
50
|
+
expect(error).to be_a(NameError)
|
51
|
+
expect(error.message).to eq("Type 'bad_filter' is not a valid output type.")
|
52
|
+
expect(error.cause).to be_a(NameError)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
describe Stevenson::OutputFilter::Jekyll do
|
2
|
+
let(:temporary_directory) { '/tmp/directory' }
|
3
|
+
let(:template) { double(:template, local_directory: temporary_directory) }
|
4
|
+
subject { described_class.new(template.local_directory) }
|
5
|
+
|
6
|
+
describe '#output' do
|
7
|
+
it "should change into the template's directory" do
|
8
|
+
expect(Dir).to receive(:chdir).with(temporary_directory)
|
9
|
+
subject.output
|
10
|
+
end
|
11
|
+
|
12
|
+
it "should build jekyll" do
|
13
|
+
allow(Dir).to receive(:chdir).with(temporary_directory).and_yield
|
14
|
+
expect(subject).to receive(:`).with("jekyll b")
|
15
|
+
subject.output
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'outputs a jekyll compiled directory' do
|
19
|
+
allow(Dir).to receive(:chdir).with(temporary_directory)
|
20
|
+
expect(subject.output).to eq File.join(temporary_directory, '_site', '.')
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
describe Stevenson::OutputFilter::Zip do
|
2
|
+
let(:temporary_directory) { '/tmp/directory' }
|
3
|
+
let(:template) { double(:template, local_directory: temporary_directory) }
|
4
|
+
subject { described_class.new(template.local_directory) }
|
5
|
+
|
6
|
+
describe '#output' do
|
7
|
+
let(:output_zip) { "#{temporary_directory}.zip" }
|
8
|
+
|
9
|
+
it "should zip the files in temporary_directory to the zip" do
|
10
|
+
expect(subject).to receive(:write).with(temporary_directory, output_zip).and_return(true)
|
11
|
+
subject.output
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should return the temporary_directory with '.zip' appended" do
|
15
|
+
allow(subject).to receive(:write).and_return(true)
|
16
|
+
expect(subject.output).to eq output_zip
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
describe Stevenson::Template::Loader do
|
2
|
+
let(:template_name) { 'template' }
|
3
|
+
let(:options) { Hash.new }
|
4
|
+
subject { described_class.new(template_name, options) }
|
5
|
+
|
6
|
+
describe "#template" do
|
7
|
+
context "when 'template_name' matches an alias" do
|
8
|
+
let(:aliased_template) do
|
9
|
+
double(:aliased_template, name: 'template_path', options: {})
|
10
|
+
end
|
11
|
+
let(:dotfile) do
|
12
|
+
double(:dotfile, template_aliases: { template_name => aliased_template })
|
13
|
+
end
|
14
|
+
|
15
|
+
before { allow(Stevenson).to receive(:dotfile).and_return(dotfile) }
|
16
|
+
|
17
|
+
it "should call Loader on Template with the name" do
|
18
|
+
expect(Stevenson::Template).to receive(:load).with(aliased_template.name, aliased_template.options)
|
19
|
+
subject.template
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
context "when 'template' matches a git repo" do
|
24
|
+
let(:template_name) { 'http://www.github.com/Org/repo.git' }
|
25
|
+
|
26
|
+
it "should return a Git template" do
|
27
|
+
expect(subject.template).to be_a Stevenson::Template::Git
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should return a Local template " do
|
32
|
+
expect(subject.template).to be_a Stevenson::Template::Local
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|