Esempio n. 1
0
File: Post.cs Progetto: szp11/nina
 public static Post Save(Post p)
 {
     p.BodyHtml = GetBodyHtml(p);
     p.SummaryHtml = GetSummaryHtml(p);
     _mongoCollection.Insert(p);
     return p;
 }
Esempio n. 2
0
File: Post.cs Progetto: szp11/nina
        private static string GetSummaryHtml(Post p)
        {
            if (string.IsNullOrEmpty(p.Body))
                return string.Empty;

            var match = Regex.Match(p.Body, "(.{200}.*?\n)");
            return new Markdown().Transform(match.Success ? match.Captures[0].Value : p.Body);
        }
Esempio n. 3
0
File: Panda.cs Progetto: szp11/nina
        public Panda()
        {
            //https://github.com/rwboyer/scanty/raw/master/public/css/main.css
            Get("/", (m,c) =>
            {
                IEnumerable<Post> findAll = Posts.FindAll(10);
                
                return View("views/index", new PostListViewData(){Blog = new Blog(), Posts = findAll.ToArray(), User=new User()})
                       .ETagged();
            });

            Get("/posts/{year}/{month}/{day}/{slug}", (m, c) =>
            {
                Post post = Posts.Find(m["slug"]);

                return View("views/post", new PostViewData() { Blog = new Blog(), Post = post, User = new User() })
                       .ETagged();
            });

            Get("/posts/{year}/{month}/{day}/{slug}/edit", (m, c) =>
            {
                Post post = Posts.Find(m["slug"]);

                return View("views/edit", new PostViewData() { Blog = new Blog(), Post = post, User = new User(), Url = post.Url });
            });

            Post("/posts/{year}/{month}/{day}/{slug}", (m, c) =>
            {
                Post post = Posts.Find(m["slug"]);
                post.Title = c.Request.Form["title"];
                post.Body = c.Request.Form["body"];
                post.StringifiedTags = c.Request.Form["tags"];
                Posts.Update(post);
                return Redirect(post.Url);
            });

            Get("/posts/new", (m, c) =>
            {
                //todo: auth
                var p = new Post();
                return View("views/edit", new PostViewData() { Post = p, Blog = new Blog(), User = new User(), Url = "/posts" });
            });

            Post("/posts", (m,c)=>
            {
                var slug = Models.Post.Sluggify(c.Request.Form["title"]);
                var post = new Post(){Body = c.Request.Form["body"], Title=c.Request.Form["title"],StringifiedTags= c.Request.Form["tags"], Created=DateTime.Now,Slug=slug };
                Posts.Save(post);
                return Redirect(post.Url);
            });

            Get("/posts/tagged/{tag}", (m,c)=>
            {
                var findAllByTag = Posts.FindAllByTag(m["tag"], 30);
                return View("views/index", new PostListViewData() { Posts = findAllByTag.ToArray(), Blog = new Blog(), User = new User() });
            });
        }
Esempio n. 4
0
File: Post.cs Progetto: szp11/nina
 private static string GetBodyHtml(Post p)
 {
     if(string.IsNullOrEmpty(p.Body))
             return string.Empty;
         return new Markdown().Transform(p.Body); 
 }
Esempio n. 5
0
File: Post.cs Progetto: szp11/nina
 public static void Update(Post p)
 {
     p.BodyHtml = GetBodyHtml(p);
     p.SummaryHtml = GetSummaryHtml(p);
     _mongoCollection.Update(Query.EQ("_id", p.Id), p);
 }