Skip to content

Commit

Permalink
Setting up the repo
Browse files Browse the repository at this point in the history
Close #1
  • Loading branch information
marclaval committed Jun 24, 2014
1 parent 8c8e9c7 commit b1a182f
Show file tree
Hide file tree
Showing 15 changed files with 337 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/node_modules
/target
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,35 @@ hashspace-bootstrap
===================

Hashspace components for Bootstrap

## Development

### Preparing your environment

- install Gulp globally: `npm install -g gulp`
- install local npm modules: `npm install`

### Running Tests

For jshint validation:

- run `gulp checkstyle`

To run the tests:

- run `gulp test`

To use the project in *dev* mode:

- run `gulp build` to build it
- run `gulp play` to build it and start a webserver which watches source files at http://localhost:8000
- run `gulp play tdd` to work in the TDD mode (i.e. watch source files to build and run all tests)

To use the project in *production* mode:

- run `gulp` or `gulp package` to package it
- run `gulp www` to package it and start a webserver at http://localhost:8000

To clean all files created during builds:

- run `gulp clean`
30 changes: 30 additions & 0 deletions build/gulp-html2hsp.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;

module.exports = function() {

function processHspFile(file, enc, cb){

if(file.isStream()){
this.emit('error', new PluginError('gulp-html2hsp', 'Streaming not supported'));
return cb();
}

if(file.isBuffer()){
try {
var content = String(file.contents);
content = "{export template description()}\r\n" + content + "\r\n{/template}";
file.contents = new Buffer(content);
file.path = gutil.replaceExtension(file.path, ".hsp");
} catch(e) {
this.emit('error', e);
}
}

this.push(file);
cb();
}

return through.obj(processHspFile);
};
28 changes: 28 additions & 0 deletions build/gulp-removehtmlcommenttags.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
var through = require('through2');
var gutil = require('gulp-util');
var PluginError = gutil.PluginError;

module.exports = function() {

function processHspFile(file, enc, cb){

if(file.isStream()){
this.emit('error', new PluginError('gulp-removehtmlcommenttags', 'Streaming not supported'));
return cb();
}

if(file.isBuffer()){
try {
var content = String(file.contents);
content = content.replace("<!--", "").replace("-->", "");
file.contents = new Buffer(content);
} catch(e) {
this.emit('error', e);
}
}
this.push(file);
cb();
}

return through.obj(processHspFile);
};
1 change: 1 addition & 0 deletions demo/carousel/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the documentation of the carousel component!
9 changes: 9 additions & 0 deletions demo/carousel/demo.hsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var description = require('./README.hsp').description;
var carouselCpt = require('../../carousel/carousel.hsp').carousel;

{export template demo()}
This is a demo of the carousel component!
<#carouselCpt />
Updated again!
<#description />
{/template}
Empty file added demo/demo.css
Empty file.
27 changes: 27 additions & 0 deletions demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<link rel="stylesheet" href="http://netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<link rel="stylesheet" href="./demo.css">
<title>Hashspace - Bootstrap</title>
<script src="http://noder-js.ariatemplates.com/dist/master/noder.min.js" type="text/javascript">
{
packaging: {
baseUrl: "/"
}
}
</script>
<script src="http://hashspace.ariatemplates.com/dist/0.0.4/hashspace-noder.min.js" type="text/javascript"></script>
<!--<script src="./hashspace-bootstrap.js" type="text/javascript"></script>
<script src="./hashspace-bootstrap-demo.js" type="text/javascript"></script>-->
<script type="noder">
var carousel = require('./demo/carousel/demo.hsp').demo;
carousel().render(document.body);
</script>

</head>
<body>
</body>
</html>
39 changes: 39 additions & 0 deletions gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
module.exports = function (grunt) {

grunt.initConfig({
atpackager : {
options : {
sourceDirectories : ['target/dev'],
sourceFiles : [ '**/*.js', '**/*.hsp'],
outputDirectory : 'target/prod/',
visitors : ["NoderDependencies"]
},
bootstrap : {
options : {
defaultBuilder : {
type : "NoderPackage",
cfg : {
outputFileWrapper : "(function(define){$CONTENT$;})(noder.define);"
}
},
packages : [
{
name : "hashspace-bootstrap-demo.js",
files : ['demo/**/*.js', 'demo/**/*.hsp']
}, {
name : "hashspace-bootstrap.js",
files : ['**/*.js', '**/*.hsp', '!demo/**/*.*']
}]
}
}
}
});

// Automatically load all the grunt tasks
require('load-grunt-tasks')(grunt);
grunt.loadNpmTasks('atpackager');
require('atpackager').loadNpmPlugin('noder-js');

grunt.registerTask('package', ['atpackager:bootstrap']);
grunt.registerTask('default', ['package']);
};
101 changes: 101 additions & 0 deletions gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
var gulp = require('gulp');
var gutil = require('gulp-util');
var watch = require('gulp-watch');
var markdown = require('gulp-markdown');
var hsp = require('gulp-hashspace');
var clean = require('gulp-clean');
var uglify = require('gulp-uglify');
var jshint = require('gulp-jshint');
var html2hsp = require('./build/gulp-html2hsp');
var removehtmlcommenttags = require('./build/gulp-removehtmlcommenttags');
var http = require('http');
var karma = require('karma').server;
var connect = require('connect');
var _ = require('lodash');


require('gulp-grunt')(gulp);
var wwwServerPort = 8080;
var _destFolder = "target";
var _devFolder = _destFolder + "/dev";
var _prodFolder = _destFolder + "/prod";

var karmaCommonConf = {
browsers: ['Chrome'],
files: [
'src/**/*.hsp',
'src/**/*.js',
'test/**/*.spec.js',
'./node_modules/hashspace/hsp/*.js',
'./node_modules/hashspace/hsp/rt/**/*.js',
'./node_modules/hashspace/hsp/gestures/**/*.js'
],
frameworks: ['mocha', 'chai', 'commonjs'],
preprocessors: {
'src/**/*.hsp': ['hsp-compile', 'commonjs'],
'src/**/*.js': ['hsp-transpile', 'commonjs'],
'test/**/*.spec.js': ['commonjs'],
'./node_modules/hashspace/hsp/**/*.js': ['commonjs']
},
commonjsPreprocessor: {
modulesRoot: './node_modules/hashspace'
}
};

gulp.task('checkstyle', function() {
return gulp.src(['src/**/*.js', 'demo/**/*.js', 'test/**/*.js', 'build/**/*.js']).pipe(jshint()).pipe(jshint.reporter("default")).pipe(jshint.reporter("fail"));
});

gulp.task('clean', ['checkstyle'], function(){
return gulp.src(_destFolder, {read: false}).pipe(clean());
});

gulp.task('build', ['clean'], function() {
gulp.src(['demo/**/*.html', 'demo/**/*.css']).pipe(gulp.dest(_devFolder));
gulp.src('demo/**/*.md').pipe(markdown()).pipe(html2hsp()).pipe(hsp.compile()).pipe(gulp.dest(_devFolder + '/demo'));
gulp.src('demo/**/*.hsp').pipe(hsp.compile()).pipe(gulp.dest(_devFolder + '/demo'));
gulp.src('demo/**/*.js').pipe(hsp.transpile()).pipe(gulp.dest(_devFolder + '/demo'));
gulp.src('src/**/*.hsp').pipe(hsp.compile()).pipe(gulp.dest(_devFolder));
gulp.src('src/**/*.js').pipe(hsp.transpile()).pipe(gulp.dest(_devFolder));
});

gulp.task('test', ['checkstyle'], function (done) {
return karma.start(_.assign({}, karmaCommonConf, {singleRun: true}), done);
});

gulp.task('play', ['clean'], function () {
watch({glob: ['demo/**/*.html', 'demo/**/*.css']}, function (files) {
files.pipe(gulp.dest(_devFolder));
});
watch({glob: 'demo/**/*.md'}, function (files) {
files.pipe(markdown().on('error', gutil.log)).pipe(html2hsp()).pipe(hsp.compile()).pipe(gulp.dest(_devFolder + '/demo'));
});
watch({glob: 'demo/**/*.hsp'}, function (files) {
files.pipe(hsp.compile().on('error', gutil.log)).pipe(gulp.dest(_devFolder + '/demo'));
});
watch({glob: 'src/**/*.hsp'}, function (files) {
files.pipe(hsp.compile().on('error', gutil.log)).pipe(gulp.dest(_devFolder));
});
watch({glob: 'src/**/*.js'}, function (files) {
files.pipe(hsp.transpile().on('error', gutil.log)).pipe(gulp.dest(_devFolder));
});

gutil.log('Starting WWW server at http://localhost:' + wwwServerPort);
http.createServer(connect().use(connect.static('./' + _devFolder))).listen(wwwServerPort);
});

gulp.task('tdd', function (done) {
karma.start(_.assign({}, karmaCommonConf), done);
});

gulp.task('package', ['build', 'grunt-package'], function() {
gulp.src([_devFolder + '/**/*.html', _devFolder + '/**/*.css']).pipe(removehtmlcommenttags()).pipe(gulp.dest(_prodFolder));
gulp.src(_prodFolder + '/*.js').pipe(uglify()).pipe(gulp.dest(_prodFolder));
})

gulp.task('www', ['package'], function() {
gutil.log('Starting WWW server at http://localhost:' + wwwServerPort);
http.createServer(connect().use(connect.static('./' + _prodFolder))).listen(wwwServerPort);
});

gulp.task('default', ['package']);
33 changes: 33 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
{
"author": "ariatemplates <[email protected]> (http://github.com/ariatemplates)",
"name": "hashspace-bootstrap",
"description": "Hashspace components for Bootstrap",
"version": "0.0.1-SNAPSHOT",
"homepage": "http://ariatemplates.github.io/hashspace-bootstrap/",
"dependencies": {},
"devDependencies": {
"gulp": "~3.8.1",
"gulp-util": "~2.2.17",
"gulp-watch": "~0.6.8",
"gulp-clean": "~0.3.0",
"gulp-markdown": "~0.1.2",
"gulp-grunt": "~0.5.1",
"gulp-hashspace": "~0.0.2",
"gulp-uglify": "~0.3.1",
"gulp-jshint" : "~1.6.3",
"hashspace": "~0.0.4",
"through2": "~0.4.1",
"grunt": "~0.4.2",
"load-grunt-tasks": "~0.2.1",
"noder-js": "1.4.0",
"atpackager": "~0.2.2",
"connect": "~2.14.2",
"karma-chrome-launcher": "~0.1.2",
"karma-mocha": "~0.1.3",
"karma-commonjs": "~0.0.9",
"karma-hashspace": "~0.0.1",
"chai": "~1.9.1",
"karma-chai": "~0.1.0",
"lodash": "~2.4.1"
}
}
5 changes: 5 additions & 0 deletions src/carousel/carousel.hsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
var CarouselController = require("./carousel").CarouselController;

{export template carousel using ctrl:CarouselController}
<h1 class="carousel">Hello carousel</h1>
{/template}
7 changes: 7 additions & 0 deletions src/carousel/carousel.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
var klass = require("hsp/klass");

exports.CarouselController = new klass({
$constructor: function () {
this.slide = 0;
}
});
10 changes: 10 additions & 0 deletions test/carousel/carousel.hsp.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
var carouselTpl = require('../../src/carousel/carousel.hsp').carousel;

describe('Carousel', function() {

it('should say Hello carousel', function() {
var n = carouselTpl();
expect(n.node.firstChild.textContent).to.equal('Hello carousel');
var a = 1;
});
});
13 changes: 13 additions & 0 deletions test/carousel/carousel.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
var CarouselController = require('../../src/carousel/carousel.js').CarouselController;

describe('Carousel controller', function() {

var ctrl;
beforeEach(function(){
ctrl = new CarouselController();
});

it('should have the index 0 slide by default', function() {
expect(ctrl.slide).to.equal(0);
});
});

0 comments on commit b1a182f

Please sign in to comment.