@coorpacademy/treantjs-adapter-dust
Advanced tools
Comparing version 3.7.3 to 4.0.0
import map from 'lodash/fp/map'; | ||
import toPairs from 'lodash/fp/toPairs'; | ||
import kebabCase from 'lodash/fp/kebabCase'; | ||
import * as treant from '@coorpacademy/treantjs-core'; | ||
import { renderToString } from '@coorpacademy/treantjs-engine-virtual-dom'; | ||
var toHelpers = function toHelpers(factories, skin) { | ||
var toHelpers = function toHelpers(React, ReactDOMServer, components) { | ||
var toHelper = function toHelper(_ref) { | ||
var key = _ref[0], | ||
factory = _ref[1]; | ||
var componentName = _ref[0], | ||
Component = _ref[1]; | ||
var isFactory = key.split('create')[1]; | ||
if (!isFactory) return; | ||
var componentName = kebabCase(isFactory); | ||
var Component = factory(treant, { skin: skin }); | ||
return function (dust, options) { | ||
dust.helpers[componentName] = function (chunk, context, bodies, props) { | ||
var vTree = Component(props); | ||
var html = renderToString(vTree); | ||
var vTree = React.createElement(Component, props); | ||
var html = ReactDOMServer.renderToString(vTree); | ||
chunk.write(html); | ||
@@ -26,3 +19,3 @@ }; | ||
return map(toHelper, toPairs(factories)); | ||
return map(toHelper, toPairs(components)); | ||
}; | ||
@@ -29,0 +22,0 @@ |
@@ -17,26 +17,13 @@ 'use strict'; | ||
var _treantjsCore = require('@coorpacademy/treantjs-core'); | ||
var treant = _interopRequireWildcard(_treantjsCore); | ||
var _treantjsEngineVirtualDom = require('@coorpacademy/treantjs-engine-virtual-dom'); | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) newObj[key] = obj[key]; } } newObj.default = obj; return newObj; } } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var toHelpers = function toHelpers(factories, skin) { | ||
var toHelpers = function toHelpers(React, ReactDOMServer, components) { | ||
var toHelper = function toHelper(_ref) { | ||
var key = _ref[0], | ||
factory = _ref[1]; | ||
var componentName = _ref[0], | ||
Component = _ref[1]; | ||
var isFactory = key.split('create')[1]; | ||
if (!isFactory) return; | ||
var componentName = (0, _kebabCase2.default)(isFactory); | ||
var Component = factory(treant, { skin: skin }); | ||
return function (dust, options) { | ||
dust.helpers[componentName] = function (chunk, context, bodies, props) { | ||
var vTree = Component(props); | ||
var html = (0, _treantjsEngineVirtualDom.renderToString)(vTree); | ||
var vTree = React.createElement(Component, props); | ||
var html = ReactDOMServer.renderToString(vTree); | ||
chunk.write(html); | ||
@@ -47,3 +34,3 @@ }; | ||
return (0, _map2.default)(toHelper, (0, _toPairs2.default)(factories)); | ||
return (0, _map2.default)(toHelper, (0, _toPairs2.default)(components)); | ||
}; | ||
@@ -50,0 +37,0 @@ |
{ | ||
"name": "@coorpacademy/treantjs-adapter-dust", | ||
"version": "3.7.3", | ||
"version": "4.0.0", | ||
"description": "", | ||
@@ -23,4 +23,2 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"@coorpacademy/treantjs-core": "^3.7.3", | ||
"@coorpacademy/treantjs-engine-virtual-dom": "^3.7.3", | ||
"lodash": "^4.14.1" | ||
@@ -33,5 +31,7 @@ }, | ||
"babel-preset-es2015": "^6.13.0", | ||
"babel-preset-stage-1": "^6.5.0" | ||
"babel-preset-stage-1": "^6.5.0", | ||
"react": "^15.4.1", | ||
"react-dom": "^15.4.1" | ||
}, | ||
"author": "CoorpAcademy" | ||
} |
import map from 'lodash/fp/map'; | ||
import toPairs from 'lodash/fp/toPairs'; | ||
import kebabCase from 'lodash/fp/kebabCase'; | ||
import * as treant from '@coorpacademy/treantjs-core'; | ||
import {renderToString} from '@coorpacademy/treantjs-engine-virtual-dom'; | ||
const toHelpers = (factories, skin) => { | ||
const toHelper = ([key, factory]) => { | ||
const isFactory = key.split('create')[1]; | ||
if (!isFactory) return; | ||
const componentName = kebabCase(isFactory); | ||
const Component = factory(treant, {skin}); | ||
const toHelpers = (React, ReactDOMServer, components) => { | ||
const toHelper = ([componentName, Component]) => { | ||
return (dust, options) => { | ||
dust.helpers[componentName] = (chunk, context, bodies, props) => { | ||
const vTree = Component(props); | ||
const html = renderToString(vTree); | ||
const vTree = React.createElement(Component, props); | ||
const html = ReactDOMServer.renderToString(vTree); | ||
chunk.write(html); | ||
@@ -23,5 +16,5 @@ }; | ||
return map(toHelper, toPairs(factories)); | ||
return map(toHelper, toPairs(components)); | ||
}; | ||
export default toHelpers; |
import test from 'ava'; | ||
import isArray from 'lodash/fp/isArray'; | ||
import isFunction from 'lodash/fp/isFunction'; | ||
import React from 'react'; | ||
import ReactDOMServer from 'react-dom/server'; | ||
import toHelpers from '..'; | ||
test('toHelpers should transform factories as helpers', t => { | ||
const factories = { | ||
createStarRating: (_treant, options) => (props, children) => true, | ||
createCatalogCard: (_treant, options) => (props, children) => true | ||
const components = { | ||
StarRating: () => true, | ||
CatalogCard: () => true | ||
}; | ||
const helpers = toHelpers(factories); | ||
const helpers = toHelpers(React, ReactDOMServer, components); | ||
@@ -14,0 +16,0 @@ t.true(isArray(helpers)); |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
1
47083
7
20
490