diff --git a/client/homebrew/navbar/continousSave.navitem.jsx b/client/homebrew/navbar/continousSave.navitem.jsx
index 5ea9d3691..8ff3d15cc 100644
--- a/client/homebrew/navbar/continousSave.navitem.jsx
+++ b/client/homebrew/navbar/continousSave.navitem.jsx
@@ -33,7 +33,7 @@ const ContinousSave = React.createClass({
window.onbeforeunload = function(){};
},
actionHandler : function(actionType){
- if(actionType == 'UPDATE_BREW_TEXT' || actionType == 'UPDATE_META'){
+ if(actionType == 'UPDATE_BREW_CODE' || actionType == 'UPDATE_META' || actionType == 'UPDATE_BREW_STYLE'){
Actions.pendingSave();
}
},
diff --git a/scripts/project.json b/scripts/project.json
index b39bc9069..03fec02eb 100644
--- a/scripts/project.json
+++ b/scripts/project.json
@@ -10,6 +10,7 @@
"codemirror",
"codemirror/mode/gfm/gfm.js",
"codemirror/mode/javascript/javascript.js",
+ "codemirror/mode/css/css.js",
"moment",
"superagent",
"marked",
diff --git a/server/brew.data.js b/server/brew.data.js
index a040468c1..c39adb672 100644
--- a/server/brew.data.js
+++ b/server/brew.data.js
@@ -10,6 +10,7 @@ const BrewSchema = mongoose.Schema({
editId : {type : String, default: shortid.generate, index: { unique: true }},
text : {type : String, default : ""},
+ style : {type : String, default : ""},
title : {type : String, default : ""},
description : {type : String, default : ""},
@@ -23,7 +24,7 @@ const BrewSchema = mongoose.Schema({
updatedAt : { type: Date, default: Date.now},
lastViewed : { type: Date, default: Date.now},
views : {type:Number, default:0},
- version : {type: Number, default:1}
+ version : {type: Number, default:2}
}, {
versionKey: false,
toJSON : {
diff --git a/shared/homebrewery/brew.actions.js b/shared/homebrewery/brew.actions.js
index 78a0546cd..5e0b41e26 100644
--- a/shared/homebrewery/brew.actions.js
+++ b/shared/homebrewery/brew.actions.js
@@ -54,10 +54,13 @@ const Actions = {
setBrew : (brew) => {
dispatch('SET_BREW', brew);
},
- updateBrewText : (brewText) => {
- dispatch('UPDATE_BREW_TEXT', brewText)
+ updateBrewCode : (brewCode) => {
+ dispatch('UPDATE_BREW_CODE', brewCode)
},
- updateMetaData : (meta) => {
+ updateBrewStyle : (style) => {
+ dispatch('UPDATE_BREW_STYLE', style)
+ },
+ updateMetadata : (meta) => {
dispatch('UPDATE_META', meta);
},
pendingSave : () => {
diff --git a/shared/homebrewery/brew.store.js b/shared/homebrewery/brew.store.js
index 483eba5f3..472c7db83 100644
--- a/shared/homebrewery/brew.store.js
+++ b/shared/homebrewery/brew.store.js
@@ -8,6 +8,7 @@ let State = {
brew : {
text : '',
+ style : '',
shareId : undefined,
editId : undefined,
createdAt : undefined,
@@ -29,9 +30,13 @@ const Store = flux.createStore({
SET_BREW : (brew) => {
State.brew = brew;
},
- UPDATE_BREW_TEXT : (brewText) => {
- State.brew.text = brewText;
- State.errors = Markdown.validate(brewText);
+ UPDATE_BREW_CODE : (brewCode) => {
+ State.brew.text = brewCode;
+ State.errors = Markdown.validate(brewCode);
+ },
+ UPDATE_BREW_STYLE : (style) => {
+ //TODO: add in an error checker?
+ State.brew.style = style;
},
UPDATE_META : (meta) => {
State.brew = _.merge({}, State.brew, meta);
@@ -50,11 +55,14 @@ Store.init = (state)=>{
Store.getBrew = ()=>{
return State.brew;
};
-Store.getBrewText = ()=>{
+Store.getBrewCode = ()=>{
return State.brew.text;
};
+Store.getBrewStyle = ()=>{
+ return State.brew.style;
+};
Store.getMetaData = ()=>{
- return _.omit(State.brew, ['text']);
+ return _.omit(State.brew, ['text', 'style']);
};
Store.getErrors = ()=>{
return State.errors;
diff --git a/shared/homebrewery/brewEditor/brewEditor.jsx b/shared/homebrewery/brewEditor/brewEditor.jsx
index 1f1a2fc52..d99e2e6e0 100644
--- a/shared/homebrewery/brewEditor/brewEditor.jsx
+++ b/shared/homebrewery/brewEditor/brewEditor.jsx
@@ -6,35 +6,36 @@ const CodeEditor = require('naturalcrit/codeEditor/codeEditor.jsx');
const SnippetBar = require('./snippetbar/snippetbar.jsx');
const MetadataEditor = require('./metadataEditor/metadataEditor.jsx');
+const Menubar = require('./menubar/menubar.jsx');
+
const splice = function(str, index, inject){
return str.slice(0, index) + inject + str.slice(index);
};
-const SNIPPETBAR_HEIGHT = 25;
+const MENUBAR_HEIGHT = 25;
const BrewEditor = React.createClass({
getDefaultProps: function() {
return {
- value : '',
- onChange : ()=>{},
+ brew : {
+ text : '',
+ style : '',
+ },
- metadata : {},
- onMetadataChange : ()=>{},
+ onCodeChange : ()=>{},
+ onStyleChange : ()=>{},
+ onMetaChange : ()=>{},
};
},
getInitialState: function() {
return {
- showMetadataEditor: false
+ view : 'code', //'code', 'style', 'meta'
};
},
- cursorPosition : {
- line : 0,
- ch : 0
- },
componentDidMount: function() {
this.updateEditorSize();
- this.highlightPageLines();
+ //this.highlightPageLines();
window.addEventListener("resize", this.updateEditorSize);
},
componentWillUnmount: function() {
@@ -42,17 +43,15 @@ const BrewEditor = React.createClass({
},
updateEditorSize : function() {
- let paneHeight = this.refs.main.parentNode.clientHeight;
- paneHeight -= SNIPPETBAR_HEIGHT + 1;
- this.refs.codeEditor.codeMirror.setSize(null, paneHeight);
+ if(this.refs.codeEditor){
+ let paneHeight = this.refs.main.parentNode.clientHeight;
+ paneHeight -= MENUBAR_HEIGHT + 1;
+ this.refs.codeEditor.codeMirror.setSize(null, paneHeight);
+ }
},
- handleTextChange : function(text){
- this.props.onChange(text);
- },
- handleCursorActivty : function(curpos){
- this.cursorPosition = curpos;
- },
+
+
handleInject : function(injectText){
const lines = this.props.value.split('\n');
lines[this.cursorPosition.line] = splice(lines[this.cursorPosition.line], this.cursorPosition.ch, injectText);
@@ -60,23 +59,32 @@ const BrewEditor = React.createClass({
this.handleTextChange(lines.join('\n'));
this.refs.codeEditor.setCursorPosition(this.cursorPosition.line, this.cursorPosition.ch + injectText.length);
},
- handgleToggle : function(){
+
+
+
+ handleViewChange : function(newView){
this.setState({
- showMetadataEditor : !this.state.showMetadataEditor
- })
+ view : newView
+ }, this.updateEditorSize);
},
+
+
+
brewJump : function(){
const currentPage = this.getCurrentPage();
window.location.hash = 'p' + currentPage;
},
//Called when there are changes to the editor's dimensions
+ /*
update : function(){
- this.refs.codeEditor.updateSize();
+ if(this.refs.codeEditor) this.refs.codeEditor.updateSize();
},
+ */
//TODO: convert this into a generic function for columns and blocks
+ //MOve this to a util.sj file
highlightPageLines : function(){
if(!this.refs.codeEditor) return;
const codeMirror = this.refs.codeEditor.codeMirror;
@@ -91,6 +99,7 @@ const BrewEditor = React.createClass({
return lineNumbers
},
+ /*
renderMetadataEditor : function(){
if(!this.state.showMetadataEditor) return;
return