Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

egg-view-swig-pagelet

Package Overview
Dependencies
Maintainers
4
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

egg-view-swig-pagelet - npm Package Compare versions

Comparing version 1.0.0 to 1.1.0

45

app/extend/context.js
'use strict';
const PAGELET_SWIG_VIEW = Symbol('context#PageletSwigView');
const View = require('../../lib/view');
const path = require('path');
module.exports = {
/**
* swig pagelet engine
*/
get swigPageletView() {
if (!this[PAGELET_SWIG_VIEW]) {
this[PAGELET_SWIG_VIEW] = new View(this);
}
return this[PAGELET_SWIG_VIEW];
},
/**
* render layout file

@@ -23,5 +13,32 @@ * @method Context#renderPage

*/
* render(name, locals, options) {
this.body = yield this.swigPageletView.renderPage(name, locals, options);
* render(name, locals, options = {}) {
const config = this.app.config || {};
const pagelets = this.get('X-Pagelets') || this.query._pagelets;
if (pagelets) {
this.type = 'json';
locals._pagelets = pagelets;
} else {
this.type = 'html';
}
locals = Object.assign({}, {
ctx: this,
request: this.request,
helper: this.helper,
}, this.locals, locals);
const layout = locals.layout || options.layout || config.swigPagelet.layout;
const normalName = name.replace(new RegExp(`${config.view.defaultExtension}$`, ''), '');
const fakePath = path.join(
config.view.root[0],
normalName.replace(/\//g, '_') + config.view.defaultExtension
);
const source = `{% extends '${layout}' %}{% block content %}{% require $id='page/${normalName}' %}{% endblock %}`;
const tplFn = this.app.swig.compile(source, { filename: fakePath });
this.body = tplFn(locals);
},
};

@@ -0,1 +1,8 @@

1.1.0 / 2017-05-26
==================
* feat: update deps and remove pageletView class (#3)
* chore: add missing history
1.0.0 / 2017-04-12

@@ -2,0 +9,0 @@ ==================

@@ -1,4 +0,4 @@

{
{
"name": "egg-view-swig-pagelet",
"version": "1.0.0",
"version": "1.1.0",
"description": "基于egg-view-swig插件扩展, 支持scrat pagelet 模式",

@@ -26,12 +26,8 @@ "eggPlugin": {

"autod-egg": "^1.0.0",
"cheerio": "^0.22.0",
"egg": "^1.0.0",
"egg-bin": "^3.2.1",
"egg-mock": "^3.2.0",
"egg-view-swig": "^0.1.0",
"egg": "^1.3.0",
"egg-bin": "^3.4.0",
"egg-mock": "^3.7.0",
"egg-view-swig": "^1.0.0",
"eslint": "^3.19.0",
"eslint-config-egg": "^3.2.0",
"expect.js": "^0.3.1",
"supertest": "^2.0.1",
"thunk-mocha": "^1.0.8",
"webstorm-disable-index": "^1.0.11"

@@ -66,2 +62,2 @@ },

}
}
}
SocketSocket SOC 2 Logo

Product

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

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc