aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/webcals/templates/calendar_data.js20
-rw-r--r--lib/webcals/templates/calendar_filter.js27
-rw-r--r--test/webcals/templates/calendar_filter_test.js55
3 files changed, 96 insertions, 6 deletions
diff --git a/lib/webcals/templates/calendar_data.js b/lib/webcals/templates/calendar_data.js
index 9ff2a1e..a0c0938 100644
--- a/lib/webcals/templates/calendar_data.js
+++ b/lib/webcals/templates/calendar_data.js
@@ -6,6 +6,10 @@
CalendarData.prototype = {
+ rootName: 'calendar-data',
+ compName: 'comp',
+ propName: 'prop',
+
/**
* Appends a list of fields
* to a given iCalendar field set.
@@ -19,7 +23,11 @@
struct[type] = [];
}
- struct[type] = struct[type].concat(list);
+ if (list instanceof Array) {
+ struct[type] = struct[type].concat(list);
+ } else {
+ struct[type] = list;
+ }
return this;
},
@@ -45,15 +53,15 @@
);
} else {
elementOutput += template.tag(
- ['caldav', 'prop'],
+ ['caldav', this.propName],
{ name: value[i] }
);
}
}
output += template.tag(
- ['caldav', 'comp'],
+ ['caldav', this.compName],
{ name: tag },
- elementOutput
+ elementOutput || null
);
elementOutput = '';
}
@@ -70,9 +78,9 @@
render: function(template) {
var struct = this.struct;
var output = template.tag(
- ['caldav', 'calendar-data'],
+ ['caldav', this.rootName],
template.tag(
- ['caldav', 'comp'],
+ ['caldav', this.compName],
{ name: 'VCALENDAR' },
this._renderFieldset(template, struct)
)
diff --git a/lib/webcals/templates/calendar_filter.js b/lib/webcals/templates/calendar_filter.js
new file mode 100644
index 0000000..15cfc8c
--- /dev/null
+++ b/lib/webcals/templates/calendar_filter.js
@@ -0,0 +1,27 @@
+(function(module, ns) {
+
+ var CalendarData = ns.require('templates/calendar_data');
+
+ function CalendarFilter() {
+ CalendarData.call(this);
+ }
+
+ CalendarFilter.prototype = {
+
+ __proto__: CalendarData.prototype,
+
+ filter: CalendarData.prototype.select,
+
+ compName: 'comp-filter',
+ rootName: 'filter'
+ };
+
+ module.exports = CalendarFilter;
+
+}.apply(
+ this,
+ (this.Webcals) ?
+ [Webcals('templates/calendar_data'), Webcals] :
+ [module, require('../webcals')]
+));
+
diff --git a/test/webcals/templates/calendar_filter_test.js b/test/webcals/templates/calendar_filter_test.js
new file mode 100644
index 0000000..517e78a
--- /dev/null
+++ b/test/webcals/templates/calendar_filter_test.js
@@ -0,0 +1,55 @@
+requireRequest();
+requireLib('templates/calendar_data');
+
+suite('webcals/templates/calendar_data', function() {
+ var CalendarFilter;
+ var Template;
+
+ var subject;
+ var template;
+
+ function filter() {
+ subject.filter('VEVENT', true);
+ }
+
+ suiteSetup(function() {
+ CalendarFilter = Webcals.require('templates/calendar_filter');
+ Template = Webcals.require('template');
+ });
+
+ setup(function() {
+ subject = new CalendarFilter();
+ template = new Template('root');
+ });
+
+ test('initialization', function() {
+ assert.deepEqual(subject.struct, {});
+ });
+
+ suite('#render', function() {
+ var output;
+ var expected;
+
+ expected = [
+ '<N0:filter>',
+ '<N0:comp-filter name="VCALENDAR">',
+ '<N0:comp-filter name="VEVENT" />',
+ '</N0:comp-filter>',
+ '</N0:filter>'
+ ].join('');
+
+ setup(function() {
+ filter();
+ });
+
+ test('output', function() {
+ var output = subject.render(template);
+ console.log();
+ console.log(output)
+ console.log();
+ assert.equal(output, expected);
+ });
+ });
+
+});
+