예제 #1
0
        public static HtmlTag BottleSnippetFor(this IFubuPage page, string snippetName)
        {
            var project  = page.Get <ITopicContext>().Project;
            var snippets = page.Get <ISnippetCache>();

            Snippet snippet = null;

            try
            {
                if (project == null)
                {
                    snippet = snippets.Find(snippetName);
                }
                else
                {
                    snippet = snippets.As <SnippetCache>().FindByBottle(snippetName, project.BottleName) ??
                              snippets.Find(snippetName);
                }
            }
            catch (Exception)
            {
                throw new ArgumentOutOfRangeException("snippetName", "Requested snippet '{0}' does not exist".ToFormat(snippetName));
            }

            if (snippet == null)
            {
                throw new ArgumentOutOfRangeException("snippetName", "Requested snippet '{0}' does not exist".ToFormat(snippetName));
            }

            return(page.CodeSnippet(snippet));
        }