diff --git a/client/publish-counts.js b/client/publish-counts.js index b4ae90e..88d26f2 100644 --- a/client/publish-counts.js +++ b/client/publish-counts.js @@ -1,20 +1,10 @@ -Counts = new Mongo.Collection('counts'); - -Counts.get = function countsGet (name) { - var count = this.findOne(name); - return count && count.count || 0; -}; - -Counts.has = function countsHas (name) { - return !!this.findOne(name); -}; - +Counts = {}; if (Package.templating) { Package.templating.Template.registerHelper('getPublishedCount', function(name) { - return Counts.get(name); + return CountsCollection.get(name); }); Package.templating.Template.registerHelper('hasPublishedCount', function(name) { - return Counts.has(name); + return CountsCollection.has(name); }); } diff --git a/lib/publish-counts.js b/lib/publish-counts.js new file mode 100644 index 0000000..a5765a5 --- /dev/null +++ b/lib/publish-counts.js @@ -0,0 +1,11 @@ +CountsCollection = new Mongo.Collection('counts'); + +Counts.get = function countsGet (name) { + + var count = CountsCollection.findOne(name); + return count && count.count || 0; +}; + +Counts.has = function countsHas (name) { + return !!CountsCollection.findOne(name); +}; \ No newline at end of file diff --git a/package.js b/package.js index 69a04ea..9b4a219 100644 --- a/package.js +++ b/package.js @@ -8,10 +8,11 @@ Package.describe({ Package.on_use(function (api, where) { api.versionsFrom("METEOR@0.9.2"); api.use(['blaze', 'templating'], 'client', { weak: true }); - api.use('mongo', 'client'); + api.use('mongo'); api.use('underscore', 'server'); api.add_files('client/publish-counts.js', 'client'); api.add_files('server/publish-counts.js', 'server'); + api.add_files('lib/publish-counts.js'); api.export('Counts'); api.export('publishCount', 'server'); });