public void SetUp() { _builder = new TokenBuilder <BlogTemplate>(); _builder.Interpolate("{Content('", ".*", "')}", data => data.ToString()); _builder.Interpolate("{Url('", @"(?<controller>.*)/(?<action>.*)(/(?<id>\d*)){0,1}", "')}", data => data.ToString()); _builder.Tokenize(b => b.BlogTitle, @"{PageTitle}"); _builder.Tokenize(b => b.JavaScriptIncludes, @"{JavaScriptIncludes}"); _builder.TokenizeIf(b => b.Post, @"{Post}", b => b.Post != null, ctx => { ctx.Tokenize(b => b.PostTitle, @"{PostTitle}"); ctx.Tokenize(b => b.PostDescription, @"{PostDescription}"); ctx.Tokenize(b => b.PostBody, @"{PostBody}"); ctx.Block(d => d.Comments, @"{Comments}", commentContext => { commentContext.Tokenize(c => c.Email, @"{Comment.Email}"); commentContext.Tokenize(c => c.Author, @"{Comment.Author}"); commentContext.Tokenize(c => c.Text, @"{Comment.Text}"); }).EndsWith(@"{/Comments}"); }).EndsWith(@"{/Post}"); _builder.Block(b => b.Posts, @"{Posts}", postContext => { postContext.Tokenize(d => d.PostTitle, @"{Post.Title}"); postContext.Tokenize(d => d.PostDescription, @"{Post.Description}"); postContext.Tokenize(d => d.PostBody, @"{Post.Body}"); postContext.Tokenize(d => d.PostedOn.ToShortDateString(), @"{Post.Date}"); postContext.Block(d => d.Comments, @"{Comments}", commentContext => { commentContext.Tokenize(c => c.Email, @"{Comment.Email}"); commentContext.Tokenize(c => c.Author, @"{Comment.Author}"); commentContext.Tokenize(c => c.Text, @"{Comment.Text}"); }).EndsWith(@"{/Comments}"); }).EndsWith(@"{/Posts}"); }
public void Builder_can_create_a_simple_token_and_two_blocks() { _builder.Tokenize(b => b.BlogTitle, @"{PageTitle}"); _builder.TokenizeIf(b => b.Post, @"{Post}", b => b.Post != null, ctx => { ctx.Tokenize(b => b.PostTitle, @"{Title}"); ctx.Tokenize(b => b.PostDescription, @"{Description}"); ctx.Tokenize(b => b.PostBody, @"{PostBody}"); }).EndsWith(@"{/Post}"); _builder.Block(b => b.Posts, @"{Posts}", postContext => { postContext.Tokenize(d => d.PostTitle, @"{Post.Title}"); postContext.Tokenize(d => d.PostDescription, @"{Post.Description}"); postContext.Tokenize(d => d.PostBody, @"{Post.Body}"); postContext.Tokenize(d => d.PostedOn.ToShortDateString(), @"{Post.Date}"); postContext.Block(d => d.Comments, @"{Comments}", commentContext => { commentContext.Tokenize(c => c.Email, @"{Comment.Email}"); commentContext.Tokenize(c => c.Author, @"{Comment.Author}"); commentContext.Tokenize(c => c.Text, @"{Comment.Text}"); }).EndsWith(@"{/Comments}"); }).EndsWith(@"{/Posts}"); _builder.Token.Children.Count().ShouldEqual(3); }