site map builds from menu using a bunch of new jekyll util items which seemed needed to support recursion
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/ad35d390 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/ad35d390 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/ad35d390 Branch: refs/heads/master Commit: ad35d3900506b67acab8ed5d31210f841ffa75bc Parents: e424b74 Author: Alex Heneveld <[email protected]> Authored: Mon Jan 12 23:32:09 2015 +0000 Committer: Alex Heneveld <[email protected]> Committed: Tue Jan 13 15:36:30 2015 +0000 ---------------------------------------------------------------------- docs/_includes/sitemap-item.html | 34 ++++++++ docs/_plugins/brooklyn_jekyll_util.rb | 129 +++++++++++++++++++++++++++++ docs/_plugins/site_structure.rb | 2 +- docs/website/meta/sitemap.md | 16 ++-- 4 files changed, 171 insertions(+), 10 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ad35d390/docs/_includes/sitemap-item.html ---------------------------------------------------------------------- diff --git a/docs/_includes/sitemap-item.html b/docs/_includes/sitemap-item.html new file mode 100644 index 0000000..e2f0e76 --- /dev/null +++ b/docs/_includes/sitemap-item.html @@ -0,0 +1,34 @@ +{% pop site_items item %} +{% set_hash_entry item path item_path %} + {% set_hash_entry item url item_url %} + +{% unless item_path %} + {% unless item_url %} + {% puts error, null item_url %} + {% putp item %} + {% putv item_url %} + {% fail item missing path and url (jekyll block evaluation order can cause this) %} + {% endunless %} +{% endunless %} + +<a id="{{ item_path }}"></a> +<li> + {% if visited contains item_path %} + {{ item['title'] }} (<a href="#{{ item_path }}">repeat</a>) + {% elsif item['external'] %} + {{ item['title'] }} (<a href="{{ item['url'] }}">external</a>) + {% else %} + <a href="{{ item['url'] }}">{{ item['title'] }}</a> + {% if item['menu'] %} + {% push visited item_path %} + <ul> + {% push site_items item %} + {% for item in site_items[-1]['menu'] %} + {% push site_items item %} + {% include sitemap-item.html %} + {% endfor %} + {% pop site_items item %} + </ul> + {% endif %} + {% endif %} +</li> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ad35d390/docs/_plugins/brooklyn_jekyll_util.rb ---------------------------------------------------------------------- diff --git a/docs/_plugins/brooklyn_jekyll_util.rb b/docs/_plugins/brooklyn_jekyll_util.rb new file mode 100644 index 0000000..fd3688d --- /dev/null +++ b/docs/_plugins/brooklyn_jekyll_util.rb @@ -0,0 +1,129 @@ +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# + +# useful tags: + +# printing +# puts message +# putv variable_to_print_raw +# putp variable_to_pretty_print + +# eval and control flow +# set_hash_entry hash key variable_to_set # because sometimes jekyll eval order is different +# fail message # to fail with a message + +# stack manipulation: +# push stack x # pushs x to stack and clears x +# pop stack x # pops from stack into x +# useful e.g. in recursive include calls where x might overwritten + +require 'pp' + +module BrooklynJekyllUtil + class PutsTag < Liquid::Tag + def initialize(tag_name, text, tokens) + super + @text = text + end + def render(context) + puts "#{@text}" + end + end + class PutvTag < Liquid::Tag + def initialize(tag_name, text, tokens) + super + @text = text + end + def render(context) + puts "#{@text}: #{context[@text]}" + end + end + class PutpTag < Liquid::Tag + def initialize(tag_name, text, tokens) + super + @text = text + end + def render(context) + puts "#{@text}:" + PP.pp(context[@text]) + nil + end + end + + class SetHashEntryTag < Liquid::Tag + def initialize(tag_name, text, tokens) + super + @text = text + end + def render(context) + args = @text.split(/\W+/) + raise "Need 3 args, the hash, the key, and the var to set" unless args.length == 3 +# puts "getting #{args[0]}['#{args[1]}']" +# PP.pp(context[args[0]]) +# PP.pp(context[args[0]][args[1]]) + + context[args[2]] = context[args[0]][args[1]] + nil + end + end + + class FailTag < Liquid::Tag + def initialize(tag_name, text, tokens) + super + @text = text + end + def render(context) + raise "Fail#{@text.length>0 ? ": #{@text}" : ""}" + end + end + + class PushTag < Liquid::Tag + def initialize(tag_name, text, tokens) + super + @text = text + end + def render(context) + args = @text.split(/\W+/) + raise "Need 2 args, the stack and the var" unless args.length == 2 + context[args[0]] = [] unless context[args[0]] + context[args[0]].push(context[args[1]]) + context[args[1]] = nil + end + end + class PopTag < Liquid::Tag + def initialize(tag_name, text, tokens) + super + @text = text + end + def render(context) + args = @text.split(/\W+/) + raise "Need 2 args, the stack and the var" unless args.length == 2 + context[args[1]] = context[args[0]].pop(); + nil + end + end +end + +Liquid::Template.register_tag('puts', BrooklynJekyllUtil::PutsTag) +Liquid::Template.register_tag('putv', BrooklynJekyllUtil::PutvTag) +Liquid::Template.register_tag('putp', BrooklynJekyllUtil::PutpTag) +Liquid::Template.register_tag('set_hash_entry', BrooklynJekyllUtil::SetHashEntryTag) +Liquid::Template.register_tag('fail', BrooklynJekyllUtil::FailTag) +Liquid::Template.register_tag('push', BrooklynJekyllUtil::PushTag) +Liquid::Template.register_tag('pop', BrooklynJekyllUtil::PopTag) http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ad35d390/docs/_plugins/site_structure.rb ---------------------------------------------------------------------- diff --git a/docs/_plugins/site_structure.rb b/docs/_plugins/site_structure.rb index ff2ab82..dd3680c 100644 --- a/docs/_plugins/site_structure.rb +++ b/docs/_plugins/site_structure.rb @@ -236,7 +236,7 @@ module SiteStructure elsif (item['link']) puts "setting up #{item} as link" if @@verbose link = render_liquid(site, parent, item['link']) - data = { 'link' => link, 'url' => link } + data = { 'link' => link, 'url' => link, 'external' => true } data['title'] = item['title'] if item['title'] breadcrumb_pages << data breadcrumb_paths << data['link'] http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/ad35d390/docs/website/meta/sitemap.md ---------------------------------------------------------------------- diff --git a/docs/website/meta/sitemap.md b/docs/website/meta/sitemap.md index efff2b2..1341959 100644 --- a/docs/website/meta/sitemap.md +++ b/docs/website/meta/sitemap.md @@ -5,15 +5,13 @@ title: Site Map <!-- TODO this is very much work in progress --> -Site map is: +<div class="sitemap"> +{% assign visited = "" | split: "|" %} +{% assign site_items = "" | split: "|" %} +<ul> {% for item in site.data.menu %} - * {{ item['title_in_menu'] }} / {{ item.data['title'] }} - {{ item.data }}<br/> - {% for item2 in item['menu'] %} - * {{ item2['title_in_menu'] }} / {{ item2['path'] }} / {{ item2['link'] }}<br/> - {% for item3 in item2['menu'] %} - * {{ item3['title_in_menu'] }} / {{ item3['path'] }} / {{ item3['breadcrumbs'] }}<br/> - {% endfor %} - {% endfor %} + {% push site_items item %} + {% include sitemap-item.html %} {% endfor %} - +</ul>
