FEATURE: rename cronos bbcode element to date

This commit is contained in:
Sam 2018-05-04 15:17:14 +10:00
parent 3d6dc764be
commit 741898a106
3 changed files with 14 additions and 18 deletions

View File

@ -73,12 +73,11 @@ export default Ember.Component.extend({
}, },
getTextConfig(config) { getTextConfig(config) {
let text = "[discourse-cronos "; let text = `[date=${config.date} `;
if (config.recurring) text += `recurring=${config.recurring};`; if (config.recurring) text += `recurring=${config.recurring} `;
text += `time=${config.time};`; text += `time=${config.time} `;
text += `date=${config.date};`; text += `format=${config.format} `;
text += `format=${config.format};`; text += `timezones="${config.timezones.join("|")}"`;
text += `timezones=${config.timezones.join("|")};`;
text += `]`; text += `]`;
return text; return text;
}, },

View File

@ -1,8 +1,4 @@
import { registerOption } from 'pretty-text/pretty-text'; import { parseBBCodeTag } from 'pretty-text/engines/discourse-markdown/bbcode-block';
registerOption((siteSettings, opts) => {
opts.features['discourse-cronos'] = !!siteSettings.discourse_cronos_enabled;
});
function addcronos(buffer, matches, state) { function addcronos(buffer, matches, state) {
let token; let token;
@ -14,11 +10,12 @@ function addcronos(buffer, matches, state) {
timezones: "" timezones: ""
}; };
const options = matches[1].split(";"); let parsed = parseBBCodeTag("[date date" + matches[1] + "]", 0, matches[1].length + 11);
options.forEach((option) => {
let o = option.split("="); config.date = parsed.attrs.date;
config[o[0]] = o[1]; config.time = parsed.attrs.time;
}); 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('a_open', 'a', 1);
token.attrs = [ token.attrs = [
@ -67,7 +64,7 @@ export function setup(helper) {
helper.registerPlugin(md => { helper.registerPlugin(md => {
const rule = { const rule = {
matcher: /\[discourse-cronos (.*?)\]/, matcher: /\[date(.*?)\]/,
onMatch: addcronos onMatch: addcronos
}; };

View File

@ -4,7 +4,7 @@ describe PrettyText do
it 'supports inserting date' do it 'supports inserting date' do
freeze_time freeze_time
cooked = PrettyText.cook <<~MD cooked = PrettyText.cook <<~MD
[discourse-cronos time=22:00;date=2018-05-08;format=LLL;timezones=Europe/Paris|America/Los_Angeles;][/discourse-cronos] [date=2018-05-08 time=22:00 format=LLL timezones="Europe/Paris|America/Los_Angeles"]
MD MD
expect(cooked).to include('class="discourse-cronos"') expect(cooked).to include('class="discourse-cronos"')