sublime_text_kit 10.0.2 → 11.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data/README.adoc +54 -70
  4. data/{bin → exe}/sublime_text_kit +1 -3
  5. data/lib/sublime_text_kit/cli/actions/config.rb +35 -0
  6. data/lib/sublime_text_kit/cli/actions/metadata.rb +63 -0
  7. data/lib/sublime_text_kit/cli/actions/session.rb +26 -0
  8. data/lib/sublime_text_kit/cli/actions/snippets.rb +37 -0
  9. data/lib/sublime_text_kit/cli/actions/update.rb +42 -0
  10. data/lib/sublime_text_kit/cli/configuration/content.rb +45 -0
  11. data/lib/sublime_text_kit/cli/configuration/defaults.yml +3 -0
  12. data/lib/sublime_text_kit/cli/configuration/loader.rb +37 -0
  13. data/lib/sublime_text_kit/cli/parsers/assembler.rb +32 -0
  14. data/lib/sublime_text_kit/cli/parsers/core.rb +99 -0
  15. data/lib/sublime_text_kit/cli/parsers.rb +11 -0
  16. data/lib/sublime_text_kit/cli/shell.rb +58 -0
  17. data/lib/sublime_text_kit/container.rb +37 -0
  18. data/lib/sublime_text_kit/identity.rb +3 -2
  19. data/lib/sublime_text_kit/metadata/handler.rb +43 -0
  20. data/lib/sublime_text_kit/metadata/pathway.rb +19 -0
  21. data/lib/sublime_text_kit/metadata/serializers/project.rb +24 -0
  22. data/lib/sublime_text_kit/metadata/serializers/workspace.rb +27 -0
  23. data/lib/sublime_text_kit/sessions/rebuilder.rb +44 -0
  24. data/lib/sublime_text_kit/snippets/collector.rb +13 -19
  25. data/lib/sublime_text_kit/snippets/model.rb +31 -0
  26. data/lib/sublime_text_kit/snippets/printers/ascii_doc.rb +7 -5
  27. data/lib/sublime_text_kit/snippets/printers/markdown.rb +7 -3
  28. data/lib/sublime_text_kit/snippets/reader.rb +21 -0
  29. data/lib/sublime_text_kit.rb +11 -10
  30. data.tar.gz.sig +0 -0
  31. metadata +59 -16
  32. metadata.gz.sig +0 -0
  33. data/lib/sublime_text_kit/cli.rb +0 -182
  34. data/lib/sublime_text_kit/metadata/base.rb +0 -60
  35. data/lib/sublime_text_kit/metadata/project_metadata.rb +0 -20
  36. data/lib/sublime_text_kit/metadata/workspace_metadata.rb +0 -23
  37. data/lib/sublime_text_kit/session.rb +0 -44
  38. data/lib/sublime_text_kit/snippets/snippet.rb +0 -56
@@ -0,0 +1,58 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SublimeTextKit
4
+ module CLI
5
+ # The main Command Line Interface (CLI) object.
6
+ class Shell
7
+ ACTIONS = {
8
+ config: Actions::Config.new,
9
+ metadata: Actions::Metadata.new,
10
+ session: Actions::Session.new,
11
+ snippets: Actions::Snippets.new,
12
+ update: Actions::Update.new
13
+ }.freeze
14
+
15
+ def initialize parser: Parsers::Assembler.new, actions: ACTIONS, container: Container
16
+ @parser = parser
17
+ @actions = actions
18
+ @container = container
19
+ end
20
+
21
+ def call arguments = []
22
+ perform parser.call(arguments)
23
+ rescue OptionParser::ParseError, Error => error
24
+ logger.error { error.message }
25
+ end
26
+
27
+ private
28
+
29
+ attr_reader :parser, :actions, :container
30
+
31
+ def perform configuration
32
+ case configuration
33
+ in action_config: Symbol => action then config action
34
+ in action_metadata: Symbol => kind then metadata kind
35
+ in action_session: true then session
36
+ in action_snippets: true then snippets
37
+ in action_update: true then update
38
+ in action_version: String => version then logger.info version
39
+ else usage
40
+ end
41
+ end
42
+
43
+ def config(action) = actions.fetch(__method__).call(action)
44
+
45
+ def metadata(kind) = actions.fetch(__method__).call(kind)
46
+
47
+ def session = actions.fetch(__method__).call
48
+
49
+ def snippets = actions.fetch(__method__).call
50
+
51
+ def update = actions.fetch(__method__).call
52
+
53
+ def usage = logger.unknown { parser.to_s }
54
+
55
+ def logger = container[__method__]
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "dry-container"
4
+ require "logger"
5
+ require "pastel"
6
+
7
+ module SublimeTextKit
8
+ # Provides a global gem container for injection into other objects.
9
+ module Container
10
+ extend Dry::Container::Mixin
11
+
12
+ register(:configuration, memoize: true) { CLI::Configuration::Loader.call }
13
+ register(:colorizer) { Pastel.new enabled: $stdout.tty? }
14
+ register(:kernel) { Kernel }
15
+
16
+ register :log_colors do
17
+ {
18
+ "DEBUG" => self[:colorizer].white.detach,
19
+ "INFO" => self[:colorizer].green.detach,
20
+ "WARN" => self[:colorizer].yellow.detach,
21
+ "ERROR" => self[:colorizer].red.detach,
22
+ "FATAL" => self[:colorizer].white.bold.on_red.detach,
23
+ "ANY" => self[:colorizer].white.bold.detach
24
+ }
25
+ end
26
+
27
+ register :logger do
28
+ Logger.new $stdout,
29
+ level: Logger.const_get(ENV.fetch("LOG_LEVEL", "INFO")),
30
+ formatter: (
31
+ lambda do |severity, _at, _name, message|
32
+ self[:log_colors][severity].call "#{message}\n"
33
+ end
34
+ )
35
+ end
36
+ end
37
+ end
@@ -5,7 +5,8 @@ module SublimeTextKit
5
5
  module Identity
6
6
  NAME = "sublime_text_kit"
7
7
  LABEL = "Sublime Text Kit"
8
- VERSION = "10.0.2"
9
- VERSION_LABEL = "#{LABEL} #{VERSION}"
8
+ VERSION = "11.0.3"
9
+ VERSION_LABEL = "#{LABEL} #{VERSION}".freeze
10
+ SUMMARY = "A command line interface for managing Sublime Text metadata."
10
11
  end
11
12
  end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "refinements/pathnames"
4
+
5
+ module SublimeTextKit
6
+ module Metadata
7
+ # Handles the creation, deletion, and recreation of metadata.
8
+ class Handler
9
+ using Refinements::Pathnames
10
+
11
+ def self.with_project project_dir, metadata_dir
12
+ new "sublime-project",
13
+ serializer: Serializers::Project.new(
14
+ Pathway[project_dir: project_dir, metadata_dir: metadata_dir]
15
+ )
16
+ end
17
+
18
+ def self.with_workspace project_dir, metadata_dir
19
+ new "sublime-workspace",
20
+ serializer: Serializers::Workspace.new(
21
+ Pathway[project_dir: project_dir, metadata_dir: metadata_dir]
22
+ )
23
+ end
24
+
25
+ def initialize extension, serializer:
26
+ @extension = extension
27
+ @serializer = serializer
28
+ end
29
+
30
+ def create = path.exist? ? path : path.write(JSON.dump(serializer.to_h))
31
+
32
+ def delete = path.exist? ? path.delete : path
33
+
34
+ def recreate = delete && create
35
+
36
+ private
37
+
38
+ attr_reader :extension, :serializer
39
+
40
+ def path = serializer.pathway.metadata_file(extension)
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SublimeTextKit
4
+ module Metadata
5
+ # Defines metadata pathways.
6
+ Pathway = Struct.new :project_dir, :metadata_dir, keyword_init: true do
7
+ using Refinements::Pathnames
8
+
9
+ def initialize *arguments
10
+ super
11
+ each_pair { |key, value| self[key] = Pathname(value).expand_path }
12
+ end
13
+
14
+ def project_name = project_dir.basename
15
+
16
+ def metadata_file(extension) = metadata_dir.join("#{project_name}.#{extension}")
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SublimeTextKit
4
+ module Metadata
5
+ module Serializers
6
+ # Serializes project metadata.
7
+ class Project
8
+ attr_reader :pathway
9
+
10
+ def initialize pathway
11
+ @pathway = pathway
12
+ end
13
+
14
+ def to_h
15
+ {
16
+ folders: [
17
+ {path: pathway.project_dir.to_s}
18
+ ]
19
+ }
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SublimeTextKit
4
+ module Metadata
5
+ module Serializers
6
+ # Serializes workspace metadata.
7
+ class Workspace
8
+ attr_reader :pathway
9
+
10
+ def initialize pathway
11
+ @pathway = pathway
12
+ end
13
+
14
+ def to_h
15
+ {
16
+ expanded_folders: [pathway.project_dir.to_s],
17
+ select_project: {
18
+ selected_items: [
19
+ [pathway.project_name.to_s, pathway.metadata_file("sublime-project").to_s]
20
+ ]
21
+ }
22
+ }
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,44 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "json"
4
+ require "refinements/pathnames"
5
+
6
+ module SublimeTextKit
7
+ module Sessions
8
+ # Manages the rebuilding of session information.
9
+ class Rebuilder
10
+ using Refinements::Pathnames
11
+
12
+ def initialize container: Container
13
+ @container = container
14
+ end
15
+
16
+ def call
17
+ session = read
18
+
19
+ return unless session.dig "workspaces", "recent_workspaces"
20
+
21
+ Pathname(metadata_dir).expand_path
22
+ .files("*.sublime-workspace")
23
+ .then do |workspaces|
24
+ session["workspaces"]["recent_workspaces"] = workspaces
25
+ write session
26
+ end
27
+ end
28
+
29
+ private
30
+
31
+ attr_reader :container
32
+
33
+ def read = source_path.exist? ? JSON(source_path.read) : {}
34
+
35
+ def write(json) = JSON.dump(json).then { |content| source_path.write content }
36
+
37
+ def metadata_dir = configuration.metadata_dir
38
+
39
+ def source_path = configuration.session_path
40
+
41
+ def configuration = container[__method__]
42
+ end
43
+ end
44
+ end
@@ -1,36 +1,30 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "pathname"
4
- require "rexml/document"
3
+ require "refinements/pathnames"
5
4
 
6
5
  module SublimeTextKit
7
6
  module Snippets
7
+ # Collects and loads all snippets into memory for further processing.
8
8
  class Collector
9
- DEFAULT_USER_PATH = "Library/Application Support/Sublime Text 3/Packages/User"
9
+ using Refinements::Pathnames
10
10
 
11
- def initialize model: Snippet, user_path: DEFAULT_USER_PATH, environment: ENV
12
- @model = model
13
- @user_path = user_path
14
- @environment = environment
15
- end
16
-
17
- def home_path
18
- Pathname environment.fetch("HOME")
19
- end
20
-
21
- def root_path
22
- home_path.join user_path
11
+ def initialize reader: Reader.new, container: Container
12
+ @reader = reader
13
+ @container = container
23
14
  end
24
15
 
25
16
  def call
26
- root_path.glob("*.sublime-snippet")
27
- .map { |path| model.new REXML::Document.new(path.read) }
28
- .sort_by(&:description)
17
+ configuration.user_dir
18
+ .files("*.sublime-snippet")
19
+ .map { |path| reader.call path }
20
+ .sort_by(&:description)
29
21
  end
30
22
 
31
23
  private
32
24
 
33
- attr_reader :model, :user_path, :environment
25
+ def configuration = container[__method__]
26
+
27
+ attr_reader :reader, :container
34
28
  end
35
29
  end
36
30
  end
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SublimeTextKit
4
+ module Snippets
5
+ KEY_MAP = {
6
+ "content" => :content,
7
+ "tabTrigger" => :trigger,
8
+ "description" => :description,
9
+ "scope" => :scope
10
+ }.freeze
11
+
12
+ # Defines a snippet record.
13
+ Model = Struct.new(*KEY_MAP.values, keyword_init: true) do
14
+ def self.for document, key_map: KEY_MAP
15
+ root = document.root
16
+
17
+ return new unless root
18
+
19
+ root.elements
20
+ .reduce({}) { |attributes, element| attributes.merge element.name => element.text }
21
+ .transform_keys(key_map)
22
+ .then { |attributes| new(**attributes) }
23
+ end
24
+
25
+ def initialize *arguments
26
+ super
27
+ freeze
28
+ end
29
+ end
30
+ end
31
+ end
@@ -1,24 +1,26 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "rexml/document"
4
-
5
3
  module SublimeTextKit
6
4
  module Snippets
7
5
  module Printers
6
+ # Prints snippets in ASCII Doc format.
8
7
  class ASCIIDoc
9
- def initialize collector: Collector.new
8
+ def initialize collector: Collector.new, container: Container
10
9
  @collector = collector
10
+ @container = container
11
11
  end
12
12
 
13
13
  def call
14
14
  collector.call.each do |snippet|
15
- puts "* #{snippet.description} - `#{snippet.trigger}`\n"
15
+ logger.info "* #{snippet.description} - `#{snippet.trigger}`"
16
16
  end
17
17
  end
18
18
 
19
19
  private
20
20
 
21
- attr_reader :collector
21
+ attr_reader :collector, :container
22
+
23
+ def logger = container[__method__]
22
24
  end
23
25
  end
24
26
  end
@@ -3,20 +3,24 @@
3
3
  module SublimeTextKit
4
4
  module Snippets
5
5
  module Printers
6
+ # Prints snippets in Markdown format.
6
7
  class Markdown
7
- def initialize collector: Collector.new
8
+ def initialize collector: Collector.new, container: Container
8
9
  @collector = collector
10
+ @container = container
9
11
  end
10
12
 
11
13
  def call
12
14
  collector.call.each do |snippet|
13
- puts "- #{snippet.description} - `#{snippet.trigger}`\n"
15
+ logger.info "- #{snippet.description} - `#{snippet.trigger}`"
14
16
  end
15
17
  end
16
18
 
17
19
  private
18
20
 
19
- attr_reader :collector
21
+ attr_reader :collector, :container
22
+
23
+ def logger = container[__method__]
20
24
  end
21
25
  end
22
26
  end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "rexml/document"
4
+
5
+ module SublimeTextKit
6
+ module Snippets
7
+ # Reads snippet and loads record into memory.
8
+ class Reader
9
+ def initialize model: Model, document: REXML::Document
10
+ @model = model
11
+ @document = document
12
+ end
13
+
14
+ def call(path) = path.exist? ? model.for(document.new(path.read)) : model.new
15
+
16
+ private
17
+
18
+ attr_reader :model, :document
19
+ end
20
+ end
21
+ end
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "sublime_text_kit/identity"
4
- require "sublime_text_kit/metadata/base"
5
- require "sublime_text_kit/metadata/project_metadata"
6
- require "sublime_text_kit/metadata/workspace_metadata"
7
- require "sublime_text_kit/snippets/snippet"
8
- require "sublime_text_kit/snippets/collector"
9
- require "sublime_text_kit/snippets/printers/ascii_doc"
10
- require "sublime_text_kit/snippets/printers/markdown"
11
- require "sublime_text_kit/session"
12
- require "sublime_text_kit/cli"
3
+ require "zeitwerk"
4
+
5
+ Zeitwerk::Loader.for_gem
6
+ .then do |loader|
7
+ loader.inflector.inflect "ascii_doc" => "ASCIIDoc", "cli" => "CLI"
8
+ loader.setup
9
+ end
10
+
11
+ # Main namespace.
12
+ module SublimeTextKit
13
+ end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,12 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sublime_text_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 10.0.2
4
+ version: 11.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
@@ -28,22 +28,50 @@ cert_chain:
28
28
  lkHilIrX69jq8wMPpBhlaw2mRmeSL50Wv5u6xVBvOHhXFSP1crXM95vfLhLyRYod
29
29
  W2A=
30
30
  -----END CERTIFICATE-----
31
- date: 2021-08-08 00:00:00.000000000 Z
31
+ date: 2021-11-20 00:00:00.000000000 Z
32
32
  dependencies:
33
+ - !ruby/object:Gem::Dependency
34
+ name: dry-container
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.8'
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '0.8'
47
+ - !ruby/object:Gem::Dependency
48
+ name: pastel
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '0.8'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '0.8'
33
61
  - !ruby/object:Gem::Dependency
34
62
  name: refinements
35
63
  requirement: !ruby/object:Gem::Requirement
36
64
  requirements:
37
65
  - - "~>"
38
66
  - !ruby/object:Gem::Version
39
- version: '8.0'
67
+ version: '8.5'
40
68
  type: :runtime
41
69
  prerelease: false
42
70
  version_requirements: !ruby/object:Gem::Requirement
43
71
  requirements:
44
72
  - - "~>"
45
73
  - !ruby/object:Gem::Version
46
- version: '8.0'
74
+ version: '8.5'
47
75
  - !ruby/object:Gem::Dependency
48
76
  name: runcom
49
77
  requirement: !ruby/object:Gem::Requirement
@@ -59,19 +87,19 @@ dependencies:
59
87
  - !ruby/object:Gem::Version
60
88
  version: '7.0'
61
89
  - !ruby/object:Gem::Dependency
62
- name: thor
90
+ name: zeitwerk
63
91
  requirement: !ruby/object:Gem::Requirement
64
92
  requirements:
65
93
  - - "~>"
66
94
  - !ruby/object:Gem::Version
67
- version: '0.20'
95
+ version: '2.5'
68
96
  type: :runtime
69
97
  prerelease: false
70
98
  version_requirements: !ruby/object:Gem::Requirement
71
99
  requirements:
72
100
  - - "~>"
73
101
  - !ruby/object:Gem::Version
74
- version: '0.20'
102
+ version: '2.5'
75
103
  description:
76
104
  email:
77
105
  - brooke@alchemists.io
@@ -84,18 +112,32 @@ extra_rdoc_files:
84
112
  files:
85
113
  - LICENSE.adoc
86
114
  - README.adoc
87
- - bin/sublime_text_kit
115
+ - exe/sublime_text_kit
88
116
  - lib/sublime_text_kit.rb
89
- - lib/sublime_text_kit/cli.rb
117
+ - lib/sublime_text_kit/cli/actions/config.rb
118
+ - lib/sublime_text_kit/cli/actions/metadata.rb
119
+ - lib/sublime_text_kit/cli/actions/session.rb
120
+ - lib/sublime_text_kit/cli/actions/snippets.rb
121
+ - lib/sublime_text_kit/cli/actions/update.rb
122
+ - lib/sublime_text_kit/cli/configuration/content.rb
123
+ - lib/sublime_text_kit/cli/configuration/defaults.yml
124
+ - lib/sublime_text_kit/cli/configuration/loader.rb
125
+ - lib/sublime_text_kit/cli/parsers.rb
126
+ - lib/sublime_text_kit/cli/parsers/assembler.rb
127
+ - lib/sublime_text_kit/cli/parsers/core.rb
128
+ - lib/sublime_text_kit/cli/shell.rb
129
+ - lib/sublime_text_kit/container.rb
90
130
  - lib/sublime_text_kit/identity.rb
91
- - lib/sublime_text_kit/metadata/base.rb
92
- - lib/sublime_text_kit/metadata/project_metadata.rb
93
- - lib/sublime_text_kit/metadata/workspace_metadata.rb
94
- - lib/sublime_text_kit/session.rb
131
+ - lib/sublime_text_kit/metadata/handler.rb
132
+ - lib/sublime_text_kit/metadata/pathway.rb
133
+ - lib/sublime_text_kit/metadata/serializers/project.rb
134
+ - lib/sublime_text_kit/metadata/serializers/workspace.rb
135
+ - lib/sublime_text_kit/sessions/rebuilder.rb
95
136
  - lib/sublime_text_kit/snippets/collector.rb
137
+ - lib/sublime_text_kit/snippets/model.rb
96
138
  - lib/sublime_text_kit/snippets/printers/ascii_doc.rb
97
139
  - lib/sublime_text_kit/snippets/printers/markdown.rb
98
- - lib/sublime_text_kit/snippets/snippet.rb
140
+ - lib/sublime_text_kit/snippets/reader.rb
99
141
  homepage: https://www.alchemists.io/projects/sublime_text_kit
100
142
  licenses:
101
143
  - Apache-2.0
@@ -103,6 +145,7 @@ metadata:
103
145
  bug_tracker_uri: https://github.com/bkuhlmann/sublime_text_kit/issues
104
146
  changelog_uri: https://www.alchemists.io/projects/sublime_text_kit/changes.html
105
147
  documentation_uri: https://www.alchemists.io/projects/sublime_text_kit
148
+ rubygems_mfa_required: 'true'
106
149
  source_code_uri: https://github.com/bkuhlmann/sublime_text_kit
107
150
  post_install_message:
108
151
  rdoc_options: []
@@ -119,7 +162,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
119
162
  - !ruby/object:Gem::Version
120
163
  version: '0'
121
164
  requirements: []
122
- rubygems_version: 3.2.25
165
+ rubygems_version: 3.2.31
123
166
  signing_key:
124
167
  specification_version: 4
125
168
  summary: A command line interface for managing Sublime Text metadata.
metadata.gz.sig CHANGED
Binary file