Esempio n. 1
0
module.exports = function createRequest(request) {

    arrayForEach(methods, function(method) {
        var upper = method.toUpperCase();

        request[method] = function(url, options) {
            options = options || {};

            options.url = url;
            options.method = upper;

            return request(options);
        };
    });

    arrayForEach(["post", "patch", "put"], function(method) {
        var upper = method.toUpperCase();

        request[method] = function(url, data, options) {
            options = options || {};

            options.url = url;
            options.data = data;
            options.method = upper;

            return request(options);
        };
    });

    request.defaults = defaults.values;
    request.plugins = new EventEmitter(-1);

    return request;
};
Esempio n. 2
0
function mount(layers, handlers) {
    arrayForEach(handlers, function(handler) {
        var mw;

        if (isFunction(handler)) {
            layers[layers.length] = handler;
        } else if (isObject(handler)) {
            if (isFunction(handler.middleware)) {
                mw = handler.middleware;

                if (mw.length >= 4) {
                    layers[layers.length] = function(err, req, res, next) {
                        handler.middleware(err, req, res, next);
                    };
                } else if (mw.length <= 3) {
                    layers[layers.length] = function(req, res, next) {
                        handler.middleware(req, res, next);
                    };
                } else {
                    throw new Error("handler middleware invalid arguments, handler([err ,]req, res, next");
                }
            } else {
                throw new Error("handler.middleware must be a function");
            }
        } else {
            throw new Error("handlers must be functions or objects with a middleware function");
        }
    });
}
Esempio n. 3
0
ComnChunk.prototype.generateSourceMap = function() {
    var sourceMap = this.sourceMap,
        positions, treeChunk, source;

    if (!sourceMap) {
        positions = this.getPositions();
        sources = this.sources = combine.create(this.name);
        treeChunk = this.treeChunk;
        source = this.source;

        arrayForEach(positions, function each(position) {
            var dependency = treeChunk.getDependency(position.id);

            sources.addFile({
                source: fs.readFileSync(dependency.fullPath).toString("utf-8"),
                sourceFile: filePath.relative(treeChunk.rootDirname, dependency.fullPath)
            }, {
                line: position.line,
                column: position.column
            });
        });

        sourceMap = this.sourceMap = convert.fromBase64(sources.base64());
    }

    return sourceMap;
};
Esempio n. 4
0
function compile(template, out, config, options, callback) {
    var opts;

    options = options || {};

    opts = {
        locals: options.data || (options.data = {}),
        settings: options.settings
    };

    arrayForEach(options.functions, function(fn) {
        extend(options.data, fn());
    });

    opts.locals.env = config.env;

    ejs.render(template, opts, function(err, str) {
        if (err) {
            callback(err);
            return;
        }

        fileUtils.writeFile(out, str, function(err) {
            callback(err);
        });
    });
}
transitionEvents.removeEndEventListener = function(node, eventListener) {
    if (END_EVENTS.length !== 0) {
        arrayForEach(END_EVENTS, function(endEvent) {
            removeEventListener(node, endEvent, eventListener);
        });
    }
};
Esempio n. 6
0
function replacePaths(tree, dependencies, reInclude, options) {
    var dependencyHash = tree.dependencyHash;

    options.throwError = false;
    arrayForEach(dependencies, function forEachDependency(dependency) {
        options.mappings = dependency.mappings;
        dependency.content = dependency.content.replace(reInclude,
            function onReplace(match, includeName, functionName, dependencyPath) {
                var resolved = resolve(dependencyPath, dependency.fullPath, options),
                    resolvedModule = resolved && resolved.pkg ? resolved : dependency.module,
                    id = resolved ? getDependencyId(resolved, resolvedModule) : false,
                    dep = id ? dependencyHash[id] : false;

                if (functionName === "resolve") {
                    if (!dep) {
                        return match;
                    } else {
                        return replaceString(dependency, match, dependencyPath, relative(dependency.rootDirname, resolved.fullPath));
                    }
                } else {
                    if (!dep) {
                        return match;
                    } else {
                        return replaceString(dependency, match, dependencyPath, dep.index, true);
                    }
                }
            }
        );
        dependency.contentSize = dependency.content.length;
    });
    options.throwError = true;
}
transitionEvents.addEndEventListener = function(node, eventListener) {
    if (END_EVENTS.length === 0) {
        requestAnimationFrame(eventListener);
    } else {
        arrayForEach(END_EVENTS, function(endEvent) {
            addEventListener(node, endEvent, eventListener);
        });
    }
};
Esempio n. 8
0
function mapChunks(chunks, dirname, options) {
    var out = {};

    arrayForEach(chunks.slice(1), function forEachChunk(chunk) {
        out[chunk.dependencies[0].index] = rename(chunk.fullPath, chunk.rootDirname, options);
    });

    return out;
}
Esempio n. 9
0
            success: function onSuccess(response) {
                var _localCardLists = _cardLists,
                    cardLists = response.data.card_lists;

                _loaded[folderId] = true;

                arrayForEach(cardLists, function each(cardList) {
                    _localCardLists[cardList.id] = cardList;
                });

                callback(undefined, cardLists);
            },
Esempio n. 10
0
RouterPrototype.use = function(path) {
    var _this = this,
        layers = this.__layers,
        middleware, middlewareStack, stack;

    if (isString(path)) {
        stack = fastSlice(arguments, 1);
    } else {
        stack = fastSlice(arguments);
        path = "/";
    }

    middlewareStack = [];

    arrayForEach(stack, function(handler) {
        var mw;

        if (isFunction(handler)) {
            middlewareStack[middlewareStack.length] = handler;
        } else if (handler.__isRouter__) {
            _this.scope(handler);
        } else if (isObject(handler)) {
            if (isFunction(handler.middleware)) {
                mw = handler.middleware;

                if (mw.length >= 3) {
                    middlewareStack[middlewareStack.length] = function(err, ctx, next) {
                        handler.middleware(err, ctx, next);
                    };
                } else {
                    middlewareStack[middlewareStack.length] = function(ctx, next) {
                        handler.middleware(ctx, next);
                    };
                }
            } else {
                throw new Error("use(handlers...) handler middleware must be a function");
            }
        } else {
            throw new Error("use(handlers...) handlers must be functions or objects with a middleware function");
        }
    });

    if (middlewareStack.length !== 0) {
        middleware = new this.Middleware(path, this, false);
        middleware.__isMiddleware__ = true;
        layers[layers.length] = middleware;
        middleware.mount(middlewareStack);
    }

    return this;
};
Esempio n. 11
0
function comn(indexPath, options) {
    var emptyPath = builtin._empty,
        out, tree, dirname, reInclude;

    options = options || {};

    options.extensions = options.extensions || options.exts || ["js", "json"];
    options.ignore = options.ignore || [];
    options.builtin = extend({}, builtin, options.builtin);
    options.beforeParse = beforeParse;
    options.packageType = options.packageType || "browser";

    if (options.node) {
        options.builtin = {};
        options.packageType = "main";
    }

    arrayForEach(options.ignore, function(value) {
        options.builtin[value] = emptyPath;
    });

    tree = new DependencyTree(indexPath, options);
    extend(options, tree.options);

    out = new Comn(tree);

    dirname = filePath.dirname(tree.fullPath);
    reInclude = tree.options.reInclude;

    tree.parse();

    arrayForEach(tree.chunks, function forEachChunk(chunk, index) {
        var outChunk = out.add(chunk);

        outChunk.name = rename(chunk.fullPath, chunk.rootDirname, options);

        replacePaths(tree, chunk.dependencies, reInclude, options);

        if (index === 0) {
            outChunk.source = render(
                out.id,
                tree.dependencies.length,
                chunk.dependencies,
                mapChunks(tree.chunks, dirname, options),
                options.parseAsync,
                tree.dirname,
                options
            );
        } else {
            outChunk.source = renderChunk(
                out.id,
                chunk.dependencies[0].index,
                chunk.dependencies,
                tree.dirname,
                options
            );
        }
    });

    return out;
}
Esempio n. 12
0
module.exports = Styles;


var css = require("./index");


function Styles() {}
StylesPrototype = Styles.prototype;

arrayForEach(properties, function(key) {
    if (indexOf(nonPrefixProperties, key) === -1) {
        StylesPrototype["set" + capitalizeString(key)] = function(value) {
            return prefix(this, key, value, null, css.stopPrefix);
        };
    } else {
        StylesPrototype["set" + capitalizeString(key)] = function(value) {
            this[key] = value;
            return this;
        };
    }
});

StylesPrototype.setTransition = function() {
    return transition(this, Array_slice.call(arguments));
};

StylesPrototype.setTextShadow = function() {
    return textShadow(this, Array_slice.call(arguments));
};