Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Legacy renderer #1184

Merged
merged 38 commits into from
Feb 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d0f634f
Include two versions of Marked.js
calculuschild May 15, 2020
b783ba3
Include two versions of Marked.js
calculuschild May 15, 2020
d9050b4
Working two different render pipelines
calculuschild Nov 28, 2020
b5602a4
Mustache-style div blocks
calculuschild Nov 29, 2020
56fa999
Legacy snippets & columnbreak
calculuschild Nov 29, 2020
cd97b20
Codemirror styling for Div Blocks
calculuschild Nov 30, 2020
ae479a5
Lint
calculuschild Nov 30, 2020
de44522
Codemirror highlights for inline Divs as well
calculuschild Nov 30, 2020
88a02b8
More lint
calculuschild Nov 30, 2020
7d00566
Merge branch 'LegacyRenderer' of https://github.com/naturalcrit/homeb…
calculuschild Dec 11, 2020
9bb0f47
Merge branch 'master' into LegacyRenderer
calculuschild Dec 27, 2020
17a2368
Update dependencies.
calculuschild Dec 27, 2020
be98fd3
Adding Button to switch render pipelines
calculuschild Dec 29, 2020
82aad3e
Merge branch 'master' into LegacyRenderer
calculuschild Jan 2, 2021
c5de722
Update Marked.js
calculuschild Jan 2, 2021
f166f1a
Popup alert to refresh page when renderer changed
calculuschild Jan 4, 2021
63c7f79
Don't compress files in Development (very slow)
calculuschild Jan 4, 2021
c8a8674
Block DIV or inline Span depending on {{ placement
calculuschild Jan 4, 2021
abc6d67
\column emits a Div instead of Span
calculuschild Jan 5, 2021
fd3e842
Allow share page to use new renderer
calculuschild Jan 5, 2021
52aaf18
{{ divs no longer need empty lines. Spans work in lists.
calculuschild Jan 5, 2021
14b809c
Typo
calculuschild Jan 5, 2021
5d5f2dd
Typo
calculuschild Jan 5, 2021
18f920e
Enforce \page must be at start of line. Code cleanup.
calculuschild Jan 5, 2021
81a3176
Inject newlines after/before {{/}} to avoid needing blank lines
calculuschild Jan 6, 2021
f3ec2b9
Remove console.log
calculuschild Jan 6, 2021
4c5b260
Fix spacing issue for Spans
calculuschild Jan 6, 2021
80a09a7
Move things from Brewrenderer to Markdown
calculuschild Jan 6, 2021
d9073c2
Rename variables
calculuschild Jan 6, 2021
ce883c2
Update Font-Awesome to v5.15. Fix style issues on popups.
calculuschild Jan 6, 2021
addfb8e
Update {{ Divs/Spans, Fix nested hilighting
calculuschild Jan 18, 2021
70a8c10
Fixed Spans/divs with no tags or just commas
calculuschild Jan 18, 2021
c8001eb
Use blacklist for {{ to allow more characters
calculuschild Jan 20, 2021
cad9218
Merge branch 'master' into LegacyRenderer
calculuschild Jan 26, 2021
fc5426a
Update package-lock.json
calculuschild Jan 26, 2021
b87405b
Update all icons to Font-awesome 5
calculuschild Feb 2, 2021
5d69216
V3 hidden behind config variable
calculuschild Feb 3, 2021
576f07b
lint
calculuschild Feb 3, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion client/admin/admin.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const Admin = createClass({

<header>
<div className='container'>
<i className='fa fa-rocket' />
<i className='fas fa-rocket' />
homebrewery admin
</div>
</header>
Expand Down
6 changes: 3 additions & 3 deletions client/admin/brewCleanup/brewCleanup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ const BrewCleanup = createClass({
return <div className='removeBox'>
<button onClick={this.cleanup} className='remove'>
{this.state.pending
? <i className='fa fa-spin fa-spinner' />
: <span><i className='fa fa-times' /> Remove</span>
? <i className='fas fa-spin fa-spinner' />
: <span><i className='fas fa-times' /> Remove</span>
}
</button>
<span>Found {this.state.count} Brews that could be removed. </span>
Expand All @@ -59,7 +59,7 @@ const BrewCleanup = createClass({

<button onClick={this.prime} className='query'>
{this.state.pending
? <i className='fa fa-spin fa-spinner' />
? <i className='fas fa-spin fa-spinner' />
: 'Query Brews'
}
</button>
Expand Down
6 changes: 3 additions & 3 deletions client/admin/brewCompress/brewCompress.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ const BrewCompress = createClass({
return <div className='removeBox'>
<button onClick={this.cleanup} className='remove'>
{this.state.pending
? <i className='fa fa-spin fa-spinner' />
: <span><i className='fa fa-compress' /> compress </span>
? <i className='fas fa-spin fa-spinner' />
: <span><i className='fas fa-compress' /> compress </span>
}
</button>
{this.state.pending
Expand All @@ -76,7 +76,7 @@ const BrewCompress = createClass({

<button onClick={this.prime} className='query'>
{this.state.pending
? <i className='fa fa-spin fa-spinner' />
? <i className='fas fa-spin fa-spinner' />
: 'Query Brews'
}
</button>
Expand Down
2 changes: 1 addition & 1 deletion client/admin/brewLookup/brewLookup.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ const BrewLookup = createClass({
<h2>Brew Lookup</h2>
<input type='text' value={this.state.query} onChange={this.handleChange} placeholder='edit or share id' />
<button onClick={this.lookup}>
<i className={cx('fa', {
<i className={cx('fas', {
'fa-search' : !this.state.searching,
'fa-spin fa-spinner' : this.state.searching,
})} />
Expand Down
2 changes: 1 addition & 1 deletion client/admin/stats/stats.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ const Stats = createClass({
</dl>

{this.state.fetching
&& <div className='pending'><i className='fa fa-spin fa-spinner' /></div>
&& <div className='pending'><i className='fas fa-spin fa-spinner' /></div>
}
</div>;
}
Expand Down
25 changes: 17 additions & 8 deletions client/homebrew/brewRenderer/brewRenderer.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ const createClass = require('create-react-class');
const _ = require('lodash');
const cx = require('classnames');

const MarkdownLegacy = require('naturalcrit/markdownLegacy.js');
const Markdown = require('naturalcrit/markdown.js');
const ErrorBar = require('./errorBar/errorBar.jsx');

Expand All @@ -18,12 +19,16 @@ const PPR_THRESHOLD = 50;
const BrewRenderer = createClass({
getDefaultProps : function() {
return {
text : '',
errors : []
text : '',
renderer : '',
errors : []
};
},
getInitialState : function() {
const pages = this.props.text.split('\\page');
const pages = this.props.text.split(/^\\page/gm);
let renderer = 'legacy';
if(this.props.renderer)
renderer = this.props.renderer;

return {
viewablePageNumber : 0,
Expand All @@ -33,8 +38,9 @@ const BrewRenderer = createClass({
pages : pages,
usePPR : pages.length >= PPR_THRESHOLD,
visibility : 'hidden',
renderer : renderer,
initialContent : `<!DOCTYPE html><html><head>
<link href="//netdna.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" />
<link href="//use.fontawesome.com/releases/v5.15.1/css/all.css" rel="stylesheet" />
<link href="//fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css" />
<link href='/homebrew/bundle.css' rel='stylesheet' />
<base target=_blank>
Expand All @@ -49,7 +55,7 @@ const BrewRenderer = createClass({
},

componentWillReceiveProps : function(nextProps) {
const pages = nextProps.text.split('\\page');
const pages = nextProps.text.split(/^\\page/gm);
this.setState({
pages : pages,
usePPR : pages.length >= PPR_THRESHOLD
Expand Down Expand Up @@ -103,12 +109,15 @@ const BrewRenderer = createClass({

renderDummyPage : function(index){
return <div className='phb' id={`p${index + 1}`} key={index}>
<i className='fa fa-spinner fa-spin' />
<i className='fas fa-spinner fa-spin' />
</div>;
},

renderPage : function(pageText, index){
return <div className='phb' id={`p${index + 1}`} dangerouslySetInnerHTML={{ __html: Markdown.render(pageText) }} key={index} />;
if(this.state.renderer == 'legacy')
return <div className='phb' id={`p${index + 1}`} dangerouslySetInnerHTML={{ __html: MarkdownLegacy.render(pageText) }} key={index} />;
else
return <div className='phb' id={`p${index + 1}`} dangerouslySetInnerHTML={{ __html: Markdown.render(pageText) }} key={index} />;
},

renderPages : function(){
Expand Down Expand Up @@ -159,7 +168,7 @@ const BrewRenderer = createClass({
: null}

<Frame initialContent={this.state.initialContent} style={{ width: '100%', height: '100%', visibility: this.state.visibility }} contentDidMount={this.frameDidMount}>
<div className='brewRenderer'
<div className={cx('brewRenderer', this.state.renderer)}
onScroll={this.handleScroll}
style={{ height: this.state.height }}>

Expand Down
12 changes: 7 additions & 5 deletions client/homebrew/brewRenderer/brewRenderer.less
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
@import (multiple, less) 'shared/naturalcrit/styles/reset.less';
.V3 {@import (multiple, less) './client/homebrew/phbStyle/phb.style.less';}
.legacy {@import (multiple, less) './client/homebrew/phbStyle/phb.styleLegacy.less';}

@import (less) './client/homebrew/phbStyle/phb.style.less';
.pane{
position : relative;
}
.brewRenderer{
will-change : transform;
overflow-y : scroll;
Expand All @@ -16,6 +15,9 @@
}
}
}
.pane{
position : relative;
}
.pageInfo{
position : absolute;
right : 17px;
Expand All @@ -37,4 +39,4 @@
font-size : 10px;
font-weight : 800;
color : white;
}
}
152 changes: 152 additions & 0 deletions client/homebrew/brewRenderer/brewRendererLegacy.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
const React = require('react');
const createClass = require('create-react-class');
const _ = require('lodash');
const cx = require('classnames');

const Markdown = require('naturalcrit/markdown.js');
const ErrorBar = require('./errorBar/errorBar.jsx');

//TODO: move to the brew renderer
const RenderWarnings = require('homebrewery/renderWarnings/renderWarnings.jsx');
const NotificationPopup = require('./notificationPopup/notificationPopup.jsx');

const PAGE_HEIGHT = 1056;
const PPR_THRESHOLD = 50;

const BrewRenderer = createClass({
getDefaultProps : function() {
return {
text : '',
errors : []
};
},
getInitialState : function() {
const pages = this.props.text.split('\\page');

return {
viewablePageNumber : 0,
height : 0,
isMounted : false,

pages : pages,
usePPR : pages.length >= PPR_THRESHOLD,
};
},
height : 0,
lastRender : <div></div>,

componentDidMount : function() {
this.updateSize();
window.addEventListener('resize', this.updateSize);
},
componentWillUnmount : function() {
window.removeEventListener('resize', this.updateSize);
},

componentWillReceiveProps : function(nextProps) {
const pages = nextProps.text.split('\\page');
this.setState({
pages : pages,
usePPR : pages.length >= PPR_THRESHOLD
});
},

updateSize : function() {
this.setState({
height : this.refs.main.parentNode.clientHeight,
isMounted : true
});
},

handleScroll : function(e){
const target = e.target;
this.setState((prevState)=>({
viewablePageNumber : Math.floor(target.scrollTop / target.scrollHeight * prevState.pages.length)
}));
},

shouldRender : function(pageText, index){
if(!this.state.isMounted) return false;

const viewIndex = this.state.viewablePageNumber;
if(index == viewIndex - 3) return true;
if(index == viewIndex - 2) return true;
if(index == viewIndex - 1) return true;
if(index == viewIndex) return true;
if(index == viewIndex + 1) return true;
if(index == viewIndex + 2) return true;
if(index == viewIndex + 3) return true;

//Check for style tages
if(pageText.indexOf('<style>') !== -1) return true;

return false;
},

renderPageInfo : function(){
return <div className='pageInfo'>
{this.state.viewablePageNumber + 1} / {this.state.pages.length}
</div>;
},

renderPPRmsg : function(){
if(!this.state.usePPR) return;

return <div className='ppr_msg'>
Partial Page Renderer enabled, because your brew is so large. May effect rendering.
</div>;
},

renderDummyPage : function(index){
return <div className='phb' id={`p${index + 1}`} key={index}>
<i className='fas fa-spinner fa-spin' />
</div>;
},

renderPage : function(pageText, index){
return <div className='phb' id={`p${index + 1}`} dangerouslySetInnerHTML={{ __html: Markdown.render(pageText) }} key={index} />;
},

renderPages : function(){
if(this.state.usePPR){
return _.map(this.state.pages, (page, index)=>{
if(this.shouldRender(page, index)){
return this.renderPage(page, index);
} else {
return this.renderDummyPage(index);
}
});
}
if(this.props.errors && this.props.errors.length) return this.lastRender;
this.lastRender = _.map(this.state.pages, (page, index)=>{
return this.renderPage(page, index);
});
return this.lastRender;
},

render : function(){
return (
<React.Fragment>
<div className='brewRenderer'
onScroll={this.handleScroll}
ref='main'
style={{ height: this.state.height }}>

<ErrorBar errors={this.props.errors} />
<div className='popups'>
<RenderWarnings />
<NotificationPopup />
</div>

<div className='pages' ref='pages'>
{this.renderPages()}
</div>
</div>;
{this.renderPageInfo()}
{this.renderPPRmsg()}
</React.Fragment>
);
}
});

module.exports = BrewRenderer;
2 changes: 1 addition & 1 deletion client/homebrew/brewRenderer/errorBar/errorBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const ErrorBar = createClass({
if(!this.props.errors.length) return null;

return <div className='errorBar'>
<i className='fa fa-exclamation-triangle' />
<i className='fas fa-exclamation-triangle' />
<h3> There are HTML errors in your markup</h3>
<small>If these aren't fixed your brew will not render properly when you print it to PDF or share it</small>
{this.renderErrors()}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,8 @@ const NotificationPopup = createClass({
if(_.isEmpty(this.state.notifications)) return null;

return <div className='notificationPopup'>
<i className='fa fa-times dismiss' onClick={this.dismiss}/>
<i className='fa fa-info-circle info' />
<i className='fas fa-times dismiss' onClick={this.dismiss}/>
<i className='fas fa-info-circle info' />
<h3>Notice</h3>
<small>This website is always improving and we are still adding new features and squashing bugs. Keep the following in mind:</small>
<ul>{_.values(this.state.notifications)}</ul>
Expand Down
Loading