yard_ghurt 1.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.
@@ -0,0 +1,183 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of YardGhurt.
7
+ # Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # YardGhurt is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU Lesser General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # YardGhurt is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU Lesser General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU Lesser General Public License
20
+ # along with YardGhurt. If not, see <https://www.gnu.org/licenses/>.
21
+ #++
22
+
23
+
24
+ require 'rake'
25
+
26
+ require 'rake/tasklib'
27
+
28
+ require 'yard_ghurt/util'
29
+
30
+ module YardGhurt
31
+ ###
32
+ # Sync YARDoc to a local GitHub Pages repo (uses +rsync+ by default).
33
+ #
34
+ # @example What I Use
35
+ # YardGhurt::GHPSyncerTask.new() do |task|
36
+ # task.ghp_dir = '../esotericpig.github.io/docs/yard_ghurt/yardoc'
37
+ # task.sync_args << '--delete-after'
38
+ # end
39
+ #
40
+ # @example Using All Options
41
+ # # Execute: rake ghp_doc[false,'Ruby']
42
+ # YardGhurt::GHPSyncerTask.new(:ghp_doc) do |task|
43
+ # task.arg_names << :name # Custom args
44
+ # task.deps << :yard # Custom dependencies
45
+ # task.description = 'Rsync my_doc/ to my page'
46
+ # task.doc_dir = 'my_doc' # YARDoc directory of generated files
47
+ # task.ghp_dir = '../dest_dir/my_page'
48
+ # task.strict = true # Fail if doc_dir doesn't exist
49
+ # task.sync_args << '--delete-after'
50
+ # task.sync_cmd = '/usr/bin/rsync'
51
+ #
52
+ # task.before = Proc.new() {|task,args| puts "Hi, #{args.name}!"}
53
+ # task.after = Proc.new() {|task,args| puts "Goodbye, #{args.name}!"}
54
+ # end
55
+ #
56
+ # @author Jonathan Bradley Whited (@esotericpig)
57
+ # @since 1.0.0
58
+ ###
59
+ class GHPSyncerTask < Rake::TaskLib
60
+ # @return [Proc,nil] the Proc ( +respond_to?(:call)+ ) to call at the end of this task or +nil+;
61
+ # default: +nil+
62
+ attr_accessor :after
63
+
64
+ # @note +:deploy+ will be added no matter what (cannot be deleted)
65
+ #
66
+ # @return [Array<Symbol>,Symbol] the custom arg(s) for this task; default: +[:deploy]+
67
+ attr_accessor :arg_names
68
+
69
+ # @return [Proc,nil] the Proc ( +respond_to?(:call)+ ) to call at the beginning of this task or +nil+;
70
+ # default: +nil+
71
+ attr_accessor :before
72
+
73
+ # @example
74
+ # task.deps = :yard
75
+ # # or...
76
+ # task.deps = [:yard,:yard_gfm_fix]
77
+ #
78
+ # @return [Array<Symbol>,Symbol] the custom dependencies for this task; default: +[]+
79
+ attr_accessor :deps
80
+
81
+ # @return [String] the description of this task (customizable)
82
+ attr_accessor :description
83
+
84
+ # @return [String] the source directory of generated YARDoc files; default: +doc+
85
+ attr_accessor :doc_dir
86
+
87
+ # @note You must set this, else an error is thrown.
88
+ #
89
+ # @return [String] the destination directory to sync {doc_dir} to
90
+ attr_accessor :ghp_dir
91
+
92
+ # @return [String] the name of this task (customizable); default: +yard_ghp_sync+
93
+ attr_accessor :name
94
+
95
+ # If you want to use a non-local {doc_dir} (a remote host), set this to +false+.
96
+ #
97
+ # @return [true,false] whether to throw an error if {doc_dir} does not exist; default: +true+
98
+ attr_accessor :strict
99
+
100
+ # @note You should pass in multi-args separately: +['--exclude','*~']+
101
+ # @note You should not single/double quote the args; +['"*~"']+ is unnecessary.
102
+ #
103
+ # @return [Array<String>] the args to pass to the {sync_cmd}; default: +['-ahv','--progress']+
104
+ attr_accessor :sync_args
105
+
106
+ # @return [String] the sync command to use on the command line; default: +rsync+
107
+ attr_accessor :sync_cmd
108
+
109
+ alias_method :strict?,:strict
110
+
111
+ # @param name [Symbol] the name of this task to use on the command line with +rake+
112
+ def initialize(name=:yard_ghp_sync)
113
+ @after = nil
114
+ @arg_names = []
115
+ @before = nil
116
+ @deps = []
117
+ @description = 'Sync YARDoc to GitHub Pages repo'
118
+ @doc_dir = 'doc'
119
+ @ghp_dir = nil
120
+ @name = name
121
+ @strict = true
122
+ @sync_args = ['-ahv','--progress']
123
+ @sync_cmd = 'rsync'
124
+
125
+ yield self if block_given?()
126
+ define()
127
+ end
128
+
129
+ # Define the Rake task and description using the instance variables.
130
+ def define()
131
+ @arg_names = *@arg_names
132
+ @arg_names.unshift(:deploy) unless @arg_names.include?(:deploy)
133
+
134
+ desc @description
135
+ task @name,@arg_names => Array(@deps) do |task,args|
136
+ deploy = Util.to_bool(args.deploy)
137
+
138
+ @before.call(self,args) if @before.respond_to?(:call)
139
+
140
+ # Without these checks, sh raises some pretty cryptic errors.
141
+ if @strict
142
+ # If you want to use a non-local dir, set strict to false.
143
+ if !File.exist?(@doc_dir)
144
+ raise ArgumentError,%Q(#{self.class}.doc_dir [#{@doc_dir}] does not exist; execute "rake yard"?)
145
+ end
146
+ end
147
+ # Do not check if ghp_dir exists because rsync may create it.
148
+ if @ghp_dir.nil?() || @ghp_dir.to_s().strip().empty?()
149
+ raise ArgumentError,"#{self.class}.ghp_dir must be set"
150
+ end
151
+
152
+ sh *build_sh_cmd(deploy)
153
+
154
+ if !deploy
155
+ puts
156
+ puts %Q(Execute "rake #{@name}[true]" for actually deploying (not a dry-run))
157
+ end
158
+
159
+ @after.call(self,args) if @after.respond_to?(:call)
160
+ end
161
+
162
+ return self
163
+ end
164
+
165
+ # Build the sync command to use on the command line.
166
+ #
167
+ # @param deploy [true,false] whether to actually deploy (+true+) or to run a dry-run (+false+)
168
+ #
169
+ # @return [Array<String>] the sync command and its args
170
+ def build_sh_cmd(deploy)
171
+ sh_cmd = [@sync_cmd]
172
+
173
+ sh_cmd << '--dry-run' unless deploy
174
+ sh_cmd.push(*@sync_args)
175
+
176
+ # File.join() to add a trailing '/' if not present
177
+ sh_cmd << File.join(@doc_dir,'')
178
+ sh_cmd << File.join(@ghp_dir,'')
179
+
180
+ return sh_cmd
181
+ end
182
+ end
183
+ end
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of YardGhurt.
7
+ # Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # YardGhurt is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU Lesser General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # YardGhurt is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU Lesser General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU Lesser General Public License
20
+ # along with YardGhurt. If not, see <https://www.gnu.org/licenses/>.
21
+ #++
22
+
23
+
24
+ module YardGhurt
25
+ ###
26
+ # Utility methods in a separate module/mixin,
27
+ # so that a programmer can require/load a sole task:
28
+ # require 'yard_ghurt/gfm_fixer_task'
29
+ #
30
+ # Else, programmers would be required to always require/load the entire +yard_ghurt+ module:
31
+ # require 'yard_ghurt'
32
+ #
33
+ # All internal code should use this module.
34
+ #
35
+ # All external code should use {YardGhurt}, which includes this module as a mixin.
36
+ #
37
+ # @author Jonathan Bradley Whited (@esotericpig)
38
+ # @since 1.0.0
39
+ ###
40
+ module Util
41
+ # @return [Array<String>] the lower-case Strings that will equal to +true+
42
+ TRUE_BOOLS = ['1','on','t','true','y','yes'].freeze()
43
+
44
+ # If +include Util+ is called, extend {ClassMethods}.
45
+ #
46
+ # @param mod [Module] the module to extend
47
+ def self.included(mod)
48
+ mod.extend ClassMethods
49
+ end
50
+
51
+ module ClassMethods
52
+ # If +filename+ exists, delete it, and if +output+ is +true+, log it to stdout.
53
+ #
54
+ # @param filename [String] the file to remove
55
+ # @param output [true,false] whether to log it to stdout
56
+ def rm_exist(filename,output=true)
57
+ return unless File.exist?(filename)
58
+
59
+ puts "[#{filename}]: - Deleted" if output
60
+ File.delete(filename)
61
+ end
62
+
63
+ # Convert +str+ to +true+ or +false+.
64
+ #
65
+ # Even if +str+ is not a String, +to_s()+ will be called, so should be safe.
66
+ #
67
+ # @param str [String,Object] the String (or Object) to convert
68
+ #
69
+ # @return [true,false] the boolean value of +str+
70
+ #
71
+ # @see TRUE_BOOLS
72
+ # @see GHPSyncerTask#arg_names
73
+ def to_bool(str)
74
+ return TRUE_BOOLS.include?(str.to_s().downcase())
75
+ end
76
+ end
77
+
78
+ extend ClassMethods
79
+ end
80
+ end
@@ -0,0 +1,26 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of YardGhurt.
7
+ # Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # YardGhurt is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU Lesser General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # YardGhurt is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU Lesser General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU Lesser General Public License
20
+ # along with YardGhurt. If not, see <https://www.gnu.org/licenses/>.
21
+ #++
22
+
23
+
24
+ module YardGhurt
25
+ VERSION = '1.0.0'
26
+ end
data/lib/yard_ghurt.rb ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: UTF-8
3
+ # frozen_string_literal: true
4
+
5
+ #--
6
+ # This file is part of YardGhurt.
7
+ # Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
8
+ #
9
+ # YardGhurt is free software: you can redistribute it and/or modify
10
+ # it under the terms of the GNU Lesser General Public License as published by
11
+ # the Free Software Foundation, either version 3 of the License, or
12
+ # (at your option) any later version.
13
+ #
14
+ # YardGhurt is distributed in the hope that it will be useful,
15
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
16
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
+ # GNU Lesser General Public License for more details.
18
+ #
19
+ # You should have received a copy of the GNU Lesser General Public License
20
+ # along with YardGhurt. If not, see <https://www.gnu.org/licenses/>.
21
+ #++
22
+
23
+
24
+ require 'yard_ghurt/anchor_links'
25
+ require 'yard_ghurt/gfm_fixer_task'
26
+ require 'yard_ghurt/ghp_syncer_task'
27
+ require 'yard_ghurt/util'
28
+ require 'yard_ghurt/version'
29
+
30
+ ###
31
+ # YARDoc GitHub Rake Tasks
32
+ #
33
+ # @author Jonathan Bradley Whited (@esotericpig)
34
+ # @since 1.0.0
35
+ ###
36
+ module YardGhurt
37
+ # Internal code should use +Util.+!
38
+ # External code should use +YardGhurt.+, but can also use +YardGhurt::Util.+.
39
+ # See {Util} for details.
40
+ include Util
41
+ end
@@ -0,0 +1,5 @@
1
+ <%# To reduce number of diffs, removed: time, YARD version, and Ruby version. %>
2
+ <div id="footer">
3
+ Generated by
4
+ <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>.
5
+ </div>
@@ -0,0 +1,60 @@
1
+ # encoding: UTF-8
2
+ # frozen_string_literal: true
3
+
4
+ #--
5
+ # This file is part of YardGhurt.
6
+ # Copyright (c) 2019 Jonathan Bradley Whited (@esotericpig)
7
+ #
8
+ # YardGhurt is free software: you can redistribute it and/or modify
9
+ # it under the terms of the GNU Lesser General Public License as published by
10
+ # the Free Software Foundation, either version 3 of the License, or
11
+ # (at your option) any later version.
12
+ #
13
+ # YardGhurt is distributed in the hope that it will be useful,
14
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ # GNU Lesser General Public License for more details.
17
+ #
18
+ # You should have received a copy of the GNU Lesser General Public License
19
+ # along with YardGhurt. If not, see <https://www.gnu.org/licenses/>.
20
+ #++
21
+
22
+
23
+ lib = File.expand_path('../lib',__FILE__)
24
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
25
+
26
+ require 'yard_ghurt/version'
27
+
28
+ Gem::Specification.new() do |spec|
29
+ spec.name = 'yard_ghurt'
30
+ spec.version = YardGhurt::VERSION
31
+ spec.authors = ['Jonathan Bradley Whited (@esotericpig)']
32
+ spec.email = ['bradley@esotericpig.com']
33
+ spec.licenses = ['LGPL-3.0-or-later']
34
+ spec.homepage = 'https://github.com/esotericpig/yard_ghurt'
35
+ spec.summary = 'YARDoc GitHub Rake Tasks'
36
+ spec.description = 'YARDoc GitHub Rake Tasks. Fix GitHub Flavored Markdown (GFM) files.'
37
+
38
+ spec.metadata = {
39
+ 'bug_tracker_uri' => 'https://github.com/esotericpig/yard_ghurt/issues',
40
+ 'changelog_uri' => 'https://github.com/esotericpig/yard_ghurt/blob/master/CHANGELOG.md',
41
+ 'documentation_uri' => 'https://esotericpig.github.io/docs/yard_ghurt/yardoc/index.html',
42
+ 'homepage_uri' => 'https://github.com/esotericpig/yard_ghurt',
43
+ 'source_code_uri' => 'https://github.com/esotericpig/yard_ghurt'
44
+ }
45
+
46
+ spec.require_paths = ['lib']
47
+
48
+ spec.files = Dir.glob(File.join("{#{spec.require_paths.join(',')},test,yard}",'**','*.{erb,rb}')) +
49
+ %W( Gemfile #{spec.name}.gemspec Rakefile ) +
50
+ %w( CHANGELOG.md LICENSE.txt README.md )
51
+
52
+ spec.required_ruby_version = '>= 2.1.10'
53
+
54
+ spec.add_runtime_dependency 'rake' #,'~> 12.3'
55
+
56
+ spec.add_development_dependency 'bundler' ,'~> 1.17'
57
+ spec.add_development_dependency 'rdoc' ,'~> 6.1' # For RDoc for YARD (*.rb)
58
+ spec.add_development_dependency 'redcarpet','~> 3.4' # For Markdown for YARD (*.md)
59
+ spec.add_development_dependency 'yard' ,'~> 0.9'
60
+ end
metadata ADDED
@@ -0,0 +1,131 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: yard_ghurt
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan Bradley Whited (@esotericpig)
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-07-22 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '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.17'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.17'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rdoc
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '6.1'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '6.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: redcarpet
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: yard
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.9'
83
+ description: YARDoc GitHub Rake Tasks. Fix GitHub Flavored Markdown (GFM) files.
84
+ email:
85
+ - bradley@esotericpig.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - CHANGELOG.md
91
+ - Gemfile
92
+ - LICENSE.txt
93
+ - README.md
94
+ - Rakefile
95
+ - lib/yard_ghurt.rb
96
+ - lib/yard_ghurt/anchor_links.rb
97
+ - lib/yard_ghurt/gfm_fixer_task.rb
98
+ - lib/yard_ghurt/ghp_syncer_task.rb
99
+ - lib/yard_ghurt/util.rb
100
+ - lib/yard_ghurt/version.rb
101
+ - yard/templates/default/layout/html/footer.erb
102
+ - yard_ghurt.gemspec
103
+ homepage: https://github.com/esotericpig/yard_ghurt
104
+ licenses:
105
+ - LGPL-3.0-or-later
106
+ metadata:
107
+ bug_tracker_uri: https://github.com/esotericpig/yard_ghurt/issues
108
+ changelog_uri: https://github.com/esotericpig/yard_ghurt/blob/master/CHANGELOG.md
109
+ documentation_uri: https://esotericpig.github.io/docs/yard_ghurt/yardoc/index.html
110
+ homepage_uri: https://github.com/esotericpig/yard_ghurt
111
+ source_code_uri: https://github.com/esotericpig/yard_ghurt
112
+ post_install_message:
113
+ rdoc_options: []
114
+ require_paths:
115
+ - lib
116
+ required_ruby_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: 2.1.10
121
+ required_rubygems_version: !ruby/object:Gem::Requirement
122
+ requirements:
123
+ - - ">="
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ requirements: []
127
+ rubygems_version: 3.0.4
128
+ signing_key:
129
+ specification_version: 4
130
+ summary: YARDoc GitHub Rake Tasks
131
+ test_files: []