[Lazarus] getlazarus.org search request

Michael Van Canneyt michael at freepascal.org
Mon Aug 12 10:59:25 CEST 2019



Ah, but this is C# ?

I don't think you need more code in FPC to do the same.
But if there are proposals to reduce the amount of code in FPC even more, I'm open for suggestions.

Michael.

On Mon, 12 Aug 2019, Anthony Walter via lazarus wrote:

> Michael,
>
> Here is an example of how easy it is.
>
>    public class CodeSearch : TemplateHandler
>    {
>        private static readonly string searchSql =
> "search.sql".LoadResourceText();
>
>        protected override void Run(Templates templates, StringBuilder
> output)
>        {
>            SearchItems = DataCommand
>                .Prepare(searchSql)
>                .Add("@phrase", Read("phrase"))
>                .Compose();
>            templates[Read("format") + "SearchItem"].FormatObject(this,
> output);
>        }
>
>        public IEnumerable<object> SearchItems { get; set; }
>    }
>
> So given the url,
> https://docs.getlazarus.org/?method=codesearch&format=xml&phrase=TStringList in
> steps:
>
> 1) The library automatically finds the CodeSearch class without any code to
> write
> 2) It runs the template handler automatically
> 3) In run we execute some SQL to search for a phrase and compose the
> results as a collection of anonymous objects
> 4) The we select the template we want and format the CodeSearch object and
> its available properties, in this case our search result "SearchItems".
>
> The FormatObject method is a template engine that uses reflection to lookup
> properties with mustache braces. It has the ability to query subproperties
> and use all available format specifiers. Collection properties (IEnumerable
> <T>) are expanded by a detail template that can read through reflection the
> properties of the anonymous objects in the collection by name and template
> them as well.
>
> Here are some template examples. Note you can access sub properties using
> object.suprop.susubprop syntax as well as custom formatting in the template
> (i.e. Price:C2 or Page.Modified:yyyyy-mm-dd).
>
> <title>{Title}</title> or <title>{Page.Title}</title> // Welcome to our
> website
> <div>Price is {Amount:C2}</div> // Price is $15.75
> <div>Page modified on {Page.Modified:yyyyy-mm-dd}</div> // Page modified on
> 2019-07-10
> <div>{SeachItems}</div> // Expands our template
>


More information about the lazarus mailing list