0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-13 06:32:39 +00:00

Added smart componenets, page line number highlighting

This commit is contained in:
Scott Tolksdorf
2016-12-26 15:52:32 -05:00
parent 7581d155a6
commit 47396e5c7e
39 changed files with 2028 additions and 119 deletions

View File

@@ -1,15 +0,0 @@
const dispatch = require('pico-flux').dispatch;
const Actions = {
addInc : (val = 1) => {
dispatch('ADD_INC', val);
},
delayInc : (val = 1) => {
dispatch('DELAY_INC', val)
},
setInc : (newInc) => {
dispatch('SET_INC', newInc);
},
};
module.exports = Actions;

View File

@@ -1,31 +0,0 @@
const _ = require('lodash');
const flux = require('pico-flux');
let State = {
count : 0
};
const Store = flux.createStore({
INC : (val) => {
State.count += val;
},
SET_INC : (val) => {
State.count = val;
return false;
},
DELAY_INC : (val) => {
setTimeout(()=>{
State.count += val;
Store.emitChange();
}, 2000);
return false;
}
});
Store.getCount = ()=>{
return State.count;
};
module.exports = Store;

View File

@@ -1,82 +0,0 @@
var _ = require('lodash');
var Markdown = require('marked');
var renderer = new Markdown.Renderer();
//Processes the markdown within an HTML block if it's just a class-wrapper
renderer.html = function (html) {
if(_.startsWith(_.trim(html), '<div') && _.endsWith(_.trim(html), '</div>')){
var openTag = html.substring(0, html.indexOf('>')+1);
html = html.substring(html.indexOf('>')+1);
html = html.substring(0, html.lastIndexOf('</div>'));
return `${openTag} ${Markdown(html)} </div>`;
}
return html;
};
const tagTypes = ['div', 'span', 'a'];
const tagRegex = new RegExp('(' +
_.map(tagTypes, (type)=>{
return `\\<${type}|\\</${type}>`;
}).join('|') + ')', 'g');
module.exports = {
marked : Markdown,
render : (rawBrewText)=>{
return Markdown(rawBrewText, {renderer : renderer})
},
validate : (rawBrewText) => {
var errors = [];
var leftovers = _.reduce(rawBrewText.split('\n'), (acc, line, _lineNumber) => {
var lineNumber = _lineNumber + 1;
var matches = line.match(tagRegex);
if(!matches || !matches.length) return acc;
_.each(matches, (match)=>{
_.each(tagTypes, (type)=>{
if(match == `<${type}`){
acc.push({
type : type,
line : lineNumber
});
}
if(match === `</${type}>`){
if(!acc.length){
errors.push({
line : lineNumber,
type : type,
text : 'Unmatched closing tag',
id : 'CLOSE'
});
}else if(_.last(acc).type == type){
acc.pop();
}else{
errors.push({
line : _.last(acc).line + ' to ' + lineNumber,
type : type,
text : 'Type mismatch on closing tag',
id : 'MISMATCH'
});
acc.pop();
}
}
});
});
return acc;
}, []);
_.each(leftovers, (unmatched)=>{
errors.push({
line : unmatched.line,
type : unmatched.type,
text : "Unmatched opening tag",
id : 'OPEN'
})
});
return errors;
},
};