snibbets 2.0.28 → 2.0.29

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6f9f01ad7e1ae9656d572bbd502f4b0dc1fa7d344509a6a93f07b765d515ddca
4
- data.tar.gz: 0bc11012e818d56256550af0b3df3fe952307d2f86b8e7da9d91a8a80dfbafee
3
+ metadata.gz: c514df1f69038d43d34563cc23735ccb8c3912f407a533d90aeacc5e924c81a5
4
+ data.tar.gz: bce3c77b30ee7369040fcc3af38801ad0b21a53c5f5ce7d991c4f95ec14a249e
5
5
  SHA512:
6
- metadata.gz: a8926027efe84785a45414761eab33b66474a819ed394e52e1f638c95e5ae7a3aad857df95728640f3ccf68ad0d471b93039b694bfa0d72886b682afad13c3c5
7
- data.tar.gz: bfc6c99b3178fb1f7cb8dc3b7aad350cca53e6f560ab19357924291346e6bc74583c9755a945363122105840ef66abee960a8aa9ca75547f23b239be088761b1
6
+ metadata.gz: a41ac5237f863911b9950670073fb6922ebf341e1ad06650e475de18f724028edcb1589b5ffcd50c47ef8f144161ecde58c50761967e6f7a60b66586ac1c2a15
7
+ data.tar.gz: a8d3281abaa277a56e85d4e5275a68cf825fe3bb13eb5714bc43d186bd1a5ec681cf44fdea35290539fb1005c15d8dde308fe44a47295e3f46a5e4e4541f03be
data/CHANGELOG.md CHANGED
@@ -1,3 +1,24 @@
1
+ ### 2.0.29
2
+
3
+ 2023-04-18 10:45
4
+
5
+ #### NEW
6
+
7
+ - `--nvultra` will open the selected snippet in nvUltra
8
+
9
+ #### IMPROVED
10
+
11
+ - Use Readline for entering info with `--paste`, allows for better editing experience
12
+ - Allow `--edit` with `--paste` to open the new snippet in your editor immediately
13
+ - Better removal of extra leading/trailing newlines
14
+
15
+ #### FIXED
16
+
17
+ - Code indentation with `--paste`
18
+ - Nil error when highlighting without extension
19
+ - When detecting indented code blocks, require a blank line (or start of file) before them, to avoid picking up lines within indented lists
20
+ - Selecting 'All snippets' could return blank results in some cases
21
+
1
22
  ### 2.0.28
2
23
 
3
24
  2023-04-18 09:18
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- snibbets (2.0.28)
4
+ snibbets (2.0.29)
5
5
  mdless (~> 1.0, >= 1.0.32)
6
6
  tty-reader (~> 0.9, >= 0.9.0)
7
7
  tty-which (~> 0.5, >= 0.5.0)
data/README.md CHANGED
@@ -157,7 +157,7 @@ Snibbet's implementation of Skylighting has limited but better-looking themes, a
157
157
  ### Usage
158
158
 
159
159
  ```
160
- Snibbets v2.0.28
160
+ Snibbets v2.0.29
161
161
 
162
162
  Usage: snibbets [options] query
163
163
  -a, --all If a file contains multiple snippets, output all of them (no menu)
@@ -16,6 +16,10 @@ module Snibbets
16
16
  replace remove_spotlight_tags
17
17
  end
18
18
 
19
+ def strip_empty
20
+ split(/\n/).strip_empty.join("\n")
21
+ end
22
+
19
23
  def remove_meta
20
24
  input = dup
21
25
  lines = input.split(/\n/)
@@ -93,22 +97,11 @@ module Snibbets
93
97
  end
94
98
  end
95
99
 
96
- # Returns an array of snippets. Single snippets are returned without a
97
- # title, multiple snippets get titles from header lines
98
- def snippets
99
- content = dup.remove_meta
100
- # If there's only one snippet, just clean it and return
101
- # return [{ 'title' => '', 'code' => content.clean_code.strip }] unless multiple?
102
-
103
- # Split content by ATX headers. Everything on the line after the #
104
- # becomes the title, code is gleaned from text between that and the
105
- # next ATX header (or end)
106
- sections = []
100
+ def replace_blocks
101
+ sans_blocks = dup
107
102
  counter = 0
108
103
  code_blocks = {}
109
104
 
110
- sans_blocks = content.dup
111
-
112
105
  if Snibbets.options[:include_blockquotes]
113
106
  sans_blocks = sans_blocks.gsub(/(?mi)(^(>.*?)(\n|$))+/) do
114
107
  counter += 1
@@ -133,6 +126,23 @@ module Snibbets
133
126
  "<block#{counter}>\n"
134
127
  end
135
128
 
129
+ [sans_blocks, code_blocks]
130
+ end
131
+
132
+ # Returns an array of snippets. Single snippets are returned without a
133
+ # title, multiple snippets get titles from header lines
134
+ def snippets
135
+ content = dup.remove_meta
136
+ # If there's only one snippet, just clean it and return
137
+ # return [{ 'title' => '', 'code' => content.clean_code.strip }] unless multiple?
138
+
139
+ # Split content by ATX headers. Everything on the line after the #
140
+ # becomes the title, code is gleaned from text between that and the
141
+ # next ATX header (or end)
142
+ sections = []
143
+
144
+ sans_blocks, code_blocks = content.replace_blocks
145
+
136
146
  content = []
137
147
  if sans_blocks =~ /<block\d+>/
138
148
  sans_blocks.each_line do |line|
@@ -165,7 +175,7 @@ module Snibbets
165
175
 
166
176
  sections << {
167
177
  'title' => title,
168
- 'code' => code,
178
+ 'code' => code.strip_empty,
169
179
  'language' => lang
170
180
  }
171
181
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Snibbets
4
- VERSION = '2.0.28'
4
+ VERSION = '2.0.29'
5
5
  end
data/lib/snibbets.rb CHANGED
@@ -282,6 +282,7 @@ module Snibbets
282
282
  header = File.basename(filepath, '.md')
283
283
  warn header
284
284
  warn '-' * header.length
285
+ warn ''
285
286
  code = snip['code']
286
287
  lang = snip['language']
287
288
  print(code, filepath, lang)
@@ -289,52 +290,54 @@ module Snibbets
289
290
  end
290
291
  elsif snippets.length > 1
291
292
  if Snibbets.options[:all]
292
- if Snibbets.options[:output] == 'json'
293
- print(snippets.to_json, filepath)
294
- else
295
-
296
- snippets.each do |snippet|
297
- lang = snippet['language']
298
- warn "### #{snippet['title']} ###"
299
- # warn "# #{'-' * snippet['title'].length}"
300
- print(snippet['code'], filepath, lang)
301
- puts
302
- end
303
- end
293
+ print_all(snippets, filepath)
304
294
  else
305
- snippets.push({ 'title' => 'All snippets', 'code' => '' })
295
+ select_snippet(snippets, filepath)
296
+ end
297
+ end
298
+ end
299
+ end
306
300
 
307
- answer = Menu.menu(snippets, filename: File.basename(filepath, '.md'), title: 'Select snippet', query: @query)
301
+ def select_snippet(snippets, filepath)
302
+ snippets.push({ 'title' => 'All snippets', 'code' => '' })
303
+ answer = Menu.menu(snippets.dup, filename: File.basename(filepath, '.md'), title: 'Select snippet', query: @query)
308
304
 
309
- if answer['title'] == 'All snippets'
310
- snippets.delete_if { |s| s['title'] == 'All snippets' }
311
- if Snibbets.options[:output] == 'json'
312
- print(snippets.to_json, filepath)
313
- else
314
- header = File.basename(filepath, '.md')
315
- warn header
316
- warn '=' * header.length
317
-
318
- snippets.each do |snippet|
319
- lang = snippet['language']
320
- warn "### #{snippet['title']} ###"
321
- # warn "# #{'-' * snippet['title'].length}"
322
- print(snippet['code'], filepath, lang)
323
- puts
324
- end
305
+ if answer['title'] == 'All snippets'
306
+ snippets.delete_if { |s| s['title'] == 'All snippets' }
307
+ if Snibbets.options[:output] == 'json'
308
+ print(snippets.to_json, filepath)
309
+ else
310
+ header = File.basename(filepath, '.md')
311
+ warn header
312
+ warn '=' * header.length
313
+ warn ''
314
+ print_all(snippets, filepath)
315
+ end
316
+ elsif Snibbets.options[:output] == 'json'
317
+ print(answer.to_json, filepath)
318
+ else
319
+ header = "#{File.basename(filepath, '.md')}: #{answer['title']}"
320
+ warn header
321
+ warn '-' * header.length
322
+ warn ''
323
+ code = answer['code']
324
+ lang = answer['language']
325
+ print(code, filepath, lang)
326
+ end
327
+ end
325
328
 
326
- end
327
- elsif Snibbets.options[:output] == 'json'
328
- print(answer.to_json, filepath)
329
- else
330
- header = "#{File.basename(filepath, '.md')}: #{answer['title']}"
331
- warn header
332
- warn '-' * header.length
333
- code = answer['code']
334
- lang = answer['language']
335
- print(code, filepath, lang)
336
- end
337
- end
329
+ def print_all(snippets, filepath)
330
+ if Snibbets.options[:output] == 'json'
331
+ print(snippets.to_json, filepath)
332
+ else
333
+
334
+ snippets.each do |snippet|
335
+ lang = snippet['language']
336
+ warn "### #{snippet['title']} ###"
337
+ warn ''
338
+ # warn "# #{'-' * snippet['title'].length}"
339
+ print(snippet['code'], filepath, lang)
340
+ puts
338
341
  end
339
342
  end
340
343
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: snibbets
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.28
4
+ version: 2.0.29
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra