public void CanGetTitle() { var command = new LoadSiteConfigCommand() { ConfigPath = "data\\site.config" }; var config = command.ExecuteAsync().Result; var site = new Site(config, Enumerable.Empty<DataFile>(), Enumerable.Empty<DocumentFile>(), Enumerable.Empty<StaticFile>(), Enumerable.Empty<LayoutFile>()); dynamic data = new DynamicSite(null, site); Assert.Equal("Test Blog.", (string)data.tiTle); }
private static IEnumerable<dynamic> ParseSource(DynamicSite site, string[] tokens, ref int i) { ++i; var source = tokens[i].ToLowerInvariant(); switch (source) { case "data": return site[source] as IEnumerable<dynamic>; case "documents": return site[source] as IEnumerable<dynamic>; //case "files": // return site.Files; //case "layouts": // return site.Layouts; default: throw new InvalidOperationException(String.Format("Unknown query source: {0}", source)); } }
public static QueryResult Parse(Site site, string query) { var dynamicSite = new DynamicSite(null, site); var result = new QueryResult(); // query documents every 10 where relativepath startswith "documents\posts\" descending date formaturl "posts/page/{0}" var tokens = ParseTokens(query).ToArray(); for (int i = 0; i < tokens.Length; ++i) { var token = tokens[i].ToLowerInvariant(); switch (token) { case "query": result.Source = ParseSource(dynamicSite, tokens, ref i); break; case "ascending": case "descending": result.Order = ParseOrder(tokens, ref i); break; case "every": result.PageEvery = ParseEvery(tokens, ref i); break; case "formaturl": result.FormatUrl = ParseFormatUrl(tokens, ref i); break; case "take": result.Take = ParseTake(tokens, ref i); break; case "where": result.Where = ParseWhere(tokens, ref i); break; default: throw new InvalidOperationException(String.Format("Unknown query token: {0}", token)); } } var q = result.Source.AsQueryable(); if (result.Where != null) { q = q.Cast<IDictionary<string, object>>().Where(e => WhereQuery(result.Where, e)); } if (result.Order != null) { if (result.Order.Operator == OrderOperator.Ascending) { q = q.Cast<IDictionary<string, object>>().OrderBy(e => OrderProperty(result.Order, e)); } else { q = q.Cast<IDictionary<string, object>>().OrderByDescending(e => OrderProperty(result.Order, e)); } } if (result.Take > 0) { q = q.Take(result.Take); } result.Results = q; return result; }