FIX: improves discourse-local-dates rendering in emails
This commit is contained in:
parent
9f92fdded0
commit
9a5aa39740
|
@ -18,7 +18,7 @@ function addLocalDate(buffer, matches, state) {
|
|||
config.format = parsed.attrs.format || config.format;
|
||||
config.timezones = parsed.attrs.timezones || config.timezones;
|
||||
|
||||
token = new state.Token('a_open', 'a', 1);
|
||||
token = new state.Token('span_open', 'span', 1);
|
||||
token.attrs = [
|
||||
['class', 'discourse-local-date'],
|
||||
['data-date', config.date],
|
||||
|
@ -46,19 +46,21 @@ function addLocalDate(buffer, matches, state) {
|
|||
}
|
||||
});
|
||||
|
||||
token.attrs.push(['data-email-preview', previews[0]]);
|
||||
|
||||
token = new state.Token('text', '', 0);
|
||||
token.content = previews.join(", ");
|
||||
buffer.push(token);
|
||||
|
||||
token = new state.Token('a_close', 'a', -1);
|
||||
token = new state.Token('span_close', 'span', -1);
|
||||
buffer.push(token);
|
||||
}
|
||||
|
||||
export function setup(helper) {
|
||||
helper.whiteList([
|
||||
'a.discourse-local-date',
|
||||
'a[data-*]',
|
||||
'a[title]'
|
||||
'span.discourse-local-date',
|
||||
'span[data-*]',
|
||||
'span[title]'
|
||||
]);
|
||||
|
||||
helper.registerOptions((opts, siteSettings) => {
|
||||
|
|
|
@ -11,4 +11,12 @@ register_asset "moment-timezone.js", :vendored_core_pretty_text
|
|||
|
||||
enabled_site_setting :discourse_local_dates_enabled
|
||||
|
||||
after_initialize do
|
||||
on(:reduce_cooked) do |fragment|
|
||||
container = fragment.children[0].children[0]
|
||||
preview = container.attributes["data-email-preview"].value
|
||||
container.content = preview
|
||||
end
|
||||
end
|
||||
|
||||
load File.expand_path('../lib/discourse_local_dates/engine.rb', __FILE__)
|
||||
|
|
|
@ -14,4 +14,16 @@ describe PrettyText do
|
|||
expect(cooked).to include('May 8, 2018 3:00 PM (America: Los Angeles)')
|
||||
expect(cooked).to include('May 9, 2018 12:00 AM (Europe: Paris)')
|
||||
end
|
||||
|
||||
it 'uses a simplified syntax in emails' do
|
||||
freeze_time
|
||||
cooked = PrettyText.cook <<~MD
|
||||
[date=2018-05-08 time=22:00 format=LLL timezones="Europe/Paris|America/Los_Angeles"]
|
||||
MD
|
||||
cooked_mail = <<~HTML
|
||||
<p><span class="discourse-local-date" data-date="2018-05-08" data-time="22:00" data-format="LLL" data-timezones="Europe/Paris|America/Los_Angeles" data-email-preview="May 9, 2018 12:00 AM (Europe: Paris)">May 9, 2018 12:00 AM (Europe: Paris)</span></p>
|
||||
HTML
|
||||
|
||||
expect(PrettyText.format_for_email(cooked)).to match_html(cooked_mail)
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue