first commit
This commit is contained in:
79
public/assets/htmx/README.md
Normal file
79
public/assets/htmx/README.md
Normal file
@@ -0,0 +1,79 @@
|
||||
HTMX - static document generator, with Javascript preprocessing
|
||||
====
|
||||
|
||||
Use Javascript where you would ordinarily use PHP or some templating language.
|
||||
|
||||
### STATUS: [v0.0.2](https://gist.github.com/godDLL/f31224df756fff2623290e331b40b1fe/2154551fb333e861ab258ccb42e6d30fd2733a04) _so **alpha** it hurts_
|
||||
This has just been hacked together, so expect a bumpy ride.
|
||||
|
||||
|
||||
Overview
|
||||
---
|
||||
|
||||
$ echo "1::b::3" | htmx --context "{b:'2'}"
|
||||
→ 123
|
||||
|
||||
Default script delimiters are the same for left and right side. Double
|
||||
colon `::` was chosen for it's scarse use in websites source-code.
|
||||
|
||||
You can set it up with `['<\\?', '\\?>']` delimiters for PHP-like short tags.
|
||||
|
||||
If your Javascript returns an object structure instead of a text response, (say
|
||||
some vDOM) you can use the `preprocess()` function to layout the final output.
|
||||
|
||||
|
||||
Download
|
||||
---
|
||||
|
||||
npm install -g htmx
|
||||
|
||||
Node.js Quickstart
|
||||
-------
|
||||
|
||||
var
|
||||
fs= require('fs'),
|
||||
htmx= require('htmx')()
|
||||
|
||||
fs.writeFileSync(
|
||||
'test.html', // → "123"
|
||||
htmx(
|
||||
fs.readFileSync('test.htmx').toString(), // → "1::b::3"
|
||||
fs.readFileSync('test.js').toString() // → "{b:2}"
|
||||
))
|
||||
|
||||
|
||||
Shell Quickstart
|
||||
-----
|
||||
|
||||
$ cat index.html
|
||||
→ "1::b::3"
|
||||
$ cat index.js
|
||||
→ {b:'2'}
|
||||
$ htmx --context index.js --template index.html
|
||||
→ 123
|
||||
// -c can be a JSON string
|
||||
// if -t is missing, STDIN is used instead
|
||||
$ htmx --root . --build ../build // see TODO.md
|
||||
// builds current dir, using index.js for context, if exists
|
||||
|
||||
F. A. Q. (advanced usage)
|
||||
-------
|
||||
|
||||
All shell options can be shortened, as long as they are distinguishable.
|
||||
So the `--root` option can become `-r` and the `--context` option can become `-c`
|
||||
|
||||
Use the `--delimiter` option like so: `htmx -d \\\{\\\{ \\\}\\\}`. Yes, I know.
|
||||
RegExp escape, shell escape, no quotes, weird space in the middle. PRs welcome.
|
||||
|
||||
The `preprocess()` function lives in the `preprocess.js` module, which
|
||||
you will have to hack on. PRs welcome.
|
||||
|
||||
|
||||
Rationale
|
||||
---
|
||||
|
||||
PHP is way too clunky still. Things like Jinja's filter pipes in Javascript naturally become chains, the script return value naturally becomes the response, I mean, I didn't do much to make all this work, not at all.
|
||||
|
||||
Javascript is a fine templating language, when used like this.
|
||||
|
||||
|
||||
27
public/assets/htmx/TODO.md
Normal file
27
public/assets/htmx/TODO.md
Normal file
@@ -0,0 +1,27 @@
|
||||
TODO
|
||||
====
|
||||
|
||||
- require command-line-args
|
||||
- build
|
||||
- watch
|
||||
|
||||
Maybe this can grow to be a PHP-like execution environment, so that live
|
||||
HTTP responses can be generated and served.
|
||||
|
||||
* * *
|
||||
|
||||
DONE
|
||||
===
|
||||
|
||||
### v0.0.2 [_alpha_](https://gist.github.com/godDLL/f31224df756fff2623290e331b40b1fe/2154551fb333e861ab258ccb42e6d30fd2733a04)
|
||||
|
||||
- fix `npm install -g htmx`
|
||||
|
||||
### v0.0.1 [_alpha_](https://gist.github.com/godDLL/f31224df756fff2623290e331b40b1fe/48c895ca80bb4b744e0336b6d71dfd27b4ca9106)
|
||||
|
||||
- npm package
|
||||
- `preprocess`, for doing whatever you want before scriptlet's final output
|
||||
- `renderTemplateWithContext`, module's main functionality
|
||||
- DELIM, for custom scriptlet delimiters, i. e. `var htmx= require('htmx')( ['<%', '%>'] )`
|
||||
|
||||
|
||||
93
public/assets/htmx/cli.js
Normal file
93
public/assets/htmx/cli.js
Normal file
@@ -0,0 +1,93 @@
|
||||
var
|
||||
fs= require('fs'),
|
||||
readFile= fs.readFileSync,
|
||||
writeFile= fs.writeFileSync,
|
||||
statPath= fs.statSync,
|
||||
|
||||
JSON= /^\s*\{[^]*\}\s*$/gi
|
||||
// relaxed Javascript Object, for use with eval([js]).pop()
|
||||
|
||||
|
||||
module.exports= function (HTMX){
|
||||
function unpickle (__json){ return eval ('[' + __json + ']')[0] }
|
||||
|
||||
var
|
||||
test= process.argv.slice(2).join(' '),
|
||||
getParam= function (name){
|
||||
return new RegExp(name + '\\s+([^]*?)\\s*(-|$)', 'gi') },
|
||||
dir= getParam('[-]?-b\\w*').exec(test),
|
||||
ctx= getParam('[-]?-c\\w*').exec(test),
|
||||
tpl= getParam('[-]?-t\\w*').exec(test),
|
||||
dat= getParam('[-]?-r\\w*').exec(test)
|
||||
|
||||
// TODO: yuck, replace this shit
|
||||
var
|
||||
delim= /[-]?-d\w*\s+([^]*?)\s([^]*?)\s*(-|$)/gi.exec(test)
|
||||
if (delim) delim= [delim[1], delim[2]]
|
||||
|
||||
var
|
||||
render= HTMX(delim)
|
||||
|
||||
if (dir) {
|
||||
dir= dir[1]
|
||||
var isdir
|
||||
try {
|
||||
isdir= statPath(dir).isDirectory
|
||||
} catch (_) { }
|
||||
if (!isdir)
|
||||
throw new Error("--build isn't a directory, can't read")
|
||||
}
|
||||
|
||||
if (dat){
|
||||
dat= dat[1]
|
||||
if (!dir)
|
||||
throw new Error("--build directory required")
|
||||
// TODO: for each file in `dat` recursively, `render()` that fucker, with it's `ctx`
|
||||
process.stderr.write( 'TODO: not implemented, PRs welcome')
|
||||
|
||||
} else {
|
||||
tpl && (tpl= tpl[1])
|
||||
|
||||
if (ctx){
|
||||
ctx= ctx[1],
|
||||
process.stderr.write('Running ' + (tpl || 'STDIN') + ' with ' + ctx + "\n")
|
||||
|
||||
if (ctx && ctx.match( JSON)){
|
||||
ctx= unpickle( ctx)
|
||||
} else {
|
||||
try {
|
||||
ctx= unpickle( readFile( ctx).toString())
|
||||
} catch (_){
|
||||
throw new Error("--context not a Javascript object, can't read as filename")
|
||||
}
|
||||
}
|
||||
}
|
||||
if (tpl){
|
||||
try {
|
||||
var out= render( readFile( tpl).toString(), ctx)
|
||||
} catch (TemplateException){
|
||||
if ('ENOENT' == TemplateException.code)
|
||||
throw new Error("--template can't be read as filename")
|
||||
else {
|
||||
process.stderr.write( "Can't render template")
|
||||
throw TemplateException
|
||||
}
|
||||
}
|
||||
if (!dir)
|
||||
process.stdout.write( out)
|
||||
else
|
||||
writeFile( dir + '/' + tpl.split('/').pop(), out)
|
||||
|
||||
} else {
|
||||
tpl= []
|
||||
process.stdin.on('readable', function (){
|
||||
tpl.push( process.stdin.read())
|
||||
})
|
||||
process.stdin.on('end', function (){
|
||||
if (tpl)
|
||||
process.stdout.write( render( tpl.join(''), ctx))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
1
public/assets/htmx/htmx.js
Normal file
1
public/assets/htmx/htmx.js
Normal file
File diff suppressed because one or more lines are too long
32
public/assets/htmx/package.json
Normal file
32
public/assets/htmx/package.json
Normal file
@@ -0,0 +1,32 @@
|
||||
{
|
||||
"name": "htmx",
|
||||
"version": "0.0.2",
|
||||
"description": "Use Javascript in place of PHP",
|
||||
"homepage": "https://gist.github.com/godDLL/f31224df756fff2623290e331b40b1fe",
|
||||
"scripts": {
|
||||
"build": "build.sh"
|
||||
},
|
||||
"repository": {
|
||||
"type": "git",
|
||||
"url": "https://gist.github.com/godDLL/f31224df756fff2623290e331b40b1fe.git"
|
||||
},
|
||||
"author": "Yuli Che. <god.DLL@iCloud.com>",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
},
|
||||
"keywords": [
|
||||
"php",
|
||||
"web"
|
||||
],
|
||||
"main": "htmx.js",
|
||||
"bin": "htmx.js",
|
||||
"files": [
|
||||
"TODO.md",
|
||||
"htmx.js",
|
||||
"cli.js",
|
||||
"preprocess.js",
|
||||
"watch.js"
|
||||
]
|
||||
}
|
||||
|
||||
|
||||
8
public/assets/htmx/preprocess.js
Normal file
8
public/assets/htmx/preprocess.js
Normal file
@@ -0,0 +1,8 @@
|
||||
// TODO: maybe set delim and preproc on the HTMX() object, or pass it in an options obj
|
||||
function preprocess (res){
|
||||
return res
|
||||
}
|
||||
|
||||
|
||||
module.exports= preprocess
|
||||
|
||||
0
public/assets/htmx/watch.js
Normal file
0
public/assets/htmx/watch.js
Normal file
Reference in New Issue
Block a user