0
0
mirror of https://github.com/naturalcrit/homebrewery.git synced 2026-01-26 00:53:05 +00:00

Compare commits

..

8 Commits

Author SHA1 Message Date
Scott Tolksdorf
cbab4f4959 added todo 2017-01-28 16:38:51 -05:00
Scott Tolksdorf
22d9982888 Added support for title description and thumbnail images 2017-01-28 16:38:51 -05:00
Scott Tolksdorf
76ced9ca49 Added comma parsing to the block code 2017-01-28 16:38:51 -05:00
Scott Tolksdorf
b1db8040a4 Added a todo for generic line styling 2017-01-28 16:38:51 -05:00
Scott Tolksdorf
c8b089f7fb Added new lexer for handling the new block syntax 2017-01-28 16:38:51 -05:00
Scott Tolksdorf
97c0443c76 Fixed bug where new page was storing null brews 2017-01-28 16:38:51 -05:00
Scott Tolksdorf
c470bed591 'Created 2017-01-28 16:38:51 -05:00
Scott Tolksdorf
4593099914 Merge branch 'newAdmin' into v3 2017-01-28 16:36:25 -05:00
10 changed files with 177 additions and 10 deletions

View File

@@ -15,6 +15,8 @@ const Utils = require('homebrewery/utils.js');
const Actions = require('homebrewery/brew.actions.js'); const Actions = require('homebrewery/brew.actions.js');
const Store = require('homebrewery/brew.store.js'); const Store = require('homebrewery/brew.store.js');
const Headtags = require('vitreum/headtags');
const SharePage = React.createClass({ const SharePage = React.createClass({
getDefaultProps: function() { getDefaultProps: function() {
return { return {
@@ -39,9 +41,28 @@ const SharePage = React.createClass({
p : Actions.print p : Actions.print
}), }),
renderMetatags : function(brew){
let metatags = [
<Headtags.meta key='site_name' property='og:site_name' content='Homebrewery'/>,
<Headtags.meta key='type' property='og:type' content='article' />
];
if(brew.title){
metatags.push(<Headtags.meta key='title' property='og:title' content={brew.title} />);
}
if(brew.description){
metatags.push(<Headtags.meta key='description' name='description' content={brew.description} />);
}
if(brew.thumbnail){
metatags.push(<Headtags.meta key='image' property='og:image' content={brew.thumbnail} />);
}
return metatags;
},
render : function(){ render : function(){
const brew = Store.getBrew(); const brew = Store.getBrew();
return <div className='sharePage page'> return <div className='sharePage page'>
{this.renderMetatags(brew)}
<Navbar> <Navbar>
<Nav.section> <Nav.section>
<Nav.item className='brewTitle'>{brew.title}</Nav.item> <Nav.item className='brewTitle'>{brew.title}</Nav.item>

View File

@@ -12,7 +12,8 @@
"postinstall": "npm run build", "postinstall": "npm run build",
"start": "node server.js", "start": "node server.js",
"test": "mocha test", "test": "mocha test",
"test:dev": "nodemon -x mocha test || exit 0" "test:dev": "nodemon -x mocha test || exit 0",
"test:markdown": "nodemon -x mocha test/markdown.test.js || exit 0"
}, },
"author": "stolksdorf", "author": "stolksdorf",
"license": "MIT", "license": "MIT",

View File

@@ -14,6 +14,7 @@ const BrewSchema = mongoose.Schema({
title : {type : String, default : ""}, title : {type : String, default : ""},
description : {type : String, default : ""}, description : {type : String, default : ""},
tags : {type : String, default : ""}, tags : {type : String, default : ""},
thumbnail : {type : String, default : ""},
systems : [String], systems : [String],
authors : [String], authors : [String],
published : {type : Boolean, default : false}, published : {type : Boolean, default : false},

View File

@@ -1,7 +1,7 @@
const _ = require('lodash'); const _ = require('lodash');
const flux = require('pico-flux'); const flux = require('pico-flux');
const Markdown = require('homebrewery/markdown.js'); const Markdown = require('homebrewery/markdown.new.js');
let State = { let State = {
version : '0.0.0', version : '0.0.0',

View File

@@ -76,6 +76,7 @@ const BrewEditor = React.createClass({
this.refs.codeEditor.updateSize(); this.refs.codeEditor.updateSize();
}, },
//TODO: convert this into a generic function for columns and blocks
highlightPageLines : function(){ highlightPageLines : function(){
if(!this.refs.codeEditor) return; if(!this.refs.codeEditor) return;
const codeMirror = this.refs.codeEditor.codeMirror; const codeMirror = this.refs.codeEditor.codeMirror;

View File

@@ -74,6 +74,7 @@ const MetadataEditor = React.createClass({
}, },
renderPublish : function(){ renderPublish : function(){
//TODO: Move the publish element into here
if(this.props.metadata.published){ if(this.props.metadata.published){
return <button className='unpublish' onClick={this.handlePublish.bind(null, false)}> return <button className='unpublish' onClick={this.handlePublish.bind(null, false)}>
<i className='fa fa-ban' /> unpublish <i className='fa fa-ban' /> unpublish
@@ -139,13 +140,12 @@ const MetadataEditor = React.createClass({
<textarea value={this.props.metadata.description} className='value' <textarea value={this.props.metadata.description} className='value'
onChange={this.handleFieldChange.bind(null, 'description')} /> onChange={this.handleFieldChange.bind(null, 'description')} />
</div> </div>
{/*} <div className='field thumbnail'>
<div className='field tags'> <label>thumbnail</label>
<label>tags</label> <input type='text' className='value'
<textarea value={this.props.metadata.tags} value={this.props.metadata.thumbnail}
onChange={this.handleFieldChange.bind(null, 'tags')} /> onChange={this.handleFieldChange.bind(null, 'thumbnail')} />
</div> </div>
*/}
<div className='field systems'> <div className='field systems'>
<label>systems</label> <label>systems</label>

View File

@@ -2,7 +2,7 @@ const React = require('react');
const _ = require('lodash'); const _ = require('lodash');
const cx = require('classnames'); const cx = require('classnames');
const Markdown = require('homebrewery/markdown.js'); const Markdown = require('homebrewery/markdown.new.js');
const ErrorBar = require('./errorBar/errorBar.jsx'); const ErrorBar = require('./errorBar/errorBar.jsx');
const RenderWarnings = require('homebrewery/renderWarnings/renderWarnings.jsx') const RenderWarnings = require('homebrewery/renderWarnings/renderWarnings.jsx')

View File

@@ -0,0 +1,123 @@
const _ = require('lodash');
const Markdown = require('marked');
/*
//Processes the markdown within an HTML block if it's just a class-wrapper
renderer.html = function (html) {
console.log(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;
};
*/
module.exports = {
marked : Markdown,
render : (rawBrewText)=>{
//Adds in the new div block syntax
let count = 0;
let blockReg = /{{[\w|,]+|}}/g;
const renderer = new Markdown.Renderer();
renderer.paragraph = function (text) {
const matches = text.match(blockReg);
if(!matches) return `<p>${text}</p>\n`;
let matchIndex = 0;
const res = _.reduce(text.split(blockReg), (r, text) => {
if(text) r.push(`<p>${text}</p>\n`);
const block = matches[matchIndex];
if(block && _.startsWith(block, '{{')){
r.push(`<div class="${block.substring(2).split(',').join(' ')}">`);
count++;
}
if(block == '}}' && count !== 0){
r.push('</div>');
count--;
}
matchIndex++;
return r;
}, []).join('\n');
return res;
};
let html = Markdown(rawBrewText, {renderer : renderer, sanitize: true});
html += _.times(count, ()=>{return '</div>'}).join('\n');
return html;
},
validate : (rawBrewText) => {
return [];
/*
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;
*/
},
};

View File

@@ -29,7 +29,7 @@ var CodeEditor = React.createClass({
value : this.props.value, value : this.props.value,
lineNumbers: true, lineNumbers: true,
lineWrapping : this.props.wrap, lineWrapping : this.props.wrap,
mode : this.props.language mode : this.props.language,
}); });
this.codeMirror.on('change', this.handleChange); this.codeMirror.on('change', this.handleChange);

View File

@@ -0,0 +1,20 @@
const testing = require('./test.init.js');
const Markdown = require('../shared/homebrewery/markdown.new.js');
describe('Markdown', ()=>{
it('should do a thing', ()=>{
const res = Markdown.render(`
test
<div> cool stuff </div>
test2
`)
console.log(res);
});
});