Skip to content

Commit

Permalink
Merge pull request #69 from Nycto/master
Browse files Browse the repository at this point in the history
Grunt build support
  • Loading branch information
sofish committed Nov 27, 2013
2 parents 696283d + 440d42e commit c7eb63c
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea/
*.lock
*.log
node_modules
build
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
language: node_js
node_js:
- 0.10
before_script:
- npm install -g grunt-cli

56 changes: 56 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* global module: false */
module.exports = function(grunt) {
"use strict";

// Project configuration.
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),

jshint: {
files: ['Gruntfile.js', 'src/**/*.js'],
options: {
globals: { 'console': false },
bitwise: true,
camelcase: false,
curly: false,
eqeqeq: true,
forin: true,
immed: true,
indent: 2,
latedef: true,
laxcomma: true,
newcap: true,
noarg: true,
nonew: true,
noempty: true,
undef: true,
unused: true,
strict: false,
trailing: true,
maxlen: 200,
browser: true
}
},

uglify: {
build: {
src: 'src/**/*.js',
dest: 'build/pen-<%= pkg.version %>.min.js'
}
},

watch: {
files: ['<%= jshint.files %>'],
tasks: ['jshint']
}
});

// Plugins
grunt.loadNpmTasks('grunt-contrib-jshint');
grunt.loadNpmTasks('grunt-contrib-uglify');
grunt.loadNpmTasks('grunt-contrib-watch');

// Default task(s).
grunt.registerTask('default', ['jshint', 'uglify']);

};
37 changes: 37 additions & 0 deletions build.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
How to Build
============

The following steps should allow you to build this project:

1. Make sure you have the lastest version of Node.js. On Ubuntu, you might
need a custom repository:

```
sudo add-apt-repository ppa:chris-lea/node.js;
sudo apt-get update;
sudo apt-get install nodejs;
sudo apt-get upgrade;
```

2. Next hop into source directory where you cloned this repo. The following
commands will install grunt and all the Node dependencies:

```
cd Wherever_You_Cloned/pen;
npm install;
sudo npm install -g grunt-cli;
```

3. Finally, you're ready to start a build:

```
grunt;
```

While editing a file, you can use `watch` to automatically rebuild every
time a file is saved:

```
grunt watch;
```

14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,15 @@
"license": {
"type": "MIT",
"url": "https://github.com/sofish/pen/blob/master/license.txt"
}
}
},
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-watch": "~0.5.3"
},
"scripts": {
"test": "grunt --verbose"
},
"readmeFilename": "README.md"
}
6 changes: 3 additions & 3 deletions src/markdown.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*! Licensed under MIT, https://github.com/sofish/pen */
~function() {
(function() {

// only works with Pen
if(!this.Pen) return;
Expand Down Expand Up @@ -67,6 +67,6 @@
};

// append to Pen
Pen.prototype.markdown = covertor;
window.Pen.prototype.markdown = covertor;

}();
}());
25 changes: 13 additions & 12 deletions src/pen.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/*! Licensed under MIT, https://github.com/sofish/pen */
~function(doc) {
/* jshint -W030, -W093, -W015 */
(function(doc) {

var Pen, FakePen, utils = {};

Expand Down Expand Up @@ -27,14 +28,14 @@

// shift a function
utils.shift = function(key, fn, time) {
time = time || 50;
var queue = this['_shift_fn' + key], timeout = 'shift_timeout' + key, current;
queue ? queue.concat([fn, time]) : (queue = [[fn, time]]);
current = queue.pop();
clearTimeout(this[timeout]);
this[timeout] = setTimeout(function() {
current[0]();
}, time);
time = time || 50;
var queue = this['_shift_fn' + key], timeout = 'shift_timeout' + key, current;
queue ? queue.concat([fn, time]) : (queue = [[fn, time]]);
current = queue.pop();
clearTimeout(this[timeout]);
this[timeout] = setTimeout(function() {
current[0]();
}, time);
};

// merge: make it easy to have a fallback
Expand Down Expand Up @@ -217,7 +218,7 @@
, effects = this._effectNode(node)
, menu = this._menu
, linkInput = menu.querySelector('input')
, highlight
, highlight;

// remove all highlights
[].slice.call(menu.querySelectorAll('.active')).forEach(function(el) {
Expand Down Expand Up @@ -332,7 +333,7 @@

Pen.prototype.destroy = function(isAJoke) {
var destroy = isAJoke ? false : true
, attr = isAJoke ? 'setAttribute' : 'removeAttribute'
, attr = isAJoke ? 'setAttribute' : 'removeAttribute';

if(!isAJoke) {
this._sel.removeAllRanges();
Expand Down Expand Up @@ -364,4 +365,4 @@
// make it accessible
this.Pen = doc.getSelection ? Pen : FakePen;

}(document);
}(document));

0 comments on commit c7eb63c

Please sign in to comment.