Skip to content
This repository was archived by the owner on Apr 8, 2020. It is now read-only.

Commit 5176afd

Browse files
committed
use redux diff-logger
1 parent 50656aa commit 5176afd

File tree

14 files changed

+340
-17
lines changed

14 files changed

+340
-17
lines changed

lib/options/configureStore.js

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/options/configureStore.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,15 @@
3232
"atom-plugin-command-line": "1.0.2",
3333
"coderoad-cli": "0.10.0",
3434
"marked": "0.3.6",
35-
"material-ui": "0.15.4",
35+
"material-ui": "0.16.0",
3636
"node-file-exists": "1.1.0",
3737
"react": "15.3.2",
3838
"react-dom": "15.3.2",
3939
"react-redux": "4.4.5",
4040
"react-router-sans-urls": "0.1.2",
4141
"react-tap-event-plugin": "1.0.0",
4242
"redux": "3.6.0",
43-
"redux-logger": "2.6.1",
43+
"redux-logger": "2.7.0",
4444
"redux-thunk": "2.1.0",
4545
"reselect": "2.5.4"
4646
},
@@ -49,8 +49,8 @@
4949
"electron-chromedriver": "^1.4.0",
5050
"eslint": "^3.6.1",
5151
"eslint-plugin-react": "^6.3.0",
52-
"jest": "^15.1.1",
53-
"jest-cli": "^15.1.1",
52+
"jest": "^16.0.1",
53+
"jest-cli": "^16.0.1",
5454
"react-addons-test-utils": "15.3.2",
5555
"react-test-renderer": "15.3.2",
5656
"redux-mock-store": "^1.2.1",
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Radium from 'radium';
2+
import * as React from 'react';
3+
4+
import {Markdown} from '../index';
5+
import {Card, CardHeader, CardText} from 'material-ui/Card';
6+
7+
const styles = {
8+
card: {
9+
margin: '5px',
10+
},
11+
};
12+
13+
@Radium()
14+
const ContentCard: React.StatelessComponent<{
15+
title: string, content?: string
16+
}> = ({title, content}) => (
17+
<Card style={styles.card}>
18+
{title ? <CardHeader title={title} /> : null}
19+
<CardText>
20+
<Markdown children={content || ''} />
21+
</CardText>
22+
</Card>
23+
);
24+
export default ContentCard;
25+
26+
// ContentCard.propTypes = {
27+
// title: React.PropTypes.string,
28+
// content: React.PropTypes.string.optional,
29+
// };
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import * as React from 'react';
2+
3+
import highlight from './syntax-highlighter';
4+
5+
const CodeBlock: React.StatelessComponent<{
6+
children: string, style?: React.CSSProperties, lang: string
7+
}> = ({style, children, lang}) => (
8+
<pre>
9+
<code
10+
style={style ? style : {}}
11+
dangerouslySetInnerHTML={{__html: highlight(children, lang)}}
12+
/>
13+
</pre>
14+
);
15+
export default CodeBlock;
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import * as marked from 'marked';
2+
3+
import highlight from './syntax-highlighter';
4+
5+
const options = {
6+
breaks: true,
7+
gfm: true,
8+
highlight,
9+
tables: true,
10+
sanitize: true,
11+
smartLists: true,
12+
};
13+
14+
export default function (text: string): string {
15+
return typeof text !== 'string' ? '' : marked(text.toString(), options);
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import * as React from 'react';
2+
3+
import formatText from './formatText';
4+
5+
const Markdown: React.StatelessComponent<{
6+
children: string, style?: React.CSSProperties
7+
}> = ({style, children}) => (
8+
<span
9+
className='cr-markdown'
10+
style={style ? style : {}}
11+
dangerouslySetInnerHTML={{__html: formatText(children)}}
12+
/>
13+
);
14+
export default Markdown;
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
import {editor} from '../../../index';
2+
3+
export default function highlight(text: string, lang: string): string {
4+
const scopeName = `source.${lang}`;
5+
// get grammar
6+
const grammar = editor.grammar.getFromScope(scopeName);
7+
// no grammar, return text
8+
if (!grammar) {
9+
return text;
10+
}
11+
// get tokens
12+
const lineTokens = editor.grammar.tokenizeLines(grammar, text);
13+
if (lineTokens.length > 0) {
14+
const lastLineTokens = lineTokens[lineTokens.length - 1];
15+
if (lastLineTokens.length === 1 && lastLineTokens[0].value === '') {
16+
lineTokens.pop();
17+
}
18+
}
19+
let html = '<pre class="editor editor-colors">';
20+
21+
lineTokens.forEach(line => {
22+
html += '<div class="line">';
23+
line.forEach(({value, scopes}) => {
24+
// account for spaces
25+
if (!value) {
26+
value = ' ';
27+
}
28+
// wrap text with class spans
29+
scopes.forEach(scope => {
30+
html += `<span class="${scope.replace(/\./g, ' ')}">`;
31+
});
32+
// text
33+
html += `${value}`;
34+
// closing tags
35+
scopes.forEach(scope => {
36+
html += '</span>';
37+
});
38+
});
39+
});
40+
html += '</div></pre>';
41+
return html;
42+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import * as React from 'react';
2+
import {connect} from 'react-redux';
3+
4+
import {routeSet} from '../../actions';
5+
import RaisedButton from 'material-ui/RaisedButton';
6+
7+
class RouteButton extends React.Component<{
8+
label: string, route: string, routeSet: any, style: React.CSSProperties
9+
}, {}> {
10+
public render() {
11+
const {label, route, style, routeSet} = this.props;
12+
return (
13+
<RaisedButton
14+
label={label}
15+
style={style || {}}
16+
onTouchTap={routeSet.bind(this, route)}
17+
secondary={true}
18+
/>
19+
);
20+
}
21+
}
22+
23+
// RouteButton.propTypes = {
24+
// label: React.PropTypes.string,
25+
// route: React.PropTypes.string,
26+
// routeSet: React.PropTypes.func.optional,
27+
// style: React.PropTypes.object.optional,
28+
// };
29+
30+
const mapStateToProps = (state, props) => ({
31+
label: props.label,
32+
route: props.route,
33+
style: props.style || {}
34+
});
35+
const mapDispatchToProps = {routeSet};
36+
37+
export default connect(mapStateToProps, mapDispatchToProps)(RouteButton);
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as React from 'react';
2+
3+
interface IStyles {
4+
editor: React.CSSProperties;
5+
};
6+
7+
const styles: IStyles = {
8+
editor: {
9+
textAlign: 'left',
10+
},
11+
};
12+
13+
export default class TextEditor extends React.Component<{
14+
name: string, text?: string, lang: string, onSave?: () => any,
15+
placeholder?: string,
16+
}, {}> {
17+
18+
// create a new TextEditor
19+
public ed = atom.workspace.buildTextEditor();
20+
public get(): string {
21+
return this.ed.getText();
22+
}
23+
public render() {
24+
return <div id={this.props.name} style={styles.editor} />;
25+
}
26+
private componentDidMount() {
27+
const {name, text, lang, placeholder} = this.props;
28+
// specify language
29+
this.ed.setGrammar(
30+
atom.grammars.grammarForScopeName(`source.${lang}`)
31+
);
32+
if (text) {
33+
this.ed.setText(text || '');
34+
}
35+
if (placeholder) {
36+
this.ed.setPlaceholderText(placeholder);
37+
}
38+
// append editor to rendered div
39+
document.querySelector(`#${name}`).appendChild(this.ed.getElement());
40+
}
41+
}

0 commit comments

Comments
 (0)