github.com/servernoj/jade@v0.0.0-20231225191405-efec98d19db1/config.go (about) 1 package jade 2 3 import "io/ioutil" 4 5 //go:generate stringer -type=itemType,NodeType -trimprefix=item -output=config_string.go 6 7 var TabSize = 4 8 var ReadFunc = ioutil.ReadFile 9 10 var ( 11 golang_mode = false 12 tag__bgn = "<%s%s>" 13 tag__end = "</%s>" 14 tag__void = "<%s%s/>" 15 tag__arg_esc = ` %s="{{ print %s }}"` 16 tag__arg_une = ` %s="{{ print %s }}"` 17 tag__arg_str = ` %s="%s"` 18 tag__arg_add = `%s " " %s` 19 tag__arg_bgn = "" 20 tag__arg_end = "" 21 22 cond__if = "{{ if %s }}" 23 cond__unless = "{{ if not %s }}" 24 cond__case = "{{/* switch %s */}}" 25 cond__while = "{{ range %s }}" 26 cond__for = "{{/* %s, %s */}}{{ range %s }}" 27 cond__end = "{{ end }}" 28 29 cond__for_if = "{{ if gt len %s 0 }}{{/* %s, %s */}}{{ range %s }}" 30 code__for_else = "{{ end }}{{ else }}" 31 32 code__longcode = "{{/* %s */}}" 33 code__buffered = "{{ %s }}" 34 code__unescaped = "{{ %s }}" 35 code__else = "{{ else }}" 36 code__else_if = "{{ else if %s }}" 37 code__case_when = "{{/* case %s: */}}" 38 code__case_def = "{{/* default: */}}" 39 code__mix_block = "{{/* block */}}" 40 41 text__str = "%s" 42 text__comment = "<!--%s -->" 43 44 mixin__bgn = "\n%s" 45 mixin__end = "" 46 mixin__var_bgn = "" 47 mixin__var = "{{ $%s := %s }}" 48 mixin__var_rest = "{{ $%s := %#v }}" 49 mixin__var_end = "\n" 50 mixin__var_block_bgn = "" 51 mixin__var_block = "" 52 mixin__var_block_end = "" 53 ) 54 55 type ReplaseTokens struct { 56 GolangMode bool 57 TagBgn string 58 TagEnd string 59 TagVoid string 60 TagArgEsc string 61 TagArgUne string 62 TagArgStr string 63 TagArgAdd string 64 TagArgBgn string 65 TagArgEnd string 66 67 CondIf string 68 CondUnless string 69 CondCase string 70 CondWhile string 71 CondFor string 72 CondEnd string 73 CondForIf string 74 75 CodeForElse string 76 CodeLongcode string 77 CodeBuffered string 78 CodeUnescaped string 79 CodeElse string 80 CodeElseIf string 81 CodeCaseWhen string 82 CodeCaseDef string 83 CodeMixBlock string 84 85 TextStr string 86 TextComment string 87 88 MixinBgn string 89 MixinEnd string 90 MixinVarBgn string 91 MixinVar string 92 MixinVarRest string 93 MixinVarEnd string 94 MixinVarBlockBgn string 95 MixinVarBlock string 96 MixinVarBlockEnd string 97 } 98 99 func Config(c ReplaseTokens) { 100 golang_mode = c.GolangMode 101 if c.TagBgn != "" { 102 tag__bgn = c.TagBgn 103 } 104 if c.TagEnd != "" { 105 tag__end = c.TagEnd 106 } 107 if c.TagVoid != "" { 108 tag__void = c.TagVoid 109 } 110 if c.TagArgEsc != "" { 111 tag__arg_esc = c.TagArgEsc 112 } 113 if c.TagArgUne != "" { 114 tag__arg_une = c.TagArgUne 115 } 116 if c.TagArgStr != "" { 117 tag__arg_str = c.TagArgStr 118 } 119 if c.TagArgAdd != "" { 120 tag__arg_add = c.TagArgAdd 121 } 122 if c.TagArgBgn != "" { 123 tag__arg_bgn = c.TagArgBgn 124 } 125 if c.TagArgEnd != "" { 126 tag__arg_end = c.TagArgEnd 127 } 128 if c.CondIf != "" { 129 cond__if = c.CondIf 130 } 131 if c.CondUnless != "" { 132 cond__unless = c.CondUnless 133 } 134 if c.CondCase != "" { 135 cond__case = c.CondCase 136 } 137 if c.CondWhile != "" { 138 cond__while = c.CondWhile 139 } 140 if c.CondFor != "" { 141 cond__for = c.CondFor 142 } 143 if c.CondEnd != "" { 144 cond__end = c.CondEnd 145 } 146 if c.CondForIf != "" { 147 cond__for_if = c.CondForIf 148 } 149 if c.CodeForElse != "" { 150 code__for_else = c.CodeForElse 151 } 152 if c.CodeLongcode != "" { 153 code__longcode = c.CodeLongcode 154 } 155 if c.CodeBuffered != "" { 156 code__buffered = c.CodeBuffered 157 } 158 if c.CodeUnescaped != "" { 159 code__unescaped = c.CodeUnescaped 160 } 161 if c.CodeElse != "" { 162 code__else = c.CodeElse 163 } 164 if c.CodeElseIf != "" { 165 code__else_if = c.CodeElseIf 166 } 167 if c.CodeCaseWhen != "" { 168 code__case_when = c.CodeCaseWhen 169 } 170 if c.CodeCaseDef != "" { 171 code__case_def = c.CodeCaseDef 172 } 173 if c.CodeMixBlock != "" { 174 code__mix_block = c.CodeMixBlock 175 } 176 if c.TextStr != "" { 177 text__str = c.TextStr 178 } 179 if c.TextComment != "" { 180 text__comment = c.TextComment 181 } 182 if c.MixinBgn != "" { 183 mixin__bgn = c.MixinBgn 184 } 185 if c.MixinEnd != "" { 186 mixin__end = c.MixinEnd 187 } 188 if c.MixinVarBgn != "" { 189 mixin__var_bgn = c.MixinVarBgn 190 } 191 if c.MixinVar != "" { 192 mixin__var = c.MixinVar 193 } 194 if c.MixinVarRest != "" { 195 mixin__var_rest = c.MixinVarRest 196 } 197 if c.MixinVarEnd != "" { 198 mixin__var_end = c.MixinVarEnd 199 } 200 if c.MixinVarBlockBgn != "" { 201 mixin__var_block_bgn = c.MixinVarBlockBgn 202 } 203 if c.MixinVarBlock != "" { 204 mixin__var_block = c.MixinVarBlock 205 } 206 if c.MixinVarBlockEnd != "" { 207 mixin__var_block_end = c.MixinVarBlockEnd 208 } 209 } 210 211 // 212 213 type goFilter struct { 214 Name, Args, Import string 215 } 216 217 var goFlt goFilter 218 219 // global variable access (goFlt) 220 func UseGoFilter() *goFilter { return &goFlt } 221 222 // 223 224 type itemType int8 225 226 const ( 227 itemError itemType = iota // error occurred; value is text of error 228 itemEOF 229 230 itemEndL 231 itemIdent 232 itemEmptyLine // empty line 233 234 itemText // plain text 235 236 itemComment // html comment 237 itemHTMLTag // html <tag> 238 itemDoctype // Doctype tag 239 240 itemDiv // html div for . or # 241 itemTag // html tag 242 itemTagInline // inline tags 243 itemTagEnd // for <tag /> 244 itemTagVoid // self-closing tags 245 itemTagVoidInline // inline + self-closing tags 246 247 itemID // id attribute 248 itemClass // class attribute 249 250 itemAttrStart 251 itemAttrEnd 252 itemAttr 253 itemAttrSpace 254 itemAttrComma 255 itemAttrEqual 256 itemAttrEqualUn 257 258 itemFilter 259 itemFilterSubf 260 itemFilterArgs 261 itemFilterText 262 263 // itemKeyword // used only to delimit the keywords 264 265 itemInclude 266 itemExtends 267 itemBlock 268 itemBlockAppend 269 itemBlockPrepend 270 itemMixin 271 itemMixinCall 272 itemMixinBlock 273 274 itemCode 275 itemCodeBuffered 276 itemCodeUnescaped 277 278 itemIf 279 itemElse 280 itemElseIf 281 itemUnless 282 283 itemEach 284 itemWhile 285 itemFor 286 itemForIfNotContain 287 itemForElse 288 289 itemCase 290 itemCaseWhen 291 itemCaseDefault 292 ) 293 294 var key = map[string]itemType{ 295 "include": itemInclude, 296 "extends": itemExtends, 297 "block": itemBlock, 298 "append": itemBlockAppend, 299 "prepend": itemBlockPrepend, 300 "mixin": itemMixin, 301 302 "if": itemIf, 303 "else": itemElse, 304 "unless": itemUnless, 305 "for": itemFor, 306 "each": itemEach, 307 "while": itemWhile, 308 "case": itemCase, 309 "when": itemCaseWhen, 310 "default": itemCaseDefault, 311 312 "doctype": itemDoctype, 313 314 "a": itemTagInline, 315 "abbr": itemTagInline, 316 "acronym": itemTagInline, 317 "b": itemTagInline, 318 "code": itemTagInline, 319 "em": itemTagInline, 320 "font": itemTagInline, 321 "i": itemTagInline, 322 "ins": itemTagInline, 323 "kbd": itemTagInline, 324 "map": itemTagInline, 325 "samp": itemTagInline, 326 "small": itemTagInline, 327 "span": itemTagInline, 328 "strong": itemTagInline, 329 "sub": itemTagInline, 330 "sup": itemTagInline, 331 332 "area": itemTagVoid, 333 "base": itemTagVoid, 334 "col": itemTagVoid, 335 "command": itemTagVoid, 336 "embed": itemTagVoid, 337 "hr": itemTagVoid, 338 "input": itemTagVoid, 339 "keygen": itemTagVoid, 340 "link": itemTagVoid, 341 "meta": itemTagVoid, 342 "param": itemTagVoid, 343 "source": itemTagVoid, 344 "track": itemTagVoid, 345 "wbr": itemTagVoid, 346 347 "br": itemTagVoidInline, 348 "img": itemTagVoidInline, 349 } 350 351 // 352 353 // nodeType identifies the type of a parse tree node. 354 type nodeType int8 355 356 // Type returns itself and provides an easy default implementation 357 // for embedding in a Node. Embedded in all non-trivial Nodes. 358 func (t nodeType) Type() nodeType { 359 return t 360 } 361 362 const ( 363 nodeText nodeType = iota 364 nodeList 365 nodeTag 366 nodeCode 367 nodeCond 368 nodeString 369 nodeDoctype 370 nodeMixin 371 nodeBlock 372 )