Can anyone give me any pointers/examples on how to use your own custom helpers with grunt-static-handlebars? I've read the documentation and can't see how to do this.
I created helpers to use when using handlebars client side and I'd love to be able to replicate that on the serverside when building pages but currently can't work out how to do that.
I tried to create the fullName helper from the handlebars docs. I set my helpersPath to /helpers and created a fullName.js with this code
Handlebars.registerHelper('fullName', function(person) {
return person.firstName + " " + person.lastName;
});
Then I added it to the base.json config file
{
...
"helpers": [
"fullName"
],
...
}
And then attempt to use it in a partial {{fullName person}}
But when I attempt to run the grunt task I getting an error. Fatal error: Object #<Object> has no method 'call'
Any ideas where I'm going wrong?
You can try out grunt-handlebars-to-static, which have a example project available solving your exact problem. Also the task is highly flexible for all different kinds of folder arrangement. The docs gives two examples of most typical folder arrangement as starters.
Disclaimer: I am the author :) Cheers.
Related
I recently installed a package w/ Bower from here: https://github.com/takuyaa/kuromoji.js/
Reading the installation on the github, I basically copied and pasted from the guide:
kuromoji.builder({ dicPath: "../bower_components/kuromoji/dict/" }).build(function (err, tokenizer) {
// tokenizer is ready
var path = tokenizer.tokenize("すもももももももものうち");
console.log(path);
});
However, I do not know what the "kuromoji" should refer to. Here is the obvious error:
Uncaught ReferenceError: kuromoji is not defined
Here is a screenshot of my directory tree:
Not sure how to properly use this.
import kuromoji from 'kuromoji'
That provides the 'kuromoji' object you're trying to reference
I am developing an Ionic app with $cordovaSQLite installed, but when I tried running openDatabase, I got the error "TypeError: Cannot read property 'openDatabase' of undefined".
I double checked my code that the openDatabase call is inside the $ionicPlatform.ready function and the database file has been properly installed, may I have any advices?
Thanks and Regards,
Jimmy
First make sure you have ngCordova properly installed. (install instructions can be found on ngcordova website), along with the named plugin.
When you get undefined error you should always look if you have the dependency defined. That is the most common mistake with people starting with AngularJS.
Example code:
//inject your dependencies;
ControllerOrConfigFunction.$inject = ["$scope", "$cordovaSQLite"]
function ControllerOrConfigFunction($scope,$cordovaSQLite){
//your code here
}
This applies to all functions in which you are using the $cordovaSQLite plugin.
You can also find a great example on ngCordova website.
There are multiple ways you can define your Dependency Injection in AngularJs, i recommend it for now, after that take a look at ng-annotate.
if (window.cordova) {
db = $cordovaSQLite.openDB({ name: "my.db" }); //Device
console.log("Android");
}
else
{
db = window.openDatabase("my.db", '1', 'my', 1024 * 1024 * 100); // Browser
console.log("browser");
}
I started compiling my Ember.js templates server-side using the "ember-template-compiler.js" file mentioned here.
After compiling my templates and transpiling the output with Babel, I get a file which contains all of my templates assigned to an object called "export". Here are the first few lines:
"use strict";
Object.defineProperty(exports, "__esModule", {
value: true
});
exports["default"] = Ember.HTMLBars.template((function () {
return {
meta: {
...
Now I've integrated jQuery, "ember.prod.js" and that file within the front-end. I thought it would work, but the only thing I get from the console, is:
ReferenceError: Can't find variable: exports
Why is "exports" not defined?
P.S.: Usually, I would use "ember-cli" for all of this. But in my current project, I need to do everything by myself (please don't ask, why).
But it should work, am I right? I mean, I did it exactly like it was stated here.
Fixed the problem by writing my own template compiler for Gulp istead of trying to use the one in Ember CLI: https://github.com/leo/gulp-ember-compiler
I want to use offline sails.js documentation in my system.
The documentation of sails.js is maintained at the link Sails.js Documentation.
As they mention there, they use doc-templater to build the documentation. I tried the code below in the node REPL.
require('doc-templater')().build({
remote: 'git#github.com:balderdashy/sails.git',
remoteSubPath: '',
cachePath: '/code/sandbox/doctemplatertest/foo/bar/cache/',
htmlDirPath: '/code/sandbox/doctemplatertest/foo/bar/html',
jsMenuPath: '/code/sandbox/doctemplatertest/foo/bar.jsmenu'
}, function (e,r) {
if (e) {console.log('ERROR:\n',require('util').inspect(e, false, null));}
else console.log('RESULT:\n',require('util').inspect(r, false, null));
});`
But it is not working; I'm getting this result:
RESULT:
[]
undefined
Can anyone please show the way it works.
It looks like they never got that module quite working:
https://github.com/balderdashy/sails-docs/issues/523#issuecomment-136823015
Alternatively you can clone the git repo of the documentation website:
https://github.com/balderdashy/www.sailsjs.org
And run it with sails?
I recently tried to use the gulp Gist posted here:
Everything builds fine, but in the browser I get an error in the generated templates.js file:
global.Handlebars = require("handlebars");
module.exports = Ember.TEMPLATES["index"] = Ember.Handlebars.template(function anonymous(Handlebars,depth0,helpers,partials,data) {
The error claiming, basically, that 'module' is undefined...
I'm getting a strong feeling that I'm missing something extremely trivial here.
Thanks in advance
Because this causes the file to be wrap in some shim javascript:
'templates': {
path: 'public/js/templates.js',
exports: 'Ember.TEMPLATES'
},
Remove it and you'll be fine.
And requiring Ember in the prebundle is useless if you are also requiring it from your code.