jekyll_push 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 636044e92b2da03bc6f0ba61b2138608abd9e0278ed167ab9524d71636328349
4
- data.tar.gz: '09b919f4384d22765314f959ad9e8328b2ee7dd0733c339274b7861203a7306f'
3
+ metadata.gz: b0a8a44d8be31ec91a15c4c3b1a0865a64a66348f2ea250e1a1903ab4f362c84
4
+ data.tar.gz: 7e6ad00bad5aa41806c3a6e1297c03370620f9a4af61861d86d84145c2c8ce3f
5
5
  SHA512:
6
- metadata.gz: 1abed319e1c23c713e4eb058e15ea01aa92537de7867cde43e99f836c777f0c39f0acae19e3d6e3c05406c30fc2bbe10ec4d63ef9574022c33e0f2bd5adc6113
7
- data.tar.gz: a3d5de256787e99b9d00b6bb9eab8601f540f5b14eeb4f151839ab4439b0a2368a16ffa891ea8fc8c2848caa2c16428e5b91ffcb9accab6c1d01a1375d73b773
6
+ metadata.gz: 3998d73d53be927fa7835148b24b0b372bc8434643a0fa96993fdb70919cc1a3638dca5ddac7f1c018860c8e28da7d4a693ef567f21018cc1a2eb29161c96ee5
7
+ data.tar.gz: b4a18d3bbd4d5942e50da728abef94f2387a5931cda4c6dce419fc7ffa32ec7171b5d6c1f29e42fbdc800d1ff7d3e603b2aae336c6d0b64de9b572a5526bb812
data/.gitignore CHANGED
@@ -9,3 +9,5 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ /test/
13
+ Gemfile.lock
data/.rubocop.yml CHANGED
@@ -1,5 +1,5 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 2.5
3
3
  Layout/EmptyComment:
4
4
  Enabled: false
5
5
  Metrics/LineLength:
@@ -15,4 +15,9 @@ Style/DoubleNegation:
15
15
  Metrics/AbcSize:
16
16
  Max: 23
17
17
  Metrics/MethodLength:
18
- Max: 15
18
+ Max: 20
19
+ Style/AndOr:
20
+ Enabled: false
21
+ Metrics/BlockLength:
22
+ Exclude:
23
+ - 'spec/**/*'
data/.travis.yml CHANGED
@@ -8,5 +8,17 @@ before_install:
8
8
  - gem update --system
9
9
  - gem install bundler
10
10
  script:
11
- - bundle exec rspec
12
11
  - bundle exec rubocop
12
+ - bundle exec rspec
13
+
14
+ # code climate
15
+
16
+ env:
17
+ global:
18
+ - CC_TEST_REPORTER_ID=09f760621cf09a9165e0202f5714ca6ca751a4a5a5e108cc50e488131390e7ac
19
+ before_script:
20
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
21
+ - chmod +x ./cc-test-reporter
22
+ - ./cc-test-reporter before-build
23
+ after_script:
24
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
data/Gemfile CHANGED
@@ -3,4 +3,8 @@
3
3
  source 'https://rubygems.org'
4
4
  gemspec
5
5
 
6
- gem 'rubocop'
6
+ # dev/test utilities
7
+ gem 'minima', require: false
8
+ gem 'rubocop', require: false
9
+ gem 'simplecov', require: false
10
+ gem 'yard', require: false
data/README.md CHANGED
@@ -1,26 +1,57 @@
1
1
  # JekyllPush
2
- Jekyll gem plugin to push a compiled site to a GitHub branch. Works locally or on Travis CI if you add an access token.
2
+
3
+ [![Build Status](https://travis-ci.org/mnyrop/jekyll_push.svg?branch=master)](https://travis-ci.org/mnyrop/jekyll_push) [![Gem Version](https://badge.fury.io/rb/jekyll_push.svg)](https://badge.fury.io/rb/jekyll_push) [![Gem Downloads](https://img.shields.io/gem/dt/jekyll_push.svg?color=046d0b)](https://badge.fury.io/rb/jekyll_push) [![Maintainability](https://api.codeclimate.com/v1/badges/25dfeec93e298350ce50/maintainability)](https://codeclimate.com/github/mnyrop/jekyll_push/maintainability) [![Test Coverage](https://api.codeclimate.com/v1/badges/25dfeec93e298350ce50/test_coverage)](https://codeclimate.com/github/mnyrop/jekyll_push/test_coverage) [![docs](http://img.shields.io/badge/docs-rdoc.info-blue.svg?style=flat)](https://www.rubydoc.info/github/mnyrop/jekyll_push/) ![License](https://img.shields.io/github/license/mnyrop/jekyll_push.svg?color=c6a1e0)
4
+
5
+ __Jekyll gem plugin to push a compiled Jekyll site to a GitHub branch.__ Works locally or on Travis CI if you add an access token to your Travis build. Great for keeping archived copies or getting to use Jekyll Plugins and still host on GitHub pages.
6
+
7
+ ![push pop gif](https://media1.giphy.com/media/RI41Y0H0osVYQ/giphy.gif)
8
+
3
9
 
4
10
  ## Installation
5
11
 
6
- Add this line to your application's Gemfile:
12
+ Add `jekyll_push` to your Jekyll sites's Gemfile within the `:jekyll_plugins` group:
7
13
 
8
14
  ```ruby
9
- gem 'jekyll_push'
15
+ group :jekyll_plugins do
16
+ gem 'jekyll_push'
17
+ end
10
18
  ```
11
19
 
12
20
  And then execute:
13
21
 
14
22
  $ bundle
15
-
16
- Or install it yourself as:
17
-
18
- $ gem install jekyll_push
23
+
24
+ Make sure you also add `jekyll_push` as a `plugin` to your `_config.yml` file:
25
+ ```yml
26
+ plugins:
27
+ - jekyll_push
28
+ ```
19
29
 
20
30
  ## Usage
21
31
 
22
32
  `$ jekyll push <branch_name>` or `$ bundle exec jekyll push <branch_name>`
23
33
 
34
+ ## Configuration
35
+
36
+ ### For GitHub pages
37
+
38
+ If you run `jekyll push gh-pages` to use __GitHub pages publishing__, `JekyllPush` will look for a `repo_name` variable in your `_config.yml` file and try to construct a `baseurl` from it.
39
+
40
+ For example, if you have a repository named `my_site` just add:
41
+
42
+ ```yaml
43
+ repo_name: my_site
44
+ ```
45
+
46
+ to your `_config.yml` file and `JekyllPush` will rebuild your site using `/my_site` as the `baseurl` before pushing it to the `gh-pages` branch. This lets you use `JekyllPush` for multiple branches and publish targets, with differing (base)url patterns.
47
+
48
+ ### When run locally
49
+
50
+ [ TO DO ]
51
+
52
+ ### When run via Travis-CI
53
+
54
+ [ TO DO ]
24
55
 
25
56
  ## Contributing
26
57
 
data/jekyll_push.gemspec CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |spec|
4
4
  spec.name = 'jekyll_push'
5
- spec.version = '0.1.0'
5
+ spec.version = '0.1.1'
6
6
  spec.authors = ['marii']
7
7
  spec.email = ['m.s.nyrop@gmail.com']
8
8
 
@@ -19,7 +19,5 @@ Gem::Specification.new do |spec|
19
19
 
20
20
  spec.add_runtime_dependency 'jekyll', '> 3.0', '< 4.0'
21
21
  spec.add_runtime_dependency 'rainbow', '~> 3.0'
22
-
23
- spec.add_development_dependency 'rake', '~> 10.0'
24
22
  spec.add_development_dependency 'rspec', '~> 3.0'
25
23
  end
@@ -6,8 +6,7 @@ module JekyllPush
6
6
  class Branch
7
7
  attr_reader :target
8
8
 
9
- # @param target [String] the name of the Git branch to deploy to
10
- # @param time [String] message with the time of deployment
9
+ # @param target [String] the name of the Git branch to deploy to
11
10
  def initialize(target)
12
11
  @target = JekyllPush::Utils.slugify target
13
12
  @time = Time.now.strftime('%H:%M on %Y-%m-%d')
@@ -23,25 +22,25 @@ module JekyllPush
23
22
  end
24
23
 
25
24
  #
26
- #
25
+ # @return [Boolean]
27
26
  def on_travis?
28
27
  !!ENV.fetch('CI', false)
29
28
  end
30
29
 
31
30
  #
32
- #
31
+ # @return [Boolean]
33
32
  def local?
34
33
  !on_travis?
35
34
  end
36
35
 
37
36
  #
38
- #
37
+ # @return [Array]
39
38
  def git_commands
40
39
  ['git init && git add .', "git commit -m '#{@commit}'", "git remote add origin #{@origin}", "git push origin master:refs/heads/#{@target} --force"]
41
40
  end
42
41
 
43
42
  #
44
- #
43
+ # @return [Nil]
45
44
  def push(dir)
46
45
  files = Dir.glob "#{dir}/**/*"
47
46
  raise JekyllPush::Error::NoFilesBuilt, "Found no files inside site directory '#{dir}' to push." if files.empty?
@@ -57,13 +56,13 @@ module JekyllPush
57
56
  end
58
57
 
59
58
  #
60
- #
59
+ # @return [Nil]
61
60
  def pretty_list(items)
62
61
  items.each { |i| puts "\t+ #{i.strip}" }
63
62
  end
64
63
 
65
64
  #
66
- #
65
+ # @return [Nil]
67
66
  def system_try(command)
68
67
  puts Rainbow("\nTrying `#{command}`").cyan
69
68
  success = system command
@@ -9,18 +9,10 @@ module JekyllPush
9
9
  prog.command(:push) do |c|
10
10
  c.syntax 'push [args]'
11
11
  c.description 'pushes compiled site to specified github branch'
12
- c.action do |args, _options|
12
+ c.action do |args, _opts|
13
13
  raise Error::MissingBranch, "You must specify a target branch name after 'jekyll push'." if args.empty?
14
14
 
15
- site = JekyllPush::Site.new
16
- branch = JekyllPush::Branch.new args.first
17
-
18
- warn Rainbow('Warning: Building the site without a baseurl is not recommended if using GitHub pages.').yellow if site.baseurl.empty? && branch.target == 'gh-pages'
19
-
20
- site.rebuild
21
- branch.push site.dir
22
-
23
- puts Rainbow("\nDone ✓").green
15
+ args.each { |a| JekyllPush.run_command a }
24
16
  end
25
17
  end
26
18
  end
@@ -3,13 +3,14 @@
3
3
  module JekyllPush
4
4
  module Error
5
5
  #
6
- #
6
+ # @param msg [String] the custom error message
7
7
  class RainbowError < StandardError
8
8
  def initialize(msg = '')
9
9
  super Rainbow(msg).magenta
10
10
  end
11
11
  end
12
12
 
13
+ class InvalidConfig < RainbowError; end
13
14
  class MissingBranch < RainbowError; end
14
15
  class NoFilesBuilt < RainbowError; end
15
16
  class NoOrigin < RainbowError; end
@@ -5,19 +5,19 @@ module JekyllPush
5
5
  #
6
6
  module Local
7
7
  #
8
- #
8
+ # @return [String]
9
9
  def commit
10
10
  "Updated via JekyllPush local task at #{@time}"
11
11
  end
12
12
 
13
13
  #
14
- #
14
+ # @return [String]
15
15
  def origin
16
16
  `git config --get remote.origin.url`.strip
17
17
  end
18
18
 
19
19
  #
20
- #
20
+ # @return [String]
21
21
  def msg
22
22
  "\nDeploying to branch '#{@target}' from local task."
23
23
  end
@@ -4,38 +4,46 @@ module JekyllPush
4
4
  #
5
5
  #
6
6
  class Site
7
- attr_reader :baseurl, :dir
8
- #
7
+ attr_reader :baseurl, :repo, :dir
9
8
  #
9
+ # @param config [Hash] a site configuration hash
10
10
  def initialize(config = nil)
11
- @config = config || config_from_file
12
- @baseurl = @config.fetch 'baseurl', ''
13
- @dir = compiled_site_dir
11
+ @config = config || JekyllPush.config_from_file
12
+ @baseurl = @config.fetch :baseurl, ''
13
+ @repo = @config.fetch :repo_name, ''
14
+ @dir = site_dir
15
+ rescue TypeError => e
16
+ raise JekyllPush::Error::InvalidConfig, "An invalid (non-Hash) config was provided.\n#{e}"
14
17
  end
15
18
 
16
- #
17
- #
18
- def config_from_file
19
- YAML.load_file "#{`pwd`.strip}/_config.yml"
19
+ # @return [String]
20
+ def site_dir
21
+ File.join `pwd`.strip, '_site'
20
22
  end
21
23
 
24
+ # Use the repostory name as the baseurl when
25
+ # publishing to GitHub pages if available
22
26
  #
23
- #
24
- def compiled_site_dir
25
- File.join `pwd`.strip, '_site'
27
+ # @return [String]
28
+ def gh_baseurl
29
+ if @repo.empty?
30
+ warn Rainbow("Warning: Building the site without the 'repo_name' baseurl is not recommended when using GitHub pages.").yellow if @baseurl.empty?
31
+ @baseurl
32
+ else
33
+ puts Rainbow("Rebuilding with baseurl '/#{@repo}'").cyan
34
+ "/#{@repo}"
35
+ end
26
36
  end
27
37
 
28
- # Rebuild the Jekyll site with @baseurl
38
+ # Rebuild the Jekyll site
29
39
  # @return [Nil]
30
- def rebuild
40
+ def rebuild(target)
41
+ @baseurl = gh_baseurl if target == 'gh-pages'
42
+
31
43
  FileUtils.rm_r @dir if File.directory? @dir
32
- opts = {
33
- destination: @dir,
34
- baseurl: @baseurl
35
- }
36
- opts['source'] = @config.dig 'source_dir' if @config.key? 'source'
37
44
 
38
- Jekyll::Site.new(Jekyll.configuration(opts)).process
45
+ opts = Jekyll.configuration destination: @dir, baseurl: @baseurl
46
+ Jekyll::Site.new(opts).process
39
47
  end
40
48
  end
41
49
  end
@@ -5,13 +5,13 @@ module JekyllPush
5
5
  #
6
6
  module Travis
7
7
  #
8
- #
8
+ # @return [String]
9
9
  def commit
10
10
  "Updated via JekyllPush Travis \"#{ENV['TRAVIS_COMMIT']}\" at #{@time}."
11
11
  end
12
12
 
13
13
  #
14
- #
14
+ # @return [String]
15
15
  def origin
16
16
  @repo_slug = ENV['TRAVIS_REPO_SLUG']
17
17
  @user = @repo_slug.split('/').first
@@ -21,7 +21,7 @@ module JekyllPush
21
21
  end
22
22
 
23
23
  #
24
- #
24
+ # @return [String]
25
25
  def msg
26
26
  "\nDeploying to branch '#{@target}' from Travis as #{@user}."
27
27
  end
@@ -5,7 +5,7 @@ module JekyllPush
5
5
  #
6
6
  module Utils
7
7
  #
8
- #
8
+ # @return [String]
9
9
  def self.slugify(str)
10
10
  safe = str.to_s.downcase.strip.gsub(' ', '-').gsub(/[^\w-]/, '')
11
11
  warn Rainbow("Warning: '#{str}' is not an acceptable branch name. Using '#{safe}' instead.").orange unless safe.eql?(str)
data/lib/jekyll_push.rb CHANGED
@@ -15,4 +15,30 @@ require_relative 'jekyll_push/utils'
15
15
 
16
16
  #
17
17
  #
18
- module JekyllPush; end
18
+ module JekyllPush
19
+ #
20
+ # @return [Nil]
21
+ def self.run_command(arg)
22
+ site = JekyllPush::Site.new
23
+ branch = JekyllPush::Branch.new arg
24
+
25
+ site.rebuild branch.target
26
+ branch.push site.dir
27
+
28
+ puts Rainbow("\nDone ✓").green
29
+ end
30
+
31
+ #
32
+ # @return [String]
33
+ def self.config_path
34
+ "#{`pwd`.strip}/_config.yml"
35
+ end
36
+
37
+ #
38
+ # @return [Hash]
39
+ def self.config_from_file(path = config_path)
40
+ YAML.load_file path
41
+ rescue StandardError => e
42
+ raise JekyllPush::Error::InvalidConfig, "Could not load config file from path '#{path}'\n#{e}"
43
+ end
44
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll_push
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - marii
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-07-24 00:00:00.000000000 Z
11
+ date: 2019-07-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jekyll
@@ -44,20 +44,6 @@ dependencies:
44
44
  - - "~>"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.0'
47
- - !ruby/object:Gem::Dependency
48
- name: rake
49
- requirement: !ruby/object:Gem::Requirement
50
- requirements:
51
- - - "~>"
52
- - !ruby/object:Gem::Version
53
- version: '10.0'
54
- type: :development
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- requirements:
58
- - - "~>"
59
- - !ruby/object:Gem::Version
60
- version: '10.0'
61
47
  - !ruby/object:Gem::Dependency
62
48
  name: rspec
63
49
  requirement: !ruby/object:Gem::Requirement
@@ -85,7 +71,6 @@ files:
85
71
  - ".travis.yml"
86
72
  - CODE_OF_CONDUCT.md
87
73
  - Gemfile
88
- - Gemfile.lock
89
74
  - LICENSE.txt
90
75
  - README.md
91
76
  - jekyll_push.gemspec
data/Gemfile.lock DELETED
@@ -1,103 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- jekyll_push (0.1.0)
5
- jekyll (> 3.0, < 4.0)
6
- rainbow (~> 3.0)
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- addressable (2.6.0)
12
- public_suffix (>= 2.0.2, < 4.0)
13
- ast (2.4.0)
14
- colorator (1.1.0)
15
- concurrent-ruby (1.1.5)
16
- diff-lcs (1.3)
17
- em-websocket (0.5.1)
18
- eventmachine (>= 0.12.9)
19
- http_parser.rb (~> 0.6.0)
20
- eventmachine (1.2.7)
21
- ffi (1.11.1)
22
- forwardable-extended (2.6.0)
23
- http_parser.rb (0.6.0)
24
- i18n (0.9.5)
25
- concurrent-ruby (~> 1.0)
26
- jaro_winkler (1.5.3)
27
- jekyll (3.8.6)
28
- addressable (~> 2.4)
29
- colorator (~> 1.0)
30
- em-websocket (~> 0.5)
31
- i18n (~> 0.7)
32
- jekyll-sass-converter (~> 1.0)
33
- jekyll-watch (~> 2.0)
34
- kramdown (~> 1.14)
35
- liquid (~> 4.0)
36
- mercenary (~> 0.3.3)
37
- pathutil (~> 0.9)
38
- rouge (>= 1.7, < 4)
39
- safe_yaml (~> 1.0)
40
- jekyll-sass-converter (1.5.2)
41
- sass (~> 3.4)
42
- jekyll-watch (2.2.1)
43
- listen (~> 3.0)
44
- kramdown (1.17.0)
45
- liquid (4.0.3)
46
- listen (3.1.5)
47
- rb-fsevent (~> 0.9, >= 0.9.4)
48
- rb-inotify (~> 0.9, >= 0.9.7)
49
- ruby_dep (~> 1.2)
50
- mercenary (0.3.6)
51
- parallel (1.17.0)
52
- parser (2.6.3.0)
53
- ast (~> 2.4.0)
54
- pathutil (0.16.2)
55
- forwardable-extended (~> 2.6)
56
- public_suffix (3.1.1)
57
- rainbow (3.0.0)
58
- rake (10.5.0)
59
- rb-fsevent (0.10.3)
60
- rb-inotify (0.10.0)
61
- ffi (~> 1.0)
62
- rouge (3.7.0)
63
- rspec (3.8.0)
64
- rspec-core (~> 3.8.0)
65
- rspec-expectations (~> 3.8.0)
66
- rspec-mocks (~> 3.8.0)
67
- rspec-core (3.8.2)
68
- rspec-support (~> 3.8.0)
69
- rspec-expectations (3.8.4)
70
- diff-lcs (>= 1.2.0, < 2.0)
71
- rspec-support (~> 3.8.0)
72
- rspec-mocks (3.8.1)
73
- diff-lcs (>= 1.2.0, < 2.0)
74
- rspec-support (~> 3.8.0)
75
- rspec-support (3.8.2)
76
- rubocop (0.73.0)
77
- jaro_winkler (~> 1.5.1)
78
- parallel (~> 1.10)
79
- parser (>= 2.6)
80
- rainbow (>= 2.2.2, < 4.0)
81
- ruby-progressbar (~> 1.7)
82
- unicode-display_width (>= 1.4.0, < 1.7)
83
- ruby-progressbar (1.10.1)
84
- ruby_dep (1.5.0)
85
- safe_yaml (1.0.5)
86
- sass (3.7.4)
87
- sass-listen (~> 4.0.0)
88
- sass-listen (4.0.0)
89
- rb-fsevent (~> 0.9, >= 0.9.4)
90
- rb-inotify (~> 0.9, >= 0.9.7)
91
- unicode-display_width (1.6.0)
92
-
93
- PLATFORMS
94
- ruby
95
-
96
- DEPENDENCIES
97
- jekyll_push!
98
- rake (~> 10.0)
99
- rspec (~> 3.0)
100
- rubocop
101
-
102
- BUNDLED WITH
103
- 2.0.1