-
Notifications
You must be signed in to change notification settings - Fork 27
/
jekyll.py
1451 lines (1023 loc) · 41.9 KB
/
jekyll.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# -*- coding: utf-8 -*-
import imghdr
import io
import os
import re
import sublime
import sublime_plugin
import sys
import traceback
import uuid
import shutil
from datetime import datetime
from functools import wraps
try:
import simple_json as json
except ImportError:
import json
## ********************************************************************************************** ##
# BEGIN STATIC VARIABLES
## ********************************************************************************************** ##
ST3 = sublime.version() >= '3000'
DEBUG = False
VALID_MARKDOWN_EXT = ('markdown', 'mdown', 'mkdn', 'mkd', 'md', )
VALID_HTML_EXT = ('html', 'htm', )
VALID_TEXTILE_EXT = ('textile', )
VALID_YAML_EXT = ('yaml', 'yml', )
VALID_PLAIN_TEXT_EXT = ('txt', )
POST_DATE_FORMAT = '%Y-%m-%d'
settings = sublime.load_settings('Jekyll.sublime-settings')
if settings.has('jekyll_debug') and settings.get('jekyll_debug') is True:
DEBUG = True
if ST3:
from .send2trash import send2trash
else:
from send2trash import send2trash
## ********************************************************************************************** ##
# BEGIN GLOBAL METHODS
## ********************************************************************************************** ##
def plugin_loaded():
if DEBUG:
UTC_TIME = datetime.utcnow()
PYTHON = sys.version_info[:3]
VERSION = sublime.version()
PLATFORM = sublime.platform()
ARCH = sublime.arch()
PACKAGE = sublime.packages_path()
INSTALL = sublime.installed_packages_path()
message = (
'Jekyll debugging mode enabled...\n'
'\tUTC Time: {time}\n'
'\tSystem Python: {python}\n'
'\tSystem Platform: {plat}\n'
'\tSystem Architecture: {arch}\n'
'\tSublime Version: {ver}\n'
'\tSublime Packages Path: {package}\n'
'\tSublime Installed Packages Path: {install}\n'
).format(time=UTC_TIME, python=PYTHON, plat=PLATFORM, arch=ARCH,
ver=VERSION, package=PACKAGE, install=INSTALL)
sublime.status_message('Jekyll: Debugging enabled...')
debug('Plugin successfully loaded.', prefix='\n\nJekyll', level='info')
debug(message, prefix='Jekyll', level='info')
def plugin_unloaded():
if DEBUG:
debug('Plugin successfully unloaded.\n\n', prefix='Jekyll', level='info')
def debug(message, prefix='Jekyll', level='debug'):
"""Console print utility method.
Prints a formatted console entry to the Sublime Text console
if debugging is enabled in the User settings file.
Args:
message (string): A message to print to the console
prefix (string): An optional prefix
level (string): One of debug, info, warning, error [Default: debug]
Return:
string: Issue a standard console print command.
"""
if DEBUG:
print('{prefix}: [{level}] {message}'.format(
message=message,
prefix=prefix,
level=level
))
def catch_errors(fn):
"""Generic function decorator for catching exceptions.
Use this to primarily catch and alert the user to path issues
which are needed for nearly every command.
Args:
fn (func): A function
Returns:
bool: Description of return value
"""
@wraps(fn)
def _fn(*args, **kwargs):
try:
return fn(*args, **kwargs)
except MissingPathException as e:
debug('Unable to resolve path information! - {error}'.format(error=e),
prefix='Jekyll', level='error')
text = (
'Jekyll: Unable to resolve path information!\n\n{error}\n\n'
'Please double-check that you have defined absolute '
'paths to your Jekyll directories, or that you have '
'enabled the `jekyll_auto_find_paths` setting.\n\n'
'If you have set your path settings correctly, please '
'copy the console output and create a new issue.\n'
)
sublime.error_message(text.format(error=e))
except Exception as e:
debug('Unexpected error: {error}.\n\t\t¯\_(ツ)_/¯\n'.format(error=e),
prefix='Jekyll', level='error')
return _fn
def get_setting(view, key, default=None):
"""Returns a specific setting key value or default.
Get a Sublime Text setting value, starting in the project-specific
settings file, then the user-specific settings file, and finally
the package-specific settings file. Also accepts an optional default.
Args:
view (obj): A Sublime view object
key (string): A settings dictionary key
Returns:
bool: Description of return value
"""
try:
debug('Getting key "{key}" from settings.'.format(key=key))
settings = view.settings()
if settings.has('Jekyll'):
s = settings.get('Jekyll').get(key, default)
if s and s is not None:
return s
else:
pass
else:
pass
except:
pass
global_settings = sublime.load_settings('Jekyll.sublime-settings')
return global_settings.get(key, default)
def find_dir_path(window, dir_name):
"""Find a named directory in a given Sublime window.
Searches the folder tree of the current window for
a named path and returns any potential matches.
Args:
window (obj): A Sublime window object
dir_name (string): A directory name
Returns:
array: An array of potential path string matches
"""
all_dirs = []
debug('Searching for directory "{name}" in folder tree.'.format(name=dir_name))
for folder in window.folders():
for root, dirs, files in os.walk(folder):
dirs[:] = [d for d in dirs if not d[0] == '.']
if all(x in dirs for x in [dir_name]):
all_dirs.append(os.path.abspath(os.path.join(root, dir_name)))
debug('Found these sub-folder(s) in the sidebar: {0}'.format(all_dirs))
return all_dirs
def clean_title_input(title, draft=False):
"""Convert a string into a valide Jekyll filename.
Remove non-word characters, replace spaces and underscores with dashes,
and add a date stamp if the file is marked as a Post, not a Draft.
Args:
title (string): A string based title
draft (bool): A boolean indicating that the file is a draft
Returns:
string: a cleaned title for saving a new Jekyll post file
"""
title_clean = title.lower()
title_clean = re.sub(r'[^\w -]', '', title_clean)
title_clean = re.sub(r' |_', '-', title_clean)
today = datetime.today()
title_date = today.strftime('%Y-%m-%d')
return title_date + '-' + title_clean if not draft else title_clean
def create_file(path):
"""Create a new file using the directory path of the filename.
Args:
path (string): A full path string for the new file
Returns:
none
"""
filename = os.path.split(path)[1]
if filename and filename != '':
io.open(path, 'a', encoding="utf-8").close()
## ********************************************************************************************** ##
# BEGIN BASE CLASSES
## ********************************************************************************************** ##
class MissingPathException(Exception):
def __init__(self, message, *args, **kwargs):
# Call the base class constructor with the parameters it needs
super(MissingPathException, self).__init__(message, *args, **kwargs)
class JekyllWindowBase(sublime_plugin.WindowCommand):
"""Abstract base class for Jekyll window commands.
"""
markup = None
def posts_path_string(self):
p = get_setting(self.window.active_view(), 'jekyll_posts_path')
return self.determine_path(p, '_posts')
def drafts_path_string(self):
p = get_setting(self.window.active_view(), 'jekyll_drafts_path')
return self.determine_path(p, '_drafts')
def uploads_path_string(self):
p = get_setting(self.window.active_view(), 'jekyll_uploads_path')
return self.determine_path(p, 'uploads')
def templates_path_string(self):
templates_dir_name = 'Jekyll Templates'
templates_path = os.path.join(sublime.packages_path(), 'User', templates_dir_name)
if not os.path.exists(templates_path):
os.makedirs(templates_path)
sublime.status_message('Jekyll: Created "{}" directory."'.format(templates_dir_name))
# TODO: specify where every template is saved, which slows down workflow?
p = get_setting(self.window.active_view(), 'jekyll_templates_path')
return self.determine_path(p if p != '' else templates_path, '_templates')
@catch_errors
def determine_path(self, path, dir_name=None):
"""Determine a directory path.
Args:
path (string): A string directory path
dir_name (string): A string directory name
Returns:
string: a cleaned title for saving a new Jekyll post file
"""
if not self.window.views():
view = self.window.new_file()
else:
view = self.window.active_view()
auto = get_setting(view, 'jekyll_auto_find_paths', False)
if auto and dir_name:
self.dirs = find_dir_path(self.window, dir_name)
if not self.dirs:
if not path or path == '' or not os.path.exists(path):
debug('Unable to find for "{dir}" directory.'.format(
dir=dir_name), prefix='Jekyll', level='error')
raise MissingPathException('Unable to find for "{dir}" directory.'.format(
dir=dir_name))
return path
elif self.dirs and len(self.dirs) > 1:
# more than one directory was found
# so choose which one to use
def callback(self, index):
if index > -1 and type(self.dirs[index]) is list:
return self.dirs[index]
else:
self.dirs = []
return None
self.window.show_quick_panel(self.dirs, callback)
elif self.dirs and len(self.dirs) == 1:
# only one directory was found, so use it
return self.dirs[0]
else:
if not path or path == '':
debug('Path is null for "{dir}" directory.'.format(
dir=dir_name), prefix='Jekyll', level='error')
raise MissingPathException('Path is null for "{dir}" directory.'.format(
dir=dir_name))
elif not os.path.exists(path):
debug('Path "{path}" does not exist for "{dir}" directory.'.format(
path=path, dir=dir_name), prefix='Jekyll', level='error')
raise MissingPathException('Path "{path}" does not exist for "{dir}" directory.'.format(
path=path, dir=dir_name))
return path
def create_post_frontmatter(self, title, comment=None):
"""Create post frontmatter content.
Args:
title (str): A post title
comment (str): An optional comment block
Returns:
string: A Sublime snippet string
"""
if not comment or comment == '':
comment = ''
else:
comment = '# {0}\n'.format(comment)
frontmatter = (
'{comment}---\n'
'title: {title}\n'
).format(comment=str(comment), title=str(title))
frontmatter += (
'layout: ${1:post}\n'
'---\n$0'
)
return frontmatter
@catch_errors
def title_input(self, title, path=None):
"""Sanitize a file title, save and open
Args:
title (string): A post title
path (string): A path string
Returns:
None
"""
post_dir = self.path_string() if path is None else path
self.markup = get_setting(self.window.active_view(), 'jekyll_default_markup', 'Markdown')
self.extension = get_setting(self.window.active_view(), 'jekyll_markdown_extension', 'markdown')
self.extension = '.' + self.extension if self.extension in VALID_MARKDOWN_EXT else '.markdown'
if self.markup == 'Textile':
file_ext = '.textile'
elif self.markup == 'HTML':
file_ext = '.html'
elif self.markup == 'Plain text':
file_ext = '.txt'
else:
file_ext = self.extension
clean_title = clean_title_input(title, self.IS_DRAFT) + file_ext
full_path = os.path.join(post_dir, clean_title)
if os.path.lexists(full_path):
sublime.error_message('Jekyll: File already exists at "{0}"'.format(full_path))
return
else:
frontmatter = self.create_post_frontmatter(title)
self.create_and_open_file(full_path, frontmatter)
def list_files(self, path, filter_ext=True):
"""Create an array of string arrays for files
Args:
path (string): A directory path of files
filter_ext (bool): Filters files by type
Returns:
None
"""
self.item_list = []
if os.path.exists(path) and os.path.isdir(path):
for root, dirs, files in os.walk(path):
for f in files:
if filter_ext and not self.get_markup(f):
continue
fname = os.path.splitext(f)[0]
fpath = os.path.join(root, f)
self.item_list.append([fname, fpath])
self.item_list.sort(key=lambda x: os.path.getmtime(x[1]), reverse=True)
else:
self.item_list.append(['Directory does not exist!'])
if not len(self.item_list) > 0:
self.item_list.append(['No items found!'])
def on_highlight(self, index):
self.window.open_file(self.item_list[index][1], sublime.TRANSIENT)
def get_markup(self, file):
if file.endswith(VALID_MARKDOWN_EXT):
self.markup = 'Markdown'
elif file.endswith(VALID_HTML_EXT):
self.markup = 'HTML'
elif file.endswith(VALID_TEXTILE_EXT):
self.markup = 'Textile'
elif file.endswith(VALID_PLAIN_TEXT_EXT):
self.markup = 'Plain text'
elif file.endswith(VALID_YAML_EXT):
self.markup = 'YAML'
else:
self.markup = None
return self.markup
def create_and_open_file(self, path, frontmatter):
create_file(path)
if not self.window.views():
view = self.window.new_file()
else:
view = self.window.active_view()
view.run_command(
'jekyll_post_frontmatter',
{
'path': path,
'frontmatter': frontmatter
}
)
def remove_file(self, file, message):
to_trash = get_setting(self.window.active_view(), 'jekyll_send_to_trash', False)
if to_trash:
message = message + (
'\n\nYou seem to be using the `jekyll_send_to_trash` setting, so you '
'can retrieve this file later in your system Trash or Recylcing Bin.'
)
else:
message = message + (
'\n\nThis action is permanent and irreversible since you are not using '
'the `jekyll_send_to_trash` setting. Are you sure you want to continue?'
)
delete = sublime.ok_cancel_dialog(message, 'Confirm Delete')
if delete is True:
self.window.run_command('close_file')
self.window.run_command('refresh_folder_list')
if to_trash:
send2trash(file)
else:
os.remove(file)
else:
return
class JekyllPostBase(JekyllWindowBase):
IS_DRAFT = False
def path_string(self):
return self.posts_path_string()
class JekyllDraftBase(JekyllWindowBase):
IS_DRAFT = True
def path_string(self):
return self.drafts_path_string()
class JekyllUploadBase(JekyllWindowBase):
def path_string(self):
return self.uploads_path_string()
class JekyllTemplateBase(JekyllWindowBase):
def path_string(self):
return self.templates_path_string()
def title_input(self, title, description=None):
template_dir = self.path_string()
if not os.path.exists(template_dir):
os.makedirs(template_dir)
clean_title = clean_title_input(title, True)
full_path = os.path.join(template_dir, clean_title + '.yaml')
if os.path.lexists(full_path):
sublime.error_message('Jekyll: File already exists at "{0}"'.format(full_path))
return
else:
frontmatter = self.create_post_frontmatter(clean_title, description)
self.create_and_open_file(
full_path,
frontmatter
)
class JekyllFromTemplateBase(JekyllTemplateBase):
def title_input(self, title, content):
if not self.window.views():
view = self.window.new_file()
else:
view = self.window.active_view()
post_dir = self.drafts_path_string() if self.IS_DRAFT is True else self.posts_path_string()
if not post_dir:
raise MissingPathException
self.markup = get_setting(view, 'jekyll_default_markup', 'Markdown')
self.extension = get_setting(self.window.active_view(), 'jekyll_markdown_extension', 'markdown')
self.extension = '.' + self.extension if self.extension in VALID_MARKDOWN_EXT else '.markdown'
if self.markup == 'Textile':
file_ext = '.textile'
elif self.markup == 'HTML':
file_ext = '.html'
else:
file_ext = self.extension
clean_title = clean_title_input(title, self.IS_DRAFT) + file_ext
full_path = os.path.join(post_dir, clean_title)
if os.path.lexists(full_path):
sublime.error_message('Jekyll: File already exists at "{0}"'.format(full_path))
return
else:
yaml_title = 'title: {0}\n'.format(title)
# Check for existence of `title` key in YAML frontmatter
re_search_title = '(?<=\\n)(title.*?)(?:\\n)'
re_add_title = '(^---\\n)'
has_title_key = re.search(re_search_title, content)
if has_title_key:
yaml_content = re.sub(re_search_title, yaml_title, content)
else:
yaml_content = re.sub(re_add_title, '---\n' + yaml_title, content)
frontmatter = self.create_post_frontmatter(yaml_content)
self.create_and_open_file(
full_path,
frontmatter
)
def create_post_frontmatter(self, frontmatter):
return frontmatter
## ********************************************************************************************** ##
# BEGIN WINDOW COMMAND CLASSES
## ********************************************************************************************** ##
class JekyllNewPostCommand(JekyllPostBase):
def on_done(self, title):
self.title_input(title)
def run(self):
self.window.show_input_panel(
'Jekyll post title:',
'',
self.on_done,
None,
None
)
class JekyllNewPostFromTemplateCommand(JekyllFromTemplateBase):
IS_DRAFT = False
def on_done(self, index):
if index > -1 and type(self.item_list[index]) is list:
template = self.item_list[index][1]
# Remove any leading comment from YAML frontmatter
with io.open(template, 'rU', encoding="utf-8") as f:
first_line = f.readline().strip()
if first_line[:1] != '#':
f.seek(0)
file_contents = f.read()
def on_done_inner(title):
self.title_input(title, file_contents)
self.window.show_input_panel(
'Jekyll post title:',
'',
on_done_inner,
None,
None
)
else:
self.item_list = []
def run(self):
template_dir = self.templates_path_string()
self.list_files(template_dir)
if ST3:
self.window.show_quick_panel(
self.item_list,
self.on_done,
on_highlight=self.on_highlight
)
else:
self.window.show_quick_panel(
self.item_list,
self.on_done
)
def is_enabled(self):
return True if os.path.exists(self.templates_path_string()) else False
class JekyllOpenPostCommand(JekyllPostBase):
def on_done(self, index):
if index > -1 and type(self.item_list[index]) is list:
f = self.item_list[index][1]
output_view = self.window.open_file(f)
else:
self.item_list = []
def run(self):
path = self.path_string()
self.list_files(path)
if ST3:
self.window.show_quick_panel(
self.item_list,
self.on_done,
on_highlight=self.on_highlight
)
else:
self.window.show_quick_panel(
self.item_list,
self.on_done
)
class JekyllRemovePostCommand(JekyllPostBase):
def on_done(self, index):
if index > -1 and type(self.item_list[index]) is list:
f = self.item_list[index][1]
confirm = 'You are about to delete the selected Jekyll post.'
self.remove_file(f, confirm)
else:
self.item_list = []
def run(self):
path = self.path_string()
self.list_files(path)
if ST3:
self.window.show_quick_panel(
self.item_list,
self.on_done,
on_highlight=self.on_highlight
)
else:
self.window.show_quick_panel(
self.item_list,
self.on_done
)
class JekyllNewDraftCommand(JekyllDraftBase):
def on_done(self, title):
self.title_input(title)
def run(self):
self.window.show_input_panel(
'Jekyll draft title:',
'',
self.on_done,
None,
None
)
class JekyllNewDraftFromTemplateCommand(JekyllFromTemplateBase):
IS_DRAFT = True
def on_done(self, index):
if index > -1 and type(self.item_list[index]) is list:
template = self.item_list[index][1]
# Remove any leading comment from YAML frontmatter
with io.open(template, 'rU', encoding="utf-8") as f:
first_line = f.readline().strip()
if first_line[:1] != '#':
f.seek(0)
file_contents = f.read()
def on_done_inner(title):
self.title_input(title, file_contents)
self.window.show_input_panel(
'Jekyll draft title:',
'',
on_done_inner,
None,
None
)
else:
self.item_list = []
def run(self):
template_dir = self.templates_path_string()
self.list_files(template_dir)
if ST3:
self.window.show_quick_panel(
self.item_list,
self.on_done,
on_highlight=self.on_highlight
)
else:
self.window.show_quick_panel(
self.item_list,
self.on_done
)
def is_enabled(self):
return True if os.path.exists(self.templates_path_string()) else False
class JekyllPromoteDraftCommand(JekyllDraftBase):
def on_done(self, index):
p_path = self.posts_path_string()
if index != -1 and type(self.item_list[index]) is list:
f = self.item_list[index][1]
# return a list of directory names using platform specific separator
dirlist = f.rsplit(os.sep)
# check the draft name for a date
# if you find one, replace it
# if you don't find one, add it
dirlist[-1] = re.sub(r'(^\d{4}-\d{2}-\d{2}-)', '', dirlist[-1])
d = datetime.today()
d_str = "{0}-".format(d.strftime(POST_DATE_FORMAT))
dirlist[-1] = d_str + dirlist[-1]
spath = dirlist[dirlist.index('_drafts')+1:]
fpath = os.path.join(p_path, *spath)
bpath = os.path.split(fpath)[0]
# if the folder path doesn't yet exist, create it recursively
if not os.path.exists(bpath):
os.makedirs(bpath)
if not os.path.exists(fpath):
shutil.move(f, fpath)
self.window.run_command('close_file')
self.window.run_command('refresh_folder_list')
output_view = self.window.open_file(fpath)
else:
self.item_list = []
def run(self):
d_path = self.drafts_path_string()
self.list_files(d_path)
if ST3:
self.window.show_quick_panel(
self.item_list,
self.on_done,
on_highlight=self.on_highlight
)
else:
self.window.show_quick_panel(
self.item_list,
self.on_done
)
class JekyllRemoveDraftCommand(JekyllDraftBase):
def on_done(self, index):
if index > -1 and type(self.item_list[index]) is list:
f = self.item_list[index][1]
confirm = 'You are about to delete the selected Jekyll draft.'
self.remove_file(f, confirm)
else:
self.item_list = []
def run(self):
path = self.path_string()
self.list_files(path)
if ST3:
self.window.show_quick_panel(
self.item_list,
self.on_done,
on_highlight=self.on_highlight
)
else:
self.window.show_quick_panel(
self.item_list,
self.on_done
)
class JekyllOpenDraftCommand(JekyllDraftBase):
def on_done(self, index):
if index > -1 and type(self.item_list[index]) is list:
f = self.item_list[index][1]
output_view = self.window.open_file(f)
else:
self.item_list = []
def run(self):
path = self.path_string()
self.list_files(path)
if ST3:
self.window.show_quick_panel(
self.item_list,
self.on_done,
on_highlight=self.on_highlight
)
else:
self.window.show_quick_panel(
self.item_list,
self.on_done
)
class JekyllNewTemplateCommand(JekyllTemplateBase):
def on_done(self, title):
self.title = title
def on_done_inner(description):
self.title_input(self.title, description)
self.window.show_input_panel(
'Jekyll template description (optional):',
'',
on_done_inner,
None,
None
)
def run(self):
self.window.show_input_panel(
'Jekyll template name:',
'',
self.on_done,
None,
None
)
class JekyllEditTemplateCommand(JekyllTemplateBase):
def on_done(self, index):
if index > -1 and type(self.item_list[index]) is list: