Skip to content

Instantly share code, notes, and snippets.

@zaydek-old
Last active September 27, 2016 08:12
Show Gist options
  • Save zaydek-old/4fdba90fecccbf74e1cc28314fe92511 to your computer and use it in GitHub Desktop.
Save zaydek-old/4fdba90fecccbf74e1cc28314fe92511 to your computer and use it in GitHub Desktop.
'use strict'
var $0, $1, $n, $t, $s; function $_() { if (!arguments.length) return ' '.repeat($($1).parents().length) }
function doc() { if (!arguments.length) {
// <html>...</html>
$('html').prepend('\n ').append('\n'); $('body').empty() } else if (arguments.length == 1) { doc()
// <head>...</head>
htm.head('<meta charset="utf-8">',
'<title>' + arguments[0] + '</title>',
'<meta name="viewport" content="width=device-width, initial-scale=1">',
'<style></style>'); htm.of() }
}
function DOM() { if (arguments.length) {
// <$1>$n$t$s</$1>
if (!$($1).html().length) { $($1).append($n + $t) } else if ($1 == 'style') { $($1).html( $($1).html().slice(0, -$_().length) ) }
// <$1>$n$t$s...$n$_</$1>
for (var i = 0; i < arguments.length - 1; i++) $($1).append($s + arguments[i] + '\n' + $t); $($1).append($s + arguments[i] + $n + $_()) }
}
function htm() { if (arguments.length) { $n = '\n\n', $t = $_(), $s = ' '.repeat(1); DOM(...arguments) } }
htm.n = function() { if (arguments.length) { $n = '\n', $t = $_(), $s = ' '.repeat(1); DOM(...arguments) } }
htm.head = function() { if (arguments.length) { htm.of('head'); htm.n(...arguments); htm.of($0) } }
function css() { if (arguments.length) { htm.of('style'); $n = '\n\n', $t = $s = ' '.repeat(0); DOM(...arguments); htm.of($0) } }
htm.of = function() { if (!arguments.length) { htm.of('body') } else if (arguments.length == 1) { $0 = $1, $1 = arguments[0] } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment