jtag 0.1.19 → 0.1.22
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/.irbrc +6 -0
- data/CHANGELOG.md +15 -0
- data/Gemfile +3 -0
- data/Jekyll/plugins/autotag_gen.rb +58 -0
- data/Jekyll/source/_layouts/tags_json.html +11 -0
- data/README.md +159 -0
- data/Rakefile +113 -0
- data/bin/jtag +378 -252
- data/jtag.completion.bash +9 -0
- data/jtag.gemspec +25 -0
- data/lib/jtag/array.rb +48 -0
- data/lib/jtag/config_files/config.yml +3 -2
- data/lib/jtag/errors.rb +31 -0
- data/lib/jtag/hash.rb +103 -0
- data/lib/jtag/jekylltag.rb +272 -225
- data/lib/jtag/string.rb +238 -42
- data/lib/jtag/stupid_json.rb +319 -0
- data/lib/jtag/util.rb +237 -0
- data/lib/jtag/version.rb +1 -1
- data/lib/jtag.rb +19 -13
- data/mise.toml +2 -0
- metadata +34 -9
data/lib/jtag/util.rb
ADDED
@@ -0,0 +1,237 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module JekyllTag
|
4
|
+
# JTag utilities
|
5
|
+
class Util
|
6
|
+
attr_writer :debug_level
|
7
|
+
attr_writer :silent
|
8
|
+
attr_accessor :log
|
9
|
+
attr_accessor :config_target
|
10
|
+
|
11
|
+
DEBUG_LEVELS = {
|
12
|
+
:error => 0,
|
13
|
+
:warn => 1,
|
14
|
+
:info => 2,
|
15
|
+
:debug => 3,
|
16
|
+
}
|
17
|
+
|
18
|
+
CONFIG_FILES = %w{blacklist.txt config.yml stopwords.txt synonyms.yml}
|
19
|
+
|
20
|
+
##
|
21
|
+
## Output tags in the specified format
|
22
|
+
##
|
23
|
+
## @param tags [Array] array of tags
|
24
|
+
## @param options [Hash] hash of options
|
25
|
+
##
|
26
|
+
## @option options :format [String] format to output tags in
|
27
|
+
## @option options :print0 [Boolean] print tags with null delimiter
|
28
|
+
## @option options :filename [String] filename to output
|
29
|
+
## @option options :content [String] content to output for complete format
|
30
|
+
## @option options :grouping [String] grouping key for YAML tags
|
31
|
+
##
|
32
|
+
## @return [void]
|
33
|
+
##
|
34
|
+
def output_tags(tags, options)
|
35
|
+
# Determine the format for output, defaulting to "yaml" if not specified
|
36
|
+
format = options[:format]&.to_format || :yaml
|
37
|
+
# Determine if tags should be printed with a null delimiter
|
38
|
+
print0 = options[:print0] || false
|
39
|
+
# Determine the filename for output, if specified
|
40
|
+
filename = options[:filename] || false
|
41
|
+
# Content that was piped in
|
42
|
+
content = options[:content] || false
|
43
|
+
|
44
|
+
tags.sort!
|
45
|
+
tags.uniq!
|
46
|
+
|
47
|
+
case format
|
48
|
+
when "complete"
|
49
|
+
if filename || content
|
50
|
+
content = filename ? IO.read(File.expand_path(filename)) : content
|
51
|
+
parts = content.split(/---\s*\n/)
|
52
|
+
if parts.count < 2
|
53
|
+
console_log "No front matter found in #{filename}", level: :error, err: true
|
54
|
+
yaml = {}
|
55
|
+
body = content
|
56
|
+
else
|
57
|
+
yaml = YAML.load(parts[1])
|
58
|
+
body = parts[2..-1].join("\n")
|
59
|
+
end
|
60
|
+
options[:grouping] ||= "tags"
|
61
|
+
yaml[options[:grouping]] = tags
|
62
|
+
console_log "#{filename}", level: :info, err: true if filename
|
63
|
+
console_log yaml.to_yaml + "---\n" + body, level: :error, err: false
|
64
|
+
else
|
65
|
+
console_log tags.join("\n"), level: :error, err: false
|
66
|
+
end
|
67
|
+
when "list"
|
68
|
+
# Join tags with a null character delimiter
|
69
|
+
console_log tags.map(&:strip).join(print0 ? "\x00" : "\n"), level: :error, err: false, file: filename
|
70
|
+
when "csv"
|
71
|
+
# Log the tags in CSV format
|
72
|
+
console_log tags.to_csv
|
73
|
+
when "json"
|
74
|
+
# Create a hash with tags and optional filename, then log as JSON
|
75
|
+
out = {}
|
76
|
+
out["tags"] = tags
|
77
|
+
out["path"] = filename if filename
|
78
|
+
console_log out.to_json
|
79
|
+
when "plist"
|
80
|
+
# Create a hash with optional filename, then log as plist
|
81
|
+
out = {}
|
82
|
+
out["path"] = filename if filename
|
83
|
+
out["tags"] = tags
|
84
|
+
console_log out.to_plist
|
85
|
+
else
|
86
|
+
# Default to YAML format, create a hash with grouping and tags, then log as YAML
|
87
|
+
out = {}
|
88
|
+
options[:grouping] ||= "tags"
|
89
|
+
out[options[:grouping]] = tags
|
90
|
+
console_log out.to_yaml
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
##
|
95
|
+
## Logging
|
96
|
+
##
|
97
|
+
### Log levels
|
98
|
+
## 0 = error
|
99
|
+
## 1 = warn
|
100
|
+
## 2 = info
|
101
|
+
## 3 = debug
|
102
|
+
##
|
103
|
+
### Debug levels
|
104
|
+
## 1 = errors only
|
105
|
+
## 2 = errors and warnings
|
106
|
+
## 3 = errors, warnings and info
|
107
|
+
## 4 = errors, warnings, info and debug
|
108
|
+
##
|
109
|
+
### Test level < debug level (true = return, false = continue)
|
110
|
+
## true = continue
|
111
|
+
## false = return
|
112
|
+
##
|
113
|
+
### Examples
|
114
|
+
## send info (2) and debug is errors and warnings (2) (2 < 2 = return)
|
115
|
+
## send error (0) and debug is errors and warnings (2) (0 < 2 = continue)
|
116
|
+
## send warning (1) and debug is errors only (1) (1 < 1 = return)
|
117
|
+
## send error (0) and debug level is silent (0) (0 < 0 = return)
|
118
|
+
## send debug (3) and debug level is info (3) (3 < 4 = return)
|
119
|
+
## send debug (3) and debug level is debug (4) (3 < 4 = continue)
|
120
|
+
##
|
121
|
+
## @example Log an info message
|
122
|
+
## console_log("This is an info message", level: :info)
|
123
|
+
##
|
124
|
+
## @example Log a warning message and output to STDERR
|
125
|
+
## console_log("This is a warning message", level: :warn, err: true)
|
126
|
+
##
|
127
|
+
## @param msg [String] message to log
|
128
|
+
## @param options [Hash] hash of options
|
129
|
+
##
|
130
|
+
## @option options :level [Symbol] level of message (info, warn, error, debug)
|
131
|
+
## @option options :err [Boolean] print to STDERR
|
132
|
+
## @option options :log [Boolean] write to log file
|
133
|
+
## @option options :filename [String] write to file
|
134
|
+
##
|
135
|
+
## @return [void]
|
136
|
+
##
|
137
|
+
def console_log(msg = "", options = {})
|
138
|
+
level = options[:level] || :info
|
139
|
+
err = options[:err] || false
|
140
|
+
options[:log] ||= false
|
141
|
+
|
142
|
+
return unless DEBUG_LEVELS[level.to_sym] < @debug_level
|
143
|
+
|
144
|
+
if options[:log]
|
145
|
+
if err
|
146
|
+
@log.warn(msg)
|
147
|
+
else
|
148
|
+
@log.info(msg)
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
if options[:filename]
|
153
|
+
File.open(options[:filename], "w") do |f|
|
154
|
+
f.puts msg
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
return if @silent
|
159
|
+
|
160
|
+
unless err
|
161
|
+
$stdout.puts msg
|
162
|
+
else
|
163
|
+
$stderr.puts msg
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
#
|
168
|
+
## Write configuration files
|
169
|
+
##
|
170
|
+
## @param atomic [Boolean] force write of config files
|
171
|
+
##
|
172
|
+
## @example Write configuration files
|
173
|
+
## write_config
|
174
|
+
##
|
175
|
+
## @return [void]
|
176
|
+
##
|
177
|
+
def write_config(atomic = false)
|
178
|
+
# Get the root path of the gem
|
179
|
+
jtag_gem = Gem.loaded_specs["jtag"]
|
180
|
+
gem_root = jtag_gem.full_gem_path || File.expand_path("../../", __dir__)
|
181
|
+
# Get the lib directory within the gem
|
182
|
+
gem_lib = File.join(gem_root, "lib")
|
183
|
+
# Define the source directory for the configuration files
|
184
|
+
config_source = File.join(gem_lib, "/jtag/config_files/")
|
185
|
+
|
186
|
+
FileUtils.rm_rf(@config_target) if File.directory?(@config_target) && atomic
|
187
|
+
|
188
|
+
# If the config target directory does not exist or atomic is true, copy the config files
|
189
|
+
if !File.directory?(@config_target)
|
190
|
+
# Ensure the target directory exists
|
191
|
+
FileUtils.mkdir_p(@config_target)
|
192
|
+
CONFIG_FILES.each do |file|
|
193
|
+
FileUtils.cp(File.join(config_source, file), @config_target)
|
194
|
+
end
|
195
|
+
# console_log "Configuration files written to #{@config_target}", level: :warn
|
196
|
+
end
|
197
|
+
|
198
|
+
# Iterate over each config file
|
199
|
+
CONFIG_FILES.each do |file|
|
200
|
+
# If the config file does not exist in the target directory, copy it from the source
|
201
|
+
unless File.exist?(File.join(@config_target, file))
|
202
|
+
# Define the source and target file paths
|
203
|
+
source_file = File.join(config_source, file)
|
204
|
+
target_file = File.join(@config_target, file)
|
205
|
+
# Copy the source file to the target location
|
206
|
+
FileUtils.cp(source_file, target_file)
|
207
|
+
# Log that the config file has been added
|
208
|
+
console_log "Config file #{file} added."
|
209
|
+
end
|
210
|
+
end
|
211
|
+
|
212
|
+
# Output the final location of the configuration files
|
213
|
+
console_log
|
214
|
+
console_log "Configuration files are located in the folder: " + @config_target
|
215
|
+
# Output a reminder to set the tags_location in the config.yml file
|
216
|
+
console_log %Q{Make sure that "tags_location" in the config.yml file is set to your tags json file.}
|
217
|
+
end
|
218
|
+
|
219
|
+
## Check if all config files are present
|
220
|
+
##
|
221
|
+
## @example Check if all config files are present
|
222
|
+
## config_files_complete?
|
223
|
+
## # => true
|
224
|
+
##
|
225
|
+
## @return [Boolean]
|
226
|
+
def config_files_complete?
|
227
|
+
# Move ~/.jtag if needed
|
228
|
+
update_deprecated_config
|
229
|
+
|
230
|
+
# Check if all config files are present
|
231
|
+
CONFIG_FILES.each do |file|
|
232
|
+
return false unless File.exist?(File.join(@config_target, file))
|
233
|
+
end
|
234
|
+
true
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
data/lib/jtag/version.rb
CHANGED
data/lib/jtag.rb
CHANGED
@@ -1,13 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
8
|
-
require
|
9
|
-
require
|
10
|
-
require
|
11
|
-
require
|
12
|
-
|
13
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "net/http"
|
4
|
+
require "cgi"
|
5
|
+
require "fileutils"
|
6
|
+
require "yaml"
|
7
|
+
require "csv"
|
8
|
+
require "json"
|
9
|
+
require "plist"
|
10
|
+
require "tmpdir"
|
11
|
+
require "logger"
|
12
|
+
require_relative "jtag/errors.rb"
|
13
|
+
require_relative "jtag/array.rb"
|
14
|
+
require_relative "jtag/hash.rb"
|
15
|
+
require_relative "jtag/version.rb"
|
16
|
+
require_relative "jtag/string.rb"
|
17
|
+
require_relative "jtag/porter_stemming.rb"
|
18
|
+
require_relative "jtag/jekylltag.rb"
|
19
|
+
require_relative "jtag/util.rb"
|
data/mise.toml
ADDED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jtag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.22
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Terpstra
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-02-24 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: rake
|
@@ -56,14 +55,14 @@ dependencies:
|
|
56
55
|
name: gli
|
57
56
|
requirement: !ruby/object:Gem::Requirement
|
58
57
|
requirements:
|
59
|
-
- -
|
58
|
+
- - '='
|
60
59
|
- !ruby/object:Gem::Version
|
61
60
|
version: 2.20.0
|
62
61
|
type: :runtime
|
63
62
|
prerelease: false
|
64
63
|
version_requirements: !ruby/object:Gem::Requirement
|
65
64
|
requirements:
|
66
|
-
- -
|
65
|
+
- - '='
|
67
66
|
- !ruby/object:Gem::Version
|
68
67
|
version: 2.20.0
|
69
68
|
- !ruby/object:Gem::Dependency
|
@@ -80,7 +79,20 @@ dependencies:
|
|
80
79
|
- - ">="
|
81
80
|
- !ruby/object:Gem::Version
|
82
81
|
version: '0'
|
83
|
-
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: csv
|
84
|
+
requirement: !ruby/object:Gem::Requirement
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
version: '0'
|
89
|
+
type: :runtime
|
90
|
+
prerelease: false
|
91
|
+
version_requirements: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
84
96
|
email: me@brettterpstra.com
|
85
97
|
executables:
|
86
98
|
- jtag
|
@@ -89,22 +101,36 @@ extra_rdoc_files:
|
|
89
101
|
- README.rdoc
|
90
102
|
- jtag.rdoc
|
91
103
|
files:
|
104
|
+
- ".irbrc"
|
105
|
+
- CHANGELOG.md
|
106
|
+
- Gemfile
|
107
|
+
- Jekyll/plugins/autotag_gen.rb
|
108
|
+
- Jekyll/source/_layouts/tags_json.html
|
109
|
+
- README.md
|
92
110
|
- README.rdoc
|
111
|
+
- Rakefile
|
93
112
|
- bin/jtag
|
113
|
+
- jtag.completion.bash
|
114
|
+
- jtag.gemspec
|
94
115
|
- jtag.rdoc
|
95
116
|
- lib/jtag.rb
|
117
|
+
- lib/jtag/array.rb
|
96
118
|
- lib/jtag/config_files/blacklist.txt
|
97
119
|
- lib/jtag/config_files/config.yml
|
98
120
|
- lib/jtag/config_files/stopwords.txt
|
99
121
|
- lib/jtag/config_files/synonyms.yml
|
122
|
+
- lib/jtag/errors.rb
|
123
|
+
- lib/jtag/hash.rb
|
100
124
|
- lib/jtag/jekylltag.rb
|
101
125
|
- lib/jtag/porter_stemming.rb
|
102
126
|
- lib/jtag/string.rb
|
127
|
+
- lib/jtag/stupid_json.rb
|
128
|
+
- lib/jtag/util.rb
|
103
129
|
- lib/jtag/version.rb
|
130
|
+
- mise.toml
|
104
131
|
homepage: http://brettterpstra.com
|
105
132
|
licenses: []
|
106
133
|
metadata: {}
|
107
|
-
post_install_message:
|
108
134
|
rdoc_options:
|
109
135
|
- "--title"
|
110
136
|
- jtag
|
@@ -124,8 +150,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
150
|
- !ruby/object:Gem::Version
|
125
151
|
version: '0'
|
126
152
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
128
|
-
signing_key:
|
153
|
+
rubygems_version: 3.6.4
|
129
154
|
specification_version: 4
|
130
155
|
summary: Auto-tagging and tagging tools for Jekyll
|
131
156
|
test_files: []
|