Last active
October 6, 2016 20:12
-
-
Save zaydek-old/3b4dd245155dab0195f3f916c86fdb9b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'use strict' | |
var $0, $1 | |
function _() { if (!arguments.length) { return _($1) } else if (arguments.length == 1) { return ' '.repeat($(arguments[0]).parents().length) } } | |
function x() { if (!arguments.length) { x($1) } else if (arguments.length == 1) { $(arguments[0]).html( $(arguments[0]).html().slice(0, -_(arguments[0]).length) ) } } | |
// doc() | |
function doc() { if (!arguments.length) { | |
// <html>...</html> | |
$('html').prepend('\n ').append('\n'); $('body').empty() } else if (arguments.length == 1) { doc() | |
// <head>...</head> | |
htm.of('head'); htm.in('<meta charset="utf-8">', '<title>' + arguments[0] + '</title>', | |
'<meta name="viewport" content="width=device-width, initial-scale=1">', '<style></style>'); css.doc(); htm.of() } | |
} | |
// htm() | |
function htm() { if (arguments.length) { | |
// <$1>\n\n_()</$1> | |
if (!$1) htm.of(); if (!$($1).html()) { $($1).append('\n\n' + _()) } else { x() } | |
// <$1>\n\n_() ...\n\n_()</$1> | |
for (var i = 0; i < arguments.length - 1; i++) $($1).append(' ' + arguments[i] + '\n' + _()); $($1).append(' ' + arguments[i] + '\n\n' + _()) } | |
} | |
// htm.etc() | |
htm.of = function() { if (!arguments.length) { htm.of('body') } else if (arguments.length) { $0 = $1, $1 = arguments[0] } } | |
htm.in = function() { if ( arguments.length) { | |
// <$1>\n_()</$1> | |
if (!$($1).html()) $($1).append('\n' + _()) | |
// <$1>\n_() ...\n_()</$1> | |
for (var argument of arguments) $($1).append(' ' + argument + '\n' + _()) } | |
} | |
// css() | |
function css() { if (arguments.length) { | |
// <style>\n\n</style> | |
if (!$('style').html()) { $('style').append('\n\n') } else { x('style') } | |
// <style>\n\n...\n\n_(style)</style> | |
for (var i = 0; i < arguments.length - 1; i++) $('style').append(arguments[i] + '\n'); $('style').append(arguments[i] + '\n\n' + _('style')) } | |
} | |
// css.etc() | |
css.doc = function() { if (!arguments.length) css('* {', ' margin: auto;', ' line-height: 1', '}') } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment