forked from fyngyrz/aa_macro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
embrace-example.py
executable file
·53 lines (45 loc) · 1.57 KB
/
embrace-example.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
# ---------------------------------
# Example of plug-in module for the
# aa_macro.py system that follows
# the [embrace module] convention
# ---------------------------------
# The class MUST be named 'plug'
# ------------------------------
class plug(object):
def __init__(self):
self.settable()
# This method MUST be named 'install'
# This provides a reference to the parent class, macro()
# ------------------------------------------------------
def install(self,parent):
self.parent = parent
# [happy content] - extension of existing built-ins
# -------------------------------------------------
def happy_fn(self,tag,data): # an extension of macro() built-ins
return data + ' :)'
# [unhappy content] - extension of existing built-ins
# ---------------------------------------------------
def unhappy_fn(self,tag,data): # another extension of macro() built-ins
return data + ' :('
# [i content] - over-ride existing built-in, use <em> instead of <i>
def i_fn(self,tag,data):
return '<em>' + data + '</em>'
# [dtcase] - dump the macro() notcase table
def dtcase_fn(self,tag,data):
o = ''
for el in self.parent.notcase:
if o != '':
o += ', '
o += el
return o
def settable(self):
self.extensions = {
'happy' : self.happy_fn, # add new built-in 'happy'
'unhappy' : self.unhappy_fn, # add new built-in 'unhappy'
'i' : self.i_fn, # replace the 'i' built-in
'dtcase' : self.dtcase_fn, # access macro() varaibles
}
# This method MUST be named "gettable()"
# --------------------------------------
def gettable(self):
return self.extensions