Skip to content

Commit 8e3d724

Browse files
committed
Refactory editor
1 parent dc0de4a commit 8e3d724

24 files changed

+147
-110
lines changed

Gruntfile.js

+28-54
Original file line numberDiff line numberDiff line change
@@ -8,37 +8,6 @@ module.exports = function(grunt) {
88

99
grunt.initConfig({
1010
pkg: pkg,
11-
jshint: {
12-
all: [
13-
'Gruntfile.js',
14-
'src/*.js'
15-
],
16-
options: {
17-
"eqeqeq": true,
18-
"forin": false,
19-
"latedef": false,
20-
"newcap": true,
21-
"quotmark": false,
22-
"undef": false,
23-
"unused": false,
24-
"trailing": true,
25-
"lastsemic": true,
26-
"asi": false,
27-
"boss": true,
28-
"expr": true,
29-
"strict": false,
30-
"funcscope": true,
31-
"loopfunc": true,
32-
"multistr": true,
33-
"proto": false,
34-
"smarttabs": true,
35-
"shadow": false,
36-
"sub": true,
37-
"passfail": false,
38-
"node": true,
39-
"white": false
40-
}
41-
},
4211
connect: {
4312
livereload: {
4413
options: {
@@ -55,62 +24,67 @@ module.exports = function(grunt) {
5524
},
5625
watch: {
5726
editor: {
58-
files: ['src/*'],
27+
files: ['*.css', 'src/*'],
5928
tasks: ['transport'],
6029
options: {
6130
livereload: true
6231
}
6332
}
6433
},
65-
generate: {
34+
transport: {
6635
seajs: {
6736
options: {
68-
buildir: 'tmp/src',
37+
dest: 'tmp/src/editor.js',
6938
header: 'define(function(require, exports, module) {',
7039
footer: [
7140
'module.exports = Editor',
7241
'});'
7342
].join('\n')
74-
},
75-
filename: 'editor.js'
43+
}
7644
},
77-
window: {
78-
filename: 'js/editor.js'
79-
}
45+
component: {
46+
options: {
47+
dest: 'index.js',
48+
header: '',
49+
footer: 'module.exports = Editor'
50+
}
51+
},
52+
window: {}
8053
}
8154
});
8255

8356
grunt.registerTask('concat', function() {
84-
var data = grunt.file.read('codemirror/codemirror.js');
57+
var data = grunt.file.read('vendor/codemirror.js');
8558
data = data.replace('window.CodeMirror', 'var CodeMirror');
8659
['continuelist', 'xml', 'markdown'].forEach(function(name) {
87-
data += '\n' + grunt.file.read('codemirror/' + name + '.js');
60+
data += '\n' + grunt.file.read('vendor/' + name + '.js');
8861
});
8962
data += '\n' + grunt.file.read('src/editor.js');
9063
grunt.file.write('tmp/editor.js', data);
9164
});
9265

93-
grunt.registerMultiTask('generate', function() {
66+
grunt.registerMultiTask('transport', function() {
9467
var options = this.options({
95-
buildir: 'build',
68+
src: 'tmp/editor.js',
69+
dest: 'build/editor.js',
9670
header: '(function(global) {',
9771
footer: 'global.Editor = Editor;\n})(this);'
9872
});
99-
var data = grunt.file.read('tmp/editor.js');
73+
var data = grunt.file.read(options.src);
10074
data = [options.header, data, options.footer].join('\n');
101-
grunt.file.write(path.join(options.buildir, this.data.filename), data);
75+
grunt.file.write(options.dest, data);
10276
});
10377

10478
grunt.registerTask('copy', function() {
105-
var dir = 'icomoon/fonts';
79+
var dir = 'vendor/icomoon/fonts';
10680
grunt.file.recurse(dir, function(fpath) {
10781
var fname = path.relative(dir, fpath);
108-
grunt.file.copy(fpath, path.join('build', 'css', 'fonts', fname));
82+
grunt.file.copy(fpath, path.join('build', 'fonts', fname));
10983
});
110-
var data = grunt.file.read('icomoon/style.css');
111-
data += grunt.file.read('src/paper.css');
112-
data += grunt.file.read('src/editor.css');
113-
grunt.file.write('build/css/editor.css', data);
84+
var data = grunt.file.read('vendor/icomoon/style.css');
85+
data += grunt.file.read('paper.css');
86+
data += grunt.file.read('editor.css');
87+
grunt.file.write('build/editor.css', data);
11488
grunt.file.copy('docs/index.html', 'build/index.html');
11589
grunt.file.copy('docs/markdown.html', 'build/markdown.html');
11690
grunt.file.copy('docs/yue.css', 'build/yue.css');
@@ -120,7 +94,7 @@ module.exports = function(grunt) {
12094
grunt.loadNpmTasks('grunt-contrib-connect');
12195
grunt.loadNpmTasks('grunt-contrib-watch');
12296

123-
grunt.registerTask('transport', ['concat', 'generate:window', 'copy']);
124-
grunt.registerTask('server', ['transport', 'connect', 'watch']);
125-
grunt.registerTask('default', ['jshint', 'server']);
97+
grunt.registerTask('build', ['concat', 'transport:window', 'copy']);
98+
grunt.registerTask('server', ['build', 'connect', 'watch']);
99+
grunt.registerTask('default', ['server']);
126100
};

Makefile

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
2+
build: components index.js editor.css
3+
@component build --dev
4+
5+
components: component.json
6+
@component install --dev
7+
8+
clean:
9+
rm -fr build components template.js
10+
11+
.PHONY: clean

README.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@
66

77
Editor is not a WYSIWYG editor, it is a plain text markdown editor. Thanks for the great project [codemirror](http://codemirror.net/), without which editor can never be created.
88

9-
![Editor Preview](./docs/preview.png)
10-
119
## Basic Usage
1210

1311
The easiest way to use Editor is to simply load the script and stylesheet:
@@ -87,4 +85,4 @@ Permission is hereby granted, free of charge to any noncommercial projects (paid
8785

8886
The above copyright notice and this permission notice shall be included in all copies of the Software.
8987

90-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
88+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

component.json

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"name": "editor",
3+
"repo": "lepture/editor",
4+
"description": "A markdown editor you really want.",
5+
"version": "0.1.0",
6+
"keywords": [],
7+
"dependencies": {},
8+
"development": {},
9+
"license": "MIT",
10+
"main": "index.js",
11+
"scripts": [
12+
"index.js"
13+
],
14+
"styles": [
15+
"editor.css",
16+
"paper.css"
17+
]
18+
}

docs/index.html

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
1818
})();
1919
</script>
20-
<script type="text/javascript" src="js/editor.js"></script>
21-
<link rel="stylesheet" href="css/editor.css" />
20+
<script type="text/javascript" src="editor.js"></script>
21+
<link rel="stylesheet" href="editor.css" />
2222
<title>Editor</title>
2323
<style type="text/css">
2424
body {
2525
padding: 0;
2626
margin: 0;
27-
background-color: #f9f9f5;
27+
background-color: #f9f9f7;
2828
}
2929
.editor-wrapper {
3030
max-width: 680px;

docs/markdown.html

+17-2
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,24 @@
22
<html>
33
<head>
44
<meta charset="utf-8">
5-
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
5+
<meta name="viewport" content="width=device-width">
66
<title>Markdown</title>
77
<link rel="stylesheet" href="yue.css" />
8+
<style type="text/css">
9+
body {
10+
margin: 0;
11+
padding: 0.4em 1em 6em;
12+
background: #f9f9f7;
13+
}
14+
.yue {
15+
max-width: 650px;
16+
*width: 650px;
17+
margin: 0 auto;
18+
}
19+
.entry-title {
20+
text-align: center;
21+
}
22+
</style>
823
<script type="text/javascript">
924
var _gaq = _gaq || [];
1025
_gaq.push(['_setAccount', 'UA-21475122-5']);
@@ -23,7 +38,7 @@
2338
</head>
2439
<body>
2540
<div class="yue">
26-
<h1>Markdown</h1>
41+
<h1 class="entry-title">Markdown</h1>
2742

2843
<hr />
2944

docs/preview.png

-122 KB
Binary file not shown.

0 commit comments

Comments
 (0)