"being of identical or similar form, shape, or structure"
"(javascript) code that is used in both client and server application"
(one of our big production Meteor apps)
▾ partup:lib/
▸ collections/
▸ helpers/
▸ private/
▸ schemas/
▸ services/
▸ startup/
▸ transformers/
error.js
globals.js
namespace.js
package.js
routes.js
version.js
/**
@namespace Networks
@name Networks
*/
Networks = new Mongo.Collection('networks', {
transform: function(document) {
return new Network(document);
}
});
/**
* Find featured networks
*
* @memberOf Networks
* @param {String} language
* @return {Mongo.Cursor}
*/
Networks.findFeatured = function(language) {
var selector = {'featured.active': true};
if (language) {
selector.language = language;
}
return Networks.find(selector);
};
/**
* New message Form
* @name inviteUpper
* @memberof Partup.schemas.forms
*/
Partup.schemas.forms.inviteUpper = new SimpleSchema({
name: {
type: String
},
email: {
type: String,
max: 255,
regEx: Partup.services.validators.email
},
message: {
type: String,
max: 2500,
custom: function() {
if (!Partup.services.validators.containsNoHtml(this.value)) {
return 'shouldNotContainHtml';
}
if (!Partup.services.validators.containsRequiredTags(this.value, ['url', 'name'])) {
return 'missingRequiredTags';
}
if (!Partup.services.validators.containsNoUrls(this.value)) {
return 'shouldNotContainUrls';
}
}
}
});
Template.InviteToActivity.helpers({
formSchema: Partup.schemas.forms.inviteUpper,
submitting: function() {
return Template.instance().submitting.get();
},
// snip
});
/**
* Invite someone to an partup
*
* @param {string} partupId
* @param {string} email
* @param {string} name
*/
'partups.invite_by_email': function(partupId, fields) {
check(fields, Partup.schemas.forms.inviteUpper);
var inviter = Meteor.user();
if (!inviter) {
throw new Meteor.Error(401, 'unauthorized');
}
var partup = Partups.findOneOrFail(partupId);
// snip
}
/**
* Extract mentions from a message
*
* e.g. "Hello [user:9ZxF5SHPjcAfbey4j|Jesse de Vries] & [user:EpWPsBoBexD9QFSMR|Nick Koster]"
*/
Partup.helpers.mentions.extract = function(message) {
var mentions = [];
// extracts user (single) mentions
extractUsers(message).forEach(function(mention) {
var existingMention = lodash.find(mentions, {_id: mention._id});
if (!existingMention) mentions.push(mention);
});
// extracts partners (group) mention
extractPartners(message).forEach(function(mention) {
var existingMention = lodash.find(mentions, {name: 'Partners'});
if (!existingMention) mentions.push(mention);
});
// extracts supporters (group) mention
extractSupporters(message).forEach(function(mention) {
var existingMention = lodash.find(mentions, {name: 'Supporters'});
if (!existingMention) mentions.push(mention);
});
return mentions;
};
/**
* Extract mentions from a message
*
* e.g. "Hello [user:9ZxF5SHPjcAfbey4j|Jesse de Vries] & [user:EpWPsBoBexD9QFSMR|Nick Koster]"
*/
export function extract(message) {
var mentions = [];
// extracts user (single) mentions
extractUsers(message).forEach(function(mention) {
var existingMention = lodash.find(mentions, {_id: mention._id});
if (!existingMention) mentions.push(mention);
});
//snip
return mentions;
};
import extract from './helpers/mentions/extract';
Template.InviteToActivity.helpers({
extractedMentions: function() {
return extract(Template.instance().message.get());
},
// snip
});