Created
January 27, 2012 06:12
-
-
Save skoon/1687322 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using ScrewTurn.Wiki.PluginFramework; | |
using ScrewTurn.Wiki; | |
using System.Text.RegularExpressions; | |
namespace DevCentral.ScrewTurnProviders | |
{ | |
public class KeywordPlugin : IFormatterProviderV30 | |
{ | |
private static readonly ComponentInformation _info = new ComponentInformation("ListPagesWithGivenKeyword" | |
, "DevCentral" | |
, "1.0.0.0" | |
, "http://devcentral.f5.com" | |
, "http://devcentral.f5.com"); | |
private static readonly Regex _customTagRegex = new Regex(@"{listpageswithkeyword key=(?<keyword>(.+?))}", | |
RegexOptions.Compiled | RegexOptions.Singleline | | |
RegexOptions.IgnoreCase | RegexOptions.CultureInvariant); | |
public int ExecutionPriority | |
{ | |
get { return 50; } | |
} | |
public string Format(string raw, ContextInformation context, FormattingPhase phase) | |
{ | |
var matches = _customTagRegex.Matches(raw); | |
if (matches != null || matches.Count == 0) return raw; | |
var buffer = new StringBuilder(raw); | |
var pages = Pages.GetPages(Tools.DetectCurrentNamespaceInfo()); | |
foreach (Match match in matches) { | |
var sb = new StringBuilder(); | |
string keywordToMatch = match.Groups["keyword"].Value; | |
sb.Append("<ul>"); | |
foreach (PageInfo p in pages) { | |
var content = p.Provider.GetContent(p); | |
if (content.Keywords.Contains(keywordToMatch)) { | |
sb.Append(@"<li><a href="""); | |
UrlTools.BuildUrl(sb, Tools.UrlEncode(p.FullName), Settings.PageExtension); | |
sb.Append(@""">"); | |
sb.Append(content.Title); | |
sb.Append("</a> - "); | |
sb.Append(content.Description); | |
sb.Append("</li>"); | |
} | |
} | |
sb.Append("</ul>"); | |
buffer.Remove(match.Index, match.Value.Length); | |
buffer.Insert(match.Index, sb.ToString()); | |
} | |
/* Get namespace and categories */ | |
return buffer.ToString(); | |
} | |
public bool PerformPhase1 | |
{ | |
get { return false; } | |
} | |
public bool PerformPhase2 | |
{ | |
get { return true; } | |
} | |
public bool PerformPhase3 | |
{ | |
get { return false; } | |
} | |
public string PrepareTitle(string title, ContextInformation context) | |
{ | |
return title; | |
} | |
public string ConfigHelpHtml | |
{ | |
get { return null; } | |
} | |
public ComponentInformation Information | |
{ | |
get { return _info; } | |
} | |
public void Init(IHostV30 host, string config) | |
{ | |
//do nothing | |
} | |
public void Shutdown() | |
{ | |
//do nothing | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment