{"size": 974, "ext": "js", "max_stars_repo_path": "packages/meteorpress-admin/lib/server/markdown-methods.js", "max_stars_repo_name": "michaltakac/meteorpress", "max_stars_repo_stars_event_min_datetime": "2015-09-20T21:00:29.000Z", "max_stars_repo_stars_event_max_datetime": "2015-09-23T20:03:07.000Z", "max_issues_repo_path": "packages/meteorpress-admin/lib/server/markdown-methods.js", "max_issues_repo_name": "michaltakac/meteor-cms", "max_issues_repo_issues_event_min_datetime": "2015-09-20T23:06:55.000Z", "max_issues_repo_issues_event_max_datetime": "2015-09-21T23:04:12.000Z", "max_forks_repo_path": "packages/meteorpress-admin/lib/server/markdown-methods.js", "max_forks_repo_name": "michaltakac/meteorpress", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 2, "max_issues_count": 1, "max_forks_count": null, "avg_line_length": 21.1739130435, "max_line_length": 76, "alphanum_fraction": 0.5872689938}
var Future = Npm.require('fibers/future');

Meteor.methods({
  insertDocument: function(){
    var fut = new Future();

    // We should't assign default title like this here... needs refractoring
    var doc = {
      title: "Post title"
    }

    try {
      var documentId = Posts.insert(doc);
      fut['return'](documentId);
    } catch(exception) {
      fut['return'](exception);
    }

    return fut.wait();
  },
  updateDocument: function( changes ){
    check( changes, {
      _id: String,
      markdown: Match.Optional( String ),
      content: Match.Optional( String ),
      title: Match.Optional( String )
    });

    var doc = changes._id;
    delete changes._id;

    try {
      var documentId = Posts.update( doc, {
        $set: changes
      });
      return documentId;
    } catch(exception) {
      return exception;
    }
  },
  convertMarkdown: function( markdown ){
    check( markdown, String );
    return parseMarkdown( markdown );
  }
});
