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