Vulcan/packages/telescope-getting-started/lib/server/dummy_content.js

108 lines
3.1 KiB
JavaScript
Raw Normal View History

2014-12-31 17:44:21 +09:00
var toTitleCase = function (str) {
return str.replace(/\w\S*/g, function(txt){return txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase();});
}
var createPost = function (slug, postedAt, username, thumbnail) {
var post = {
2014-12-31 17:52:06 +09:00
postedAt: postedAt,
2014-12-31 17:44:21 +09:00
body: Assets.getText("content/" + slug + ".md"),
title: toTitleCase(slug.replace(/_/g, ' ')),
dummySlug: slug,
isDummy: true,
userId: Meteor.users.findOne({username: username})._id
}
if (typeof thumbnail !== "undefined")
post.thumbnailUrl = "/packages/telescope-getting-started/content/images/" + thumbnail
submitPost(post);
}
2014-12-31 17:52:06 +09:00
var createComment = function (slug, username, body, parentBody) {
2014-12-31 17:44:21 +09:00
var comment = {
2014-12-31 17:52:06 +09:00
postId: Posts.findOne({dummySlug: slug})._id,
2014-12-31 17:44:21 +09:00
userId: Meteor.users.findOne({username: username})._id,
body: body,
isDummy: true,
disableNotifications: true
}
if (parentComment = Comments.findOne({body: parentBody}))
comment.parentCommentId = parentComment._id;
submitComment(comment);
}
var createDummyUsers = function () {
Accounts.createUser({
username: 'Bruce',
email: 'dummyuser1@telescopeapp.org',
profile: {
isDummy: true
}
});
Accounts.createUser({
username: 'Arnold',
email: 'dummyuser2@telescopeapp.org',
profile: {
isDummy: true
}
});
Accounts.createUser({
username: 'Julia',
email: 'dummyuser3@telescopeapp.org',
profile: {
isDummy: true
}
});
}
var createDummyPosts = function () {
createPost("read_this_first", moment().toDate(), "Bruce", "telescope.png");
createPost("deploying_telescope", moment().subtract(10, 'minutes').toDate(), "Arnold");
createPost("customizing_telescope", moment().subtract(3, 'hours').toDate(), "Julia");
createPost("getting_help", moment().subtract(1, 'days').toDate(), "Bruce", "stackoverflow.png");
createPost("removing_getting_started_posts", moment().subtract(2, 'days').toDate(), "Julia");
}
var createDummyComments = function () {
createComment("read_this_first", "Bruce", "What an awesome app!");
createComment("deploying_telescope", "Arnold", "Deploy to the choppah!");
createComment("deploying_telescope", "Julia", "Do you really need to say this all the time?", "Deploy to the choppah!");
createComment("customizing_telescope", "Julia", "I can't wait to make my app pretty. Get it? *Pretty*?");
createComment("removing_getting_started_posts", "Bruce", "Yippee ki-yay, motherfucker!");
2014-12-31 17:52:06 +09:00
createComment("removing_getting_started_posts", "Arnold", "I don't think you're supposed to swear in here…", "Yippee ki-yay, motherfucker!");
2014-12-31 17:44:21 +09:00
}
deleteDummyContent = function () {
Meteor.users.remove({'profile.isDummy': true});
Posts.remove({isDummy: true});
Comments.remove({isDummy: true});
}
Meteor.methods({
removeGettingStartedContent: function () {
if(isAdmin(Meteor.user()))
deleteDummyContent();
}
})
Meteor.startup(function () {
if (!Events.findOne({name: 'createDummyContent'})) {
createDummyUsers();
createDummyPosts();
createDummyComments();
logEvent({name: 'createDummyContent', important: true});
}
});