stevenson 2.0.0 → 2.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d4bbb1c5387f8971d634dbab92d275947b481e6a
4
- data.tar.gz: 8944fee22ba3f747259246c6512c9b13860a6b2f
3
+ metadata.gz: 65c934219c82cb57f9ed0cb87eda58348cc6219d
4
+ data.tar.gz: ffc0f55365499f06312e1ae956f5f6847eb25072
5
5
  SHA512:
6
- metadata.gz: a06819996cd37937b72e2d6e000336a867af6723402b41e353654c913a739b8cc9f87bad2e25a27cdb0d051e65e2593cbd87f1d14c38251d8d7c37f3b7734029
7
- data.tar.gz: a91025832a88cf33489e40a6360c6ee78c6c1f91b70f392f88564966b6e9ad1fd6491df3ece4827b555a5257e6ad80b6a4b13384b7ff859d3b127008088300c4
6
+ metadata.gz: 6adb7a7c86cc0f9616e9d44568180a3017eb3c31899e10ddeccaccf8699bcb372793c24197bb2b37425279ce34f88557776cdd03ff2204b168d5fab0b8559555
7
+ data.tar.gz: bf375e0bc19e27e9b26151d3573dbb4ad786aea0ae4bded4c906d624eedd207b76ede31bd9a315583d18d828ab0224f31385b5f2ce7725980358cf3c6e23241f
data/.travis.yml CHANGED
@@ -3,3 +3,6 @@ cache: bundler
3
3
  sudo: false
4
4
  rvm:
5
5
  - 2.1.2
6
+ addons:
7
+ code_climate:
8
+ repo_token: 501db1ee30adeb1d36c5ad36fc6db62a75f7fdd43d4df3da1e55a8be7e76e179
data/CHANGELOG.md ADDED
@@ -0,0 +1,8 @@
1
+ 2.1.0 (October 3rd, 2015)
2
+ - Add deployer logic
3
+ - Add S3 deployer class for sending compiled projects to S3 buckets
4
+
5
+ 2.0.0 (September 30th, 2015)
6
+ - Add template aliases as dotfile
7
+ - Remove individual template config logic and inputs
8
+ - Refactor processing logic from templates, with data files, and through output filters
data/Gemfile CHANGED
@@ -2,3 +2,5 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in stevenson.gemspec
4
4
  gemspec
5
+
6
+ gem "codeclimate-test-reporter", group: :test, require: nil
data/README.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Stevenson
2
2
  [![Build Status](https://travis-ci.org/RootsRated/stevenson.png)](https://travis-ci.org/RootsRated/stevenson)
3
+ [![Gem Version](https://badge.fury.io/rb/stevenson.svg)](http://badge.fury.io/rb/stevenson)
4
+ [![Code Climate](https://codeclimate.com/github/RootsRated/stevenson/badges/gpa.svg)](https://codeclimate.com/github/RootsRated/stevenson)
5
+ [![Test Coverage](https://codeclimate.com/github/RootsRated/stevenson/badges/coverage.svg)](https://codeclimate.com/github/RootsRated/stevenson/coverage)
3
6
 
4
7
  Stevenson is a [Jekyll](http://jekyllrb.com) microsite generator created by
5
8
  RootsRated.com. Stevenson is named for Robert Louis Stevenson, author of *The
@@ -35,35 +38,6 @@ This will create a new directory in your current working directory named
35
38
  `hello_world`. This directory should be a ready-to-use Jekyll
36
39
  installation.
37
40
 
38
- ### Jekyll Compiling
39
-
40
- Stevenson can automatically jekyll build a project and output a built directory
41
- using the `-j` or `--jekyll`. Following the example from above, you can use the
42
- following command:
43
-
44
- $ stevenson new hello_world -j
45
-
46
- This will output a directory called `hello_world` with the built assets from the
47
- jekyll project created by the earlier command without the jekyll flag.
48
-
49
- ### Zip Output
50
-
51
- Stevenson can also output directories as a zip archive using the `-z` or `--zip`
52
- flags. The following command will produce the same result as the first example
53
- as a zip archive:
54
-
55
- $ stevenson new hello_world.zip -z
56
-
57
- Also, the zip flag and jekyll flag can be used together to produce a built and
58
- compress out like so:
59
-
60
- $ stevenson new hello_world.zip -z -j
61
-
62
- This will output a file called `hello_world.zip` with a ready-built website.
63
-
64
- Remember that the first argument to `stevenson new` should have a `.zip` on the
65
- end, as stevenson will not automatically add this extension.
66
-
67
41
  ### Templates
68
42
 
69
43
  By default, stevenson will use RootsRated's
@@ -74,138 +48,27 @@ option, like so:
74
48
  $ stevenson new hello_world -t https://github.com/YourUsername/YourTemplate.git
75
49
 
76
50
  This will clone the repo at `https://github.com/YourUsername/YourTemplate.git`
77
- to `hello_world` and begin altering the repo based on the contents of a
78
- YAML file in your template's root directory named `_stevenson.yml`. This file
79
- should contain config options to be set in various files of your Jekyll
80
- installation along with information on whether these options should be secret,
81
- validated as emails, validated as URLs, or limited to a certain length.
82
-
83
- Here's an example of the YAML file:
84
-
85
- # _stevenson.yml
86
-
87
- '_config.yml':
88
- title:
89
- type: 'text'
90
- prompt: 'Title: '
91
- limit: 40
92
- email:
93
- type: 'email'
94
- prompt: 'Email: '
95
- description:
96
- type: 'text'
97
- prompt: 'Description: '
98
- url:
99
- type: 'url'
100
- prompt: 'URL: '
101
-
102
- This file will produce the following questions when
103
- `stevenson new hello_world https://github.com/YourUsername/YourTemplate.git` is
104
- used:
105
-
106
- $ stevenson new hello_world -t https://github.com/YourUsername/YourTemplate.git
107
- Title: My Site
108
- Email: info@example.org
109
- Description: Lorem Ipsum...
110
- URL: http://www.example.org
111
-
112
- When these questions are answered, the following will be added to
113
- `hello_world/_config.yml`:
114
-
115
- # _config.yml
116
-
117
- title: RootsRated.com
118
- email: info@rootsrated.com
119
- description: This is a microsite created by RootsRated.com
120
- url: http://www.rootsrated.com
51
+ to `hello_world`.
121
52
 
122
- The `prompt` attribute defines how the user should be prompted for input, the
123
- `type` attribute specifies which kind of input the prompt should accept, and any
124
- values already set in the `_config.yml` will be used as defaults for these
125
- questions. Alternatively, defaults can be overriden with a `default` attribute.
126
-
127
- ### Input Types
128
-
129
- There are several input types available now, and hopefully, there will be more
130
- in the future.
131
-
132
- #### Text
133
-
134
- The most basic input is the text input. This simply accepts a text string.
135
- Optionally, a limit can be added with the `limit` attribute.
136
-
137
- #### Email
138
-
139
- This input is a subclass of the text input that only accepts emails as validated
140
- with the following regex: `/\A[\w+\-.]+@[a-z\d\-]+(\.[a-z]+)*\.[a-z]+\z/i`.
141
- Additionally, Email has the same options as Text.
142
-
143
- #### Password
144
-
145
- This input is also a subclass of text, but unlike text, it will not output the
146
- input string to the console for added security.
147
-
148
- #### Url
149
-
150
- This input, another subclass of text, accepts only text that satisfies this
151
- regex: `/https?:\/\/[\S]+/`.
152
-
153
- #### Select
154
-
155
- This input prompts the user to choose from a list of given options. The options
156
- can be provided as subkeys to the `options` attribute like so:
157
-
158
- favorite_color:
159
- type: 'select'
160
- prompt: 'Favorite Color: '
161
- options:
162
- 'Red': '#FF0000'
163
- 'Blue': '#00FF00'
164
- 'Green': '#0000FF'
53
+ ### Zip Output
165
54
 
166
- The first value given is the value that will be offer to the user to choose. The
167
- second value is the value that will be written to `_config.yml`.
55
+ Stevenson can output directories as a zip archive using the `-z` or `--zip`
56
+ flags. The following command will produce a zipped version of the first
57
+ example's result:
168
58
 
169
- Optionally, you can also fetch more options from a JSON API source using the
170
- `url`, `list_key`, `name_key`, and `value_key` attributes. `url` specifies the
171
- url to fetch json options from. `list_key` specifies the root element of the
172
- JSON document to iterate over for options. `name_key` specifies the name from
173
- each iterated item to use as a name. `value_key` specifies the value from each
174
- iterated item to use as a value. The following example is identical to the
175
- previous example using the `options` attribute:
59
+ $ stevenson new hello_world.zip -z
176
60
 
177
- # http://someapi.com/source.json
61
+ This will output a file called `hello_world.zip` with a ready-built website.
178
62
 
179
- {
180
- "response": [
181
- {
182
- "name": "Red",
183
- "value": "#FF0000"
184
- },
185
- {
186
- "name": "Blue",
187
- "value": "#00FF00"
188
- },
189
- {
190
- "name": "Green",
191
- "value": "#0000FF"
192
- }
193
- ]
194
- }
63
+ ### S3 Deploy
195
64
 
196
- # _stevenson.yml
65
+ Stevenson can deploy projects to S3 using the `--s3` flag. The following
66
+ command will deploy the resulting output to S3:
197
67
 
198
- favorite_color:
199
- type: 'select'
200
- prompt: 'Favorite Color: '
201
- url: 'http://someapi.com/source.json'
202
- list_key: 'response'
203
- name_key: 'name'
204
- value_key: 'value'
68
+ $ stevenson new hello_world.zip --s3=bucket file_key AWS_KEY AWS_SECRET
205
69
 
206
- Additionally, remote sources and the `options` attribute can be used together.
207
- If two keys collide between the two, the remote source will always override the
208
- `options` attribute.
70
+ Additionally, Stevenson can use the `AWS_ACCESS_KEY_ID` and
71
+ `AWS_SECRET_ACCESS_KEY` environment variables.
209
72
 
210
73
  ## Similar Projects
211
74
 
@@ -228,3 +91,10 @@ idea a while back, but unfortunately it hasn't been updated in over 2 years.
228
91
  3. Commit your changes (`git commit -am 'Add some feature'`)
229
92
  4. Push to the branch (`git push origin my-new-feature`)
230
93
  5. Create a new Pull Request
94
+
95
+ ### Contributors
96
+
97
+ - [Dylan Karr](https://github.com/dylankarr)
98
+ - [Scott BonAmi](http://github.com/sbonami)
99
+
100
+ Don't forget to check out other open-source projects from [RootsRated](http://github.com/RootsRated)!
@@ -22,9 +22,10 @@ module Stevenson
22
22
  aliases: "-d",
23
23
  desc: 'The path to related data yml files'
24
24
 
25
- # Output Options
25
+ # Output Filter Options
26
26
  method_option :output,
27
27
  type: :array,
28
+ enum: [:zip],
28
29
  aliases: "-o",
29
30
  desc: 'Array of output filters to be applied in order'
30
31
  method_option :zip,
@@ -32,6 +33,12 @@ module Stevenson
32
33
  aliases: "-z",
33
34
  desc: 'Zip compresses the output directory'
34
35
 
36
+ # Deploy Options
37
+ method_option :s3,
38
+ type: :array,
39
+ banner: 'bucket key access_key access_secret',
40
+ desc: 'The s3 information necessary for deploying to S3'
41
+
35
42
  def new(output_directory, config_path)
36
43
  # Load the template using the template loader
37
44
  template = Stevenson::Template.load(options[:template], options)
@@ -41,7 +48,10 @@ module Stevenson
41
48
  template.place_files(options[:data], '_data') if options[:data]
42
49
 
43
50
  # Run output filters, in order, against the template
44
- puts Stevenson::OutputFilter.generate!(template, options)
51
+ directory = Stevenson::OutputFilter.generate!(template, options)
52
+
53
+ # Run deployers against filtered template directory
54
+ Stevenson::Deployer.deploy(directory, options)
45
55
 
46
56
  rescue StandardError => e
47
57
  say e.message
@@ -0,0 +1,53 @@
1
+ module Stevenson
2
+ module Deployer
3
+ autoload :S3, 'stevenson/deployers/s3'
4
+
5
+ module Base
6
+ attr_reader :options
7
+
8
+ def self.included(deployer)
9
+ deployer.extend ClassMethods
10
+
11
+ Stevenson.deployers[deployer.deployer_name] = deployer
12
+ end
13
+
14
+ module ClassMethods
15
+ def deployer_name
16
+ name.gsub(/^.*::/, '').downcase.to_sym
17
+ end
18
+ end
19
+
20
+ def initialize(options)
21
+ @options = options
22
+ end
23
+
24
+ def deploy!(directory)
25
+ raise NotImplementedError
26
+ end
27
+ end
28
+
29
+ class << self
30
+ def deploy(directory, options)
31
+ deployers_for(options).each do |deployer|
32
+ deployer.new(options).deploy!(directory)
33
+ end
34
+ end
35
+
36
+ private
37
+
38
+ def deployers_for(options)
39
+ [].tap do |deployers|
40
+ deployers << deployer_for(:s3) if options.keys.include?("s3")
41
+ end
42
+ end
43
+
44
+ def deployer_for(type)
45
+ Stevenson.deployers.fetch(type, nil) || const_get(type.to_s.capitalize)
46
+ rescue NameError
47
+ raise InvalidDeployerException.new "Type '#{type}' is not a valid deployer."
48
+ end
49
+ end
50
+
51
+ class InvalidDeployerException < StandardError; end
52
+ end
53
+ end
@@ -0,0 +1,40 @@
1
+ require 'fog'
2
+
3
+ module Stevenson
4
+ module Deployer
5
+ class S3
6
+ include Deployer::Base
7
+
8
+ attr_reader :deployment_bucket_name, :deployment_key
9
+
10
+ def initialize(options)
11
+ @deployment_bucket_name, @deployment_key, @deployment_access_key, @deployment_access_secret = options["s3"]
12
+ super
13
+ end
14
+
15
+ def deploy!(directory)
16
+ Dir.glob("#{directory}/**/*").each do |file|
17
+ s3_bucket.files.create(
18
+ key: File.join(deployment_key, file.partition(directory).last),
19
+ body: File.read(file),
20
+ public: true,
21
+ ) if File.file?(file)
22
+ end
23
+ end
24
+
25
+ private
26
+
27
+ def fog
28
+ @_fog ||= Fog::Storage.new(
29
+ provider: 'AWS',
30
+ aws_access_key_id: @deployment_access_key || ENV["AWS_ACCESS_KEY_ID"],
31
+ aws_secret_access_key: @deployment_access_secret || ENV["AWS_SECRET_ACCESS_KEY"],
32
+ )
33
+ end
34
+
35
+ def s3_bucket
36
+ @_s3_bucket = fog.directories.new(key: deployment_bucket_name)
37
+ end
38
+ end
39
+ end
40
+ end
@@ -17,7 +17,7 @@ module Stevenson
17
17
  end
18
18
 
19
19
  def place_config(config_file)
20
- place_files(config_file, 'config.yml')
20
+ place_files(config_file, '_config.yml')
21
21
  end
22
22
 
23
23
  def place_files(files, directory)
@@ -1,3 +1,3 @@
1
1
  module Stevenson
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.0"
3
3
  end
data/lib/stevenson.rb CHANGED
@@ -2,10 +2,15 @@ require 'stevenson/version'
2
2
 
3
3
  module Stevenson
4
4
  autoload :Application, 'stevenson/application'
5
+ autoload :Deployer, 'stevenson/deployer'
5
6
  autoload :Dotfile, 'stevenson/dotfile'
6
7
  autoload :Template, 'stevenson/template'
7
8
  autoload :OutputFilter, 'stevenson/output_filter'
8
9
 
10
+ def self.deployers
11
+ @_deployers ||= {}
12
+ end
13
+
9
14
  def self.dotfile
10
15
  @_dotfile ||= Dotfile.new
11
16
  end
@@ -0,0 +1,38 @@
1
+ class Stevenson::Deployer::Test
2
+ include Stevenson::Deployer::Base
3
+ end
4
+
5
+ describe Stevenson::Deployer do
6
+ let(:deployer) { Stevenson::Deployer::Test }
7
+
8
+ describe ".deploy(directory, options)" do
9
+ let(:directory) { "/tmp/path/to/template" }
10
+ let(:options) { Hash.new }
11
+ let(:deployer) { double(:deployer, deploy!: true) }
12
+ subject { described_class.generate!(template, options) }
13
+ end
14
+
15
+ describe ".deployer_for()" do
16
+ context "when the deployer has been registered previously" do
17
+ it "should return the deployer class from Stevenson.deployers" do
18
+ expect(Stevenson::Deployer.send(:deployer_for, :test)).to eq(deployer)
19
+ end
20
+ end
21
+
22
+ context "when the deployer has not been registered previously" do
23
+ it "should return the deployer class from Stevenson.deployers" do
24
+ allow(Stevenson).to receive(:deployers).and_return({})
25
+ expect(Stevenson::Deployer.send(:deployer_for, :test)).to eq(deployer)
26
+ end
27
+ end
28
+
29
+ context "when the deployer doesn't exist" do
30
+ it "should raise a NameError with a descriptive error message" do
31
+ expect { Stevenson::Deployer.send(:deployer_for, :bad_deployer) }.to raise_error do |error|
32
+ expect(error).to be_a(Stevenson::Deployer::InvalidDeployerException)
33
+ expect(error.message).to eq("Type 'bad_deployer' is not a valid deployer.")
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,3 @@
1
+ describe Stevenson::Deployer::S3 do
2
+
3
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,6 +1,9 @@
1
1
  require 'bundler/setup'
2
2
  Bundler.setup
3
3
 
4
+ require "codeclimate-test-reporter"
5
+ CodeClimate::TestReporter.start
6
+
4
7
  require 'helpers'
5
8
  require 'stevenson'
6
9
 
data/stevenson.gemspec CHANGED
@@ -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 "fog"
26
27
  spec.add_dependency "hashie"
27
28
  spec.add_dependency "highline"
28
29
  spec.add_dependency "jekyll"
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: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - RootsRated
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-30 00:00:00.000000000 Z
11
+ date: 2015-10-03 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: fog
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: hashie
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -147,6 +161,7 @@ files:
147
161
  - ".gitignore"
148
162
  - ".rspec"
149
163
  - ".travis.yml"
164
+ - CHANGELOG.md
150
165
  - Gemfile
151
166
  - LICENSE.txt
152
167
  - README.md
@@ -155,6 +170,8 @@ files:
155
170
  - bin/stevenson
156
171
  - lib/stevenson.rb
157
172
  - lib/stevenson/application.rb
173
+ - lib/stevenson/deployer.rb
174
+ - lib/stevenson/deployers/s3.rb
158
175
  - lib/stevenson/dotfile.rb
159
176
  - lib/stevenson/output_filter.rb
160
177
  - lib/stevenson/output_filter/generator.rb
@@ -167,6 +184,8 @@ files:
167
184
  - lib/stevenson/version.rb
168
185
  - spec/bin/.gitkeep
169
186
  - spec/helpers.rb
187
+ - spec/lib/deployer_spec.rb
188
+ - spec/lib/deployers/s3_spec.rb
170
189
  - spec/lib/output_filter/generator_spec.rb
171
190
  - spec/lib/output_filter_spec.rb
172
191
  - spec/lib/output_filters/jekyll_spec.rb
@@ -204,6 +223,8 @@ summary: Stevenson is a generator for Jekyll microsites created by RootsRated.co
204
223
  test_files:
205
224
  - spec/bin/.gitkeep
206
225
  - spec/helpers.rb
226
+ - spec/lib/deployer_spec.rb
227
+ - spec/lib/deployers/s3_spec.rb
207
228
  - spec/lib/output_filter/generator_spec.rb
208
229
  - spec/lib/output_filter_spec.rb
209
230
  - spec/lib/output_filters/jekyll_spec.rb