diff --git a/app/css/pug.css b/app/css/pug.css new file mode 100644 index 0000000..3fbc97c --- /dev/null +++ b/app/css/pug.css @@ -0,0 +1,18 @@ +textarea { + width: 500px; + height: 200px; +} + +body { + font-family: 'Lato', sans-serif; +} + +#result { + clear: both; + margin-top: 10; +} + +.error { + font-style: italic; + color: red; +} \ No newline at end of file diff --git a/app/pug-app.js b/app/pug-app.js new file mode 100644 index 0000000..82c1abc --- /dev/null +++ b/app/pug-app.js @@ -0,0 +1,48 @@ +document.addEventListener('DOMContentLoaded', init, false); +let pug, $input, $data, $result, $jsonError, $pugError; +function init() { + pug = require('pug'); + $input = document.querySelector('#input'); + $data = document.querySelector('#data'); + $result = document.querySelector('#result'); + $jsonError = document.querySelector('#jsonError'); + $pugError = document.querySelector('#pugError'); + + $input.addEventListener('input', doRender, false); + $data.addEventListener('input', doRender, false); + console.log('Ready'); + +} + +function doRender() { + let input = $input.value; + let data = $data.value; + + $pugError.innerHTML = ''; + + if(!input.length) return; + + if(data.length) + try { + data = JSON.parse(data); + console.log(data); + $jsonError.innerHTML = ''; + } catch(e) { + console.log('invalid json'); + $jsonError.innerHTML = 'Invalid JSON'; + data = {}; + } + else { + data = {}; + $jsonError.innerHTML = ''; + } + try { + let result = pug.render(input, data); + console.log(result); + $result.innerHTML = result; + } catch(e) { + console.log('pug error'); + $pugError.innerHTML = e.message; + console.dir(e); + } +} diff --git a/lib/btc.js b/lib/btc.js index e9f5eaa..1a1b884 100644 --- a/lib/btc.js +++ b/lib/btc.js @@ -51,6 +51,7 @@ function getBitcoin () { btcQuery(a => { // logger.info(a); logger.info('Got btc data. Storing it'); + logger.debug('>> btc', a); btcCache = a; history.push(a.bpi.USD.rate_float); btcCache.history = history.get(); diff --git a/lib/fx.js b/lib/fx.js index 5ecc1eb..e595af3 100644 --- a/lib/fx.js +++ b/lib/fx.js @@ -2,7 +2,7 @@ const http = require('http'); const LimitedArray = require('limitedarray'); const trend = require('trend'); const logger = require('log4js').getLogger('fx'); -const delay = (60000 * 30); +const delay = 2764800; // 32 days divided by 1000 let fxCache = {}; let history = new LimitedArray(48); // one days worth in 5 minute chunks @@ -36,6 +36,8 @@ function getFx() { logger.info('Got FX data. Storing it'); fxCache = a; + let minRates = {USD:fxCache.rates.USD, GBP:fxCache.rates.GBP, SEK:fxCache.rates.SEK}; + fxCache.rates = minRates; history.push(a.rates.GBP); fxCache.history = history.get(); fxCache.trend = trend(fxCache.history, {avgPoints: 12}); diff --git a/views/pages/pug.ejs b/views/pages/pug.ejs new file mode 100644 index 0000000..0b54ffa --- /dev/null +++ b/views/pages/pug.ejs @@ -0,0 +1,33 @@ + + + + + + + + + + + + + +

Pug Tester

+ +
+

Template String

+ +
+
+ +
+

JSON Data for Template

+ +
+
+ +
+ + + + + \ No newline at end of file