github_pages_rake_tasks 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3c1c26a1c1d2a2f421fb63e5ee55069934e330b5
4
+ data.tar.gz: ae3f9ed9b8e1382f75c76927e64b4b0d7f01cf35
5
+ SHA512:
6
+ metadata.gz: 7f922d47b730f6b7366001dbe3d966ba528724ba1f4d49515fc806ffedfaff9bb484b2f3a0065a8bce1a568c1fba02447e05da9d2bd49b1d3257c8b56c16e25c
7
+ data.tar.gz: bec3b910b62b6e85783933d66972b8682587f42e6a5d78a56871092afece607dd0977b0ded31fbfdce539aa0d072d55c4d204c36d90c092251dfb3237e2b449d
data/.gitignore ADDED
@@ -0,0 +1,23 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
12
+
13
+ # rubocop
14
+ rubocop-report.json
15
+
16
+ # yardstick
17
+ measurements
18
+
19
+ Gemfile.lock
20
+
21
+ # JetBrains files
22
+ *.iml
23
+ .idea
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,25 @@
1
+ AllCops:
2
+ # Output extra information for each offense to make it easier to diagnose:
3
+ DisplayCopNames: true
4
+ DisplayStyleGuide: true
5
+ ExtraDetails: true
6
+ # Rubocop enforces rules depending on the oldest version of Ruby which
7
+ # your project supports:
8
+ TargetRubyVersion: 2.5
9
+
10
+ # The default max line length for this project
11
+ Metrics/LineLength:
12
+ Max: 100
13
+
14
+ # The DSL for RSpec and the gemspec file make it very hard to limit block length:
15
+ Metrics/BlockLength:
16
+ Exclude:
17
+ - "spec/**/*_spec.rb"
18
+ - "*.gemspec"
19
+
20
+ # All Ruby files are required to have a Copyright notice.
21
+ # Run `rubocop -a` to automatically add missing copyright notices.
22
+ Style/Copyright:
23
+ Enabled: true
24
+ Notice: 'Copyright (\(c\) )?2019 James Couball'
25
+ AutocorrectNotice: "# Copyright (c) 2019 James Couball\n"
data/.travis.yml ADDED
@@ -0,0 +1,19 @@
1
+ language: ruby
2
+
3
+ cache: bundler
4
+
5
+ rvm:
6
+ - 2.3
7
+ - 2.4
8
+ - 2.5
9
+ - 2.6
10
+
11
+ before_install: gem install bundler -v 2.0.1
12
+
13
+ deploy:
14
+ provider: rubygems
15
+ api_key:
16
+ secure: HA1sMG5jqnSSpcIEi0Ej3HDAzff5dMNvGeb1FK5BAnfV+C5pHTkUU26+fEUmrr31nDeU3hgEv+rDdz7+Udt5hO9NGIF3bRhlqBYkkaIwLfOragaoROyq+tAPag7Mm5VKfzbXYE7dqEDZSQLjHIiY3UxksNnV3kQ+VvXL1eHg5n765EnwJP2F+FYWd7NBaq+QitdKEUZlY1Xktyq+5Isk7g0mYKZEf8K1S7MU79m4vHLI6GAT2sTCxGSsAAJejL7OYNF7Yo/8DcIsyqQjjJmkZVbHfIgpw9GrQVILNeP+4tA4LdZ9us/uk+VyM5iWMdAvQk9MW3Sl3VNo2fj9IYkOtTpqPiHoWD/zKdjI0qeDFLhaj7inSvLsXRL3IAibGV0zaNi7pNg5bwL4jKcXQDeJri4m0eKfYZQKOXQ9NqbnAHUiSrpdgJxbzmaZvMfIEI18aBXa3xdKKdBQk0ogeh2FvqIL7dCHamMsyAZRWIqOLiKwNnZ2o/4JvCgnELPo/nhmvdAE08KV4i3TE8eHBipY6ZLIThVMNURGAF9Le4bcFrGcCvPVEvzPXHV9QE91cQ8mN9NM9Rz3SZuqvSIwLGDAmor5oyxnWr9Vwm2S/7OAxdD2X2l+sTks0U/EXQ+I+axEexMUgCOgUChSz8pAHxujc+/nRLJ4VE/MZ1ZO7KMAMok=
17
+ gem: github_pages_rake_tasks
18
+ on:
19
+ repo: jcouball/github_pages_rake_tasks
data/.yardopts ADDED
@@ -0,0 +1,3 @@
1
+ --no-private
2
+ --hide-void-return
3
+ --markup markdown
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ # Copyright (c) 2019 James Couball
2
+ # frozen_string_literal: true
3
+
4
+ source 'https://rubygems.org'
5
+
6
+ # Specify your gem's dependencies in github_pages_rake_tasks.gemspec
7
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 James Couball
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 all
13
+ 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 THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,63 @@
1
+ # Publish Documentation to GitHub Pages
2
+
3
+ [![Build Status](https://travis-ci.com/jcouball/github_pages_rake_tasks.svg?branch=master)](https://travis-ci.com/jcouball/github_pages_rake_tasks)
4
+
5
+ The `github_pages_rake_tasks` gem creates a rake task that pushes the contents
6
+ from a local documentation directory to a remote Git repository branch.
7
+
8
+ By default, the rake task `github-pages:publish` is created which pushes the `doc`
9
+ directory within the local copy of your repository to the same repository's
10
+ `gh-pages` branch. The contents of the branch are completely replaced by the
11
+ contents of the documentation directory.
12
+
13
+ This task is useful for publishing `rdoc` or `yard` documentation using
14
+ [GitHub Pages](https://pages.github.com).
15
+
16
+ ## Installation
17
+
18
+ Add this line to your application's Gemfile:
19
+
20
+ gem 'github_pages_rake_tasks'
21
+
22
+ And then execute:
23
+
24
+ $ bundle
25
+
26
+ Or install it directly with the `gem` command line:
27
+
28
+ $ gem install github_pages_rake_tasks
29
+
30
+ ## Usage
31
+
32
+ Add the `github-pages:publish` task to Rake by adding the following lines in your Rakefile:
33
+
34
+ ```Ruby
35
+ require 'github_pages_rake_tasks'
36
+ GitHubPagesRakeTasks.Tasks.new
37
+ ```
38
+
39
+ You can also configure the task by providing a block during initialization:
40
+
41
+ ```Ruby
42
+ require 'github_pages_rake_tasks'
43
+ GitHubPagesRakeTasks.Tasks.new do |task|
44
+ task.doc_dir = 'documentation'
45
+ task.repo_url = 'https://github.com/jcouball/github_pages_documentation'
46
+ task.branch_name = 'master'
47
+ end
48
+ ```
49
+
50
+ See [the full usage documentation](https://github.com/pages/jcouball/guthub_pages_rake_tasks) for more details.
51
+
52
+ ## Development
53
+
54
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
55
+
56
+ To install this gem onto your local machine, run `bundle exec rake install`.
57
+ To release a new version, update the version number in `version.rb`, and then run
58
+ `bundle exec rake release`, which will create a git tag for the version, push git
59
+ commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
60
+
61
+ ## Contributing
62
+
63
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jcouball/github_pages_rake_tasks.
data/Rakefile ADDED
@@ -0,0 +1,41 @@
1
+ # Copyright (c) 2019 James Couball
2
+ # frozen_string_literal: true
3
+
4
+ require 'bundler/gem_tasks'
5
+ CLOBBER << 'Gemfile.lock'
6
+
7
+ require 'rspec/core/rake_task'
8
+ RSpec::Core::RakeTask.new(:spec)
9
+ CLEAN << '.rspec_status'
10
+ CLEAN << 'coverage'
11
+
12
+ require 'bundler/audit/task'
13
+ Bundler::Audit::Task.new
14
+
15
+ require 'bump/tasks'
16
+
17
+ require 'rubocop/rake_task'
18
+ RuboCop::RakeTask.new do |t|
19
+ t.options = %w[--format progress --format json --out rubocop-report.json]
20
+ end
21
+ CLEAN << 'rubocop-report.json'
22
+
23
+ require 'yard'
24
+ YARD::Rake::YardocTask.new
25
+ CLEAN << '.yardoc'
26
+ CLEAN << 'doc'
27
+
28
+ require 'yardstick/rake/verify'
29
+ require 'yaml'
30
+ Yardstick::Rake::Verify.new('yardstick:verify')
31
+
32
+ require 'yardstick/rake/measurement'
33
+ Yardstick::Rake::Measurement.new('yardstick:measure')
34
+ CLEAN << 'measurements'
35
+
36
+ desc 'Run yardstick to check yard docs'
37
+ task :yardstick do
38
+ sh "yardstick 'lib/**/*.rb'"
39
+ end
40
+
41
+ task default: [:spec, 'bundle:audit', :rubocop, :yard, :build]
data/bin/console ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # Copyright (c) 2019 James Couball
3
+ # frozen_string_literal: true
4
+
5
+ require 'bundler/setup'
6
+ require 'github_pages_rake_tasks'
7
+
8
+ # You can add fixtures and/or initialization code here to make experimenting
9
+ # with your gem easier. You can also use a different console, if you like.
10
+
11
+ # (If you use this, don't forget to add pry to your Gemfile!)
12
+ # require "pry"
13
+ # Pry.start
14
+
15
+ require 'irb'
16
+ IRB.start(__FILE__)
data/bin/setup ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ # Copyright (c) 2019 James Couball
3
+
4
+ set -euo pipefail
5
+ IFS=$'\n\t'
6
+ set -vx
7
+
8
+ bundle install
9
+
10
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,54 @@
1
+ # Copyright (c) 2019 James Couball
2
+ # frozen_string_literal: true
3
+
4
+ lib = File.expand_path('lib', __dir__)
5
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
6
+ require 'github_pages_rake_tasks/version'
7
+
8
+ Gem::Specification.new do |spec|
9
+ spec.name = 'github_pages_rake_tasks'
10
+ spec.version = GithubPagesRakeTasks::VERSION
11
+ spec.authors = ['James Couball']
12
+ spec.email = ['jcouball@yahoo.com']
13
+
14
+ spec.summary = 'Rake tasks for publishing documentation to GitHub Pages'
15
+ spec.description = <<~DESCRIPTION
16
+ A Rake task to publish documentation like yard or mkdocs to GitHub Pages.
17
+
18
+ The rake task copies all files from the src_dir and pushes them to the
19
+ GitHub repository and branch identified by repo_url and branch_name.
20
+
21
+ The contents of the branch are completely overwritten by the contents of src_dir.
22
+ DESCRIPTION
23
+
24
+ spec.homepage = 'https://github.com/jcouball/github_pages_rake_tasks'
25
+ spec.license = 'MIT'
26
+
27
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
28
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
29
+ if spec.respond_to?(:metadata)
30
+ spec.metadata['homepage_uri'] = spec.homepage
31
+ spec.metadata['source_code_uri'] = spec.homepage
32
+ spec.metadata['changelog_uri'] = spec.homepage
33
+ end
34
+
35
+ # Specify which files should be added to the gem when it is released.
36
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
37
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
38
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
39
+ end
40
+ spec.bindir = 'exe'
41
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
42
+ spec.require_paths = ['lib']
43
+
44
+ spec.add_development_dependency 'bump', '~> 0.8'
45
+ spec.add_development_dependency 'bundler', '~> 2.0'
46
+ spec.add_development_dependency 'bundler-audit', '~> 0.6'
47
+ spec.add_development_dependency 'rake', '~> 12.3'
48
+ spec.add_development_dependency 'rspec', '~> 3.8'
49
+ spec.add_development_dependency 'rubocop', '~> 0.70'
50
+ spec.add_development_dependency 'simplecov', '~> 0.16'
51
+ spec.add_development_dependency 'simplecov-lcov', '~> 0.7'
52
+ spec.add_development_dependency 'yard', '~> 0.9'
53
+ spec.add_development_dependency 'yardstick', '~> 0.9'
54
+ end
@@ -0,0 +1,8 @@
1
+ # Copyright (c) 2019 James Couball
2
+
3
+ # frozen_string_literal: true
4
+
5
+ require 'github_pages_rake_tasks/version'
6
+ require 'github_pages_rake_tasks/interface'
7
+ require 'github_pages_rake_tasks/publish_task'
8
+ require 'github_pages_rake_tasks/state'
@@ -0,0 +1,77 @@
1
+ # Copyright (c) 2019 James Couball
2
+ # frozen_string_literal: true
3
+
4
+ require 'forwardable'
5
+ require 'rake'
6
+
7
+ module GithubPagesRakeTasks
8
+ # Whenever the publish task has to interact with things outside of itself,
9
+ # it uses an instance of the interface class. This makes the tests easy to
10
+ # mock.
11
+ #
12
+ # @example
13
+ # interface = Interface.new
14
+ # interface.chdir(path) do |path|
15
+ # interface.sh('git clone https://github.com/jcouball/project')
16
+ # end
17
+ #
18
+ # Inject an object into an instance of PublishTask in order to mock the
19
+ # task's interaction with the outside world.
20
+ #
21
+ # @example
22
+ # PublishTask.new do |t|
23
+ # t.interface = Object.new
24
+ # def chdir(path); end
25
+ # ...
26
+ # end
27
+ # end
28
+ #
29
+ # @see https://docs.ruby-lang.org/en/2.6.0/Dir.html Dir documentation
30
+ # @see https://docs.ruby-lang.org/en/2.6.0/File.html File documentation
31
+ # @see https://docs.ruby-lang.org/en/2.6.0/FileUtils.html FileUtils documentation
32
+ #
33
+ # @api public
34
+ #
35
+ class Interface
36
+ extend Forwardable
37
+
38
+ def_delegators :@file_utils, :chdir, :rm_rf, :cp_r, :sh, :verbose
39
+ def_delegators :@dir, :mktmpdir
40
+ def_delegator :@dir, :exist?, :dir_exist?
41
+ def_delegators :@file, :expand_path
42
+ def_delegator :@file, :write, :file_write
43
+
44
+ # Creates a new interface object
45
+ #
46
+ # This object will delegate methods to the objects passed in as defined in
47
+ # the Forwardable def_delegators above.
48
+ #
49
+ # @example
50
+ # interface = GithubPagesRakeTasks.new
51
+ # interface.chdir('test') do
52
+ # interface.cp_r(src, dest)
53
+ # end
54
+ #
55
+ # @return [void]
56
+ #
57
+ def initialize
58
+ @file_utils = Rake::FileUtilsExt
59
+ @dir = Dir
60
+ @file = File
61
+ end
62
+
63
+ # Delegates call to Kernel::`
64
+ #
65
+ # @example
66
+ # interface = GithubPagesRakeTasks::Interface.new
67
+ # project_root = interface.send(:`, 'git rev-parse --show-toplevel').chomp
68
+ #
69
+ # @param cmd the command to run
70
+ #
71
+ # @return [String] the output of the command
72
+ #
73
+ def `(cmd)
74
+ super
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,182 @@
1
+ # Copyright (c) 2019 James Couball
2
+ # frozen_string_literal: true
3
+
4
+ require 'forwardable'
5
+ require 'rake'
6
+ require 'rake/tasklib'
7
+ require 'tmpdir'
8
+
9
+ require 'github_pages_rake_tasks/interface'
10
+ require 'github_pages_rake_tasks/state'
11
+
12
+ module GithubPagesRakeTasks
13
+ # Instantiate this class to create a Rake task that pushes the contents from a
14
+ # local documentation directory to a GitHub repository branch.
15
+ #
16
+ # See {GithubPagesRakeTasks::PublishTask#initialize} for more details.
17
+ #
18
+ # @api public
19
+ #
20
+ class PublishTask < ::Rake::TaskLib
21
+ extend Forwardable
22
+
23
+ def_delegators(
24
+ :@state,
25
+ :interface, :interface=, :project_root, :project_root=, :rake_namespace, :rake_namespace=,
26
+ :doc_dir, :doc_dir=, :remote_name, :remote_name=, :repo_url, :repo_url=,
27
+ :staging_dir, :staging_dir=, :branch_name, :branch_name=,
28
+ :quiet, :quiet=, :verbose, :verbose=
29
+ )
30
+
31
+ # Create the publish task
32
+ #
33
+ # By default, the rake task `github-pages:publish` is created which pushes the `doc`
34
+ # directory within the local copy of your repository to the same repository's
35
+ # `gh-pages` branch. The contents of the branch are completely replaced by the
36
+ # contents of the documentation directory.
37
+ #
38
+ # @example with default options
39
+ # require 'github_pages_rake_tasks'
40
+ # GitHubPagesRakeTasks.Tasks.new
41
+ # task default: 'github-pages:publish'
42
+ #
43
+ # An initialization block can be passed to the initializer to set attributes
44
+ # to customize the behavior of the rake task created. {GithubPagesRakeTasks::State}
45
+ # details all the attributes which can be set and what effect they have on the task.
46
+ #
47
+ # @example with an initialization block
48
+ # require 'github_pages_rake_tasks'
49
+ # GitHubPagesRakeTasks.Tasks.new do |task|
50
+ # task.doc_dir = 'documentation'
51
+ # task.verbose = true
52
+ # end
53
+ # task default: 'github-pages:publish'
54
+ #
55
+ # @param [Array<Object>] task_args arguments to pass to the task initialization
56
+ # block.
57
+ #
58
+ # @param initialization_block If given, the task initialization will yield to
59
+ # this block with the `task_args` to perform user initialization of the publish
60
+ # task.
61
+ #
62
+ # @yield yields to the passed `initialization_block` for user initialization of this task.
63
+ # @yieldparam state [GithubPagesRakeTasks::State] the configuration state of this task. See
64
+ # {State} for a description of the configuration attributes that can be set.
65
+ # @yieldparam task_args [Array<Object>] any args passed to this initializer
66
+ # are passed to the yielded block.
67
+ #
68
+ def initialize(*task_args, &initialization_block)
69
+ @state = State.new
70
+
71
+ # Allow user to override defaults
72
+ #
73
+ yield(*[@state, task_args].slice(0, initialization_block.arity)) if initialization_block
74
+
75
+ namespace rake_namespace do
76
+ desc "Publish #{doc_dir} to #{repo_url}##{branch_name}"
77
+ task :publish do
78
+ display_header
79
+ publish
80
+ display_footer
81
+ end
82
+ end
83
+ end
84
+
85
+ private
86
+
87
+ # @!visibility private
88
+
89
+ def display_header
90
+ print "Publishing #{doc_dir} to #{repo_url}##{branch_name}..." unless quiet
91
+ puts if verbose
92
+ end
93
+
94
+ def display_footer
95
+ puts 'SUCCESS' unless quiet
96
+ end
97
+
98
+ def publish
99
+ interface.verbose(verbose) do
100
+ initialize_staging_dir
101
+ copy_doc_dir_to_staging_dir
102
+ commit_and_push_staging_dir
103
+ clean_staging_dir
104
+ end
105
+ end
106
+
107
+ def checkout_existing_branch
108
+ # only download the needed branch from GitHub
109
+ interface.sh("git fetch '#{remote_name}' '#{branch_name}'")
110
+ interface.sh("git checkout '#{branch_name}'")
111
+ end
112
+
113
+ def create_new_branch
114
+ interface.sh("git checkout --orphan '#{branch_name}'")
115
+ interface.file_write('index.html', 'Future home of documentation')
116
+ interface.sh('git add .')
117
+ interface.sh("git commit -m 'Create the documentation branch'")
118
+ interface.sh("git push '#{remote_name}' '#{branch_name}'")
119
+ end
120
+
121
+ def remote_branch_exists?
122
+ cmd = "git ls-remote --exit-code --heads '#{repo_url}' '#{branch_name}'"
123
+ interface.sh(cmd) do |branch_exists, _process_status|
124
+ branch_exists
125
+ end
126
+ end
127
+
128
+ def initialize_staging_repo
129
+ interface.mkdir_p(staging_dir) unless interface.dir_exist?(staging_dir)
130
+
131
+ interface.sh('git init')
132
+ interface.sh("git remote add '#{remote_name}' '#{repo_url}'")
133
+ end
134
+
135
+ # Creates `staging_dir` (if needed), clones the remote repository to it, and checks
136
+ # out `branch_name`. Creates `branch_name` in the remote is needed.
137
+ #
138
+ # Finally, removes all files using git rm
139
+ #
140
+ def initialize_staging_dir
141
+ initialize_staging_repo
142
+ if remote_branch_exists?
143
+ checkout_existing_branch
144
+ else
145
+ create_new_branch
146
+ end
147
+ remove_staging_files
148
+ end
149
+
150
+ def clean_staging_dir
151
+ interface.rm_rf staging_dir
152
+ end
153
+
154
+ def absolute_doc_dir
155
+ @absolute_doc_dir ||= interface.expand_path(doc_dir, project_root)
156
+ end
157
+
158
+ def commit_message
159
+ @commit_message ||= 'Updating documentation'
160
+ end
161
+
162
+ def remove_staging_files
163
+ interface.chdir staging_dir do
164
+ interface.sh('git rm -r .') do
165
+ # ignore failure
166
+ end
167
+ end
168
+ end
169
+
170
+ def copy_doc_dir_to_staging_dir
171
+ interface.cp_r(File.join(absolute_doc_dir, '.'), staging_dir)
172
+ end
173
+
174
+ def commit_and_push_staging_dir
175
+ interface.chdir staging_dir do
176
+ interface.sh('git add .')
177
+ interface.sh("git commit -m '#{commit_message}'")
178
+ interface.sh("git push --set-upstream #{remote_name} #{branch_name}")
179
+ end
180
+ end
181
+ end
182
+ end
@@ -0,0 +1,171 @@
1
+ # Copyright (c) 2019 James Couball
2
+ # frozen_string_literal: true
3
+
4
+ require 'forwardable'
5
+ require 'rake'
6
+ require 'rake/tasklib'
7
+ require 'tmpdir'
8
+ require 'github_pages_rake_tasks/interface'
9
+
10
+ module GithubPagesRakeTasks
11
+ # Keeps all attributes for {GithubPagesRakeTasks::PublishTask}. These attributes control
12
+ # how the task works.
13
+ #
14
+ # All attributes have sensible defaults which will cause {GithubPagesRakeTasks::PublishTask}
15
+ # to completely overwrite the project's `gh-pages` branch with the contents of the project's
16
+ # `doc` directory.
17
+ #
18
+ # Most used attributes are {doc_dir}, {project_root}, {repo_url}, and {branch_name}.
19
+ #
20
+ class State
21
+ # The directory, relative to {project_root}, that contains the documentation to
22
+ # publish to GitHub.
23
+ #
24
+ # The default value is 'doc'
25
+ #
26
+ # @return [String] directory
27
+ #
28
+ def doc_dir
29
+ @doc_dir ||= 'doc'
30
+ end
31
+ attr_writer :doc_dir
32
+
33
+ # The absolute path to the project's Git repository. {doc_dir} is relative to this
34
+ # path.
35
+ #
36
+ # The default value is the value returned from `git rev-parse --show-toplevel` when
37
+ # run in the current working directory
38
+ #
39
+ # @return [String] directory
40
+ #
41
+ def project_root
42
+ @project_root ||= interface.send(:`, 'git rev-parse --show-toplevel').chomp
43
+ end
44
+ attr_writer :project_root
45
+
46
+ # The URL to the remote repository to push documentation.
47
+ #
48
+ # The default value is the value returned from `git config --get remote.origin.url`
49
+ #
50
+ # @return [String] url
51
+ #
52
+ def repo_url
53
+ @repo_url ||= Dir.chdir(project_root) do |_path|
54
+ interface.send(:`, "git config --get remote.#{remote_name}.url").chomp
55
+ end
56
+ end
57
+ attr_writer :repo_url
58
+
59
+ # The branch to push documentation to.
60
+ #
61
+ # The default value is 'gh-pages'
62
+ #
63
+ # @return [String] the branch name
64
+ #
65
+ def branch_name
66
+ @branch_name ||= 'gh-pages'
67
+ end
68
+ attr_writer :branch_name
69
+
70
+ # The directory where the documentation is staged prior to pushing to the Git remote.
71
+ # All files are copied from {doc_dir} to {staging_dir} where the push to the Git remote is
72
+ # done.
73
+ #
74
+ # @note This directory is deleted at the end of the publish task.
75
+ #
76
+ # The default value is a temporary directory created with
77
+ # [Dir.mktmpdir](https://ruby-doc.org/stdlib-2.6.3/libdoc/tmpdir/rdoc/Dir.html)
78
+ # with the prefix 'github-pages-publish-'
79
+ #
80
+ # @return [String] a temporary directory.
81
+ #
82
+ def staging_dir
83
+ @staging_dir ||= interface.mktmpdir('github-pages-publish-')
84
+ end
85
+ attr_writer :staging_dir
86
+
87
+ # @!attribute quiet
88
+ # Silence all output from the `github-pages:publish` task.
89
+ #
90
+ # When {quiet} is true, the `github-pages:publish` task will not emit any output
91
+ # unless there is an error.
92
+ #
93
+ # Setting {quiet} to true will also set {verbose} to false.
94
+ #
95
+ # The default value is false
96
+ #
97
+ # @return [Boolean] the quiet flag value
98
+ #
99
+ def quiet
100
+ return @quiet if instance_variable_defined?(:@quiet)
101
+
102
+ @quiet = false
103
+ end
104
+
105
+ def quiet=(value)
106
+ @quiet = value
107
+ @verbose = false if quiet
108
+ end
109
+
110
+ # @!attribute verbose
111
+ # Make the `github-pages:publish` emit extra output.
112
+ #
113
+ # When {verbose} is true, the `github-pages:publish` task will emit extra output
114
+ # that is useful for debugging.
115
+ #
116
+ # Setting {verbose} to true will also set {quiet} to false.
117
+ #
118
+ # The default value is false
119
+ #
120
+ # @return [Boolean] the verbose flag value
121
+ #
122
+ def verbose
123
+ return @verbose if instance_variable_defined?(:@verbose)
124
+
125
+ @verbose = false
126
+ end
127
+
128
+ def verbose=(value)
129
+ @verbose = value
130
+ @quiet = false if verbose
131
+ end
132
+
133
+ # The name of the Git remote to use for pushing documentation.
134
+ #
135
+ # The default value is 'origin'
136
+ #
137
+ # @return [String] the Git remote name
138
+ #
139
+ def remote_name
140
+ @remote_name ||= 'origin'
141
+ end
142
+ attr_writer :remote_name
143
+
144
+ # An object that implements all methods that touch the world outside of
145
+ # the PublishTask class. This includes dealing with the file system, issuing
146
+ # shell commands, etc.
147
+ #
148
+ # The default value is a new instance of {GithubPagesRakeTasks::Interface}
149
+ #
150
+ # @note {interface} is used for mocking during testing of this gem and is probably
151
+ # not useful for users of this gem.
152
+ #
153
+ # @return [GithubPagesRakeTasks::Instance] an interface object
154
+ #
155
+ def interface
156
+ @interface ||= Interface.new
157
+ end
158
+ attr_writer :interface
159
+
160
+ # The Rake namespace for the publish task.
161
+ #
162
+ # The default value is 'github-pages'
163
+ #
164
+ # @return [String] Rake namespace
165
+ #
166
+ def rake_namespace
167
+ @rake_namespace ||= 'github-pages'
168
+ end
169
+ attr_writer :rake_namespace
170
+ end
171
+ end
@@ -0,0 +1,7 @@
1
+ # Copyright (c) 2019 James Couball
2
+ # frozen_string_literal: true
3
+
4
+ module GithubPagesRakeTasks
5
+ # Version of this module
6
+ VERSION = '0.1.1'
7
+ end
metadata ADDED
@@ -0,0 +1,210 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: github_pages_rake_tasks
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - James Couball
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2019-05-29 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bump
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.8'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler-audit
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.6'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.6'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '12.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '12.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.8'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.8'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rubocop
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.70'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.70'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '0.16'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '0.16'
111
+ - !ruby/object:Gem::Dependency
112
+ name: simplecov-lcov
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.7'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.7'
125
+ - !ruby/object:Gem::Dependency
126
+ name: yard
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: '0.9'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: '0.9'
139
+ - !ruby/object:Gem::Dependency
140
+ name: yardstick
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '0.9'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '0.9'
153
+ description: |
154
+ A Rake task to publish documentation like yard or mkdocs to GitHub Pages.
155
+
156
+ The rake task copies all files from the src_dir and pushes them to the
157
+ GitHub repository and branch identified by repo_url and branch_name.
158
+
159
+ The contents of the branch are completely overwritten by the contents of src_dir.
160
+ email:
161
+ - jcouball@yahoo.com
162
+ executables: []
163
+ extensions: []
164
+ extra_rdoc_files: []
165
+ files:
166
+ - ".gitignore"
167
+ - ".rspec"
168
+ - ".rubocop.yml"
169
+ - ".travis.yml"
170
+ - ".yardopts"
171
+ - Gemfile
172
+ - LICENSE.txt
173
+ - README.md
174
+ - Rakefile
175
+ - bin/console
176
+ - bin/setup
177
+ - github_pages_rake_tasks.gemspec
178
+ - lib/github_pages_rake_tasks.rb
179
+ - lib/github_pages_rake_tasks/interface.rb
180
+ - lib/github_pages_rake_tasks/publish_task.rb
181
+ - lib/github_pages_rake_tasks/state.rb
182
+ - lib/github_pages_rake_tasks/version.rb
183
+ homepage: https://github.com/jcouball/github_pages_rake_tasks
184
+ licenses:
185
+ - MIT
186
+ metadata:
187
+ homepage_uri: https://github.com/jcouball/github_pages_rake_tasks
188
+ source_code_uri: https://github.com/jcouball/github_pages_rake_tasks
189
+ changelog_uri: https://github.com/jcouball/github_pages_rake_tasks
190
+ post_install_message:
191
+ rdoc_options: []
192
+ require_paths:
193
+ - lib
194
+ required_ruby_version: !ruby/object:Gem::Requirement
195
+ requirements:
196
+ - - ">="
197
+ - !ruby/object:Gem::Version
198
+ version: '0'
199
+ required_rubygems_version: !ruby/object:Gem::Requirement
200
+ requirements:
201
+ - - ">="
202
+ - !ruby/object:Gem::Version
203
+ version: '0'
204
+ requirements: []
205
+ rubyforge_project:
206
+ rubygems_version: 2.6.14.4
207
+ signing_key:
208
+ specification_version: 4
209
+ summary: Rake tasks for publishing documentation to GitHub Pages
210
+ test_files: []