Skip to content

Commit c74de88

Browse files
committed
embed ace
1 parent 361e9c6 commit c74de88

11 files changed

Lines changed: 71 additions & 48 deletions

File tree

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[submodule "browser/ace"]
2+
path = browser/ace
3+
url = https://github.com/ajaxorg/ace-builds.git

browser/ace

Submodule ace added at 9d12839
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
var React = require('react/addons')
2+
3+
var ace = require('ace')
4+
var CodeViewer = React.createClass({
5+
propTypes: {
6+
code: React.PropTypes.string,
7+
mode: React.PropTypes.string
8+
},
9+
componentDidMount: function () {
10+
var el = React.findDOMNode(this.refs.target)
11+
var editor = ace.edit(el)
12+
editor.setValue(this.props.code)
13+
editor.$blockScrolling = Infinity
14+
editor.renderer.setShowGutter(false)
15+
editor.setReadOnly(true)
16+
17+
var session = editor.getSession()
18+
session.setMode('ace/mode/' + this.props.mode)
19+
session.setUseSoftTabs(true)
20+
21+
this.setState({editor: editor})
22+
},
23+
componentDidUpdate: function () {
24+
this.state.editor.setValue(this.props.code)
25+
this.state.editor.getSession().setMode('ace/mode/' + this.props.mode)
26+
},
27+
render: function () {
28+
return (
29+
<div ref='target'></div>
30+
)
31+
}
32+
})
33+
34+
module.exports = CodeViewer

browser/main/Containers/SnippetContainer.jsx

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
var React = require('react/addons')
22
var Snippet = require('../Services/Snippet')
3+
var CodeViewer = require('../Components/CodeViewer')
34

45
var SnippetList = React.createClass({
56
propTypes: {
@@ -8,7 +9,6 @@ var SnippetList = React.createClass({
89
},
910
itemClickHandlerFactory: function (snippet) {
1011
return function () {
11-
console.log(this.props.selectSnippet)
1212
this.props.selectSnippet(snippet)
1313
}.bind(this)
1414
},
@@ -55,13 +55,21 @@ var SnippetViewer = React.createClass({
5555
})
5656
content = (
5757
<div className='SnippetViewer'>
58-
<div className='viewer-header'><i className='fa fa-code'></i> {snippet.callSign} <small className='updatedAt'>{snippet.updatedAt}</small></div>
58+
<div className='viewer-header'>
59+
<i className='fa fa-code'></i> {snippet.callSign} <small className='updatedAt'>{snippet.updatedAt}</small>
60+
<span className='control-group'>
61+
<button className='btn-default btn-square btn-sm'><i className='fa fa-edit fa-fw'></i></button>
62+
<button className='btn-default btn-square btn-sm'><i className='fa fa-trash fa-fw'></i></button>
63+
</span>
64+
</div>
5965
<div className='viewer-body'>
6066
<div className='viewer-detail'>
6167
<div className='description'>{snippet.description}</div>
6268
<div className='tags'><i className='fa fa-tags'/>{tags}</div>
6369
</div>
64-
<div>{snippet.content}</div>
70+
<div className='content'>
71+
<CodeViewer code={snippet.content} mode={snippet.mode}/>
72+
</div>
6573
</div>
6674
</div>
6775
)

browser/main/Services/Snippet.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ var snippets = {
1818
callSign: 'log',
1919
description: 'javascript log',
2020
content: 'console.log(\'yolo\')',
21-
mode: 'js',
21+
mode: 'javascript',
2222
createdAt: '2015-06-26T15:10:59.000Z',
2323
updatedAt: '2015-06-26T15:10:59.000Z',
2424
UserId: 1,

browser/main/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
<title>CodeXen</title>
55

66
<link rel="stylesheet" href="../vendor/fontawesome/css/font-awesome.min.css" media="screen" title="no title" charset="utf-8">
7+
78
<script src="../vendor/react/react-with-addons.js"></script>
89
<script src="../vendor/react-router/build/umd/ReactRouter.js"></script>
10+
<script src="../ace/src-min/ace.js"></script>
911

1012
</head>
1113
<body>

browser/styles/main/containers/SnippetContainer.styl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,20 @@
4343
box-sizing border-box
4444
small
4545
font-size 0.5em
46+
.control-group
47+
float right
48+
button
49+
margin 0 2px
4650
.viewer-body
47-
absolute bottom left right
51+
absolute bottom right
52+
left 1px
4853
top 44px
4954
.viewer-detail
5055
border-bottom solid 1px borderColor
5156
padding 10px
5257
.description
5358
margin-bottom 15px
59+
.content
60+
padding 5px 0
61+
.ace_editor
62+
height 500px

browser/styles/shared/btn.styl

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
background-color brandColor
3737

3838
.btn-default
39-
border-color invBorderColor
39+
border-color lightButtonColor
4040
background-color transparent
41-
color invBorderColor
41+
color lightButtonColor
4242
&:hover, &.hover, &:active, &.active
43-
color white
44-
background-color invBorderColor
43+
background-color lighten(lightButtonColor, 75%)

npm-debug.log

Lines changed: 0 additions & 36 deletions
This file was deleted.

package.json

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,6 @@
3030
},
3131
"homepage": "https://github.com/Rokt33r/codexen-app#readme",
3232
"dependencies": {
33-
"@rokt33r/ace-builds": "^1.1.9",
34-
"del": "^1.2.0",
3533
"dotenv": "^1.1.0",
3634
"marked": "^0.3.3",
3735
"moment": "^2.10.3",

0 commit comments

Comments
 (0)