Skip to content

Commit

Permalink
feat(Template): accepts any parameters and forwards them
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexandre Stanislawski committed Jan 19, 2016
1 parent 49bf364 commit 5170f53
Show file tree
Hide file tree
Showing 2 changed files with 199 additions and 159 deletions.
47 changes: 28 additions & 19 deletions src/components/Template.js
Original file line number Diff line number Diff line change
@@ -1,30 +1,39 @@
import React from 'react';
import mapValues from 'lodash/object/mapValues';

import curry from 'lodash/function/curry';
import cloneDeep from 'lodash/lang/cloneDeep';
import keys from 'lodash/object/keys';
import omit from 'lodash/object/omit';
import mapValues from 'lodash/object/mapValues';

import hogan from 'hogan.js';

class Template extends React.Component {
render() {
let compileOptions = this.props.useCustomCompileOptions[this.props.templateKey] ?
this.props.templatesConfig.compileOptions :
{};

let content = renderTemplate({
template: this.props.templates[this.props.templateKey],
compileOptions: compileOptions,
helpers: this.props.templatesConfig.helpers,
data: transformData(this.props.transformData, this.props.templateKey, this.props.data)
});
function Template(props) {
const useCustomCompileOptions = props.useCustomCompileOptions[props.templateKey];
const compileOptions = useCustomCompileOptions ? props.templatesConfig.compileOptions : {};

if (content === null) {
// Adds a noscript to the DOM but virtual DOM is null
// See http://facebook.github.io/react/docs/component-specs.html#render
return null;
}
const content = renderTemplate({
template: props.templates[props.templateKey],
compileOptions: compileOptions,
helpers: props.templatesConfig.helpers,
data: transformData(props.transformData, props.templateKey, props.data)
});

return <div className={this.props.cssClass} dangerouslySetInnerHTML={{__html: content}} />;
if (content === null) {
// Adds a noscript to the DOM but virtual DOM is null
// See http://facebook.github.io/react/docs/component-specs.html#render
return null;
}

const otherProps = omit(props, keys(Template.propTypes));

return (
<div
{...otherProps}
className={props.cssClass}
dangerouslySetInnerHTML={{__html: content}}
/>
);
}

Template.propTypes = {
Expand Down
Loading

0 comments on commit 5170f53

Please sign in to comment.