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

@frctl/adapters

Package Overview
Dependencies
Maintainers
2
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@frctl/adapters - npm Package Compare versions

Comparing version 0.1.1 to 0.2.0

16

index.js

@@ -30,17 +30,1 @@ /**

};
/**
* This is passed to the precompile function and called when precomilation is complete
* @callback precompileComplete
* @global
* @param {error|null} err Runtime errors, if applicable
* @param {function} result The render method
*/
/**
* This is passed to the render function and called when rendering is complete
* @callback renderComplete
* @global
* @param {error|null} err Runtime errors, if applicable
* @param {string} result The html output of the renderer
*/

4

package.json
{
"name": "@frctl/adapters",
"version": "0.1.1",
"description": "Adapters for rendering fractal component files with different template engines",
"version": "0.2.0",
"description": "Work-in-progress template engine adapters for Fractal v2",
"homepage": "https://github.com/frctl/adapters",

@@ -6,0 +6,0 @@ "repository": "https://github.com/frctl/adapters",

@@ -22,10 +22,12 @@

const fractal = require('@frctl/fractal');
const adapters = require('@frctl/adapters');
const parser = fractal({
src: './path/to/components'
src: './path/to/components',
adapters: [
adapters.nunjucks
]
});
parser.addAdapter('nunjucks'); // nunjucks / handlebars / react
parser.parse(function(err, library) {
parser.parse(function(err, components) {
if (err) {

@@ -35,4 +37,11 @@ return console.log(err);

const view = library.findView('button', 'nunjucks'); // get the nunjucks template for the 'button' component
library.renderView(view, {label: 'Click me!'}, function(err, html){
const component = components.find({
name: 'button'
});
const view = component.files.find({
role: 'view',
adapter: 'nunjucks'
}); // get the nunjucks template for the 'button' component
components.renderView(view, {label: 'Click me!'}, function(err, html){
console.log(html);

@@ -39,0 +48,0 @@ });

@@ -0,1 +1,2 @@

/* eslint import/no-dynamic-require: "off", "no-unused-vars": "off" */
/**

@@ -21,9 +22,12 @@ * Fractal Handlerbars Adapter module

/**
* This method takes a file object and context data and outputs rendered html
* @param {Object} file An object containing Fractal file information
* @param {Object} context An object that supplies data to the component
* @param {renderComplete} done A callback function that is passed an Error if applicable and the html string result
* This method takes a set of arguments including a file object and
* context data and outputs rendered html
*
* @param {array} args Arguments array
* @param {object} state Current component and file collection states
* @param {Fractal} app The current Fractal instance
*/
render(file, context, done) {
render(args, state, app) {
const Handlebars = require('handlebars');
let [file, context, opts, done] = args;
let error = null;

@@ -30,0 +34,0 @@ let html;

@@ -0,1 +1,2 @@

/* eslint import/no-dynamic-require: "off", "no-unused-vars": "off" */
/**

@@ -22,9 +23,12 @@ * Fractal Nunjuck Adapter module

/**
* This method takes a file object and context data and outputs rendered html
* @param {Object} file An object containing Fractal file information
* @param {Object} context An object that supplies data to the component
* @param {renderComplete} done A callback function that is passed an Error if applicable and the html string result
* This method takes a set of arguments including a file object and
* context data and outputs rendered html
*
* @param {array} args Arguments array
* @param {object} state Current component and file collection states
* @param {Fractal} app The current Fractal instance
*/
render(file, context, done) {
var env = new nunjucks.Environment(new nunjucks.FileSystemLoader(file.base));
render(args, state, app) {
let [file, context, opts, done] = args;
const env = new nunjucks.Environment(new nunjucks.FileSystemLoader(file.base));
env.render(file.relative, context, done);

@@ -31,0 +35,0 @@ }

@@ -1,2 +0,2 @@

/* eslint import/no-dynamic-require: "off" */
/* eslint import/no-dynamic-require: "off", "no-unused-vars": "off" */
/**

@@ -38,8 +38,11 @@ * Fractal React Adapter module

/**
* This method takes a file object and context data and outputs rendered html
* @param {Object} file An object containing Fractal file information
* @param {Object} context An object that supplies data to the component
* @param {renderComplete} done A callback function that is passed an Error if applicable and the html string result
* This method takes a set of arguments including a file object and
* context data and outputs rendered html
*
* @param {array} args Arguments array
* @param {object} state Current component and file collection states
* @param {Fractal} app The current Fractal instance
*/
render(file, context, done) {
render(args, state, app) {
let [file, context, opts, done] = args;
try {

@@ -46,0 +49,0 @@ const Component = interOp(require(path.resolve(file.path)));

@@ -57,7 +57,7 @@ /* eslint no-unused-expressions : "off" */

handlebarsAdapter.files = [];
handlebarsAdapter.render(fileWithError, context, function (err, result) {
handlebarsAdapter.render([fileWithError, context, {}, function (err, result) {
expect(result).to.not.exist;
expect(err.message).to.match(/Parse error/);
done(null);
});
}]);
});

@@ -67,3 +67,3 @@ it(`should render simple file correctly`, function (done) {

handlebarsAdapter.files = [];
handlebarsAdapter.render(file, context, handleRender.bind(null, done, fileOutput));
handlebarsAdapter.render([file, context, {}, handleRender.bind(null, done, fileOutput)]);
});

@@ -74,3 +74,3 @@

handlebarsAdapter.files = files;
handlebarsAdapter.render(fileWithIncludes, context, handleRender.bind(null, done, fileWithIncludesOutput));
handlebarsAdapter.render([fileWithIncludes, context, {}, handleRender.bind(null, done, fileWithIncludesOutput)]);
});

@@ -77,0 +77,0 @@ });

@@ -47,11 +47,11 @@ /* eslint no-unused-expressions : "off" */

const nunjucksAdapter = nunjucksAdapterFactory();
nunjucksAdapter.render(fileWithError, context, function (err, result) {
nunjucksAdapter.render([fileWithError, context, {}, function (err, result) {
expect(result).to.not.exist;
expect(err.name).to.match(/Template/);
done(null);
});
}]);
});
it(`should render simple file correctly`, function (done) {
const nunjucksAdapter = nunjucksAdapterFactory();
nunjucksAdapter.render(file, context, handleRender.bind(null, done, fileOutput));
nunjucksAdapter.render([file, context, {}, handleRender.bind(null, done, fileOutput)]);
});

@@ -61,3 +61,3 @@

const nunjucksAdapter = nunjucksAdapterFactory();
nunjucksAdapter.render(fileWithIncludes, context, handleRender.bind(null, done, fileWithIncludesOutput));
nunjucksAdapter.render([fileWithIncludes, context, {}, handleRender.bind(null, done, fileWithIncludesOutput)]);
});

@@ -64,0 +64,0 @@ });

@@ -40,3 +40,3 @@ /* eslint no-unused-expressions : "off" */

const reactAdapter = reactAdapterFactory();
reactAdapter.render(fileWithError, context, function (err, result) {
reactAdapter.render([fileWithError, context, {}, function (err, result) {
expect(result).to.not.exist;

@@ -46,7 +46,7 @@ expect(err.name).to.match(/Error/);

done(null);
});
}]);
});
it(`should render correctly`, function (done) {
const reactAdapter = reactAdapterFactory();
reactAdapter.render(file, context, handleRender.bind(null, done));
reactAdapter.render([file, context, {}, handleRender.bind(null, done)]);
});

@@ -53,0 +53,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