feat: text resource renderer

This commit is contained in:
cha0s 2021-01-24 12:58:14 -06:00
parent cbe2c18140
commit 66103e63ff
3 changed files with 34 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import flatten from 'lodash.flatten'; import flatten from 'lodash.flatten';
import BinaryRenderer from '../binary-renderer'; import BinaryRenderer from '../binary-renderer';
import TextResourceRenderer from '../text-renderer';
export default { export default {
hooks: { hooks: {
@ -12,5 +13,8 @@ export default {
}; };
latus.set('%resource-renderers', Renderer); latus.set('%resource-renderers', Renderer);
}, },
'@persea/core/resource-renderers': () => [
TextResourceRenderer,
],
}, },
}; };

View File

@ -0,0 +1,27 @@
import './index.scss';
import {PropTypes, React} from '@latus/react';
const TextRendererComponent = ({buffer}) => (
<div className="text-renderer">{buffer.toString()}</div>
);
TextRendererComponent.propTypes = {
buffer: PropTypes.shape({
toString: PropTypes.func,
}).isRequired,
};
export default class TextResourceRenderer {
static Component({buffer}) {
return (
<TextRendererComponent buffer={buffer} />
);
}
static get matcher() {
return /\.txt$/;
}
}

View File

@ -0,0 +1,3 @@
.text-renderer {
font-family: monospace;
}