why do u need to extract text between paragraph tag on server side??
that will be something we do on client side js
in your case, context
should be a parameter you pass to jade view, by res.render('view', {context : "My content."})
or res.locals
so you can deal with your #{context}
in Jade view
if you want to declare variable context
in Jade view
it should be like
-var context= "My content."
p #{content}
reply to jsdom
code
in your code
posts[i]
is undefined.
I suppose u want to iterate posts, so you should use a iterator
here
you can use async
module here
in this case, map
is very suitable
see here for document -> async map
Creation.findAll({where: "state = 1",order: 'id DESC', limit: 2}).success(function(creations) {
Post.findAll({where: "state = 1",order: 'id DESC', limit: 2}).success(function(posts){
async.map(posts, function(postEntity, callback){
jsdom.env(
postEntity.content,
["http://code.jquery.com/jquery.js"],
function(errors, window) {
//deal with errors
if(errors) return callback(errors);
postEntity.content = window.$("p").text();
callback(null, postEntity);
}
);
}, function(err, transformedPosts){
if(err) return callback(err);
res.render('index', {
creations: creations,
posts: transformedPosts,
title: "Anthony Cluse | Portfolio"
});
});
});
});
FYI, you should use control flow library to manage your callback code
otherwise, it would be really hard to maintain
I recommend async
(.*?)
– Jean-Philippe Leclerc Feb 20 '13 at 00:28(.*?)<\/p>/g. You only need to remove the quotes. Plus, you will need the function provided in the other post.
– Jean-Philippe Leclerc Feb 20 '13 at 00:36(.*?)<\/p>/g); //extract all the sentence, it doesn't work.
– tonymx227 Feb 20 '13 at 00:41(.*?)<\/p>/g); return tab.join(''); }
– tonymx227 Feb 20 '13 at 01:09