I've looked at the dojo-node module (https://github.com/agebrock/dojo-node) and the author says that Dojo 1.7 will support Node.js natively.
There is a configNode.js file in Dojo 1.7, but I'm not sure how to use it to have Dojo up and running.
http://download.dojotoolkit.org/release-1.7.0b1/dojo-release-1.7.0b1/dojo/_base/
Can somebody point me into the right direction? Perhaps show me a small example also?
Appreciate any help I can get.
Here's my solution, although it may look tricky since I can't search out any official examples, I have to read the source and work it out:
Assume dojo is under /home/root/dojoroot/dojo/dojo.js
Create /home/root/mynode/test.js with content:
dojoConfig = {packages:[{name: 'test', location: '../../mynode'}]};
require('../dojoroot/dojo/dojo');
Create /home/root/mynode/main.js with content:
define(['dojo/date'], function(date){
console.log('Hi ' + date.getTimezoneName(new Date()) + ', welcome to NodeJS!');
});
$> node /home/root/mynode/test.js load=test
Related
I’m having an issue where buttons and actions in hero and adaptive cards won’t wrap text. I have searched the internet and everyone is mentioning a webchat.js and botchat.js files that can be adjusted to fix this. I can’t seem to find those in my code. Has the name changed? I know botchat was changed to webchat. Would anyone happen to know where to fix this in the Basic Bot NodeJS implementation SDK V4?
Assuming you are using webchat, you could use plain css. This worked for me:
.ac-pushButton > div {
white-space: normal !important;
}
I was able to find an answer in node_modules > wordwrap. There is a function that you can call in there to wrap any text you'd like. Thank you #Hessel for the help.
var wrap = require('wordwrap')(70);
return CardFactory.heroCard(
'',
answer,
CardFactory.images([]),
CardFactory.actions([
{
type: 'postBack',
title: wrap(YOUR_TEXT),
value: YOUR_VALUE
}
])
);
I wanted to follow this technique https://www.liquidlight.co.uk/blog/article/creating-svg-sprites-using-gulp-and-sass/ but when I tried to use gulp-svg-sprites I had problem with installation on Win 7. So I used svg-sprite but then I got
"However I got events.js:72 thro er; // UInhandled error event. ArgumentError: SVGSpriter.compile: "{}" is not a valid mode configuraiton."
I guess I should change these lines below for gulp-svg-sprite. Does anyone can tell me what I should change?
return gulp.src(paths.sprite.src)
.pipe(svgo())
.pipe(svgSprites({
cssFile: paths.sprite.css,
preview: false,
layout: 'diagonal',
padding: 5,
svg: {
sprite: paths.sprite.svg
},
templates: {
css: require("fs").readFileSync(paths.templates.src + 'sprite-template.scss', "utf-8")
}
}))
.pipe(gulp.dest(basePaths.dest));
I understand it might be too late but as the author of svg-sprite (and its Grunt / Gulp wrappers) I suppose you got confused by the incompatibility between gulp-svg-sprites (which was written by Shane Osbourne as a stop-gap until I had ported svg-sprite to Gulp myself; mind the "s" at the end) and the final gulp-svg-sprite that is referenced in the liquidlight article. You could probably solve your configuration woes by using the online configuration kickstarter that's available in the meantime.
I have asked google like million times and haven't got any concrete answers... I would like to use, say, following code in the jade template... however it gives an error on the first line... Please could you point me to the right direction... Thanks in advance!!
var fs = require('fs');
fs.unlink('/tmp/hello', function (err) {
if (err) throw err;
console.log('successfully deleted /tmp/hello');
});
First, you're missing hyphens to escape your template code to JavaScript. Add a hyphen to each line for starters.
- var something = 0; // example!
Source: Jade reference
Second, #barry-johnson is right to point out your Node code probably belongs somewhere else. It looks like you're trying to clean up a directory during the build. There are other, better ways to accomplish this. I suggest taking a look at the Writing Plugins page for more info.
If that doesn't suit you, please describe in more detail what you're trying to accomplish for better guidance. I hope that helps!
I want to use compiled jade templates on client side. How should I compile them to get javascript files ?
https://github.com/visionmedia/jade
Yes you can! https://github.com/techpines/asset-rack#jadeasset
I just open sourced "asset-rack", a nodejs project that can can precompile jade templates and serve them in the browser as javascript functions.
This means that rendering is blazingly fast, even faster then micro-templates because there is no compilation step in the browser.
First you set it up on the server as follows:
new JadeAsset({
url: '/templates.js',
dirname: __dirname + '/templates'
});
If you template directory looked like this:
templates/
navbar.jade
user.jade
footer.jade
Then all your templates come into the browser under the variable "Templates":
$('body').append(Templates.navbar());
$('body').append(Templates.user({name: 'mike', occupation: 'sailor'});
$('body').append(Templates.footer());
#coffeescript
jade = require 'jade'
data = '#menu'
options =
client: true
compileDebug: false
fn = jade.compile data, options
console.log fn.toString()
Look for proposed solutions in the jade issue 149 discussion. Unfortunately, there is no built-in ready for use option, as I know.
You should probably look at integrating this into a Grunt build task.
See grunt-contrib-jade
Blade is a Jade-like HTML template engine that has a built-in middleware for serving compiled templates to the client. :) Check it out!
This question is a bit dated, but there is a method of compiling Jade templates,
var jade = require('jade');
var fn = jade.compile(jadeTemplate);
var htmlOutput = fn({
maintainer: {
name: 'Forbes Lindesay',
twitter: '#ForbesLindesay',
blog: 'forbeslindesay.co.uk'
}
})
Just got to the tutorial and search for compile, or the API under
jade.compile(source, options)
Be sure to set, compileDebug so you get the source,
Set this to false to disable debugging instrumentation (recommended in production). Set it to true to include the function source in the compiled template for better error messages (sometimes useful in development).
Only info I found was this:
http://forrst.com/posts/Node_js_Jade_Import_Jade_File-CZW
I replicated the suggested folder structure (views/partials) But it didn't work, as soon as I put
!=partial('header', {})
!=partial('menu', {})
into index.jade, I get a blank screen, the error message I receive from jade is:
ReferenceError: ./views/index.jade:3
1. 'p index'
2. ''
3. '!=partial(\'header', {})'
partial is not defined
I'd be very grateful for any help ! (I strongly prefer not to use express.js)
Jade has a command called include. Just use
include _form
given that the filename of the partial is *_form.jade*, and is in the same directory
As of August 2012 (possibly earlier) Partials have been removed from Express.
A lot of tutorials are now out of date. It seems that you can replicate much of the partial functionality with include.
Eg.
movies.jade
div(id='movies')
- each movie in movies
include movie
movie.jade
h2= movie.title
.description= movie.description
HTH
With the latest node/express I get the following movies.jade template to call partials:
div(id='movies')
- each movie in movies
!=partial('movie', movie)
where I have movie.jade in the views directory alongside movies.jade.
movies.jade is called from app.js with:
res.render('movies', { movies: [{ title: 'Jaws' }, { title: 'Un Chien Andalou' }] });
I think partial rendering is done in express, so you will have to snag that code or write your own.
I have my own helper class for jade rendering with partials that you can use or get some ideas from here, (it's using Joose and Cactus)