bug fixes

* Makefile: my deploy config

* NpgsqlMembershipProvider.cs: Fixes a Bug introduced by Npgsql driver
  upgrade

* ResultPages.cs: .

* style.css: other colors

* BlogsController.cs: code cleaning

* GoogleController.cs: refactoring

* ErrorHtmlFormatter.cs: MarkdownDeep calls now come from yavscModel

* YavscHelpers.cs: xmldoc

* Index.aspx: code formatting

* UserPosts.aspx: nothing to note

* Web.csproj: MarkdownHelper has gone to the yavscModel project

* MarkdownHelper.cs:
* BlogEntryCollection.cs: refactoring + extract an intro from Markdown
  for PostInfo*

* YavscModel.csproj: MarkdownHelper integration
This commit is contained in:
Paul Schneider 2015-10-04 03:02:17 +02:00
commit ce1689df7b
19 changed files with 193 additions and 129 deletions

View file

@ -56,51 +56,50 @@ namespace Yavsc.Model.Blogs
{
return this.Where (x => x.Title == title).ToArray ();
}
/// <summary>
/// Base post info.
/// </summary>
public class BasePostInfo {
/// <summary>
/// The identifier.
/// </summary>
public long Id;
/// <summary>
/// The posted.
/// </summary>
public DateTime Posted;
/// <summary>
/// The modified.
/// </summary>
public DateTime Modified;
/// <summary>
/// The intro.
/// </summary>
public string Intro;
}
/// <summary>
/// Post info.
/// </summary>
public struct PostInfoByTitle {
public class PostInfoByTitle : BasePostInfo {
/// <summary>
/// The name of the user.
/// </summary>
public string Author;
/// <summary>
/// The identifier.
/// </summary>
public long Id;
/// <summary>
/// The posted.
/// </summary>
public DateTime Posted;
/// <summary>
/// The modified.
/// </summary>
public DateTime Modified;
}
/// <summary>
/// Post info by user.
/// </summary>
public struct PostInfoByUser {
public class PostInfoByUser : BasePostInfo {
/// <summary>
/// The name of the user.
/// </summary>
public string Title;
/// <summary>
/// The identifier.
/// </summary>
public long Id;
/// <summary>
/// The posted.
/// </summary>
public DateTime Posted;
/// <summary>
/// The modified.
/// </summary>
public DateTime Modified;
}
/// <summary>
@ -108,11 +107,12 @@ namespace Yavsc.Model.Blogs
/// </summary>
public IEnumerable<IGrouping<string,PostInfoByTitle>> GroupByTitle()
{
bool truncated;
return from be in this
orderby be.Posted descending
group
new PostInfoByTitle { Author=be.Author, Id=be.Id,
Posted=be.Posted, Modified=be.Modified }
Posted=be.Posted, Modified=be.Modified, Intro = MarkdownHelper.MarkdownIntro(be.Content, out truncated) }
by be.Title
into titlegroup
select titlegroup;
@ -123,11 +123,12 @@ namespace Yavsc.Model.Blogs
/// <returns>The by user.</returns>
public IEnumerable<IGrouping<string,PostInfoByUser>> GroupByUser()
{
bool truncated;
return from be in this
orderby be.Posted descending
group
new PostInfoByUser { Title=be.Title, Id=be.Id,
Posted=be.Posted, Modified=be.Modified }
Posted=be.Posted, Modified=be.Modified, Intro = MarkdownHelper.MarkdownIntro(be.Content, out truncated) }
by be.Author
into usergroup
select usergroup;

View file

@ -0,0 +1,102 @@
using System.Web;
using System.Web.Mvc;
using MarkdownDeep;
namespace Yavsc.Model.Blogs
{
/// <summary>
/// Helper class for transforming Markdown.
/// </summary>
public static partial class MarkdownHelper
{
/// <summary>
/// Transforms a string of Markdown into HTML.
/// </summary>
/// <param name="text">The Markdown that should be transformed.</param>
/// <returns>The HTML representation of the supplied Markdown.</returns>
public static IHtmlString Markdown(string text)
{
// Transform the supplied text (Markdown) into HTML.
var markdownTransformer = new Markdown();
markdownTransformer.ExtraMode = true;
string html = markdownTransformer.Transform(text);
// Wrap the html in an MvcHtmlString otherwise it'll be HtmlEncoded and displayed to the user as HTML :(
return new MvcHtmlString(html);
}
/// <summary>
/// Transforms a string of Markdown into HTML.
/// </summary>
/// <param name="helper">HtmlHelper - Not used, but required to make this an extension method.</param>
/// <param name="text">The Markdown that should be transformed.</param>
/// <param name="urlBaseLocation">The url Base Location.</param>
/// <returns>The HTML representation of the supplied Markdown.</returns>
public static IHtmlString Markdown(this HtmlHelper helper, string text, string urlBaseLocation="")
{
// Transform the supplied text (Markdown) into HTML.
var markdownTransformer = new Markdown();
markdownTransformer.ExtraMode = true;
markdownTransformer.UrlBaseLocation = urlBaseLocation;
string html = markdownTransformer.Transform(text);
// Wrap the html in an MvcHtmlString otherwise it'll be HtmlEncoded and displayed to the user as HTML :(
return new MvcHtmlString(html);
}
public static string MarkdownIntro(string markdown, out bool truncated) {
int maxLen = 250;
if (markdown.Length < maxLen) {
truncated = false;
return markdown;
}
string intro = markdown.Remove (maxLen);
truncated = true;
int inl = intro.LastIndexOf ("\n");
if (inl > 20)
intro = intro.Remove (inl);
intro += " ...";
return intro;
}
/// <summary>
/// Markdowns to html intro.
/// </summary>
/// <returns>The to html intro.</returns>
/// <param name="truncated">Truncated.</param>
/// <param name="text">Text.</param>
/// <param name="urlBaseLocation">URL base location.</param>
public static string MarkdownToHtmlIntro(out bool truncated, string text, string urlBaseLocation="") {
var md = MarkdownIntro(text, out truncated);
var markdownTransformer = new Markdown();
markdownTransformer.ExtraMode = true;
markdownTransformer.UrlBaseLocation = urlBaseLocation;
string html = markdownTransformer.Transform(md);
return html;
}
/// <summary>
/// Markdowns to html intro.
/// </summary>
/// <returns>The to html intro.</returns>
/// <param name="helper">Helper.</param>
/// <param name="truncated">Truncated.</param>
/// <param name="text">Text.</param>
/// <param name="urlBaseLocation">URL base location.</param>
public static IHtmlString MarkdownToHtmlIntro(this HtmlHelper helper, out bool truncated, string text, string urlBaseLocation="")
{
// Wrap the html in an MvcHtmlString otherwise it'll be HtmlEncoded and displayed to the user as HTML :(
return new MvcHtmlString(MarkdownToHtmlIntro (out truncated, text, urlBaseLocation));
}
/// <summary>
/// Transforms a string of Markdown into HTML.
/// </summary>
/// <param name="helper">HtmlHelper - Not used, but required to make this an extension method.</param>
/// <param name="text">The Markdown that should be transformed.</param>
/// <returns>The HTML representation of the supplied Markdown.</returns>
public static IHtmlString Markdown(this HtmlHelper helper, string text)
{
// Just call the other one, to avoid having two copies (we don't use the HtmlHelper).
return Markdown(text);
}
}
}