Skip to content

Instantly share code, notes, and snippets.

@jolle-c
Last active November 18, 2015 08:45
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jolle-c/95847fcd568d63d09aed to your computer and use it in GitHub Desktop.
Save jolle-c/95847fcd568d63d09aed to your computer and use it in GitHub Desktop.
<?LassoScript
/**!
jc_include
Includes a file for processing but allows the call to hand over params to the included file.
Now also supports including files stored in compiled LassoApps
Examples
jc_include(file('includetest.inc'), -name = 'brad', -country = 'UK')
includetest.inc:
#name
br
#country
jc_include(
lassoapp_include('/myapp/mytest', 'lasso'),
'/myapp/mytest.lasso',
-title = 'Hello World',
-content = 'Here be content'
)
mytest.lasso:
[no_square_brackets]<!DOCTYPE html>
<html lang="en">
<head>
<title>[#title]</title>
</head>
<body>
[#content]
</body>
</html>
jc_include(
lassoapp_include('/myapp/mytest', 'html'),
'/myapp/mytest.html',
-title = 'Hello World',
-content = 'Here be content'
)
mytest.html:
<!DOCTYPE html>
<html lang="en">
<head>
<title>[#title]</title>
</head>
<body>
[#content]
</body>
</html>
Changes
2015-10-16 JC Added new method to support files stored in compiled LassoApps
2012-11-27 JC First implementation.
**/
define jc_include(file::file,...) => {
local(
i = 0,
pre = string,
src
)
with p in #rest || staticarray do {
#p -> isa(::keyword) && #rest -> size > #i++
? #pre -> append('local(' + #p -> name + ' = #' + #i + '->value) ')
}
#src = '[' + #pre + ']' + #file -> readstring
return sourcefile(#src, #file->path, true, true) -> invoke(:#rest ||
staticarray)
}
define jc_include(file::string, path::string, ...) => {
local(
i = 0,
pre = string,
src
)
with p in #rest || staticarray do {
#p -> isa(::keyword) && #rest -> size > #i++
? #pre -> append('local(' + #p -> name + ' = #' + #i + '->value) ')
}
#src = '[' + #pre + ']' + #file
return sourcefile(#src, #path, true, true) -> invoke(:#rest ||
staticarray)
}
define jc_include(file::lassoapp_long_expiring_bytes, path::string, ...) => {
local(
i = 0,
pre = string,
src
)
with p in #rest || staticarray do {
#p -> isa(::keyword) && #rest -> size > #i++
? #pre -> append('local(' + #p -> name + ' = #' + #i + '->value) ')
}
#src = '[' + #pre + ']' + #file -> asstring
return sourcefile(#src, #path, true, true) -> invoke(:#rest ||
staticarray)
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment