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.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/README.adoc +54 -70
- data/{bin → exe}/sublime_text_kit +1 -3
- data/lib/sublime_text_kit/cli/actions/config.rb +35 -0
- data/lib/sublime_text_kit/cli/actions/metadata.rb +63 -0
- data/lib/sublime_text_kit/cli/actions/session.rb +26 -0
- data/lib/sublime_text_kit/cli/actions/snippets.rb +37 -0
- data/lib/sublime_text_kit/cli/actions/update.rb +42 -0
- data/lib/sublime_text_kit/cli/configuration/content.rb +45 -0
- data/lib/sublime_text_kit/cli/configuration/defaults.yml +3 -0
- data/lib/sublime_text_kit/cli/configuration/loader.rb +37 -0
- data/lib/sublime_text_kit/cli/parsers/assembler.rb +32 -0
- data/lib/sublime_text_kit/cli/parsers/core.rb +99 -0
- data/lib/sublime_text_kit/cli/parsers.rb +11 -0
- data/lib/sublime_text_kit/cli/shell.rb +58 -0
- data/lib/sublime_text_kit/container.rb +37 -0
- data/lib/sublime_text_kit/identity.rb +3 -2
- data/lib/sublime_text_kit/metadata/handler.rb +43 -0
- data/lib/sublime_text_kit/metadata/pathway.rb +19 -0
- data/lib/sublime_text_kit/metadata/serializers/project.rb +24 -0
- data/lib/sublime_text_kit/metadata/serializers/workspace.rb +27 -0
- data/lib/sublime_text_kit/sessions/rebuilder.rb +44 -0
- data/lib/sublime_text_kit/snippets/collector.rb +13 -19
- data/lib/sublime_text_kit/snippets/model.rb +31 -0
- data/lib/sublime_text_kit/snippets/printers/ascii_doc.rb +7 -5
- data/lib/sublime_text_kit/snippets/printers/markdown.rb +7 -3
- data/lib/sublime_text_kit/snippets/reader.rb +21 -0
- data/lib/sublime_text_kit.rb +11 -10
- data.tar.gz.sig +0 -0
- metadata +59 -16
- metadata.gz.sig +0 -0
- data/lib/sublime_text_kit/cli.rb +0 -182
- data/lib/sublime_text_kit/metadata/base.rb +0 -60
- data/lib/sublime_text_kit/metadata/project_metadata.rb +0 -20
- data/lib/sublime_text_kit/metadata/workspace_metadata.rb +0 -23
- data/lib/sublime_text_kit/session.rb +0 -44
- data/lib/sublime_text_kit/snippets/snippet.rb +0 -56
data/lib/sublime_text_kit/cli.rb
DELETED
@@ -1,182 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "thor"
|
4
|
-
require "thor/actions"
|
5
|
-
require "runcom"
|
6
|
-
|
7
|
-
module SublimeTextKit
|
8
|
-
# The Command Line Interface (CLI) for the gem.
|
9
|
-
class CLI < Thor
|
10
|
-
include Thor::Actions
|
11
|
-
|
12
|
-
package_name Identity::VERSION_LABEL
|
13
|
-
|
14
|
-
def self.configuration
|
15
|
-
Runcom::Config.new "#{Identity::NAME}/configuration.yml"
|
16
|
-
end
|
17
|
-
|
18
|
-
# Initialize.
|
19
|
-
def initialize args = [], options = {}, config = {}
|
20
|
-
super args, options, config
|
21
|
-
@markdown_printer = Snippets::Printers::Markdown.new
|
22
|
-
@ascii_doc_printer = Snippets::Printers::ASCIIDoc.new
|
23
|
-
end
|
24
|
-
|
25
|
-
desc "-u, [--update]", "Update Sublime Text with current settings."
|
26
|
-
map %w[-u --update] => :update
|
27
|
-
def update
|
28
|
-
create_metadata
|
29
|
-
say
|
30
|
-
rebuild_session
|
31
|
-
end
|
32
|
-
|
33
|
-
desc "-s, [--session]", "Manage session metadata."
|
34
|
-
map %w[-s --session] => :session
|
35
|
-
method_option :rebuild,
|
36
|
-
aliases: "-R",
|
37
|
-
desc: "Rebuild session metadata.",
|
38
|
-
type: :boolean,
|
39
|
-
default: false
|
40
|
-
def session
|
41
|
-
say
|
42
|
-
options.rebuild? ? rebuild_session : help("--session")
|
43
|
-
say
|
44
|
-
end
|
45
|
-
|
46
|
-
desc "-p, [--snippets]", "Print user defined snippets."
|
47
|
-
map %w[-p --snippets] => :snippets
|
48
|
-
method_option :ascii_doc,
|
49
|
-
aliases: "-a",
|
50
|
-
desc: "Print snippets in ASCII Doc format.",
|
51
|
-
type: :boolean,
|
52
|
-
default: false
|
53
|
-
method_option :markdown,
|
54
|
-
aliases: "-m",
|
55
|
-
desc: "Print snippets in Markdown format.",
|
56
|
-
type: :boolean,
|
57
|
-
default: false
|
58
|
-
def snippets
|
59
|
-
say
|
60
|
-
|
61
|
-
if options.ascii_doc? then ascii_doc_printer.call
|
62
|
-
elsif options.markdown? then markdown_printer.call
|
63
|
-
else help "--snippets"
|
64
|
-
end
|
65
|
-
|
66
|
-
say
|
67
|
-
end
|
68
|
-
|
69
|
-
desc "-m, [--metadata]", "Manage project/workspace metadata."
|
70
|
-
map %w[-m --metadata] => :metadata
|
71
|
-
method_option :create, aliases: "-c", desc: "Create metadata.", type: :boolean, default: false
|
72
|
-
method_option :destroy, aliases: "-D", desc: "Destroy metadata.", type: :boolean, default: false
|
73
|
-
method_option :rebuild, aliases: "-R", desc: "Rebuild metadata.", type: :boolean, default: false
|
74
|
-
def metadata
|
75
|
-
say
|
76
|
-
|
77
|
-
if options.create? then create_metadata
|
78
|
-
elsif options.destroy? then destroy_metadata
|
79
|
-
elsif options.rebuild? then rebuild_metadata
|
80
|
-
else help "--metadata"
|
81
|
-
end
|
82
|
-
|
83
|
-
say
|
84
|
-
end
|
85
|
-
|
86
|
-
desc "-c, [--config]", "Manage gem configuration."
|
87
|
-
map %w[-c --config] => :config
|
88
|
-
method_option :edit,
|
89
|
-
aliases: "-e",
|
90
|
-
desc: "Edit gem configuration.",
|
91
|
-
type: :boolean,
|
92
|
-
default: false
|
93
|
-
method_option :info,
|
94
|
-
aliases: "-i",
|
95
|
-
desc: "Print gem configuration.",
|
96
|
-
type: :boolean,
|
97
|
-
default: false
|
98
|
-
def config
|
99
|
-
path = self.class.configuration.current
|
100
|
-
|
101
|
-
if options.edit? then `#{ENV["EDITOR"]} #{path}`
|
102
|
-
elsif options.info?
|
103
|
-
path ? say(path) : say("Configuration doesn't exist.")
|
104
|
-
else help :config
|
105
|
-
end
|
106
|
-
end
|
107
|
-
|
108
|
-
desc "-v, [--version]", "Show gem version."
|
109
|
-
map %w[-v --version] => :version
|
110
|
-
def version
|
111
|
-
say Identity::VERSION_LABEL
|
112
|
-
end
|
113
|
-
|
114
|
-
desc "-h, [--help=COMMAND]", "Show this message or get help for a command."
|
115
|
-
map %w[-h --help] => :help
|
116
|
-
def help task = nil
|
117
|
-
say and super
|
118
|
-
end
|
119
|
-
|
120
|
-
private
|
121
|
-
|
122
|
-
attr_reader :ascii_doc_printer, :markdown_printer
|
123
|
-
|
124
|
-
def project_roots
|
125
|
-
@project_roots ||= self.class.configuration.to_h.fetch :project_roots, []
|
126
|
-
end
|
127
|
-
|
128
|
-
def metadata_dir
|
129
|
-
@metadata_dir ||= File.expand_path self.class.configuration.to_h.fetch(:metadata_dir)
|
130
|
-
end
|
131
|
-
|
132
|
-
def create_metadata
|
133
|
-
say_status :info, "Creating metadata...", :green
|
134
|
-
say_status :info, "Metadata Path: #{metadata_dir}", :green
|
135
|
-
project_roots.each do |project_root|
|
136
|
-
say_status :info, "Processing project root: #{File.expand_path project_root}...", :green
|
137
|
-
Metadata::Project.create project_root, metadata_dir
|
138
|
-
Metadata::Workspace.create project_root, metadata_dir
|
139
|
-
end
|
140
|
-
say_status :info, "Metadata created.", :green
|
141
|
-
end
|
142
|
-
|
143
|
-
def destroy_metadata
|
144
|
-
if yes? "Delete metadata in #{metadata_dir}?"
|
145
|
-
say_status :info, "Deleting metadata...", :green
|
146
|
-
Metadata::Project.delete metadata_dir
|
147
|
-
Metadata::Workspace.delete metadata_dir
|
148
|
-
say_status :info, "Metadata deleted.", :green
|
149
|
-
else
|
150
|
-
say_status :info, "Metadata deletion aborted.", :green
|
151
|
-
end
|
152
|
-
end
|
153
|
-
|
154
|
-
def rebuild_metadata
|
155
|
-
if yes? "Rebuild metadata in #{metadata_dir}?"
|
156
|
-
say_status :info, "Deleting metadata...", :green
|
157
|
-
Metadata::Project.delete metadata_dir
|
158
|
-
Metadata::Workspace.delete metadata_dir
|
159
|
-
|
160
|
-
say_status :info, "Creating metadata...", :green
|
161
|
-
project_roots.each do |project_root|
|
162
|
-
say_status :info, "Processing project root: #{File.expand_path project_root}...", :green
|
163
|
-
Metadata::Project.create project_root, metadata_dir
|
164
|
-
Metadata::Workspace.create project_root, metadata_dir
|
165
|
-
end
|
166
|
-
|
167
|
-
say_status :info, "Metadata rebuilt.", :green
|
168
|
-
else
|
169
|
-
say_status :info, "Metadata rebuild aborted.", :green
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
def rebuild_session
|
174
|
-
say_status :info, "Rebuilding session metadata...", :green
|
175
|
-
say_status :info, "Metadata (project/workspace) Path: #{metadata_dir}", :green
|
176
|
-
say_status :info, "Session Path: #{Session.session_path}", :green
|
177
|
-
session = Session.new metadata_dir
|
178
|
-
session.rebuild_recent_workspaces
|
179
|
-
say_status :info, "Session metadata rebuilt.", :green
|
180
|
-
end
|
181
|
-
end
|
182
|
-
end
|
@@ -1,60 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "json"
|
4
|
-
require "pathname"
|
5
|
-
|
6
|
-
module SublimeTextKit
|
7
|
-
module Metadata
|
8
|
-
# Abstract class for processing metadata.
|
9
|
-
class Base
|
10
|
-
attr_reader :name, :project_dir, :metadata_dir, :metadata_file
|
11
|
-
|
12
|
-
def self.create projects_dir, metadata_dir
|
13
|
-
instance = new projects_dir, metadata_dir
|
14
|
-
return unless valid_dir? instance.project_dir, "Projects"
|
15
|
-
return unless valid_dir? instance.metadata_dir, "Metadata"
|
16
|
-
|
17
|
-
project_paths = ::Pathname.new(instance.project_dir).children.select(&:directory?)
|
18
|
-
project_paths.each { |project_dir| new(project_dir, metadata_dir).save }
|
19
|
-
end
|
20
|
-
|
21
|
-
def self.delete metadata_dir
|
22
|
-
instance = new "", metadata_dir
|
23
|
-
return unless valid_dir? instance.metadata_dir, "Metadata"
|
24
|
-
|
25
|
-
::Pathname.glob("#{instance.metadata_dir}/*.#{instance.file_extension}").each(&:delete)
|
26
|
-
end
|
27
|
-
|
28
|
-
def initialize project_dir, metadata_dir
|
29
|
-
@name = File.basename project_dir
|
30
|
-
@project_dir = File.expand_path project_dir
|
31
|
-
@metadata_dir = File.expand_path metadata_dir
|
32
|
-
@metadata_file = File.join @metadata_dir, "#{name}.#{file_extension}"
|
33
|
-
end
|
34
|
-
|
35
|
-
def file_extension
|
36
|
-
"sublime-unknown"
|
37
|
-
end
|
38
|
-
|
39
|
-
def to_h
|
40
|
-
{}
|
41
|
-
end
|
42
|
-
|
43
|
-
def save
|
44
|
-
return if File.exist? metadata_file
|
45
|
-
|
46
|
-
File.open(metadata_file, "w") { |file| file.write JSON.dump(to_h) }
|
47
|
-
end
|
48
|
-
|
49
|
-
def self.valid_dir? dir, label
|
50
|
-
if File.exist? dir
|
51
|
-
true
|
52
|
-
else
|
53
|
-
puts "#{label} directory doesn't exist: #{dir}."
|
54
|
-
false
|
55
|
-
end
|
56
|
-
end
|
57
|
-
private_class_method :valid_dir?
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SublimeTextKit
|
4
|
-
module Metadata
|
5
|
-
# Processes project metadata.
|
6
|
-
class Project < Base
|
7
|
-
def file_extension
|
8
|
-
"sublime-project"
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_h
|
12
|
-
{
|
13
|
-
folders: [
|
14
|
-
{path: project_dir}
|
15
|
-
]
|
16
|
-
}
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,23 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module SublimeTextKit
|
4
|
-
module Metadata
|
5
|
-
# Processes workspace metadata.
|
6
|
-
class Workspace < Base
|
7
|
-
def file_extension
|
8
|
-
"sublime-workspace"
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_h
|
12
|
-
{
|
13
|
-
expanded_folders: [project_dir],
|
14
|
-
select_project: {
|
15
|
-
selected_items: [
|
16
|
-
[name, File.join(metadata_dir, "#{name}.sublime-project")]
|
17
|
-
]
|
18
|
-
}
|
19
|
-
}
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,44 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "json"
|
4
|
-
|
5
|
-
module SublimeTextKit
|
6
|
-
# Manages Sublime Text session data.
|
7
|
-
class Session
|
8
|
-
attr_reader :metadata_dir
|
9
|
-
|
10
|
-
def self.home_path
|
11
|
-
ENV.fetch "HOME"
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.session_path
|
15
|
-
"#{home_path}/Library/Application Support/Sublime Text 3/Local/Session.sublime_session"
|
16
|
-
end
|
17
|
-
|
18
|
-
def initialize metadata_directory
|
19
|
-
@metadata_dir = File.expand_path metadata_directory
|
20
|
-
end
|
21
|
-
|
22
|
-
def workspaces
|
23
|
-
Dir["#{metadata_dir}/*.sublime-workspace"]
|
24
|
-
end
|
25
|
-
|
26
|
-
def rebuild_recent_workspaces
|
27
|
-
session = load_session
|
28
|
-
return unless session && session["workspaces"] && session["workspaces"]["recent_workspaces"]
|
29
|
-
|
30
|
-
session["workspaces"]["recent_workspaces"] = workspaces
|
31
|
-
save_session session
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def load_session
|
37
|
-
File.exist?(self.class.session_path) ? JSON.parse(File.read(self.class.session_path)) : {}
|
38
|
-
end
|
39
|
-
|
40
|
-
def save_session json
|
41
|
-
File.open(self.class.session_path, "w") { |file| file.write JSON.dump(json) }
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
@@ -1,56 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require "rexml/document"
|
4
|
-
|
5
|
-
module SublimeTextKit
|
6
|
-
module Snippets
|
7
|
-
class Snippet
|
8
|
-
ELEMENT_TRANSLATIONS = {
|
9
|
-
"content" => :content,
|
10
|
-
"tabTrigger" => :trigger,
|
11
|
-
"description" => :description,
|
12
|
-
"scope" => :scope
|
13
|
-
}.freeze
|
14
|
-
|
15
|
-
ALLOWED_METHODS = ELEMENT_TRANSLATIONS.values.freeze
|
16
|
-
|
17
|
-
def initialize document
|
18
|
-
@document = document
|
19
|
-
assign_elements
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
attr_reader :document,
|
25
|
-
:content_element,
|
26
|
-
:trigger_element,
|
27
|
-
:description_element,
|
28
|
-
:scope_element
|
29
|
-
|
30
|
-
def assign_elements
|
31
|
-
root_element.elements.each do |element|
|
32
|
-
name = element.name
|
33
|
-
|
34
|
-
fail StandardError, "Unknown element: #{element}." unless ELEMENT_TRANSLATIONS.key? name
|
35
|
-
|
36
|
-
instance_variable_set "@#{ELEMENT_TRANSLATIONS[name]}_element", element
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
def root_element
|
41
|
-
document.root || REXML::Element.new
|
42
|
-
end
|
43
|
-
|
44
|
-
def method_missing name, *arguments, &block
|
45
|
-
return super unless respond_to_missing? name
|
46
|
-
|
47
|
-
String((__send__("#{name}_element") || REXML::Element.new).text)
|
48
|
-
end
|
49
|
-
|
50
|
-
# :reek:BooleanParameter
|
51
|
-
def respond_to_missing? name, include_private = false
|
52
|
-
ALLOWED_METHODS.include?(name) || super
|
53
|
-
end
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|