New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

twig-layout

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

twig-layout - npm Package Compare versions

Comparing version 0.1.3 to 0.1.4

2

package.json

@@ -44,3 +44,3 @@ {

},
"version": "0.1.3"
"version": "0.1.4"
}

@@ -1,11 +0,9 @@

## twig-layout
## express-twig-layout
! In Dev dont use this !
express-twig-layout is a layout system based on twig.
twig-layout is a layout system based on twig.
## Instalation
```bash
$ npm install twig-layout
$ npm install express-twig-layout
```

@@ -32,15 +30,20 @@

//set the views directory
app.set('view', './views')
app.use(layout({
extendFilter: {},
extendFunction:{}
app.set('views', './views')
app.use(layout({
cache: false,
tmpDir: './tmp',
sourceMap: false,
mode: 'eval',
}))
//home route
app.get('/home', async (req, res) => {
app.get('/home', function (req, res) {
//load the layout from the file home.html
await req.layout.loadTemplate('home.html')
req.layout.loadTemplate('home.html').then(() => {
//send the layout html
const html = await req.layout.render()
res.send(html)
req.layout.render().then((html) => {
res.send(html)
})
})
})

@@ -51,8 +54,10 @@

//load the layout from the file test.html
await req.layout.loadTemplate('test.html')
//Set the title of the block head
req.layout.getBlock('head').data.title = 'Test page'
//send the layout html
const html = await req.layout.render()
res.send(html)
req.layout.loadTemplate('test.html').then(() => {
//Set the title of the block head
req.layout.getBlock('head').data.title = 'Test page'
//send the layout html
req.layout.render().then((html) => {
res.send(html)
})
})
})

@@ -93,6 +98,4 @@

<main role="main">
<h1>{{ this.getSomething() }}</h1>
<!-- block content -->
{{ getBlockHtml('content') }}
<!-- /block content -->
<!-- block content -->
{{ getBlockHtml('content') }}
</main>

@@ -108,7 +111,7 @@

//Require the block dependency
const Block = require('node-twig-layout/block')
var Block = require('twig-layout/block')
//Block for the page
class Default extends Block {
async init () {
init () {
//set the name of the block

@@ -127,12 +130,5 @@ //the name of the block can be define in this way or for other block it can be defined in the config

/**
* A method called in the template
*/
async getSomething() {
return 'something';
}
/**
* before render callback
*/
async beforeRender () {
beforeRender () {
//Add a css file

@@ -157,9 +153,9 @@ this.layout.getBlock('head').addCss('https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css', -10)

<title>{{title}}</title>
{% for file in css %}
<link rel="stylesheet" href="{{file}}">
<title>{{ title }}</title>
{% for css in this.css %}
<link rel="stylesheet" href="{{ css.file }}">
{% endfor %}
{% for file in js %}
<script src="{{file}}"></script>
{% for js in this.js %}
<script src="{{ js.file }}"></script>
{% endfor %}

@@ -170,3 +166,3 @@ </head>

//requite the block object
const Block = require('node-twig-layout/block')
var Block = require('twig-layout/block')

@@ -178,20 +174,18 @@ //A Test class for the test page

*/
async init() {
//unsorted array
this._css = []
this._js = []
init() {
this.name = 'head'
//data array for render
this.data.css = []
this.data.js = []
this.css = []
this.js = []
}
//add css files
async addCss (cssFiles, weight = 0) {
addCss (cssFiles, weight = 0) {
if (Array.isArray(cssFiles)) {
for (let key in cssFiles) {
this._css.push({weight: weight, file: cssFiles[key]})
for (const key in cssFiles) {
this.css.push({weight: weight, file: cssFiles[key]})
}
} else if (typeof cssFiles === 'string') {
this._css.push({weight: weight, file: cssFiles})
this.css.push({weight: weight, file: cssFiles})
} else {

@@ -203,9 +197,9 @@ throw Error('Invalid addCss argument')

//add js files to the data object
async addJs (jsFiles) {
addJs (jsFiles) {
if (Array.isArray(jsFiles)) {
for (let key in jsFiles) {
this._js.push({weight: weight, file: jsFiles[key]})
for (const key in jsFiles) {
this.js.push({weight: weight, file: jsFiles[key]})
}
} else if (typeof jsFiles === 'string') {
this._js.push({weight: weight, file: jsFiles})
this.js.push({weight: weight, file: jsFiles})
} else {

@@ -219,13 +213,8 @@ throw Error('Invalid addJs argument')

*/
async beforeRender() {
beforeRender() {
const sort = function(a, b) {
return a.weight - b.weight
}
this._css.sort(sort);
for (const key in this._css)
this.data.css.push(this._css[key].file)
this._js.sort(sort);
for (const key in this._js)
this.data.js.push(this._js[key].file)
this.css.sort(sort);
this.js.sort(sort);
}

@@ -243,3 +232,3 @@ }

<div>
<h1>Home page</h1>
<h1>{{ this.title }}</h1>
</div>

@@ -249,7 +238,7 @@ </template>

//requite the block object
const Block = require('node-twig-layout/block')
var Block = require('twig-layout/block')
//A Block class for the home page
class Home extends Block {
async init () {
init () {
this.page ='page/default.html'

@@ -259,2 +248,5 @@ //name of the parent block of this block

this.parent = 'content'
this.name = 'home'
this.title = 'Home page'
}

@@ -275,3 +267,3 @@

<div class="test">
<h1>Test</h1>
<h1>{{ this.title }}</h1>
</div>

@@ -281,3 +273,3 @@ </template>

//requite the block object
const Block = require('node-twig-layout/block')
var Block = require('twig-layout/block')

@@ -290,3 +282,5 @@ //A Test class for the test page

//here the block content, it is defined in the file page/default.html
this.parent= 'content'
this.parent = 'content'
this.name = 'test'
this.title = 'Test'
}

@@ -293,0 +287,0 @@ }

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