Skip to content

Commit 28864c0

Browse files
committed
Initial commit of version 0.0.2
0 parents  commit 28864c0

24 files changed

+1286
-0
lines changed

.gitignore

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
build/*.js
2+
3+
src/*.js
4+
src/*.js.map
5+
src/*.src.coffee
6+
7+
coverage
8+
node_modules

Gruntfile.js

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
module.exports = function(grunt) {
2+
grunt.initConfig({
3+
pkg: grunt.file.readJSON('package.json'),
4+
5+
watch: {
6+
files: ['<%= coffee.compile.files %>'],
7+
tasks: ['coffee', 'concat', 'uglify']
8+
},
9+
10+
coffee: {
11+
compile: {
12+
files: {
13+
'src/main.js': 'src/main.coffee', // 1:1 compile
14+
'src/widget.js': 'src/widget.coffee',
15+
'src/engine.js': ['src/engine/*.coffee'] // compile and concat into single file
16+
}
17+
},
18+
19+
compileBare: {
20+
options: {
21+
bare: true
22+
},
23+
files: {
24+
'src/main.js': 'src/main.coffee', // 1:1 compile
25+
'src/widget.js': 'src/widget.coffee',
26+
'src/engine.js': ['src/engine/*.coffee'] // compile and concat into single file
27+
}
28+
},
29+
30+
compileJoined: {
31+
options: {
32+
join: true
33+
},
34+
files: {
35+
'src/main.js': 'src/main.coffee', // 1:1 compile
36+
'src/widget.js': 'src/widget.coffee',
37+
'src/engine.js': ['src/engine/*.coffee'] // compile and concat into single file
38+
}
39+
}
40+
},
41+
42+
concat: {
43+
options: {
44+
banner: '/*! <%= pkg.name %>-<%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
45+
},
46+
'build/<%= pkg.name %>.js': ['src/*.js'],
47+
'build/<%= pkg.name %>-<%= pkg.version %>.js': ['src/*.js']
48+
},
49+
50+
uglify: {
51+
options: {
52+
banner: '/*! <%= pkg.name %>-<%= pkg.version %> <%= grunt.template.today("yyyy-mm-dd") %> */\n'
53+
},
54+
dist: {
55+
src: 'build/<%= pkg.name %>-<%= pkg.version %>.js',
56+
dest: 'build/<%= pkg.name %>-<%= pkg.version %>.min.js'
57+
}
58+
},
59+
60+
clean: {
61+
folder: ['src/*.js', 'src/*.js.map', 'src/*.src.coffee']
62+
}
63+
});
64+
65+
grunt.loadNpmTasks('grunt-contrib-watch');
66+
grunt.loadNpmTasks('grunt-contrib-coffee');
67+
grunt.loadNpmTasks('grunt-contrib-concat');
68+
grunt.loadNpmTasks('grunt-contrib-uglify');
69+
grunt.loadNpmTasks('grunt-contrib-clean');
70+
71+
grunt.registerTask('default', ['coffee', 'concat', 'uglify', 'clean']);
72+
};

LICENSE.txt

+674
Large diffs are not rendered by default.

README.md

+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# js-widget
2+
3+
## About
4+
js-widget provides some helpful features to manage widgets in your web application.
5+
It can be used with different template engines, even with none, with or without jQuery
6+
and can be used as open source ([see license](#license)).
7+
8+
## Installation
9+
Simply download the file from the [releases](https://github.com/hanspolo/js-widget/releases) and include it to your website with
10+
```html
11+
<script src="path/to/js-widget-$version{.min}.js"></script>
12+
```
13+
14+
## Usage
15+
First of all you need to create a new widget object
16+
```javascript
17+
my_widget = new window.JsWidget.Widget(my_engine);
18+
```
19+
20+
The `my_engine` parameter should be one of the supported engines.
21+
* When using underscore.js for your templates use `window.JsWidget.Engine.Underscore`
22+
* when using handlebars for your templates use `window.JsWidget.Engine.Handlebars`
23+
* when using mustache for your templates use `window.JsWidget.Engine.Mustache`
24+
* when using jquery-templating for your templatews use `window.JsWidget.Engine.JQuery`
25+
* if you don't want to use a template engine, use `window.JsWidget.Engine.None`
26+
27+
To render a template as a widget the object gives you some ways to load the content
28+
```javascript
29+
# You can load a template file from a path via ajax.
30+
# before_callback and after_callback are called before and after rendering.
31+
# The call for the template starts before the callback.
32+
# This is the only one that needs a template engine to be loaded.
33+
my_widget.render_template(path, before_callback, after_callback)
34+
35+
# The same is done by render_static_template.
36+
# The only difference is, that it will not compile the template.
37+
# This is helpful when using no template engine
38+
my_widget.render_static_template(path, before_callback, after_callback)
39+
40+
# If you have the html code already loaded and only want to attach it to the DOM,
41+
# you can use render_html method
42+
my_widget.render_html(code, before_callback, after_callback)
43+
```
44+
45+
After loading a template or html code into the widget,
46+
it provides some useful methods to manage it.
47+
```javascript
48+
# To display the widget you can call the show method
49+
# You can pass 2 callbacks that will be performed before and after the widget is shown
50+
my_widget.show(before_callback, after_callback)
51+
52+
# The opposite is done by hide method
53+
my_widget.hide(before_callback, after_callback)
54+
55+
# To get an overview of the state of your widget you can ask for its current state with
56+
# to see if the widget is currently displayed
57+
my_widget.is_visible()
58+
# or to check if it is currently hidden
59+
my_widget.is_invisible()
60+
```
61+
62+
## License
63+
This project uses the GPL-3.0 license.
64+
Read [the license file](https://github.com/hanspolo/js-widget/blob/LICENSE.txt) for more information.

bower.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "js-widget",
3+
"description": "",
4+
"keywords": [
5+
"js",
6+
"template",
7+
"widgets"
8+
],
9+
"homepage": "",
10+
"license": "GPL-3.0",
11+
"moduleType": "globals",
12+
"main": [
13+
"build/js-widget.js"
14+
],
15+
"ignore": [
16+
"/.*",
17+
"_config.yml",
18+
"CNAME",
19+
"composer.json",
20+
"CONTRIBUTING.md",
21+
"docs",
22+
"js/tests",
23+
"test-infra",
24+
"spec",
25+
"coverage",
26+
"node_modules".
27+
],
28+
"dependencies": {
29+
}
30+
}

build/.keep

Whitespace-only changes.

karma.conf.js

+70
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
// Karma configuration
2+
// Generated on Mon Oct 10 2016 11:47:14 GMT+0200 (CEST)
3+
4+
module.exports = function(config) {
5+
config.set({
6+
7+
// base path that will be used to resolve all patterns (eg. files, exclude)
8+
basePath: '',
9+
10+
// frameworks to use
11+
// available frameworks: https://npmjs.org/browse/keyword/karma-adapter
12+
frameworks: ['mocha', 'chai'],
13+
14+
// list of files / patterns to load in the browser
15+
files: [
16+
'build/js-widget.js',
17+
'spec/unit/**/*.js',
18+
{
19+
pattern: 'spec/tmpl/**/*.html',
20+
watched: false,
21+
served: true,
22+
included: false
23+
}
24+
],
25+
26+
// list of files to exclude
27+
exclude: [
28+
],
29+
30+
// preprocess matching files before serving them to the browser
31+
// available preprocessors: https://npmjs.org/browse/keyword/karma-preprocessor
32+
preprocessors: {
33+
'**/build/js-widget.js': 'coverage'
34+
},
35+
36+
// test results reporter to use
37+
// possible values: 'dots', 'progress'
38+
// available reporters: https://npmjs.org/browse/keyword/karma-reporter
39+
reporters: ['progress', 'coverage'],
40+
41+
// web server port
42+
port: 9876,
43+
44+
// enable / disable colors in the output (reporters and logs)
45+
colors: true,
46+
47+
// level of logging
48+
// possible values: config.LOG_DISABLE || config.LOG_ERROR || config.LOG_WARN || config.LOG_INFO || config.LOG_DEBUG
49+
logLevel: config.LOG_INFO,
50+
51+
// enable / disable watching file and executing tests whenever any file changes
52+
autoWatch: true,
53+
54+
// start these browsers
55+
// available browser launchers: https://npmjs.org/browse/keyword/karma-launcher
56+
browsers: [
57+
'PhantomJS',
58+
'Chrome',
59+
'Firefox'
60+
],
61+
62+
// Continuous Integration mode
63+
// if true, Karma captures browsers, runs the tests and exits
64+
singleRun: true,
65+
66+
// Concurrency level
67+
// how many browser should be started simultaneous
68+
concurrency: Infinity
69+
})
70+
}

package.json

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"name": "js-widget",
3+
"version": "0.0.2",
4+
"description": "",
5+
"author": "Philipp Hirsch <[email protected]>",
6+
"license": "GPL-3.0",
7+
"scripts": {
8+
"test": "karma start --reporters clear-screen,dots,coverage"
9+
},
10+
"devDependencies": {
11+
"chai": "^3.5.0",
12+
"grunt": "^0.4.5",
13+
"grunt-contrib-clean": "^1.0.0",
14+
"grunt-contrib-coffee": "^1.0.0",
15+
"grunt-contrib-concat": "^1.0.1",
16+
"grunt-contrib-uglify": "^0.5.1",
17+
"grunt-contrib-watch": "^1.0.0",
18+
"istanbul": "^0.4.4",
19+
"karma": "^1.1.2",
20+
"karma-chai": "^0.1.0",
21+
"karma-chrome-launcher": "^1.0.1",
22+
"karma-clear-screen-reporter": "^1.0.0",
23+
"karma-cli": "^1.0.1",
24+
"karma-coverage": "^1.1.1",
25+
"karma-firefox-launcher": "^1.0.0",
26+
"karma-phantomjs-launcher": "^1.0.2",
27+
"karma-mocha": "^1.1.1",
28+
"mocha": "^3.0.1"
29+
}
30+
}

spec/unit/engine/engine.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
describe('engine-test', function() {
2+
/***********************
3+
* Engine::Engine::run *
4+
***********************/
5+
it('should throw an exception if the abstract method `run` is called', function() {
6+
e = new window.JsWidget.Engine.Engine();
7+
8+
expect(e.run).to.throw(Error, 'Not implemented. The method `run` can\'t be called on the Engine class. Please use a concrete engine.');
9+
});
10+
11+
/********************************
12+
* Engine::Engine::check_engine *
13+
********************************/
14+
it('check_engine doesn\'t throw an exception for engine `handlebars` if handlebars is installed', function() {
15+
e = new window.JsWidget.Engine.Handlebars();
16+
window.JsWidget.EnginePresence = ['handlebars'];
17+
18+
expect(e.check_engine).to.not.throw(Error);
19+
});
20+
21+
it('check_engine throws an exception for engine `handlebars` if handlebars isn\'t installed', function() {
22+
e = new window.JsWidget.Engine.Handlebars();
23+
window.JsWidget.EnginePresence = [];
24+
25+
expect(e.check_engine).to.throw(Error, 'Template Engine \'handlebars\' is missing. Please install the template engine you want to use and try again');
26+
});
27+
28+
it('check_engine doesn\'t throw an exception for engine `jquery` if jquery-templating is installed', function() {
29+
e = new window.JsWidget.Engine.JQuery();
30+
window.JsWidget.EnginePresence = ['jquery-templating'];
31+
32+
expect(e.check_engine).to.not.throw(Error);
33+
});
34+
35+
it('check_engine throws an exception for engine `jquery` if jquery-templating isn\'t installed', function() {
36+
e = new window.JsWidget.Engine.JQuery();
37+
window.JsWidget.EnginePresence = [];
38+
39+
expect(e.check_engine).to.throw(Error, 'Template Engine \'jquery-templating\' is missing. Please install the template engine you want to use and try again');
40+
});
41+
42+
it('check_engine doesn\'t throw an exception for engine `mustache` if mustache is installed', function() {
43+
e = new window.JsWidget.Engine.Mustache();
44+
window.JsWidget.EnginePresence = ['mustache'];
45+
46+
expect(e.check_engine).to.not.throw(Error);
47+
});
48+
49+
it('check_engine throws an exception for engine `mustache` if mustache isn\'t installed', function() {
50+
e = new window.JsWidget.Engine.Mustache();
51+
window.JsWidget.EnginePresence = [];
52+
53+
expect(e.check_engine).to.throw(Error, 'Template Engine \'mustache\' is missing. Please install the template engine you want to use and try again');
54+
});
55+
56+
it('check_engine doesn\'t throw an exception for engine `underscore` if underscore.js is installed', function() {
57+
e = new window.JsWidget.Engine.Underscore();
58+
window.JsWidget.EnginePresence = ['underscore.js'];
59+
60+
expect(e.check_engine).to.not.throw(Error);
61+
});
62+
63+
it('check_engine throws an exception for engine `underscore` if underscore.js isn\'t installed', function() {
64+
e = new window.JsWidget.Engine.Underscore();
65+
window.JsWidget.EnginePresence = [];
66+
67+
expect(e.check_engine).to.throw(Error, 'Template Engine \'underscore.js\' is missing. Please install the template engine you want to use and try again');
68+
});
69+
});

spec/unit/engine/handlebars.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
describe('handlebars-engine-test', function() {
2+
});

spec/unit/engine/jquery.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
describe('jquery-engine-test', function() {
2+
});

spec/unit/engine/mustache.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
describe('mustache-engine-test', function() {
2+
});

spec/unit/engine/none.js

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
describe('none-engine-test', function() {
2+
/*********************
3+
* Engine::None::run *
4+
*********************/
5+
it('should throw an exception if the run method is called', function() {
6+
e = new window.JsWidget.Engine.None();
7+
8+
try {
9+
e.run('', {});
10+
expect(true).to.be.false;
11+
} catch(e) {
12+
expect(e.name === 'Can\'t render without an engine').to.be.true;
13+
}
14+
})
15+
});

spec/unit/engine/underscore.js

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
describe('underscore-engine-test', function() {
2+
});

spec/unit/main.js

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
describe('main-test', function() {
2+
it('should pass this canary test', function() {
3+
expect(true).to.be.true;
4+
});
5+
});

0 commit comments

Comments
 (0)