asciisourcerer 0.1.0 → 0.2.1
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 +4 -4
- data/README.adoc +393 -37
- data/lib/asciidoctor/extensions/source-skim-tree-processor/extension.rb +55 -0
- data/lib/asciisourcerer.rb +1 -0
- data/lib/sourcerer/asciidoc.rb +13 -9
- data/lib/sourcerer/attributes_filter.rb +72 -0
- data/lib/sourcerer/rendering.rb +29 -0
- data/lib/sourcerer/source_skim/config.rb +53 -0
- data/lib/sourcerer/source_skim/skimmer.rb +298 -0
- data/lib/sourcerer/source_skim.rb +76 -0
- data/lib/sourcerer/sync/block_parser.rb +245 -0
- data/lib/sourcerer/sync/cast.rb +274 -0
- data/lib/sourcerer/sync.rb +33 -0
- data/lib/sourcerer/util/list_amend.rb +63 -0
- data/lib/sourcerer/util/pathifier.rb +101 -0
- data/lib/sourcerer/version.rb +1 -1
- data/lib/sourcerer.rb +3 -0
- metadata +13 -6
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'find'
|
|
4
|
+
|
|
5
|
+
module Sourcerer
|
|
6
|
+
module Util
|
|
7
|
+
# Classify an input string as file/dir/glob/missing and yield matching paths lazily.
|
|
8
|
+
#
|
|
9
|
+
# Not required internally; callers must require this file explicitly.
|
|
10
|
+
module Pathifier
|
|
11
|
+
GLOB_METACHARACTERS = /[*?\[\]{}]/
|
|
12
|
+
|
|
13
|
+
# A small value object returned by +.match+.
|
|
14
|
+
Result = Struct.new(:type, :input, :enum, keyword_init: true)
|
|
15
|
+
|
|
16
|
+
# Classify +input+ and return a +Result+ with a lazy path enumerator.
|
|
17
|
+
#
|
|
18
|
+
# @param input [String] file path, directory path, or glob pattern
|
|
19
|
+
# @param recursive [Boolean] if dir, traverse recursively (default: +true+)
|
|
20
|
+
# @param include_dirs [Boolean] if dir traversal, also yield directory paths (default: +false+)
|
|
21
|
+
# @param follow_symlinks [Boolean] follow symlink directories during recursal (default: +false+)
|
|
22
|
+
# @return [Result]
|
|
23
|
+
def self.match input, recursive: true, include_dirs: false, follow_symlinks: false
|
|
24
|
+
type = classify(input)
|
|
25
|
+
Result.new(
|
|
26
|
+
type: type,
|
|
27
|
+
input: input,
|
|
28
|
+
enum: build_enum(
|
|
29
|
+
type, input, recursive: recursive, include_dirs: include_dirs,
|
|
30
|
+
follow_symlinks: follow_symlinks))
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Classify the input string without enumerating paths.
|
|
34
|
+
#
|
|
35
|
+
# @param input [String]
|
|
36
|
+
# @return [:file, :dir, :glob, :missing]
|
|
37
|
+
def self.classify input
|
|
38
|
+
if File.file?(input)
|
|
39
|
+
:file
|
|
40
|
+
elsif File.directory?(input)
|
|
41
|
+
:dir
|
|
42
|
+
elsif GLOB_METACHARACTERS.match?(input)
|
|
43
|
+
:glob
|
|
44
|
+
else
|
|
45
|
+
:missing
|
|
46
|
+
end
|
|
47
|
+
end
|
|
48
|
+
private_class_method :classify
|
|
49
|
+
|
|
50
|
+
def self.build_enum type, input, recursive:, include_dirs:, follow_symlinks:
|
|
51
|
+
case type
|
|
52
|
+
when :file
|
|
53
|
+
Enumerator.new do |y|
|
|
54
|
+
y << File.expand_path(input)
|
|
55
|
+
end
|
|
56
|
+
when :dir
|
|
57
|
+
build_dir_enum(
|
|
58
|
+
input, recursive: recursive, include_dirs: include_dirs,
|
|
59
|
+
follow_symlinks: follow_symlinks)
|
|
60
|
+
when :glob
|
|
61
|
+
Enumerator.new do |y|
|
|
62
|
+
Dir.glob(input) { |path| y << path }
|
|
63
|
+
end
|
|
64
|
+
else # :missing
|
|
65
|
+
Enumerator.new { |_y| nil }
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
private_class_method :build_enum
|
|
69
|
+
|
|
70
|
+
def self.build_dir_enum input, recursive:, include_dirs:, follow_symlinks:
|
|
71
|
+
abs = File.expand_path(input)
|
|
72
|
+
if recursive
|
|
73
|
+
Enumerator.new do |y|
|
|
74
|
+
Find.find(abs) do |path|
|
|
75
|
+
# Prune symlink directories unless follow_symlinks is set.
|
|
76
|
+
if File.symlink?(path) && File.directory?(path) && !follow_symlinks
|
|
77
|
+
Find.prune
|
|
78
|
+
elsif File.directory?(path)
|
|
79
|
+
y << path if include_dirs && path != abs
|
|
80
|
+
else
|
|
81
|
+
y << path
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
85
|
+
else
|
|
86
|
+
Enumerator.new do |y|
|
|
87
|
+
Dir.each_child(abs) do |name|
|
|
88
|
+
path = File.join(abs, name)
|
|
89
|
+
if File.directory?(path)
|
|
90
|
+
y << path if include_dirs
|
|
91
|
+
else
|
|
92
|
+
y << path
|
|
93
|
+
end
|
|
94
|
+
end
|
|
95
|
+
end
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
private_class_method :build_dir_enum
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
data/lib/sourcerer/version.rb
CHANGED
data/lib/sourcerer.rb
CHANGED
|
@@ -17,8 +17,11 @@ require_relative 'sourcerer/yaml'
|
|
|
17
17
|
# Requiring `sourcerer` also makes adjacent public constants (for example,
|
|
18
18
|
# `Sourcerer::Builder`) available to downstream callers.
|
|
19
19
|
module Sourcerer
|
|
20
|
+
autoload :AttributesFilter, 'sourcerer/attributes_filter'
|
|
20
21
|
autoload :Jekyll, 'sourcerer/jekyll'
|
|
21
22
|
autoload :MarkDownGrade, 'sourcerer/mark_down_grade'
|
|
23
|
+
autoload :SourceSkim, 'sourcerer/source_skim'
|
|
24
|
+
autoload :Sync, 'sourcerer/sync'
|
|
22
25
|
|
|
23
26
|
DEPRECATED_FACADE_METHODS = {
|
|
24
27
|
# DO NOT add new public methods to this surface
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: asciisourcerer
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1
|
|
4
|
+
version: 0.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- DocOps Lab
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: asciidoctor
|
|
@@ -119,9 +118,11 @@ extra_rdoc_files: []
|
|
|
119
118
|
files:
|
|
120
119
|
- LICENSE
|
|
121
120
|
- README.adoc
|
|
121
|
+
- lib/asciidoctor/extensions/source-skim-tree-processor/extension.rb
|
|
122
122
|
- lib/asciisourcerer.rb
|
|
123
123
|
- lib/sourcerer.rb
|
|
124
124
|
- lib/sourcerer/asciidoc.rb
|
|
125
|
+
- lib/sourcerer/attributes_filter.rb
|
|
125
126
|
- lib/sourcerer/builder.rb
|
|
126
127
|
- lib/sourcerer/jekyll.rb
|
|
127
128
|
- lib/sourcerer/jekyll/bootstrapper.rb
|
|
@@ -132,7 +133,15 @@ files:
|
|
|
132
133
|
- lib/sourcerer/mark_down_grade.rb
|
|
133
134
|
- lib/sourcerer/plaintext_converter.rb
|
|
134
135
|
- lib/sourcerer/rendering.rb
|
|
136
|
+
- lib/sourcerer/source_skim.rb
|
|
137
|
+
- lib/sourcerer/source_skim/config.rb
|
|
138
|
+
- lib/sourcerer/source_skim/skimmer.rb
|
|
139
|
+
- lib/sourcerer/sync.rb
|
|
140
|
+
- lib/sourcerer/sync/block_parser.rb
|
|
141
|
+
- lib/sourcerer/sync/cast.rb
|
|
135
142
|
- lib/sourcerer/templating.rb
|
|
143
|
+
- lib/sourcerer/util/list_amend.rb
|
|
144
|
+
- lib/sourcerer/util/pathifier.rb
|
|
136
145
|
- lib/sourcerer/version.rb
|
|
137
146
|
- lib/sourcerer/yaml.rb
|
|
138
147
|
homepage: https://github.com/DocOps/asciisourcerer
|
|
@@ -141,7 +150,6 @@ licenses:
|
|
|
141
150
|
metadata:
|
|
142
151
|
allowed_push_host: https://rubygems.org
|
|
143
152
|
rubygems_mfa_required: 'true'
|
|
144
|
-
post_install_message:
|
|
145
153
|
rdoc_options: []
|
|
146
154
|
require_paths:
|
|
147
155
|
- lib
|
|
@@ -156,8 +164,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
156
164
|
- !ruby/object:Gem::Version
|
|
157
165
|
version: '0'
|
|
158
166
|
requirements: []
|
|
159
|
-
rubygems_version: 3.
|
|
160
|
-
signing_key:
|
|
167
|
+
rubygems_version: 3.7.2
|
|
161
168
|
specification_version: 4
|
|
162
169
|
summary: APIs for specialized handling of AsciiDoc, YAML, and Liquid documents.
|
|
163
170
|
test_files: []
|