From a5546b9fd6e1dd838be1b2b671c4aa2b117029a9 Mon Sep 17 00:00:00 2001 From: irfaan Date: Sat, 22 May 2021 18:10:21 -0600 Subject: [PATCH 1/5] Support `SOURCE` icalendar parameter (RFC 7986) See issue: https://github.com/sebbo2002/ical-generator/issues/260 --- src/calendar.ts | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/calendar.ts b/src/calendar.ts index 307974723..059049ded 100755 --- a/src/calendar.ts +++ b/src/calendar.ts @@ -22,6 +22,7 @@ export interface ICalCalendarData { name?: string | null; description?: string | null; timezone?: ICalTimezone | string | null; + source?: string | null; url?: string | null; scale?: string | null; ttl?: number | Duration | null; @@ -35,6 +36,7 @@ interface ICalCalendarInternalData { name: string | null; description: string | null; timezone: ICalTimezone | null; + source: string | null; url: string | null; scale: string | null; ttl: number | null; @@ -120,6 +122,7 @@ export default class ICalCalendar { name: null, description: null, timezone: null, + source: null, url: null, scale: null, ttl: null, @@ -132,6 +135,7 @@ export default class ICalCalendar { data.name !== undefined && this.name(data.name); data.description !== undefined && this.description(data.description); data.timezone !== undefined && this.timezone(data.timezone); + data.source !== undefined && this.source(data.source); data.url !== undefined && this.url(data.url); data.scale !== undefined && this.scale(data.scale); data.ttl !== undefined && this.ttl(data.ttl); @@ -343,6 +347,32 @@ export default class ICalCalendar { return this; } + + /** + * Get your feed's refresh URL + * @since 0.x.x + */ + source(): string | null; + + /** + * Set your feed's refresh URL + * + * ```javascript + * calendar.source('http://example.com/my/original_source.ical'); + * ``` + * + * @since 0.x.x + */ + source(source: string | null): this; + source(source?: string | null): this | string | null { + if (url === undefined) { + return this.data.source; + } + + this.data.source = source || null; + return this; + } + /** * Get your feed's URL @@ -749,6 +779,11 @@ export default class ICalCalendar { if (this.data.url) { g += 'URL:' + this.data.url + '\r\n'; } + + // SOURCE + if (this.data.source) { + g += 'SOURCE:' + this.data.source + '\r\n'; + } // CALSCALE if (this.data.scale) { From 0ae498dbb85b4264aa432f9ac5e87108cf4cd46c Mon Sep 17 00:00:00 2001 From: irfaan Date: Sat, 22 May 2021 20:32:25 -0600 Subject: [PATCH 2/5] Use proper syntax + clearer comments --- src/calendar.ts | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/calendar.ts b/src/calendar.ts index 059049ded..ee8eb5fde 100755 --- a/src/calendar.ts +++ b/src/calendar.ts @@ -349,13 +349,14 @@ export default class ICalCalendar { /** - * Get your feed's refresh URL + * Get current value of the `SOURCE` attribute. * @since 0.x.x */ source(): string | null; /** - * Set your feed's refresh URL + * Use this method to set your feed's `SOURCE` attribute. + * This tells the client where to refresh your feed. * * ```javascript * calendar.source('http://example.com/my/original_source.ical'); @@ -782,7 +783,7 @@ export default class ICalCalendar { // SOURCE if (this.data.source) { - g += 'SOURCE:' + this.data.source + '\r\n'; + g += 'SOURCE;VALUE=URI:' + this.data.source + '\r\n'; } // CALSCALE From 7603e23823102b8639e82c98fe6ad183b8f4f8dc Mon Sep 17 00:00:00 2001 From: irfaan Date: Sat, 22 May 2021 20:35:25 -0600 Subject: [PATCH 3/5] Add tests for `SOURCE` attribute --- test/calendar.ts | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/test/calendar.ts b/test/calendar.ts index 4608a07fa..743051bc4 100644 --- a/test/calendar.ts +++ b/test/calendar.ts @@ -20,6 +20,7 @@ describe('ical-generator Calendar', function () { description: 'Hi, I am the description.', timezone: null, url: 'https://github.com/sebbo2002/ical-generator', + source: 'http://example.com/my/original_source.ical', scale: null, ttl: null, events: [], @@ -228,6 +229,32 @@ describe('ical-generator Calendar', function () { assert.strictEqual(cal.ttl(), 86400); }); }); + + describe('source()', function () { + it('setter should return this', function () { + const cal = new ICalCalendar(); + assert.deepStrictEqual(cal, cal.source('http://example.com/my/original_source.ical')); + }); + + it('getter should return value', function () { + const cal = new ICalCalendar(); + assert.strictEqual(cal.source(), null); + cal.source('http://example.com/my/original_source.ical'); + assert.strictEqual(cal.source(), 'http://example.com/my/original_source.ical'); + cal.url(null); + assert.strictEqual(cal.url(), null); + }); + + it('should change something', function () { + const cal = new ICalCalendar().source('http://example.com/my/original_source.ical'); + cal.createEvent({ + start: new Date(), + end: new Date(new Date().getTime() + 3600000), + summary: 'Example Event' + }); + assert.ok(cal.url(), 'http://example.com/my/original_source.ical'); + }); + }); describe('url()', function () { it('setter should return this', function () { From 86ba0dd55ba67b070918c4c1d9c707b707ac6e55 Mon Sep 17 00:00:00 2001 From: Sebastian Pekarek Date: Mon, 24 May 2021 18:20:01 +0200 Subject: [PATCH 4/5] Fix source tests --- src/calendar.ts | 9 +++++---- test/calendar.ts | 20 +++++++++----------- 2 files changed, 14 insertions(+), 15 deletions(-) diff --git a/src/calendar.ts b/src/calendar.ts index ee8eb5fde..8f5cde887 100755 --- a/src/calendar.ts +++ b/src/calendar.ts @@ -50,6 +50,7 @@ export interface ICalCalendarJSONData { name: string | null; description: string | null; timezone: string | null; + source: string | null; url: string | null; scale: string | null; ttl: number | null; @@ -347,7 +348,7 @@ export default class ICalCalendar { return this; } - + /** * Get current value of the `SOURCE` attribute. * @since 0.x.x @@ -359,14 +360,14 @@ export default class ICalCalendar { * This tells the client where to refresh your feed. * * ```javascript - * calendar.source('http://example.com/my/original_source.ical'); + * cal.source('http://example.com/my/original_source.ical'); * ``` * * @since 0.x.x */ source(source: string | null): this; source(source?: string | null): this | string | null { - if (url === undefined) { + if (source === undefined) { return this.data.source; } @@ -780,7 +781,7 @@ export default class ICalCalendar { if (this.data.url) { g += 'URL:' + this.data.url + '\r\n'; } - + // SOURCE if (this.data.source) { g += 'SOURCE;VALUE=URI:' + this.data.source + '\r\n'; diff --git a/test/calendar.ts b/test/calendar.ts index 743051bc4..59b5c9bb8 100644 --- a/test/calendar.ts +++ b/test/calendar.ts @@ -229,7 +229,7 @@ describe('ical-generator Calendar', function () { assert.strictEqual(cal.ttl(), 86400); }); }); - + describe('source()', function () { it('setter should return this', function () { const cal = new ICalCalendar(); @@ -239,21 +239,13 @@ describe('ical-generator Calendar', function () { it('getter should return value', function () { const cal = new ICalCalendar(); assert.strictEqual(cal.source(), null); + cal.source('http://example.com/my/original_source.ical'); assert.strictEqual(cal.source(), 'http://example.com/my/original_source.ical'); + cal.url(null); assert.strictEqual(cal.url(), null); }); - - it('should change something', function () { - const cal = new ICalCalendar().source('http://example.com/my/original_source.ical'); - cal.createEvent({ - start: new Date(), - end: new Date(new Date().getTime() + 3600000), - summary: 'Example Event' - }); - assert.ok(cal.url(), 'http://example.com/my/original_source.ical'); - }); }); describe('url()', function () { @@ -670,6 +662,12 @@ describe('ical-generator Calendar', function () { assert.ok(cal.toString().indexOf('X-WR-TIMEZONE:TEST') > -1); }); + it('should include the source', function () { + const cal = new ICalCalendar(); + cal.source('http://foo.bar.example.com/ical.cal'); + assert.ok(cal.toString().includes('http://foo.bar.example.com/ical.cal')); + }); + it('should include VTimezone objects if generator was supplied', function () { const cal = new ICalCalendar(); cal.timezone({name: 'Europe/Berlin', generator: getVtimezoneComponent}); From ff725ccc407920ec3d64538b4ce7f5beab6df3cf Mon Sep 17 00:00:00 2001 From: Sebastian Pekarek Date: Mon, 24 May 2021 18:21:41 +0200 Subject: [PATCH 5/5] Add version to source() --- src/calendar.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/calendar.ts b/src/calendar.ts index 8f5cde887..7549cd82c 100755 --- a/src/calendar.ts +++ b/src/calendar.ts @@ -350,8 +350,8 @@ export default class ICalCalendar { /** - * Get current value of the `SOURCE` attribute. - * @since 0.x.x + * Get current value of the `SOURCE` attribute. + * @since 2.2.0-develop.1 */ source(): string | null; @@ -363,7 +363,7 @@ export default class ICalCalendar { * cal.source('http://example.com/my/original_source.ical'); * ``` * - * @since 0.x.x + * @since 2.2.0-develop.1 */ source(source: string | null): this; source(source?: string | null): this | string | null {