Advertisement
Guest User

codebotsharpweb2

a guest
Nov 17th, 2015
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.79 KB | None | 0 0
  1. namespace Codebot.Lazaurs.Web.Docs
  2. {
  3.     /* CodeSearchTemplate is designed to be run from a web page ajax call */
  4.     [Template("CodeSearch"), Template("CodeSearchItem")]
  5.     public class CodeSearchTemplate : TemplateHandler
  6.     {
  7.         private static string codeSearchSql = DataConnect.LoadResourceText("codesearch.sql");
  8.  
  9.         protected override void Run(StringBuilder output, Templates templates)
  10.         {
  11.             /* Validate input from an ajax post or query string */
  12.             var phrase = Read("phrase").Trim();
  13.             if (phrase.Length < 3)
  14.                 return;
  15.             if (!phrase.IsIdentifier())
  16.                 return;
  17.             /* Convert a sql query to anonymous search result items */
  18.             var searchItems = (DataCommand.Prepare(codeSearchSql)
  19.                 .Add("@phrase", phrase)
  20.                 .Compose(r => new {
  21.                     Path = r.ReadString("path"),
  22.                     Bolden = BoldText(r.ReadString("path"), r.ReadString("name"), phrase),
  23.                     Name = r.ReadString("name"),
  24.                     Kind = BuildKind(r.ReadString("kind"), r.ReadString("path")),
  25.                     Source = r.ReadString("source"),
  26.                     Description = BuildDescription(r.ReadString("description"))
  27.                 }));
  28.             /* Return nothing if there is no result */
  29.             if (searchItems.Count() == 0)
  30.                 return;
  31.             /* Format each item to html with a template */
  32.             SearchItems = templates["CodeSearchItem"].FormatObject(searchItems);
  33.             /* Format an html container for all the results */
  34.             templates["CodeSearch"].FormatObject(this, output);
  35.         }
  36.  
  37.         /* Storage for seach items as html */
  38.         public StringBuilder SearchItems { get; set; }
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement