guard-asciidoc 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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 621a8d0d226fdec058e5239ae62091c1998b96378b7732c9038fb4e3d7f733f2
4
+ data.tar.gz: 057e64e55fce0abf3abf84260b9467a654112afa04aaffacb387f267eb0ad471
5
+ SHA512:
6
+ metadata.gz: f55e6ec7ecf4969d6ca53f0af21507a3ce04f84cd22a4aeaea5961f371448769148d84abba65b6833e12405f3f99941913b6e4437cb2bb9a1bb7e9d8adcef009
7
+ data.tar.gz: 5ae5ca408016dfb46dc17df32662790dce054cc74e0f9efe4c72ec30de27ff84ad4ded72c7acf110426cee775befbbe4b0916da7cc5383122b2b6226d4ce2c84
data/CHANGELOG.adoc ADDED
@@ -0,0 +1,13 @@
1
+ = Guard AsciiDoc Changelog
2
+ :url-repo: https://github.com/asciidoctor/guard-asciidoc
3
+
4
+ This document provides a curated view of the changes to Guard AsciiDoc in each release.
5
+ For a detailed view of what has changed, refer to the {url-repo}/commits/main[commit history] on GitHub.
6
+
7
+ == 1.0.0 (2023-10-30) - @mojavelinux
8
+
9
+ Initial release.
10
+ === Details
11
+
12
+ {url-repo}/releases/tag/v1.0.0[git tag]
13
+
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2013-present Paul Rayner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.adoc ADDED
@@ -0,0 +1,136 @@
1
+ = Guard::AsciiDoc
2
+ Paul Rayner; Dan Allen <https://github.com/mojavelinux[@mojavelinux]>
3
+ v1.0.0, 2023-10-30
4
+ :idprefix:
5
+ :idseparator: -
6
+ :url-rvm: https://rvm.io
7
+ :url-repo: https://github.com/asciidoctor/guard-asciidoc
8
+
9
+ Guard::AsciiDoc is a plugin for Guard that uses Asciidoctor to convert watched AsciiDoc files to the specified output format.
10
+
11
+ AsciiDoc:: https://asciidoc.org
12
+ Guard:: https://github.com/guard/guard
13
+ Asciidoctor:: https://github.com/asciidoctor/asciidoctor
14
+
15
+ == Prerequisites
16
+
17
+ Guard::AsciiDoc is a plugin for Guard, which is a Ruby application you install using Ruby packaging.
18
+ To run Guard with this plugin, you need Ruby 3.0 or better.
19
+
20
+ Run the following command to check which version of Ruby you have installed, if any:
21
+
22
+ $ ruby -v
23
+
24
+ If Ruby is not installed, you can install it using {url-rvm}[RVM] (or, if you prefer, the package manager for your system).
25
+ We generally recommend using RVM as it allows you to install gems without requiring elevated privileges or messing with system libraries.
26
+
27
+ == Installation
28
+
29
+ Set up your [.path]_Gemfile_:
30
+
31
+ [,ruby]
32
+ .Gemfile
33
+ ----
34
+ source 'https://rubygems.org'
35
+
36
+ gem 'guard-asciidoc'
37
+ ----
38
+
39
+ Install the dependencies:
40
+
41
+ $ bundle config set --local path .bundle/gems
42
+ bundle
43
+
44
+ Create a [.path]_Guardfile_ at the root of the project by running:
45
+
46
+ $ bundle exec guard init
47
+
48
+ Now you can run Guard so it starts watching your files:
49
+
50
+ $ bundle exec guard
51
+
52
+ In the console, you should see:
53
+
54
+ INFO - Guard::AsciiDoc is now watching for changes
55
+ INFO - Guard is now watching at '/path/to/current/directory'
56
+
57
+ By default, the plugin looks for all AsciiDoc files in the project.
58
+
59
+ == Configuration
60
+
61
+ You can then configure the options of the plugins.
62
+ For example, if your docs are located in the [.path]_docs_ folder, you can tell the plugin watch this folder instead of the root folder:
63
+
64
+ [,ruby]
65
+ .Guardfile
66
+ ----
67
+ guard :asciidoc, watch_dir: 'docs'
68
+ ----
69
+
70
+ You can also set AsciiDoc attributes:
71
+
72
+ [,ruby]
73
+ .Guardfile
74
+ ----
75
+ guard :asciidoc, attributes: { 'toc' => '' }
76
+ ----
77
+
78
+ If you want to convert to PDF, you first need to declare a dependency on the *asciidoctor-pdf* gem:
79
+
80
+ $ bundle add asciidoctor-pdf
81
+
82
+ Now set the `:backend` option to `:pdf` in [.path]_Guardfile_.
83
+
84
+ [,ruby]
85
+ .Guardfile
86
+ ----
87
+ guard :asciidoc, backend: :pdf
88
+ ----
89
+
90
+ You can also require an extension, such as Asciidoctor Diagram.
91
+ You first need to declare a dependency on the *asciidoctor-diagram* gem:
92
+
93
+ $ bundle add asciidoctor-diagram
94
+
95
+ Now add *asciidoctor-diagram* to the `:requires` option in [.path]_Guardfile_.
96
+
97
+ [,ruby]
98
+ .Guardfile
99
+ ----
100
+ guard :asciidoc, requires: ['asciidoctor-diagram']
101
+ ----
102
+
103
+ If you want to output files to a build directory, such as [.path]_build_, set the `:to_dir` option in [.path]_Guardfile_.
104
+ When the `:to_dir` option is specified, the directory structure of the input file is preserved (relative to the `:watch_dir` value, if present, or the project root otherwise).
105
+
106
+ [,ruby]
107
+ .Guardfile
108
+ ----
109
+ guard :asciidoc, to_dir: 'build'
110
+ ----
111
+
112
+ You can combine any of the options mentioned previously.
113
+
114
+ By default, the plugin looks for files that have the `.adoc` file extension.
115
+ If you want to watch for files with other file extensions, or in other folders, you can set up a custom watcher in [.path]_Guardfile_.
116
+ Note that if you define a watcher, the default watcher will not be created (and hence the `:watch_dir` option is not relevant).
117
+
118
+ [,ruby]
119
+ .Guardfile
120
+ ----
121
+ guard :asciidoc
122
+ watch %r{^docs/.+\.adoc$}
123
+ watch(%r{^docs/.+\.rb$}) { 'docs' }
124
+ end
125
+ ----
126
+
127
+ == Copyright and License
128
+
129
+ Copyright (C) 2013-present Paul Rayner and Dan Allen.
130
+ Use of this software is granted under the terms of the MIT License.
131
+
132
+ See the link:LICENSE[LICENSE] for the full license text.
133
+
134
+ == Trademarks
135
+
136
+ AsciiDoc(R) and AsciiDoc Language(TM) are trademarks of the Eclipse Foundation, Inc.
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require_relative 'lib/guard/asciidoc/version'
5
+ rescue LoadError
6
+ require 'guard/asciidoc/version'
7
+ end
8
+
9
+ Gem::Specification.new do |s|
10
+ s.name = 'guard-asciidoc'
11
+ s.version = Guard::AsciiDocVersion::VERSION
12
+ s.summary = 'Guard::AsciiDoc automatically converts your AsciiDoc documents.'
13
+ s.description = 'Watches the specified source folder and automatically converts AsciiDoc documents to the backend format into a target directory.'
14
+ s.authors = ['Paul Rayner', 'Dan Allen']
15
+ s.email = ['paul@virtual-genius.com']
16
+ s.homepage = 'https://github.com/asciidoctor/guard-asciidoc'
17
+ s.license = 'MIT'
18
+
19
+ s.metadata = {
20
+ 'bug_tracker_uri' => 'https://github.com/asciidoctor/guard-asciidoc/issues',
21
+ 'changelog_uri' => 'https://github.com/asciidoctor/guard-asciidoc/blob/main/CHANGELOG.adoc',
22
+ 'mailing_list_uri' => 'https://chat.asciidoctor.org',
23
+ 'source_code_uri' => 'https://github.com/asciidoctor/guard-asciidoc'
24
+ }
25
+
26
+ # NOTE the logic to build the list of files is designed to produce a usable package even when the git command is not available
27
+ begin
28
+ files = (result = `git ls-files -z`.split ?\0).empty? ? Dir['**/*'] : result
29
+ rescue
30
+ files = Dir['**/*']
31
+ end
32
+ s.files = files.grep %r/^(?:lib\/.+|LICENSE|(?:CHANGELOG|README)\.adoc|#{s.name}\.gemspec)$/
33
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
34
+ s.require_paths = ['lib']
35
+
36
+ s.add_dependency 'guard', '~> 2.18.0'
37
+ s.add_dependency 'guard-compat', '~> 1.2.0'
38
+ s.add_dependency 'asciidoctor', '~> 2.0'
39
+
40
+ s.add_development_dependency 'rake', '~> 13.1.0'
41
+ s.add_development_dependency 'rspec', '~> 3.12.0'
42
+ end
@@ -0,0 +1,11 @@
1
+ # options:
2
+ # :watch_dir - sets which directory to watch if no watches are specified
3
+ # :watch_ext - sets which file extensions to watch if no watches are specified
4
+ # :watch_hidden - if true, sets whether to watch hidden files
5
+ # :run_on_start - if true, run when Guard is starting; otherwise, wait for a change
6
+ # :always_build_all - if true, always build all files instead of files which changed
7
+ guard :asciidoc do
8
+ # uncomment to customize the watch patterns; alternately, use :watch_dir to change which directory the plugin watches
9
+ #watch %r{^docs/.+\.adoc$}
10
+ #watch 'README.adoc'
11
+ end
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Guard
4
+ module AsciiDocVersion
5
+ VERSION = '1.0.0'
6
+ end
7
+ end
@@ -0,0 +1,107 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'guard/compat/plugin'
4
+ autoload :Pathname, 'pathname'
5
+
6
+ module Guard
7
+ class AsciiDoc < Plugin
8
+ BACKEND_ALIASES = { 'html' => 'html5', 'docbook' => 'docbook5' }
9
+ DEFAULT_BACKEND = 'html5'
10
+ DEFAULT_OPTIONS = {
11
+ watch_dir: '.',
12
+ watch_ext: %w(adoc),
13
+ watch_hidden: false,
14
+ run_on_start: false,
15
+ always_build_all: false,
16
+ }
17
+ FILE_SEPARATOR = ::File::SEPARATOR
18
+ PLUGIN_KEYS = [:any_return, :group, :watchers]
19
+ CONFIG_KEYS = DEFAULT_OPTIONS.keys
20
+
21
+ attr_reader :asciidoc_opts
22
+
23
+ def initialize options = {}
24
+ compiled_opts = DEFAULT_OPTIONS.merge
25
+ compiled_opts[:watch_dir] = (options.delete :watch_dir) || '.' if options.key? :watch_dir
26
+ compiled_opts.merge! options
27
+ compiled_opts[:watch_dir] = '.' if compiled_opts[:watch_dir].to_s.empty?
28
+ @asciidoc_opts = compiled_opts.except(*(PLUGIN_KEYS + CONFIG_KEYS))
29
+ unless (@asciidoc_opts[:backend] = BACKEND_ALIASES[(backend = @asciidoc_opts[:backend])] || backend)
30
+ @asciidoc_opts[:backend] = DEFAULT_BACKEND
31
+ end
32
+ case (attributes = @asciidoc_opts[:attributes] ||= {})
33
+ when ::Hash
34
+ attributes['env-guard'] = ''
35
+ when ::Array
36
+ attributes << 'env-guard'
37
+ when ::String
38
+ @asciidoc_opts[:attributes] += ' env-guard'
39
+ end
40
+ @asciidoc_opts[:safe] ||= :unsafe
41
+ if (compiled_opts[:watchers] ||= []).empty? && (watch_dir = compiled_opts[:watch_dir])
42
+ watch_dir = compiled_opts[:watch_dir] = (::Pathname.new watch_dir).cleanpath.to_s
43
+ watch_re = watch_dir == '.' ? '' : %(^#{::Regexp.escape watch_dir}(?=#{FILE_SEPARATOR}))
44
+ watch_re += compiled_opts[:watch_hidden] ? '.+?' : %((?:[^#{FILE_SEPARATOR}]|#{FILE_SEPARATOR}[^.])+?)
45
+ watch_re += %((?:#{compiled_opts[:watch_ext].join '|'})$)
46
+ watch_rx = ::Regexp.new watch_re
47
+ compiled_opts[:watchers] = [(Watcher.new watch_rx)]
48
+ end
49
+ super compiled_opts
50
+ end
51
+
52
+ def start
53
+ Compat::UI.info 'Guard::AsciiDoc is now watching files'
54
+ require 'asciidoctor'
55
+ require %(asciidoctor-#{asciidoc_opts[:backend]}) unless ::Asciidoctor::Converter.for asciidoc_opts[:backend]
56
+ if (requires = asciidoc_opts.delete :requires)
57
+ Array(requires).each {|require_| require require_ }
58
+ end
59
+ run_all if options[:run_on_start]
60
+ end
61
+
62
+ def run_all
63
+ run match_all, force: true
64
+ end
65
+
66
+ def run_on_changes paths
67
+ options[:always_build_all] ? run_all : (run paths)
68
+ end
69
+
70
+ alias run_on_additions run_on_changes
71
+ alias run_on_modifications run_on_changes
72
+
73
+ private
74
+
75
+ def run paths, force: nil
76
+ paths.each do |filepath|
77
+ if ::File.directory? filepath
78
+ run (match_all filepath), force: true
79
+ else
80
+ convert_asciidoc filepath, asciidoc_opts, force: force
81
+ end
82
+ end
83
+ true
84
+ end
85
+
86
+ def convert_asciidoc filepath, opts, force: nil
87
+ Compat::UI.info %(Converting#{force ? '' : ' changed'} file: #{filepath})
88
+ if (to_dir = opts[:to_dir])
89
+ filepath_segments = (::Pathname.new filepath).each_filename.to_a
90
+ if (watch_dir = options[:watch_dir]) != '.' && watch_dir == filepath_segments[0]
91
+ to_dir = File.join [to_dir] + (filepath_segments.slice 1...-1)
92
+ else
93
+ to_dir = File.join [to_dir] + (filepath_segments.slice 0...-1)
94
+ end
95
+ end
96
+ ::Asciidoctor.convert_file filepath, (to_dir ? (opts.merge mkdirs: true, to_dir: to_dir) : opts)
97
+ rescue => e
98
+ Compat::UI.error e.message
99
+ raise :task_has_failed
100
+ end
101
+
102
+ def match_all from = nil
103
+ glob = from ? (::File.join from, '**', '*.*') : (::File.join '**', '*.*')
104
+ (Compat.matching_files self, ::Dir[glob]).select {|it| ::File.file? it }
105
+ end
106
+ end
107
+ end
metadata ADDED
@@ -0,0 +1,126 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: guard-asciidoc
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Paul Rayner
8
+ - Dan Allen
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2023-10-30 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: guard
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - "~>"
19
+ - !ruby/object:Gem::Version
20
+ version: 2.18.0
21
+ type: :runtime
22
+ prerelease: false
23
+ version_requirements: !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - "~>"
26
+ - !ruby/object:Gem::Version
27
+ version: 2.18.0
28
+ - !ruby/object:Gem::Dependency
29
+ name: guard-compat
30
+ requirement: !ruby/object:Gem::Requirement
31
+ requirements:
32
+ - - "~>"
33
+ - !ruby/object:Gem::Version
34
+ version: 1.2.0
35
+ type: :runtime
36
+ prerelease: false
37
+ version_requirements: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - "~>"
40
+ - !ruby/object:Gem::Version
41
+ version: 1.2.0
42
+ - !ruby/object:Gem::Dependency
43
+ name: asciidoctor
44
+ requirement: !ruby/object:Gem::Requirement
45
+ requirements:
46
+ - - "~>"
47
+ - !ruby/object:Gem::Version
48
+ version: '2.0'
49
+ type: :runtime
50
+ prerelease: false
51
+ version_requirements: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - "~>"
54
+ - !ruby/object:Gem::Version
55
+ version: '2.0'
56
+ - !ruby/object:Gem::Dependency
57
+ name: rake
58
+ requirement: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - "~>"
61
+ - !ruby/object:Gem::Version
62
+ version: 13.1.0
63
+ type: :development
64
+ prerelease: false
65
+ version_requirements: !ruby/object:Gem::Requirement
66
+ requirements:
67
+ - - "~>"
68
+ - !ruby/object:Gem::Version
69
+ version: 13.1.0
70
+ - !ruby/object:Gem::Dependency
71
+ name: rspec
72
+ requirement: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - "~>"
75
+ - !ruby/object:Gem::Version
76
+ version: 3.12.0
77
+ type: :development
78
+ prerelease: false
79
+ version_requirements: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - "~>"
82
+ - !ruby/object:Gem::Version
83
+ version: 3.12.0
84
+ description: Watches the specified source folder and automatically converts AsciiDoc
85
+ documents to the backend format into a target directory.
86
+ email:
87
+ - paul@virtual-genius.com
88
+ executables: []
89
+ extensions: []
90
+ extra_rdoc_files: []
91
+ files:
92
+ - CHANGELOG.adoc
93
+ - LICENSE
94
+ - README.adoc
95
+ - guard-asciidoc.gemspec
96
+ - lib/guard/asciidoc.rb
97
+ - lib/guard/asciidoc/templates/Guardfile
98
+ - lib/guard/asciidoc/version.rb
99
+ homepage: https://github.com/asciidoctor/guard-asciidoc
100
+ licenses:
101
+ - MIT
102
+ metadata:
103
+ bug_tracker_uri: https://github.com/asciidoctor/guard-asciidoc/issues
104
+ changelog_uri: https://github.com/asciidoctor/guard-asciidoc/blob/main/CHANGELOG.adoc
105
+ mailing_list_uri: https://chat.asciidoctor.org
106
+ source_code_uri: https://github.com/asciidoctor/guard-asciidoc
107
+ post_install_message:
108
+ rdoc_options: []
109
+ require_paths:
110
+ - lib
111
+ required_ruby_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ required_rubygems_version: !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - !ruby/object:Gem::Version
120
+ version: '0'
121
+ requirements: []
122
+ rubygems_version: 3.4.10
123
+ signing_key:
124
+ specification_version: 4
125
+ summary: Guard::AsciiDoc automatically converts your AsciiDoc documents.
126
+ test_files: []