Security News
tea.xyz Spam Plagues npm and RubyGems Package Registries
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
laravel-blade-js
Advanced tools
Readme
To start work with blade, you must to create blade Renderer
:
const BladeRenderer = require('laravel-blade-js').Renderer;
And create new instance of BladeRenderer
:
let renderer = new BladeRenderer();
You can set renderer config:
/**
* @param {Object} config
* @param {String} [config.views] - Input views folder, default is `__dirname/views`.
* @param {Boolean} [config.cacheEnabled] - Enable or disable compiled view cache, default is true.
* @param {String} [config.cache] - Compiled views cache folder, default is `__dirname/cache`.
* @param {Boolean} [config.production] - Minimizes filesystem interaction, speed-up all views rendering, default is false.
*
* @return {Renderer}
*/
BladeRenderer.set(config);
To render your view('*.bjs'):
/**
* @param {String} view - View name to render
* @param {Object} [properties] - Properties can be used inside view
* @param {Object} [settings] - Settings can be used in custom functions
*
* @return {String}
*/
Renderer.render(view, properties = {}, settings = {});
bladeRenderer.render('index', {
'content': 'Hello world'
}, {
lang: 'ru' // Give language for custom variables(functions)
});
Or async:
/**
* @param {String} view - View name to render
* @param {Object} [properties] - Properties can be used inside view
* @param {Object} [settings] - Settings can be used in custom functions
*
* @return {Promise}
*/
Renderer.renderAsync(view, properties = {}, settings = {});
Add custom blade function:
/**
* Adds blade function(start at @).
*
* @param {String} name - The function name
* @param {Object} object - The function object
* @param {Function} object.callback - The function callback(parameters). Must return expression will be instead of blade function.
* @param {Boolean} [object.output] - If true, this function has an output. Default is false.
* @param {Boolean} [object.escape] - If true, output of the function will be escaped(html). Default is false.
*/
Renderer.registerFunction(name, object);
bladeRenderer.registerFunction('lang', {
callback: parameters => `trans(${parameters})`, // Will compile blade '@lang(...)' to javascript 'trans(...)'
output: true, // True if function adds anything to content
escape: true // Will escape all output
});
Add custom blade variable(function):
/**
* Adds a shared variable for all views.
*
* @param {String} name - Name of shared variable
* @param value - Value of shared variable
* @param {Boolean} interactive - If true, value must be a function and it will be called on view rendering start
*/
Renderer.registerVariable(name, value);
/*
* {Object} view is object that contains {properties, settings}.
* Warning! view.properties can be empty in nested view.
* If you want to use something like this even in nested view, use
* view.settings.
*/
bladeRenderer.registerVariable('trans', (view, key) => {
let entry = Language.get(view.settings.lang, key);
return entry;
});
Testing view:
Results:
production
is true
then 0.5-5ms.FAQs
Laravel's blade templating engine for JavaScript
The npm package laravel-blade-js receives a total of 1 weekly downloads. As such, laravel-blade-js popularity was classified as not popular.
We found that laravel-blade-js demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
Tea.xyz, a crypto project aimed at rewarding open source contributions, is once again facing backlash due to an influx of spam packages flooding public package registries.
Security News
As cyber threats become more autonomous, AI-powered defenses are crucial for businesses to stay ahead of attackers who can exploit software vulnerabilities at scale.
Security News
UnitedHealth Group disclosed that the ransomware attack on Change Healthcare compromised protected health information for millions in the U.S., with estimated costs to the company expected to reach $1 billion.