-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMalouCommand.py
executable file
·69 lines (54 loc) · 2.35 KB
/
MalouCommand.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
import sublime
import sublime_plugin
import random
import json
from os.path import dirname, realpath
class MalouCommand(sublime_plugin.TextCommand):
dictionary = []
sizes_json = {
"malou-xs": 1,
"malou-sm": 2,
"malou-md": 3,
"malou-lg": 4,
}
sizes_list = []
def makeParagraph(self, size):
number = self.sizes_json[size]
paragraph = ""
for i in range(number):
paragraph += random.choice (self.dictionary['sentences_1']) + " "
paragraph += random.choice (self.dictionary['sentences_2']) + " "
paragraph += random.choice (self.dictionary['sentences_3']) + " "
paragraph += random.choice (self.dictionary['sentences_4']) + " "
paragraph += random.choice (self.dictionary['sentences_5']) + " "
paragraph += random.choice (self.dictionary['sentences_6']) + " "
paragraph += random.choice (self.dictionary['sentences_7'])
paragraph += random.choice (self.dictionary['sentences_8']) + ". "
return paragraph[:-1]
def run(self, edit, nb=1):
for i in self.sizes_json:
self.sizes_list.append(i)
nb=nb-1
package_path = "Packages/EddyMalou LoremIpsum"
jsonfile = package_path + "/dictionary.json"
content = sublime.load_resource(jsonfile)
self.dictionary = json.loads(content)
selects = self.view.sel()
for select in selects:
default = sublime.Region(select.begin() - 5, select.begin())
size = sublime.Region(select.begin() - 8, select.begin())
current_text = self.view.substr(size).lower()
if current_text not in self.sizes_list:
current_text = self.view.substr(default).lower()
if current_text == 'malou':
txt = str(self.makeParagraph('malou-xs'))
self.view.erase(edit, default)
select = sublime.Region(default.begin())
elif current_text in self.sizes_list:
txt = str(self.makeParagraph(current_text))
self.view.erase(edit, size)
select = sublime.Region(size.begin())
else:
txt = str(self.makeParagraph(self.sizes_list[nb]))
self.view.erase(edit, select)
self.view.insert(edit, select.begin(), txt)