Skip to content

Instantly share code, notes, and snippets.

@3rd-Eden
Created February 27, 2015 05:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save 3rd-Eden/c31ead1c17b8393c2b88 to your computer and use it in GitHub Desktop.
Save 3rd-Eden/c31ead1c17b8393c2b88 to your computer and use it in GitHub Desktop.
/** @jsx React.DOM **/
<div>
<FormattedMessage
message={getIntlMessage('post.meta')}
num={props.post.comments.length}
ago={<FormattedRelative value={props.post.date} />}
/>
<span>{random}</span>
</div>
/** @jsx React.DOM **/
<PostMeta post={post} {...intlData} />
'use strict';
//
// Required for old node.js builds and io.js
//
if (!global.Intl) global.Intl = require('intl');
var path = require('path')
, React = require('react')
, jsx = require('react-jsx')
, ReactIntl = require('react-intl')
, read = require('fs').readFileSync
, IntlMixin = ReactIntl.IntlMixin;
var templates = {
component: jsx.server(read(path.join(__dirname, 'component.jsx'), 'utf-8')),
postmeta: jsx.server(read(path.join(__dirname, 'postmeta.jsx'), 'utf-8'))
};
var Component = React.createClass({
mixins: [ReactIntl.IntlMixin],
render: function render() {
return templates.component({
FormattedMessage: this.FormattedMessage,
props: this.props,
getIntlMessage: this.getIntlMessage,
FormattedRelative: this.FormattedRelative,
random: 'lol cakes'
});
}
});
console.log(templates.postmeta({
PostMeta: Component,
post: {
date : 1422046290531,
comments: [1]
},
intlData:{
locales : ['en-US'],
messages: {
post: {
meta: 'Posted {ago}, {num, plural, one{# comment} other{# comments}}'
}
}
}
}, { html: true }));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment