Skip to content

Instantly share code, notes, and snippets.

View juandopazo's full-sized avatar

Juan Dopazo juandopazo

View GitHub Profile
@juandopazo
juandopazo / gist:3193926
Created July 28, 2012 16:34
Server Y.Router
YUI.add('router', function (Y) {
/**
Provides URL-based routing for Node
@module app
@submodule router
@since 3.4.0
**/
var QS = Y.QueryString,
var http = require('http');
exports.proxy = function (prefix) {
return function (req, res, next) {
var options = {
port: 3000,
path: req.url.substr(prefix.length),
method: req.method,
headers: req.headers
};
@juandopazo
juandopazo / gist:3174141
Created July 25, 2012 03:03
YUI AMD loader
var YUI_config = {};
(function (YUI, global) {
var modules = {};
var justLoaded = [];
var AMD_prefix = '~AMD~';
function nameFromPath(path) {
var parts = path.split(/\//g).pop().split(/\./g),
ext = parts.pop();
@juandopazo
juandopazo / combo.js
Created July 19, 2012 21:26
Streaming combo handler
var fs = require('fs'),
Stream = require('stream'),
util = require('util');
function ComboStream(files, opts) {
Stream.call(this);
opts = opts || {};
if (!Array.isArray(files)) {
throw new TypeError('First argument must be an Array');
@juandopazo
juandopazo / gist:3117644
Created July 15, 2012 16:29
Express vs YAF

I think the goal should be to replace Express with Y.App. Express does:

  • Routing
  • Redirection
  • Environment configuration
  • View templating and rendering
  • Everything Connect does

Routing and redirection are very much in the scope of Y.Router/Y.App. Environment configuration is in the scope of YUI. View templating and rendering are also covered. Rendering of static files, middleware, logging, caching, cookies, compression, etc are all covered by Connect. So... Shouldn't the goal be to make Y.App work nicely with Connect?

@juandopazo
juandopazo / current.js
Created July 13, 2012 02:57
Stateful TreeNode
// CURRENT IMPLEMENTATION
expand : function (target) {
var treeNode = target ?
target.ancestor('.'+ classNames.treeviewcontent) :
this.get("contentBox"),
treeWidget = Y.Widget.getByNode(treeNode),
isPopulated = treeWidget.get("populated");
if (this.get("lazyLoad") && !isPopulated) {
@juandopazo
juandopazo / gist:3098478
Created July 12, 2012 14:32
Allow HTML in a YUI TabView
var _queries = Y.TabviewBase._queries,
_classNames = Y.TabviewBase._classNames;
Y.TabView.prototype._renderTabs = function(contentBox) {
var tabs = contentBox.all(_queries.tab),
panelNode = this.get('panelNode'),
panels = (panelNode) ? this.get('panelNode').get('children') : null,
tabview = this;
if (tabs) { // add classNames and fill in Tab fields from markup when possible
@juandopazo
juandopazo / gist:3073050
Created July 8, 2012 21:47
App confusion nr 1
var UserView = Y.Base.create('userView', Y.View, [], {
template: Y.Handlebars.compile(Y.one('#user-template').getHTML()),
initializer: function () {
this.after('modelChange', this._onModelChange);
this.after('modelChange', this.render);
this._onModelChange({
newVal: this.get('model')
});
},
@juandopazo
juandopazo / gist:3013250
Created June 28, 2012 19:06
npm install yuidocjs
C:\node>npm install yuidocjs
npm ERR! notsup Unsupported
npm ERR! notsup Not compatible with your operating system or architecture: yuido
cjs@0.1.9
npm ERR! notsup Valid OS: darwin,linux
npm ERR! notsup Valid Arch: any
npm ERR! notsup Actual OS: win32
npm ERR! notsup Actual Arch: ia32
npm ERR! System Windows_NT 6.1.7601
@juandopazo
juandopazo / gist:3008202
Created June 28, 2012 01:44
Y.Base help
var instance = new Y.SomeBaseSubclass('#node');
// you probably want this instead:
var instance = new Y.SomeBaseSubclass({
tabNode: '#node'
});
// and for the class...
Y.ResponsiveSelect = Y.Base.create('responsiveSelect', Y.Model, [], {
initializer: function (config) {
// here config.tabNode == '#node'