Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- namespace Codebot.Lazaurs.Web.Docs
- {
- /* CodeSearchTemplate is designed to be run from a web page ajax call */
- [Template("CodeSearch"), Template("CodeSearchItem")]
- public class CodeSearchTemplate : TemplateHandler
- {
- private static string codeSearchSql = DataConnect.LoadResourceText("codesearch.sql");
- protected override void Run(StringBuilder output, Templates templates)
- {
- /* Validate input from an ajax post or query string */
- var phrase = Read("phrase").Trim();
- if (phrase.Length < 3)
- return;
- if (!phrase.IsIdentifier())
- return;
- /* Convert a sql query to anonymous search result items */
- var searchItems = (DataCommand.Prepare(codeSearchSql)
- .Add("@phrase", phrase)
- .Compose(r => new {
- Path = r.ReadString("path"),
- Bolden = BoldText(r.ReadString("path"), r.ReadString("name"), phrase),
- Name = r.ReadString("name"),
- Kind = BuildKind(r.ReadString("kind"), r.ReadString("path")),
- Source = r.ReadString("source"),
- Description = BuildDescription(r.ReadString("description"))
- }));
- /* Return nothing if there is no result */
- if (searchItems.Count() == 0)
- return;
- /* Format each item to html with a template */
- SearchItems = templates["CodeSearchItem"].FormatObject(searchItems);
- /* Format an html container for all the results */
- templates["CodeSearch"].FormatObject(this, output);
- }
- /* Storage for seach items as html */
- public StringBuilder SearchItems { get; set; }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement