How to use the string-template.bind function in string-template

To help you get started, we’ve selected a few string-template examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Raynos / http-framework / examples / mvc / features / user / index.js View on Github external
// to enable using sub routes in our controller we create
    // a new router. This router is a ChildRouter and will delegate
    // all error and 404 handler to it's parent. i.e. the global
    // application
    var controller = Router({ prefix: prefix })

    // We instantiate our model here with the database configuration
    // the model is local to this user feature
    var model = UserModel(config.db)
    
    // we set up configuration to pass to our views.
    // we also set up an urlMap so that views are not hard coded
    // to specific paths
    var viewsConfig = { layout: config.layout, urlMap: {
        "user": format.bind(null, prefix + "/{userId}"),
        "userEdit": format.bind(null, prefix + "/{userId}/edit"),
        "userPet": format.bind(null, prefix + "/{userId}/pet"),
        "pet": format.bind(null, config.features.pet + "/{petId}")
    } }

    // optionally /. so its /user & /user/
    controller.addRoute("/?", function (req, res, opts, cb) {
        model.getAll(function (err, users) {
            if (err) {
                return cb(err)
            }

            sendHtml(req, res, usersPage(users, viewsConfig))
        })
    })
github Raynos / http-framework / examples / mvc / features / user / index.js View on Github external
// to enable using sub routes in our controller we create
    // a new router. This router is a ChildRouter and will delegate
    // all error and 404 handler to it's parent. i.e. the global
    // application
    var controller = Router({ prefix: prefix })

    // We instantiate our model here with the database configuration
    // the model is local to this user feature
    var model = UserModel(config.db)
    
    // we set up configuration to pass to our views.
    // we also set up an urlMap so that views are not hard coded
    // to specific paths
    var viewsConfig = { layout: config.layout, urlMap: {
        "user": format.bind(null, prefix + "/{userId}"),
        "userEdit": format.bind(null, prefix + "/{userId}/edit"),
        "userPet": format.bind(null, prefix + "/{userId}/pet"),
        "pet": format.bind(null, config.features.pet + "/{petId}")
    } }

    // optionally /. so its /user & /user/
    controller.addRoute("/?", function (req, res, opts, cb) {
        model.getAll(function (err, users) {
            if (err) {
                return cb(err)
            }

            sendHtml(req, res, usersPage(users, viewsConfig))
        })
    })

    controller.addRoute("/:userId/edit", function (req, res, opts, cb) {
github Raynos / http-framework / examples / mvc / features / user / index.js View on Github external
// a new router. This router is a ChildRouter and will delegate
    // all error and 404 handler to it's parent. i.e. the global
    // application
    var controller = Router({ prefix: prefix })

    // We instantiate our model here with the database configuration
    // the model is local to this user feature
    var model = UserModel(config.db)
    
    // we set up configuration to pass to our views.
    // we also set up an urlMap so that views are not hard coded
    // to specific paths
    var viewsConfig = { layout: config.layout, urlMap: {
        "user": format.bind(null, prefix + "/{userId}"),
        "userEdit": format.bind(null, prefix + "/{userId}/edit"),
        "userPet": format.bind(null, prefix + "/{userId}/pet"),
        "pet": format.bind(null, config.features.pet + "/{petId}")
    } }

    // optionally /. so its /user & /user/
    controller.addRoute("/?", function (req, res, opts, cb) {
        model.getAll(function (err, users) {
            if (err) {
                return cb(err)
            }

            sendHtml(req, res, usersPage(users, viewsConfig))
        })
    })

    controller.addRoute("/:userId/edit", function (req, res, opts, cb) {
        model.get(opts.userId, function (err, user) {
github Raynos / http-framework / examples / mvc / features / user / index.js View on Github external
// all error and 404 handler to it's parent. i.e. the global
    // application
    var controller = Router({ prefix: prefix })

    // We instantiate our model here with the database configuration
    // the model is local to this user feature
    var model = UserModel(config.db)
    
    // we set up configuration to pass to our views.
    // we also set up an urlMap so that views are not hard coded
    // to specific paths
    var viewsConfig = { layout: config.layout, urlMap: {
        "user": format.bind(null, prefix + "/{userId}"),
        "userEdit": format.bind(null, prefix + "/{userId}/edit"),
        "userPet": format.bind(null, prefix + "/{userId}/pet"),
        "pet": format.bind(null, config.features.pet + "/{petId}")
    } }

    // optionally /. so its /user & /user/
    controller.addRoute("/?", function (req, res, opts, cb) {
        model.getAll(function (err, users) {
            if (err) {
                return cb(err)
            }

            sendHtml(req, res, usersPage(users, viewsConfig))
        })
    })

    controller.addRoute("/:userId/edit", function (req, res, opts, cb) {
        model.get(opts.userId, function (err, user) {
            if (err) {

string-template

A simple string template function based on named or indexed arguments

MIT
Latest version published 8 years ago

Package Health Score

67 / 100
Full package analysis

Popular string-template functions