Skip to content

Commit

Permalink
Sitemap and twitterfeed stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
perploug committed Aug 16, 2012
1 parent dcd460a commit e35f24b
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 66 deletions.
82 changes: 29 additions & 53 deletions Stubs/cshtml/SiteMap.cshtml
Original file line number Diff line number Diff line change
@@ -1,62 +1,38 @@
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@inherits umbraco.MacroEngines.DynamicNodeContext

@{
@* Walk up the tree from the current page to get the root node *@
var rootNode = CurrentPage.AncestorsOrSelf.Last();
var rootNode = Model.AncestorOrself(1);
}

@* Ensure that the Root Node has children, where the property umbracoNaviHide is not True *@
@if (rootNode.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Get the first page in the children, where the property umbracoNaviHide is not True *@
var naviLevel = rootNode.Children.Where("umbracoNaviHide != @0", "True").First().Level;

@* Add in level for a CSS hook *@
<ul class="level-@naviLevel">
@* For each child page under the root node, where the property umbracoNaviHide is not True *@
@foreach (var childPage in rootNode.Children.Where("umbracoNaviHide != @0", "True"))
{
<li>
<a href="@childPage.Url">@childPage.Name</a>

@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (childPage.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Call our helper to display the children *@
@childPages(childPage.Children)
}
</li>
}
</ul>
}
@*Render the sitemap by passing the root node to the traverse helper*@
<div class="sitemap">
@traverse(@Model.AncestorOrSelf())
</div>



@*Helper method to travers through all descendants*@
@helper traverse(dynamic node){

@*If a MaxLevelForSitemap parameter is passed to the macro, otherwise default to 4 levels*@
var maxLevelForSitemap = String.IsNullOrEmpty(Parameter.MaxLevelForSitemap) ? 4 : int.Parse(Parameter.MaxLevelForSitemap);

@*Select visible children *@
var items = node.Children.Where("Visible").Where("Level <= " + maxLevelForSitemap);


@*If any items are returned, render a list *@
if (items.Any()) {
<ul>
@foreach (var item in items) {
<li class="[email protected]">
<a href="@item.Url">@item.Name</a>

@helper childPages(dynamic pages)
{
@* Ensure that we have a collection of pages *@
if (pages.Any())
{
@* Get the first page in pages and get the level *@
var naviLevel = pages.First().Level;

@* Add in level for a CSS hook *@
<ul class="level-@(naviLevel)">
@foreach (var page in pages.Where("umbracoNaviHide != @0", "True"))
{
<li>
<a href="@page.Url">@page.Name</a>

@* if the current page has any children, where the property umbracoNaviHide is not True *@
@if (page.Children.Where("umbracoNaviHide != @0", "True").Any())
{
@* Call our helper to display the children *@
@childPages(page.Children)
}
</li>
}
</ul>
@*Run the traverse helper again *@
@traverse(item)
</li>
}
</ul>
}
}
24 changes: 11 additions & 13 deletions Stubs/cshtml/TwitterFeed.cshtml
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
@inherits PartialViewMacroPage
@using Umbraco.Cms.Web
@using Umbraco.Cms.Web.Macros
@using Umbraco.Framework
@inherits umbraco.MacroEngines.DynamicNodeContext


@{
@*
=== Macro Parameters To Create ===
Macro Parameters To Create
Show:True Alias:twitterUsername Name:Twitter Username Type:Textstring Defaults to: umbraco
Show:True Alias:includeRTs Name:Include Retweets? Type:Textstring Defaults to: false
Show:True Alias:excludeReplies Name:Exclude @Replies? Type:Textstring Defaults to: false
Show:True Alias:includeRTs Name:Include Retweets Type:Textstring Defaults to: false
Show:True Alias:excludeReplies Name:Exclude Replies Type:Textstring Defaults to: false
Show:True Alias:noTweets Name:Number of Tweets Type:Integer Defaults to: 1
*@
*@

var twitterUsername = String.IsNullOrEmpty(Model.MacroParameters.twitterUsername) ? "umbraco" : Model.MacroParameters.twitterUsername;
var includeRTs = String.IsNullOrEmpty(Model.MacroParameters.includeRTs) ? false : Model.MacroParameters.includeRTs;
var excludeReplies = String.IsNullOrEmpty(Model.MacroParameters.excludeReplies) ? false : Model.MacroParameters.excludeReplies;
var noTweets = String.IsNullOrEmpty(Model.MacroParameters.noTweets) ? 1 : Model.MacroParameters.noTweets;
var twitterUsername = String.IsNullOrEmpty(Parameter.twitterUsername) ? "umbraco" : Parameter.twitterUsername;
var includeRTs = String.IsNullOrEmpty(Parameter.includeRTs) ? false : Parameter.includeRTs;
var excludeReplies = String.IsNullOrEmpty(Parameter.excludeReplies) ? false : Parameter.excludeReplies;
var noTweets = String.IsNullOrEmpty(Parameter.noTweets) ? 1 : Parameter.noTweets;


@* Twitter JSON URL *@
Expand All @@ -25,9 +23,9 @@
includeRTs,
excludeReplies,
noTweets);

}


@* Fetch the JSON from Twitters API *@
@using (var client = new System.Net.WebClient())
{
Expand Down

0 comments on commit e35f24b

Please sign in to comment.