Skip to content

Instantly share code, notes, and snippets.

@lepinekong
Created March 14, 2018 11:09
Show Gist options
  • Save lepinekong/c73e935951df7d3ed2003289e53f16d1 to your computer and use it in GitHub Desktop.
Save lepinekong/c73e935951df7d3ed2003289e53f16d1 to your computer and use it in GitHub Desktop.
.system.override
.system.override: function['.func-name][
Context [
func-name: form .func-name
func-src: get :.func-name
spec: mold/only spec-of :func-src
template: {if not value? 'sys<%func-name%> [
sys<%func-name%>: :<%func-name%>
<%func-name%>: function [<%spec%>][
]
]
}
.out: build-markup/bind template self
write-clipboard .out
]
]
; uses @endo build-markup
build-markup: func [
{Return markup text replacing <%tags%> with their evaluated results.}
content [string! file! url!]
/bind obj [object!] "Object to bind" ;ability to run in a local context
/quiet "Do not show errors in the output."
/local out eval value
][
content: either string? content [copy content] [read content]
out: make string! 126
eval: func [val /local tmp] [
either error? set/any 'tmp try [either bind [do system/words/bind load val obj] [do val]] [
if not quiet [
tmp: disarm :tmp
append out reform ["***ERROR" tmp/id "in:" val]
]
] [
if not unset? get/any 'tmp [append out :tmp]
]
]
parse content [
any [
end break
| "<%" [copy value to "%>" 2 skip | copy value to end] (eval value)
| copy value [to "<%" | to end] (append out value)
]
]
out
]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment