Socket
Socket
Sign inDemoInstall

render_and_script

Package Overview
Dependencies
102
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.0.2 to 0.0.3

lib/runScriptFile.js

37

lib/renderAndScript.js

@@ -1,14 +0,25 @@

var jsdom = require('jsdom'),
async = require('async');
var path = require('path'),
jsdom = require('jsdom'),
async = require('async'),
_ = require('underscore');
// renderして、クライアントサイドのスクリプトを実行してから返す
var renderAndScript = function (view, options, script) {
var renderAndScript = function (view, options, scripts) {
var self = this;
// options省略処理
if (typeof options == 'function') {
script = options;
options = {};
}
scripts = scripts || [];
// 実行する関数のリスト
var scriptFns = _.select(scripts, function (script) {
return typeof script == 'function';
});
// 関数実行の前に読み込むライブラリのリスト
var scriptFiles = _.select(scripts, function (script) {
return typeof script == 'string';
});
scriptFiles = _.map(scriptFiles, function (scriptFile) {
return path.join(__dirname + '/../', scriptFile);
});
async.waterfall([function (next) {

@@ -19,8 +30,14 @@ // render engineによるレンダリング

// レンダリング結果をもとにjsdom環境を作る
jsdom.env(html, [], next);
jsdom.env(html, scriptFiles, next);
}, function(window, next) {
// scriptを実行 実行後のwindowを次へ渡す
script(window, function (err) {
async.forEachSeries(scriptFns, function (script, next) {
script(window, function (err) {
next(err);
});
}, function (err) {
next(err, window);
});
}, function(window, next) {

@@ -27,0 +44,0 @@ // windowからhtmlを再度取り出して、send

{
"name": "render_and_script",
"version": "0.0.2",
"version": "0.0.3",
"scripts": {

@@ -9,3 +9,4 @@ "start": "node app"

"jsdom": "*",
"async": "*"
"async": "*",
"underscore": "*"
},

@@ -12,0 +13,0 @@ "devDependencies": {

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc