Skip to content

Instantly share code, notes, and snippets.

View edwardhotchkiss's full-sized avatar

Edward Hotchkiss edwardhotchkiss

View GitHub Profile
// wrapper v0.0.3
// http://github.com/CandidBlend/wrapper
(function(n){"use strict";function e(n){return n.charAt(0).toUpperCase()+n.slice(1)}n.wrapper=function(t,i,r){var u="function"==typeof define&&define.amd?define:function(t,i,r){i=i.map(function(t){return"jquery"===t?n[$]:n[e(t)]}),n[e(t)]=r.apply(null,i)};return function(n){n(t,i,r)}(u)}})(window);
wrapper('logger', [], function() {
'use strict';
var _hasConsole = (typeof(window.console) === 'object');
return {
log: function(msg) {
if (!_hasConsole) {
wrapper('skeleton', ['logger'], function(Logger) {
'use strict';
function Skeleton(params) {
params = params || {};
this.name = params.name || 'default';
this.initialize();
}
Skeleton.prototype = {
initialize: function() {
Logger.log('this skeleton\'s name is %s', this.name);
wrapper('logger', [], function() {
'use strict';
var _hasConsole = (typeof(window.console) === 'object');
return {
log: function(msg) {
if (!_hasConsole) {
return;
}
var log, args;
args = Array.prototype.slice.call(arguments);
module.exports = function(grunt) {
grunt.initConfig({
pkg: grunt.file.readJSON('package.json'),
uglify: {
options: {
banner: '// <%= pkg.name %> v<%= pkg.version %>\n'
},
build: {
src: 'dist/<%= pkg.name %>-<%= pkg.version %>.js',
{
"name": "skeleton",
"description": "demo for usage in library/module creation with wrapper and grunt for build",
"version": "0.0.1",
"devDependencies": {
"grunt": "0.4.1",
"grunt-contrib-uglify": "0.1.1",
"grunt-contrib-jshint": "0.2.0",
"grunt-contrib-concat": "0.1.3",
"grunt-contrib-watch": "0.2.0"
/**
* @library wrapper.js
* @author Edward Hotchkiss <edward@candidblend.la>
* @contributor Avi Deitcher <avi@deitcher.net>
* @description wraps any function/module/object/lib within an
* AMD-compliant definition if possible, otherwise binding to `window`
* @license MIT
*/
// configure
require.config({
baseUrl: './',
paths: {
'skeleton': 'skeleton'
},
shim: {
skeleton: {
exports: 'Skeleton',
deps: []
// usage
var skeleton = new Skeleton({ name : 'example2' });
=> this skeleton's name is "skeleton2"
// compatible with (if available) RequireJS/AMD
(function(root) {
'use strict';
/* ---- private ---- */
/**
* @private _hasConsole
*/
// private example
_log('hi');
=> Uncaught ReferenceError: _log is not defined