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

gulp-ejs-monster

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-ejs-monster

OBT

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
107
Maintainers
1
Weekly downloads
 
Created
Source

gulp-ejs-monster

Open Beta test npm es2015 license

Gulp plugin for ejs. The project is inspired by ejs-locals

js happiness style


Disclaimer v0.1.0

This is an open test version,
No guarantee of correct operation
You can use it at your own risk.


usage example

const gulp = require('gulp');
const lodash = require('lodash');

const ejsMonster = require('gulp-ejs-monster');

// give +100500 for incremental build
const isWatching = true;
const watchAndTouch = require('gulp-watch-and-touch'); 
const fileWatcher = watchAndTouch(gulp);

// format
const isProduction = true;
const jsBeautify = require('js-beautify');

// Send some data for your workflow
const ejsData = {
    // some data
    // for example
    NODE_MODULES: {
        _: lodash
    },
    PROJECT_STATS: {
        version: '1.0.0'
        // ...
    }
};

// render options
const ejsOptions = {
    ext: '.html', // or .php, or ...
    layouts: './src/ejs/layouts', // resolve path
    partials: './src/ejs/partials', // resolve path
    configs: './src/ejs/configs', // resolve path
    controllers: './src/ejs/controllers', // resolve path
    reservedLocalsKeys: [ // protected properties from writing
        'NODE_MODULES',
        'PROJECT_STATS'
    ],
    afterRender: function(markup, file, data) {
        if (isWatching) {
        	let filePath = file.path;
			let sources = data.__INSTANCE.SOURCES.files[filePath] || [];
			
            fileWatcher(filePath, filePath, sources);
        }
        
        if (__ARGS.flags.production) {
        	let beautyMarkup = jsBeautify.html(markup, {
        		indent_level: 0,
                eol: '\n',
                max_preserve_newlines: 1,
                // ...
        	});
        	
        	return beautyMarkup;
        }
    }
};

// task
gulp.task('ejs', function(done) {
    return gulp.src('./src/ejs/*.ejs')
        .pipe(ejsMonster(ejsData, ejsOptions))
        /// ...
})

markup

base.ejs layout

<!DOCTYPE html>
<html lang="ru" dir="ltr">
    <head>
        <title>blocks</title>
    </head>
    <body>
        <div class="wrapper">
            <%- blocks.header %>
            <div class="container">
                <%- blocks.breadcrumbs %>
                <%- body -%>
            </div>
            <%- blocks.footer %>
        </div>
    </body>
</html>

index.ejs view

<%
    layout('base');
    
    importController('utils.js');
    importConfig('main-menu.js'); 
    
    locals.View = {
        title: 'Главная страница',
    };
    
    block('header', partial('structure/header', {
    	title: View.title
    }));
    block('footer', partial('structure/footer'));
-%>
<h1>Hello world!</h1>
<%- partial('widgets/features') %> 
<%- partial('widgets/discounts') %> 
<%- partial('widgets/special-offers') %> 
<%- partial('widgets/popular-services') %>  
<%- partial('widgets/promotions') %> 
<%- partial('widgets/reviews') %> 

header.ejs partial

<%
    let {
        title = 'default header title',
        subTitle = 'default header subtitle'
    } = ENTRY;
-%>
<header>
    <div class="center">
        <h2 class="title"><%- title %></h2>
        <div class="subtitle"><%- subtitle %></div>
    </div>
</header>

Keywords

FAQs

Package last updated on 23 Jun 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

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