From cadf33056640442cf7c12de2d0c06b6fdcbf75e6 Mon Sep 17 00:00:00 2001 From: SleepWalker Date: Sat, 1 Oct 2016 11:06:47 +0300 Subject: [PATCH] Support for components in BitmapText --- .eslintrc.json | 2 +- src/components/text/BitmapText.jsx | 30 ++++++++++++++++++++---------- 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/.eslintrc.json b/.eslintrc.json index 411df8f..200af04 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -100,7 +100,7 @@ "strict": ["warn", "never"], // babel все сделает за нас // variables - "no-catch-shadow": "error", + "no-catch-shadow": "off", "no-delete-var": "error", "no-label-var": "error", "no-shadow-restricted-names": "error", diff --git a/src/components/text/BitmapText.jsx b/src/components/text/BitmapText.jsx index 8200fff..b6abc3b 100644 --- a/src/components/text/BitmapText.jsx +++ b/src/components/text/BitmapText.jsx @@ -5,24 +5,34 @@ import { FormattedMessage as Message } from 'react-intl'; export function BitmapText(props) { const parts = props.message.id.split('.'); - if (parts[0] !== 'emails') { - throw new Error('Only src/emails subdirectories supported for now'); + if (parts[0] !== 'emails' && parts[0] !== 'components') { + throw new Error('Only src/emails and src/components subdirectories supported for now'); } if (parts.length !== 3) { - throw new Error('The message.id must be contain 3 parts separated by dots'); + throw new Error('The message.id must contain 3 parts separated by dots'); } let src; let size; try { - src = require(`emails/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`); - // TODO: we can improve this loader in future by adding an option to disable file emitting - // because this thing is handled by url-loader - size = require(`image-size!emails/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`); - } catch (err) { // fallback to default locale - src = require(`emails/${parts[1]}/images/${props.intl.defaultLocale}/${parts[2]}.png`); - size = require(`image-size!emails/${parts[1]}/images/${props.intl.defaultLocale}/${parts[2]}.png`); + try { + src = require(`emails/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`); + // TODO: we can improve this loader in future by adding an option to disable file emitting + // because this thing is handled by url-loader + size = require(`image-size!emails/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`); + } catch (err) { // fallback to default locale + src = require(`emails/${parts[1]}/images/${props.intl.defaultLocale}/${parts[2]}.png`); + size = require(`image-size!emails/${parts[1]}/images/${props.intl.defaultLocale}/${parts[2]}.png`); + } + } catch (err) { // try components + try { + src = require(`components/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`); + size = require(`image-size!components/${parts[1]}/images/${props.intl.locale}/${parts[2]}.png`); + } catch (err) { // fallback to default locale + src = require(`components/${parts[1]}/images/${props.intl.defaultLocale}/${parts[2]}.png`); + size = require(`image-size!components/${parts[1]}/images/${props.intl.defaultLocale}/${parts[2]}.png`); + } } const width = props.retina ? size.width / 2 : size.width;