rake-jekyll 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 9b24b1b646810e6d3ccfad8ae77f5e169936b1ae
4
+ data.tar.gz: 6f954130217f2c8678edf4c1ca878eaf900527bf
5
+ SHA512:
6
+ metadata.gz: c0be582d3f7ca2959c362cce605e3783e2ef75219c7b5ebf1e5c452c73502247c6f2496163ae494bf098a9a2945936a1a4bddd6d97181f6c688f5612aeccf8dd
7
+ data.tar.gz: cf4cc0211472ba961570535003f6638fba566fdeca8e39bb10cf532d753760868343d53dce8207eb9d1f8fa11d79aa570c72ad581e72b2dad3987020eefb352d
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright 2015 Jakub Jirutka <jakub@jirutka.cz>.
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,162 @@
1
+ = Rake tasks for Jekyll
2
+ Jakub Jirutka <https://github.com/jirutka[@jirutka]>
3
+ :page-layout: base
4
+ :idprefix:
5
+ ifdef::env-github[:idprefix: user-content-]
6
+ :idseparator: -
7
+ // custom
8
+ :gem-name: rake-jekyll
9
+ :gh-name: jirutka/{gem-name}
10
+ :gh-branch: master
11
+ :badge-style: flat
12
+
13
+ image:https://inch-ci.org/github/{gh-name}.svg?branch={gh-branch}&style={badge-style}[Inline docs, link="http://inch-ci.org/github/{gh-name}"]
14
+ image:https://img.shields.io/gem/v/{gem-name}.svg?style={badge-style}[Gem Version, link="https://rubygems.org/gems/{gem-name}"]
15
+ image:https://img.shields.io/badge/yard-docs-blue.svg?style={badge-style}[Yard Docs, link="http://www.rubydoc.info/github/{gh-name}/frames"]
16
+
17
+
18
+ == Installation
19
+
20
+ Add this line to your application’s Gemfile:
21
+
22
+ gem 'rake-jekyll'
23
+
24
+ and then execute:
25
+
26
+ $ bundle
27
+
28
+
29
+ == Tasks
30
+
31
+ === Deploy to Git
32
+
33
+ This task builds the Jekyll site and deploys it to a remote Git repository.
34
+
35
+ ==== Usage
36
+
37
+ The most simple usage suitable for GitHub and Travis CI:
38
+
39
+ [source, ruby]
40
+ ----
41
+ require 'rake-jekyll'
42
+
43
+ Rake::Jekyll::GitDeployTask.new
44
+ ----
45
+
46
+ This listing introduces all the configurable options with their default values:
47
+
48
+ [source, ruby]
49
+ ----
50
+ require 'rake-jekyll'
51
+
52
+ Rake::Jekyll::GitDeployTask.new(:deploy) do |t|
53
+
54
+ # Description of the rake task.
55
+ t.description = 'Generate the site and push changes to remote repository'
56
+
57
+ # Overrides the *author* of the commit being created with author of the
58
+ # source commit (i.e. HEAD in the current branch).
59
+ t.author = -> {
60
+ `git log -n 1 --format='%aN <%aE>'`.strip
61
+ }
62
+ # Overrides the *author date* of the commit being created with date of the
63
+ # source commit.
64
+ t.author_date = -> {
65
+ `git log -n 1 --format='%aD'`.strip
66
+ }
67
+ # The commit message will contain hash of the source commit.
68
+ t.commit_message = -> {
69
+ "Built from #{`git rev-parse --short HEAD`.strip}"
70
+ }
71
+ # Use 'Jekyll' as the default *committer* name (with empty email) when the
72
+ # user.name is not set in git config.
73
+ t.committer = 'Jekyll'
74
+
75
+ # Deploy the built site into remote branch named 'gh-pages'. It will be
76
+ # automatically created if not exist yet.
77
+ t.deploy_branch = 'gh-pages'
78
+
79
+ # Run this command to build the site.
80
+ t.jekyll_build = ->(dest_dir) {
81
+ system "bundle exec jekyll build --destination #{dest_dir}"
82
+ }
83
+ # Use the default committer (configured in git) when available.
84
+ t.override_committer = false
85
+
86
+ # Use URL of the 'origin' remote to fetch/push the built site into. If env.
87
+ # variable GH_TOKEN is set, then it adds it as a userinfo to the URL.
88
+ t.remote_url = -> {
89
+ `git config remote.origin.url`.strip.gsub(/^git:/, 'https:').tap do |url|
90
+ url.gsub!(%r{^https://}, "https://#{ENV['GH_TOKEN']}@") if ENV.key? 'GH_TOKEN'
91
+ end
92
+ }
93
+ # Skip commit and push when building a pull request or env. variable
94
+ # SKIP_COMMIT represents truthy.
95
+ t.skip_commit = -> {
96
+ ENV['TRAVIS_PULL_REQUEST'].to_i > 0 ||
97
+ %w[yes y true 1].include?(ENV['SKIP_COMMIT'].to_s.downcase)
98
+ }
99
+ end
100
+ ----
101
+
102
+ Note: All options except `name` and `description` accepts both String and Proc as a value.
103
+
104
+
105
+ ==== Setup for GitHub Pages and Travis CI
106
+
107
+ . Create or edit file `Rakefile` in your Jekyll repository:
108
+ +
109
+ [source, ruby]
110
+ ----
111
+ require 'rake-jekyll'
112
+
113
+ Rake::Jekyll::GitDeployTask.new(:deploy)
114
+ ----
115
+ . Install travis gem:
116
+ +
117
+ $ gem install travis
118
+ +
119
+ . Create file `.travis.yml` in the root of your Jekyll repository:
120
+ +
121
+ [source, yaml]
122
+ ----
123
+ language: ruby
124
+ sudo: false
125
+ rvm: 2.2.0
126
+ script: bundle exec rake deploy
127
+ ----
128
+ . Enable Travis CI for your Jekyll repository:
129
+ .. open your https://travis-ci.org/profile/[profile page] on Travis,
130
+ .. find the repository and turn on the switch,
131
+ .. then click on repository settings (next to the switch) and enable “Build only if .travis.yml is present.”
132
+ . Generate a new personal access token on GitHub:
133
+ .. open https://github.com/settings/tokens/new[this page] to generate a new personal access token,
134
+ .. select the scope _public_repo_, fill some description and confirm.
135
+ . Encrypt the token and add it to your `.travis.yml`:
136
+ .. replace `<token>` with the GitHub token and execute:
137
+ +
138
+ $ travis encrypt GH_TOKEN=<token> --add env.global
139
+ +
140
+ .. and check that it added something like the following to `.travis.yml`:
141
+ +
142
+ [source, yaml]
143
+ ----
144
+ env:
145
+ global:
146
+ secure: YOUR-ENCRYPTED-TOKEN
147
+ ----
148
+ . Commit changes, push to GitHub and check that Travis has started the job and finished it successfully.
149
+
150
+
151
+ == Contributing
152
+
153
+ 1. Fork it.
154
+ 2. Create your feature branch (`git checkout -b my-new-feature`).
155
+ 3. Commit your changes (`git commit -am 'Add some feature'`).
156
+ 4. Push to the branch (`git push origin my-new-feature`).
157
+ 5. Create a new Pull Request.
158
+
159
+
160
+ == License
161
+
162
+ This project is licensed under http://opensource.org/licenses/MIT/[MIT License]. For the full text of the license, see the link:LICENSE[LICENSE] file.
@@ -0,0 +1,9 @@
1
+ require 'bundler/gem_tasks'
2
+
3
+ begin
4
+ require 'yard'
5
+ # options are defined in .yardopts
6
+ YARD::Rake::YardocTask.new(:yard)
7
+ rescue LoadError => e
8
+ warn "#{e.path} is not available"
9
+ end
@@ -0,0 +1,2 @@
1
+ require 'rake-jekyll/version'
2
+ require 'rake-jekyll/git_deploy_task'
@@ -0,0 +1,270 @@
1
+ require 'rake/tasklib'
2
+ require 'tmpdir'
3
+
4
+ module Rake::Jekyll
5
+ ##
6
+ # This task builds the Jekyll site and deploys it to a remote Git repository.
7
+ class GitDeployTask < ::Rake::TaskLib
8
+
9
+ ##
10
+ # @private
11
+ # Functions that wraps calls to +git+ command.
12
+ module GitCommands
13
+
14
+ def any_changes?
15
+ ! `git status --porcelain`.empty?
16
+ end
17
+
18
+ def clone_repo(url)
19
+ sh "git clone '#{url}' ."
20
+ end
21
+
22
+ def checkout_remote_branch(name)
23
+ sh "git checkout --track #{name}"
24
+ end
25
+
26
+ def commit_all(message, author = '', date = '')
27
+ opts = [ "--message='#{message}'" ]
28
+ opts << "--author='#{author}'" unless author.empty?
29
+ opts << "--date='#{date}'" unless date.empty?
30
+
31
+ sh "git add --all && git commit #{opts.join(' ')}"
32
+ end
33
+
34
+ def config_set?(key)
35
+ ! `git config --get #{key}`.empty?
36
+ end
37
+
38
+ def config_user_set(name_email)
39
+ name, email = parse_name_email(name_email)
40
+ sh "git config --local user.name '#{name}'"
41
+ sh "git config --local user.email '#{email}'"
42
+ end
43
+
44
+ def create_orphan_branch(name)
45
+ sh "git checkout --orphan #{name}"
46
+ sh 'git rm -rf . &>/dev/null || true'
47
+ end
48
+
49
+ # @return [String] name of the current active branch.
50
+ def current_branch
51
+ `git symbolic-ref --short -q HEAD`.strip
52
+ end
53
+
54
+ def push(remote_url, branch)
55
+ sh "git push -q #{remote_url} #{branch}:#{branch}"
56
+ end
57
+
58
+ private
59
+
60
+ def parse_name_email(str)
61
+ if matched = str.match(/^([^<]*)(?:<([^>]*)>)?$/)
62
+ matched[1..2].map do |val|
63
+ val.strip.empty? ? nil : val.strip if val
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ include GitCommands
70
+
71
+ ##
72
+ # @private
73
+ # Defines attribute accessor with optional default value.
74
+ # When attribute's value is a +Proc+ with arity 0, then the attribute
75
+ # reader calls it and returns the result.
76
+ #
77
+ # @param attr_name [#to_s] name of the attribute to define.
78
+ # @param default_value [Object] the default value (optional).
79
+ # @yield When the block is given, then it's used as a default value.
80
+ # It takes precedence over +default_value+.
81
+ def self.callable_attr(attr_name, default_value = nil, &default_block)
82
+ var_name = "@#{attr_name}".sub('?', '').to_sym
83
+
84
+ define_method attr_name do
85
+ value = instance_variable_get(var_name)
86
+ if value.nil? && default_block
87
+ do_in_working_dir &default_block
88
+ elsif value.nil?
89
+ default_value
90
+ elsif value.is_a?(Proc) && value.arity.zero?
91
+ do_in_working_dir &value
92
+ else
93
+ value
94
+ end
95
+ end
96
+
97
+ attr_writer attr_name.to_s.sub('?', '')
98
+ end
99
+
100
+ # @return [#to_sym] name of the task.
101
+ attr_accessor :name
102
+
103
+ # @return [#to_s] description of the task.
104
+ attr_accessor :description
105
+
106
+ ##
107
+ # @!attribute author
108
+ # Overrides the _author_ of the commit being created in {#deploy_branch}.
109
+ # Defaults to author of the HEAD in the current (i.e. source) branch.
110
+ #
111
+ # @return [String, Proc] author name and email in the standard mail format,
112
+ # e.g. Kevin Flynn <kevin@flynn.com>, or empty string to not override.
113
+ #
114
+ callable_attr :author do
115
+ `git log -n 1 --format='%aN <%aE>'`.strip
116
+ end
117
+
118
+ ##
119
+ # @!attribute author_date
120
+ # Overrides the _author date_ of the commit being created in
121
+ # {#deploy_branch}. Defaults to date of the HEAD in the current
122
+ # (i.e. source) branch.
123
+ #
124
+ # @return [String, Proc] date in any format supported by git (i.e. Git
125
+ # internal format, RFC 2822, or RFC 8601).
126
+ #
127
+ callable_attr :author_date do
128
+ `git log -n 1 --format='%aD'`.strip
129
+ end
130
+
131
+ ##
132
+ # @!attribute commit_message
133
+ # @return [String, Proc] the commit message. Defaults to +Built from {REV}+,
134
+ # where +{REV}+ is hash of the HEAD in the current (i.e. source) branch.
135
+ callable_attr :commit_message do
136
+ hash = `git rev-parse --short HEAD`.strip
137
+ "Built from #{hash}"
138
+ end
139
+
140
+ ##
141
+ # @!attribute committer
142
+ # Defines the default _committer_ to be used when the +user.name+ is not
143
+ # set in git config and/or {#override_committer?} is +true+.
144
+ #
145
+ # @return [String, Proc] author name and email in the standard mail format,
146
+ # e.g. Kevin Flynn <kevin@flynn.com>. (default: +Jekyll+).
147
+ #
148
+ callable_attr :committer, 'Jekyll'
149
+
150
+ ##
151
+ # @!attribute deploy_branch
152
+ # Defines name of the remote branch to deploy the built site into.
153
+ # If the remote branch doesn't exist yet, then it's automatically created
154
+ # as an orphan branch.
155
+ #
156
+ # @return [String, Proc] name of the remote branch (default: +gh-pages+).
157
+ #
158
+ callable_attr :deploy_branch, 'gh-pages'
159
+
160
+ ##
161
+ # @!attribute jekyll_build
162
+ # Defines a function that executes Jekyll to build the site.
163
+ # Defaults to:
164
+ # sh "bundle exec jekyll build --destination #{dest_dir}"
165
+ #
166
+ # @return [Proc] a Proc that accepts one argument; the destination
167
+ # directory to generate the site into.
168
+ #
169
+ callable_attr :jekyll_build, ->(dest_dir) {
170
+ system "bundle exec jekyll build --destination #{dest_dir}"
171
+ }
172
+
173
+ ##
174
+ # @!attribute override_committer?
175
+ # @return [Boolean, Proc] +true+ to always use {#committer}, +false+ to use
176
+ # the default committer (configured in git) when available.
177
+ callable_attr :override_committer?, false
178
+
179
+ ##
180
+ # @!attribute remote_url
181
+ # @return [String, Proc] URL of the remote git repository to fetch and push
182
+ # the built site into. The default is to use URL of the +origin+ remote,
183
+ # replace +git:+ schema with +https:+ and add environment variable
184
+ # +GH_TOKEN+ as an userinfo (if exists).
185
+ callable_attr :remote_url do
186
+ `git config remote.origin.url`.strip.gsub(/^git:/, 'https:').tap do |url|
187
+ url.gsub!(%r{^https://}, "https://#{ENV['GH_TOKEN']}@") if ENV.key? 'GH_TOKEN'
188
+ end
189
+ end
190
+
191
+ ##
192
+ # @!attribute [w] skip_commit
193
+ # Whether to skip the commit and push phase.
194
+ # Default is to return +false+ when env variable +TRAVIS_PULL_REQUEST+
195
+ # is an integer value greater than 0 or +SKIP_COMMIT+ represents truthy
196
+ # (i.e. contains yes, y, true, or 1).
197
+ #
198
+ # @return [Boolean, Proc]
199
+ #
200
+ callable_attr :skip_commit? do
201
+ ENV['TRAVIS_PULL_REQUEST'].to_i > 0 ||
202
+ %w[yes y true 1].include?(ENV['SKIP_COMMIT'].to_s.downcase)
203
+ end
204
+
205
+
206
+ ##
207
+ # @param name [#to_sym] name of the task to define.
208
+ # @yield The block to configure this task.
209
+ def initialize(name = :deploy)
210
+ @name = name
211
+ @description = 'Generate the site and push changes to remote repository'
212
+ @working_dir = Dir.pwd
213
+
214
+ yield self if block_given?
215
+
216
+ define_task!
217
+ end
218
+
219
+ private
220
+
221
+ def define_task!
222
+ desc description.to_s
223
+
224
+ task name.to_sym do
225
+ @working_dir = Dir.pwd
226
+
227
+ Dir.mktmpdir do |temp_dir|
228
+ Dir.chdir temp_dir do
229
+ clone_repo remote_url
230
+
231
+ if current_branch != deploy_branch
232
+ begin
233
+ checkout_remote_branch "origin/#{deploy_branch}"
234
+ rescue RuntimeError
235
+ puts "\nBranch #{deploy_branch} doesn't exist yet, initializing..."
236
+ create_orphan_branch deploy_branch
237
+ end
238
+ end
239
+ end
240
+
241
+ puts "\nRunning Jekyll..."
242
+ jekyll_build[temp_dir]
243
+
244
+ Dir.chdir temp_dir do
245
+ unless any_changes?
246
+ puts 'Nothing to commit.'; next
247
+ end
248
+
249
+ if skip_commit?
250
+ puts 'Skipping commit.'; next
251
+ end
252
+
253
+ if override_committer? || !config_set?('user.name')
254
+ config_user_set committer
255
+ end
256
+
257
+ commit_all commit_message, author, author_date
258
+ push remote_url, deploy_branch
259
+ end
260
+ end
261
+ end
262
+ end
263
+
264
+ def do_in_working_dir
265
+ Dir.chdir @working_dir do
266
+ yield
267
+ end
268
+ end
269
+ end
270
+ end
@@ -0,0 +1,5 @@
1
+ module Rake
2
+ module Jekyll
3
+ VERSION = '1.0.2'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-jekyll
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Jakub Jirutka
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-01-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '10.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '10.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: yard
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.8'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.8'
55
+ description: Tasks for deploying Jekyll site to Git etc.
56
+ email: jakub@jirutka.cz
57
+ executables: []
58
+ extensions: []
59
+ extra_rdoc_files: []
60
+ files:
61
+ - LICENSE
62
+ - README.adoc
63
+ - Rakefile
64
+ - lib/rake-jekyll.rb
65
+ - lib/rake-jekyll/git_deploy_task.rb
66
+ - lib/rake-jekyll/version.rb
67
+ homepage: https://github.com/jirutka/rake-jekyll
68
+ licenses:
69
+ - MIT
70
+ metadata: {}
71
+ post_install_message:
72
+ rdoc_options: []
73
+ require_paths:
74
+ - lib
75
+ required_ruby_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - ">="
78
+ - !ruby/object:Gem::Version
79
+ version: '2.0'
80
+ required_rubygems_version: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ requirements: []
86
+ rubyforge_project:
87
+ rubygems_version: 2.4.5
88
+ signing_key:
89
+ specification_version: 4
90
+ summary: Rake tasks for Jekyll.
91
+ test_files: []
92
+ has_rdoc: yard