sublime_text_kit 9.6.0 → 11.0.0

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 +18 -48
  4. data/bin/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 +35 -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 +96 -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 +69 -27
  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,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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sublime_text_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 9.6.0
4
+ version: 11.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brooke Kuhlmann
@@ -10,9 +10,9 @@ bindir: bin
10
10
  cert_chain:
11
11
  - |
12
12
  -----BEGIN CERTIFICATE-----
13
- MIIC/jCCAeagAwIBAgIBAzANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBpicm9v
14
- a2UvREM9YWxjaGVtaXN0cy9EQz1pbzAeFw0yMDAzMTUxNDQ1MzJaFw0yMTAzMTUx
15
- NDQ1MzJaMCUxIzAhBgNVBAMMGmJyb29rZS9EQz1hbGNoZW1pc3RzL0RDPWlvMIIB
13
+ MIIC/jCCAeagAwIBAgIBBDANBgkqhkiG9w0BAQsFADAlMSMwIQYDVQQDDBpicm9v
14
+ a2UvREM9YWxjaGVtaXN0cy9EQz1pbzAeFw0yMTAzMTkxMjQ4MDZaFw0yMjAzMTkx
15
+ MjQ4MDZaMCUxIzAhBgNVBAMMGmJyb29rZS9EQz1hbGNoZW1pc3RzL0RDPWlvMIIB
16
16
  IjANBgkqhkiG9w0BAQEFAAOCAQ8AM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oRf/rwBrU39/KRfuhbb
27
+ cm+nNCEtO35gTmZ2bVDHLGvWazi3gJt6+huQjfXTCUUG2YYBxwhu+GPdAGQPxpf9
28
+ lkHilIrX69jq8wMPpBhlaw2mRmeSL50Wv5u6xVBvOHhXFSP1crXM95vfLhLyRYod
29
+ W2A=
30
30
  -----END CERTIFICATE-----
31
- date: 2020-12-13 00:00:00.000000000 Z
31
+ date: 2021-10-06 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: '7.16'
67
+ version: '8.4'
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: '7.16'
74
+ version: '8.4'
47
75
  - !ruby/object:Gem::Dependency
48
76
  name: runcom
49
77
  requirement: !ruby/object:Gem::Requirement
50
78
  requirements:
51
79
  - - "~>"
52
80
  - !ruby/object:Gem::Version
53
- version: '6.4'
81
+ version: '7.0'
54
82
  type: :runtime
55
83
  prerelease: false
56
84
  version_requirements: !ruby/object:Gem::Requirement
57
85
  requirements:
58
86
  - - "~>"
59
87
  - !ruby/object:Gem::Version
60
- version: '6.4'
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.4'
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.4'
75
103
  description:
76
104
  email:
77
105
  - brooke@alchemists.io
@@ -86,16 +114,30 @@ files:
86
114
  - README.adoc
87
115
  - bin/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
@@ -112,14 +154,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
112
154
  requirements:
113
155
  - - "~>"
114
156
  - !ruby/object:Gem::Version
115
- version: '2.7'
157
+ version: '3.0'
116
158
  required_rubygems_version: !ruby/object:Gem::Requirement
117
159
  requirements:
118
160
  - - ">="
119
161
  - !ruby/object:Gem::Version
120
162
  version: '0'
121
163
  requirements: []
122
- rubygems_version: 3.2.0
164
+ rubygems_version: 3.2.28
123
165
  signing_key:
124
166
  specification_version: 4
125
167
  summary: A command line interface for managing Sublime Text metadata.
metadata.gz.sig CHANGED
Binary file