From 66103e63ffd7514cadab5edc213ffffa0fd61d54 Mon Sep 17 00:00:00 2001 From: cha0s Date: Sun, 24 Jan 2021 12:58:14 -0600 Subject: [PATCH] feat: text resource renderer --- packages/core/src/client/index.js | 4 ++++ packages/core/src/text-renderer/index.jsx | 27 ++++++++++++++++++++++ packages/core/src/text-renderer/index.scss | 3 +++ 3 files changed, 34 insertions(+) create mode 100644 packages/core/src/text-renderer/index.jsx create mode 100644 packages/core/src/text-renderer/index.scss diff --git a/packages/core/src/client/index.js b/packages/core/src/client/index.js index 20bdce4..21c90a2 100644 --- a/packages/core/src/client/index.js +++ b/packages/core/src/client/index.js @@ -1,6 +1,7 @@ import flatten from 'lodash.flatten'; import BinaryRenderer from '../binary-renderer'; +import TextResourceRenderer from '../text-renderer'; export default { hooks: { @@ -12,5 +13,8 @@ export default { }; latus.set('%resource-renderers', Renderer); }, + '@persea/core/resource-renderers': () => [ + TextResourceRenderer, + ], }, }; diff --git a/packages/core/src/text-renderer/index.jsx b/packages/core/src/text-renderer/index.jsx new file mode 100644 index 0000000..d1dca45 --- /dev/null +++ b/packages/core/src/text-renderer/index.jsx @@ -0,0 +1,27 @@ +import './index.scss'; + +import {PropTypes, React} from '@latus/react'; + +const TextRendererComponent = ({buffer}) => ( +
{buffer.toString()}
+); + +TextRendererComponent.propTypes = { + buffer: PropTypes.shape({ + toString: PropTypes.func, + }).isRequired, +}; + +export default class TextResourceRenderer { + + static Component({buffer}) { + return ( + + ); + } + + static get matcher() { + return /\.txt$/; + } + +} diff --git a/packages/core/src/text-renderer/index.scss b/packages/core/src/text-renderer/index.scss new file mode 100644 index 0000000..6c767b4 --- /dev/null +++ b/packages/core/src/text-renderer/index.scss @@ -0,0 +1,3 @@ +.text-renderer { + font-family: monospace; +}