public Post Save(string slug, Post content)
        {
            var isNew = string.IsNullOrEmpty(slug);
            if (isNew)
            {
                // No slug was specified, so we need to get the next one
                var docs = db.GetCollection("sequences");

                docs.EnsureIndex(IndexKeys.Ascending("Name"), IndexOptions.SetUnique(true));

                var sequence = docs.FindAndModify(Query.EQ("Name", "slug"), null, Update.Inc("Current", 1), true, true)
                                   .GetModifiedDocumentAs<Incrementor>();

                slug = Base36Encoder.Encode(sequence.Current);
            }

            content.Slug = slug;

            content.Version = isNew ? 1 : GetLatestVersion(slug) + 1;

            db.GetCollection<Post>("posts").Save(content, SafeMode.True);

            return content;
        }
Ejemplo n.º 2
0
 private IEnumerable<EditorError> GetErrorsInPost(Post post)
 {
     return compiler.GetCompilationErrors(post);
 }
Ejemplo n.º 3
0
        private static Post BuildSamplePost()
        {
            var post = new Post();
             var builder = new StringBuilder();

             post.Classes = builder.AppendLine("class Person")
                               .AppendLine("{")
                               .AppendLine("    public Person(string name)")
                               .AppendLine("    {")
                               .AppendLine("        Name = name;")
                               .AppendLine("    }")
                               .AppendLine()
                               .AppendLine("    public string Name { get; private set; }")
                               .AppendLine()
                               .AppendLine("    public string Greet()")
                               .AppendLine("    {")
                               .AppendLine("        if (Name == null)")
                               .AppendLine("            return \"Hello, stranger!\";")
                               .AppendLine()
                               .AppendLine("        return string.Format(\"Hello, {0}!\", Name);")
                               .AppendLine("    }")
                               .AppendLine("}")
                               .ToString();

             post.Content = builder.Clear()
                               .AppendLine("var person = new Person(name: null);")
                               .AppendLine()
                               .AppendLine("return person.Greet();")
                               .ToString();

             return post;
        }