Lines Matching refs:view

125 local function rpos(view, s)
127 local c = byte(view, s, s)
137 local function escaped(view, s)
138 if s > 1 and byte(view, s - 1, s - 1) == BSOL then
139 if s > 2 and byte(view, s - 2, s - 2) == BSOL then
158 return function(view, plain)
159 if plain == true then return view end
160 local path, root = view, template.root
163 if byte(view, 1) == SOL then path = sub(view, 2) end
166 return plain == false and assert(read_file(path)) or read_file(path) or view
171 return function(view) return func(view, false) end
175 return function(view) return func(view, true) end
179 return function(view)
180 return assert(load(view, nil, nil, setmetatable({ template = template }, VIEW_ENV)))
244 function template.new(view, layout)
245 local vt = type(view)
247 if vt == "boolean" then return new(nil, view) end
248 if vt == "table" then return new(view, safe) end
258 context.view = template.process(view, context)
260 layout.view = context.view or EMPTY
266 context.view = template.process(view, context)
268 layout.view = context.view
275 context.view = template.process(view, context)
281 context.view = template.process(view, context)
287 return template.render(view, context or self)
290 return template.process(view, context or self)
327 function template.precompile(view, path, strip, plain)
328 local chunk = dump(template.compile(view, nil, plain), strip ~= false)
337 function template.precompile_string(view, path, strip)
338 return template.precompile(view, path, strip, true)
341 function template.precompile_file(view, path, strip)
342 return template.precompile(view, path, strip, false)
345 function template.compile(view, cache_key, plain)
346 assert(view, "view was not provided for template.compile(view, cache_key, plain)")
348 return load_chunk(template.parse(view, plain)), false
350 cache_key = cache_key or view
353 local func = load_chunk(template.parse(view, plain))
358 function template.compile_file(view, cache_key)
359 return template.compile(view, cache_key, false)
362 function template.compile_string(view, cache_key)
363 return template.compile(view, cache_key, true)
366 function template.parse(view, plain)
367 assert(view, "view was not provided for template.parse(view, plain)")
369 view = template.load(view, plain)
370 if byte(view, 1, 1) == ESC then return view end
379 local i, s = 1, find(view, "{", 1, true)
381 local t, p = byte(view, s + 1, s + 1), s + 2
383 local e = find(view, "}}", p, true)
385 local z, w = escaped(view, s)
388 c[j+1] = visit(visitors, sub(view, i, s - 1 - w))
396 c[j+1] = visit(visitors, trim(sub(view, p, e - 1)), "{")
403 local e = find(view, "*}", p, true)
405 local z, w = escaped(view, s)
408 c[j+1] = visit(visitors, sub(view, i, s - 1 - w))
416 c[j+1] = visit(visitors, trim(sub(view, p, e - 1)), "*")
423 local e = find(view, "%}", p, true)
425 local z, w = escaped(view, s)
429 c[j+1] = visit(visitors, sub(view, i, s - 1 - w))
436 if byte(view, n, n) == LF then
439 local r = rpos(view, s - 1)
442 c[j+1] = visit(visitors, sub(view, i, r))
446 c[j] = visit(visitors, trim(sub(view, p, e - 1)), "%")
453 local e = find(view, ")}", p, true)
455 local z, w = escaped(view, s)
458 c[j+1] = visit(visitors, sub(view, i, s - 1 - w))
465 local f = visit(visitors, sub(view, p, e - 1), "(")
484 local e = find(view, "]}", p, true)
486 local z, w = escaped(view, s)
489 c[j+1] = visit(visitors, sub(view, i, s - 1 - w))
497 c[j+1] = visit(visitors, trim(sub(view, p, e - 1)), "[")
504 local e = find(view, "-}", p, true)
506 local x, y = find(view, sub(view, s, e + 1), e + 2, true)
508 local z, w = escaped(view, s)
512 c[j+1] = visit(visitors, sub(view, i, s - 1 - w))
520 if byte(view, y, y) == LF then
523 local b = trim(sub(view, p, e - 1))
527 c[j+1] = visit(visitors, sub(view, i, s - 1 - w))
532 c[j+1] = visit(visitors, sub(view, e + 2, x))
536 if byte(view, x, x) == LF then
539 local r = rpos(view, s - 1)
542 c[j+1] = visit(visitors, sub(view, i, r))
549 c[j+3] = visit(visitors, sub(view, e + 2, x), "-", b)
558 local e = find(view, "#}", p, true)
560 local z, w = escaped(view, s)
563 c[j+1] = visit(visitors, sub(view, i, s - 1 - w))
571 if byte(view, e, e) == LF then
578 s = find(view, "{", s + 1, true)
580 s = sub(view, i)
591 function template.parse_file(view)
592 return template.parse(view, false)
595 function template.parse_string(view)
596 return template.parse(view, true)
599 function template.process(view, context, cache_key, plain)
600 assert(view, "view was not provided for template.process(view, context, cache_key, plain)")
601 return template.compile(view, cache_key, plain)(context)
604 function template.process_file(view, context, cache_key)
605 assert(view, "view was not provided for template.process_file(view, context, cache_key)")
606 return template.compile(view, cache_key, false)(context)
609 function template.process_string(view, context, cache_key)
610 assert(view, "view was not provided for template.process_string(view, context, cache_key)")
611 return template.compile(view, cache_key, true)(context)
614 function template.render(view, context, cache_key, plain)
615 assert(view, "view was not provided for template.render(view, context, cache_key, plain)")
616 template.print(template.process(view, context, cache_key, plain))
619 function template.render_file(view, context, cache_key)
620 assert(view, "view was not provided for template.render_file(view, context, cache_key)")
621 template.render(view, context, cache_key, false)
624 function template.render_string(view, context, cache_key)
625 assert(view, "view was not provided for template.render_string(view, context, cache_key)")
626 template.render(view, context, cache_key, true)