Skip to content
Permalink
Browse files

more package changes, sketches for new features

# Conflicts:
#	package-lock.json
#	package.json
  • Loading branch information...
lunelson committed May 9, 2018
1 parent 5ff3046 commit d9fbc8d30f2143fb108159660da08578ed1cfab5
Showing with 33 additions and 5 deletions.
  1. +1 −1 bin/cli.js
  2. +1 −0 lib/serve.js
  3. +9 −4 test/emmet-context.js
  4. +22 −0 test/new-src-server.js
@@ -1,4 +1,4 @@
#!/usr/bin/env NODE_NO_WARNINGS=1 node
#!/usr/bin/env node

'use-strict';

@@ -11,6 +11,7 @@ const srcContentTypes = {
'.scss': 'text/css; charset=utf-8',
'.html': 'text/html; charset=utf-8',
'.pug': 'text/html; charset=utf-8',
'.md': 'text/html; charset=utf-8',
'.js': 'text/javascript; charset=utf-8'
};

@@ -1,15 +1,19 @@
import parse from '@emmetio/abbreviation';
import Profile from '@emmetio/output-profile';
import format from '@emmetio/markup-formatters';
import transform from '@emmetio/html-transform';

import pug from 'pug';

const pugProfile = new Profile({ indent: ' ' });

const abbr = parse('ul#test>li.tester'+'>block');
console.log(abbr);
// const abbr = parse('table>.row>.col');
const abbr = transform(parse('ul>.item>block'));
// console.log(abbr);
console.log(format(abbr, pugProfile, 'html'));
console.log(format(abbr, pugProfile, 'pug'));

console.log('mixin _abbr\n'+format(abbr, pugProfile, 'pug').replace(/^(.)/mg, ' $1'));
// console.log('mixin _abbr\n'+format(abbr, pugProfile, 'pug').replace(/^(.)/mg, ' $1'));

const testPugString = `
${'mixin _wrap\n'+format(abbr, pugProfile, 'pug').replace(/^(.)/mg, ' $1')}
@@ -18,4 +22,5 @@ ${'mixin _wrap\n'+format(abbr, pugProfile, 'pug').replace(/^(.)/mg, ' $1')}
`;

console.log(testPugString);
console.log(pug.render(testPugString));
console.log(pug.compile(testPugString));
console.log(format(transform(parse('.outer>.inner*'), pug.render('h1 hello world')), pugProfile, 'html'));
@@ -0,0 +1,22 @@
function srcServer(...srcExts) {
const renderFns = srcExts.reduce((obj, ext) => {/*...*/})
return function(reqFile, res, next) {
return srcExts.find(srcExt => {
const srcFile = replaceExt(reqFile, srcExt); // 0.
return stat(srcFile, (err, stats) => { // 1.
if (err || !stats.isFile()) return false; // 2.
res.setHeader('Cache-Control', isDev?'no-cache':'public'); // 3a.
res.setHeader('Content-Type', srcContentTypes[srcExt]); // 3b.
if (!(srcFile in renderCache) || renderTimes[srcFile] < changeTimes[srcExt]) { // 4.
renderTimes && (renderTimes[srcFile] = Date.now());
renderCache[srcFile] = renderFns[srcExt](srcFile);
}
renderCache[srcFile].then(data => { // 5.-5c.
loggerFn.debug(`${relative(srcDir, srcFile)}\nchanged: ${changeTimes[srcExt]} \nrendered: ${renderTimes[srcFile]}\nserved: ${Date.now()}`);
res.end(data);
});
return true;
});
}) || next();
}
}

0 comments on commit d9fbc8d

Please sign in to comment.
You can’t perform that action at this time.