@@ -9,18 +9,29 @@ keywords = ["extends","for","endfor","addResource"] #Not all implemented yet
9
9
# Type Tlaloc
10
10
type TlalocEngine
11
11
viewPath:: ASCIIString # path to views
12
- TemplatePath :: ASCIIString # path to templates
13
- ResourcePath :: ASCIIString # path to resources
12
+ templatePath :: ASCIIString # path to templates
13
+ resourcePath :: ASCIIString # path to resources
14
14
# Constructor
15
15
function TlalocEngine (path:: ASCIIString = " " )
16
16
if path != " "
17
17
conf = ConfParse (path)
18
18
parse_conf! (conf)
19
19
viewPath = retrieve (conf, " default" , " viewPath" )
20
- TemplatePath = retrieve (conf, " default" , " TemplatePath" )
21
- ResourcePath = retrieve (conf, " default" , " ResourcePath" )
20
+ templatePath = retrieve (conf, " default" , " templatePath" )
21
+ resourcePath = retrieve (conf, " default" , " resourcePath" )
22
+
23
+ if ((viewPath[end - 1 : end ] != " /" ) && (viewPath[end - 1 : end ] != " \\ " ))
24
+ viewPath = string (viewPath," /" )
25
+ end
26
+ if ((templatePath[end - 1 : end ] != " /" ) && (templatePath[end - 1 : end ] != " \\ " ))
27
+ templatePath = string (templatePath," /" )
28
+ end
29
+ if ((resourcePath[end - 1 : end ] != " /" ) && (resourcePath[end - 1 : end ] != " \\ " ))
30
+ resourcePath = string (resourcePath," /" )
31
+ end
32
+
22
33
end
23
- new (viewPath, TemplatePath, ResourcePath )
34
+ new (viewPath, templatePath, resourcePath )
24
35
end
25
36
end
26
37
44
55
function parseView (page:: Page )
45
56
response = open (readall, page. tlaloc. viewPath * page. view)
46
57
difference = 0 # We need this because eachMatch collects all the match and then treats them, which means the data concerning indexes starting from the second match needs to be adjusted
47
- for match in eachmatch (r" \$\{ ([a-zA-Z0-9_ ]+)\} " ,response)
48
-
58
+ for amatch in eachmatch (r" \$\{ ([a-zA-Z0-9_ .\" ]+)\} " ,response)
49
59
for keyword in keywords
50
60
reg_string = " $(keyword) "
51
61
reg = Regex (reg_string)
52
- if ismatch (reg,match . match)
62
+ if ismatch (reg,amatch . match)
53
63
if keyword == " extends"
54
- # Soon
64
+ if ismatch (Regex (" extends \" ([a-zA-Z0-9_. ]+)\" " ),amatch. match)
65
+ statement = match (Regex (" \" ([a-zA-Z0-9_. ]+)\" " ),amatch. match)
66
+ content = open (readall,page. tlaloc. templatePath * (statement. match)[2 : end - 1 ])
67
+ response = string (response[1 : (amatch. offset)- 1 + difference],content,response[((amatch. offset)+ difference+ (length (amatch. match))): end ] )
68
+ difference = difference + length (content) - length (amatch. match)
69
+ end
70
+ elseif keyword == " addResource"
71
+ # Soon
55
72
end
56
73
end
57
74
end
58
75
59
- if haskey (page. args,(match . match)[3 : end - 1 ])
60
- var = (page. args)[(match . match)[3 : end - 1 ]]
61
- response = string (response[1 : (match . offset)- 1 + difference],var,response[((match . offset)+ difference+ (length (match . match))): end ] )
62
- difference = difference + length (var) - length (match . match)
76
+ if haskey (page. args,(amatch . match)[3 : end - 1 ])
77
+ var = (page. args)[(amatch . match)[3 : end - 1 ]]
78
+ response = string (response[1 : (amatch . offset)- 1 + difference],var,response[((amatch . offset)+ difference+ (length (amatch . match))): end ] )
79
+ difference = difference + length (var) - length (amatch . match)
63
80
end
64
81
end
65
82
0 commit comments