Last active
May 17, 2017 17:56
-
-
Save gkspranger/086593b7c5bb832634dfc8f079fbf9b6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Commands: | |
// hubot handlebar me - example of how to use handlebars | |
const logger = require("winston"); | |
const handlebars = require("handlebars"); | |
const fs = require("fs"); | |
module.exports = function(robot) { | |
// this is the controller | |
robot.respond(/handlebar me/i, function(message) { | |
// this is me getting the view | |
fs.readFile('./views/mytemplate.txt', 'utf-8', function(error, source) { | |
var template = handlebars.compile(source); | |
// this is me passing the model into the view | |
var output = template({ | |
line1: "this is line 1", | |
arr1: [ | |
"this", | |
"is", | |
"an", | |
"array" | |
], | |
obj1: { | |
obj: "object within an object" | |
} | |
}); | |
// this is me replying to the hubot command | |
message.send(output); | |
}); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment