brooklyn-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From henev...@apache.org
Subject [03/44] incubator-brooklyn git commit: refactor site_structure so it allows arbitrarily-deep menus
Date Fri, 09 Jan 2015 15:34:32 GMT
refactor site_structure so it allows arbitrarily-deep menus

and update html menus to use it, including showing current submenu.
no more need for 'navgroup' or 'id' either, as the page knows where
it is in the menu hierarchy.

(but that will need updating for non-menu pages!)


Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/406948f0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/406948f0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/406948f0

Branch: refs/heads/master
Commit: 406948f0e1672bbf2d2acd3dae2a7aa9e7ea665c
Parents: 7c35d20
Author: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Authored: Tue Dec 23 14:18:13 2014 +0000
Committer: Alex Heneveld <alex.heneveld@cloudsoftcorp.com>
Committed: Wed Jan 7 14:20:38 2015 +0000

----------------------------------------------------------------------
 docs/_includes/topmenu.html       | 32 +++++++------
 docs/_layouts/website-normal.html | 56 +++++++++++++++++++---
 docs/_plugins/site_structure.rb   | 87 +++++++++++++++-------------------
 docs/style/css/base.scss          | 62 +++++++++++++++++++++++-
 docs/website/documentation.md     |  2 +-
 docs/website/index.md             | 10 +---
 docs/website/learnmore/theory.md  |  1 -
 docs/website/sitemap.md           | 19 ++++++++
 8 files changed, 188 insertions(+), 81 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/406948f0/docs/_includes/topmenu.html
----------------------------------------------------------------------
diff --git a/docs/_includes/topmenu.html b/docs/_includes/topmenu.html
index 0230f1c..cd32c9f 100644
--- a/docs/_includes/topmenu.html
+++ b/docs/_includes/topmenu.html
@@ -21,32 +21,34 @@
                     <span class="icon-bar"></span>
                     <span class="icon-bar"></span>
                 </button>
-                {% if page.navgroup != 'home' %}<a class="navbar-brand" href="{{site.path.website}}/"><img
src="{{site.path.style}}/img/apache-brooklyn-logo-244px-wide.png" alt="brooklyn"></a>{%
endif %}
+                {% unless page.landing %}<a class="navbar-brand" href="{{site.path.website}}/"><img
src="{{site.path.style}}/img/apache-brooklyn-logo-244px-wide.png" alt="brooklyn"></a>{%
endunless %}
             </div>
 
             <!-- Collect the nav links, forms, and other content for toggling -->
             <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1">
                 <ul class="nav navbar-nav navbar-right">
-                    {% for navgroup in site.data.navgroups %}
-                    {% if navgroup.page.menu2 %}
-                    <li class="dropdown{% if page.navgroup == navgroup.id %} active{%
endif %}">
-                        <a href="{{navgroup.page.url}}">{{navgroup.title}}</a>
+                  {% for item in site.data.menu %}
+                   {% if item.menu %}
+                    <li class="dropdown{% if page.breadcrumb_paths contains item.path
%} active{% endif %}">
+                        <a href="{{item.url}}">{{ item.title_in_menu | downcase }}</a>
                         <ul class="dropdown-menu" role="menu">
                             <li>
-                                <a href="{{navgroup.page.url}}">{{navgroup.title_in_menu}}</a>
+                                <a href="{{item.url}}">{{item.title_in_menu}}</a>
                             </li>
                             <li class="divider"></li>
-                            {% for child in navgroup.page.menu2 %}
-                            <li>
-                                <a href="{{child.reference.url}}">{{child.reference.title}}</a>
-                            </li>
+                            {% for item2 in item.menu %}
+                              <li>
+                                <a href="{{item2.url}}">{{item2.title_in_menu}}</a>
+                              </li>
                             {% endfor %}
                         </ul>
-                    </li><!-- {{ navgroup.id }} -->
-                    {% else %}
-                    <li class="{% if page.navgroup == navgroup.id %}active{% endif %}"><a
href="{{navgroup.page.url}}">{{navgroup.title}}</a></li><!-- {{ navgroup.id
}} -->
-                    {% endif %}
-                    {% endfor %}
+                    </li>
+                   {% else %}
+                    <li class="{% if page.breadcrumb_paths contains item.path %}active{%
endif %}">
+                      <a href="{{item.url}}">{{ item.title_in_menu | downcase }}</a>
+                    </li>
+                   {% endif %}
+                  {% endfor %}
                 </ul>
             </div><!-- /.navbar-collapse -->
             

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/406948f0/docs/_layouts/website-normal.html
----------------------------------------------------------------------
diff --git a/docs/_layouts/website-normal.html b/docs/_layouts/website-normal.html
index a0596e4..c253664 100644
--- a/docs/_layouts/website-normal.html
+++ b/docs/_layouts/website-normal.html
@@ -27,14 +27,56 @@ layout: website-base
             {{ content }}
         </div>
         <div class="col-md-3">
-            {% if page.menu2 %}
-            <div class="list-group">
-                <h4><a href="{{page.menu2parent.url}}" class="list-group-item{%
if page.menu2parent.path == page.path %} active{% endif %}">{{ page.menu2parent.title }}</a></h4>
-                {% for child in page.menu2 %}
-                <a href="{{child.reference.url}}" class="list-group-item{% if child.reference.path
== page.path %} active{% endif %}">{{ child.reference.title }}</a>
-                {% endfor %}
+            <div class="list-group side-menu">
+{% comment %}
+
+  Case 1) If we're the landing page show nothing.
+  Case 2) If we're contained in the top (landing page) menu, show our menu if we have one.
+  Case 3a) Otherwise if we're contained in a menu, show that menu.
+  Case 3b) And if we have a menu, show our menu nested.
+  
+{% endcomment %}
+{% unless page.landing %}
+  {% if page.menu_parent %}
+    {% if page.menu_parent.landing %} {% comment %} case 2 {% endcomment %}
+              {% for item in page.breadcrumb_pages offset:1 %}
+                  <h4 class="{% if forloop.index0 > 0 %} with_preceding{% endif %}{%
if forloop.rindex0 > 0 %} with_following{% endif %}">
+                    <a href="{{item.url}}" class="list-group-item{% if item.path == page.path
%} active{% endif %} breadcrumb breadcrumb{{ forloop.index0 }}">
+                      {{ item.title_in_menu }}</a></h4>
+              {% endfor %}
+              {% for item in page.menu %}
+                <a href="{{item.url}}" class="list-group-item{% if page.breadcrumbs contains
item %} active{% endif %}">{{ item.title_in_menu }}</a>
+              {% endfor %}
+    
+    {% else %} {% comment %} case 3a {% endcomment %}
+              {% for item in page.menu_parent.breadcrumb_pages offset:1 %}
+                  <h4 class="{% if forloop.index0 > 0 %} with_preceding{% endif %}{%
if forloop.rindex0 > 0 %} with_following{% endif %}">
+                    <a href="{{item.url}}" class="list-group-item{% if item.path == page.path
%} active{% endif %} breadcrumb breadcrumb{{ forloop.index0 }}">
+                      {{ item.title_in_menu }}</a></h4>
+              {% endfor %}
+              {% for item in page.menu_parent.menu %}
+                {% if (page.breadcrumb_paths contains item.path) and page.menu %}
+                  {% comment %} case 3b {% endcomment %}
+                  <a href="{{item.url}}" class="list-group-item active with-sub-item">{{
item.title_in_menu }}</a>
+                  <div class="sub-item">
+                   {% for item2 in page.menu %}
+                    <a href="{{item2.url}}" class="list-group-item sub-item">
+                      {{ item2.title_in_menu }}</a>
+                   {% endfor %}
+                  </div>
+                {% else %}
+                  {% comment %} case 3a side menu item {% endcomment %}
+                  <a href="{{item.url}}" class="list-group-item{% if page.breadcrumb_paths
contains item.path %} active{% endif %}">{{ item.title_in_menu }}</a>
+                {% endif %}
+              {% endfor %}
+        
+    {% endif %}    
+  {% elsif page.menu %}
+    <!-- no pages have a menu without being in the top menu, won't come here -->
+  {% endif %}
+{% endunless %}
+        
             </div>
-            {% endif %}
         </div>
     </div>
 </div>

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/406948f0/docs/_plugins/site_structure.rb
----------------------------------------------------------------------
diff --git a/docs/_plugins/site_structure.rb b/docs/_plugins/site_structure.rb
index e943730..44fec4f 100644
--- a/docs/_plugins/site_structure.rb
+++ b/docs/_plugins/site_structure.rb
@@ -5,10 +5,12 @@ module SiteStructure
   BROOKLYN_WEBSITE_ROOT = "/website/index.md" unless defined? BROOKLYN_WEBSITE_ROOT
   
   class Generator < Jekyll::Generator
+
     def find_page_with_path_absolute_or_relative_to(site, path, referrent, structure_processed_pages)
       uncleaned_path = path
       
       # Pathname API ignores first arg below if second is absolute
+#      puts "converting #{path} wrt #{referrent ? referrent.path : ""}"
       file = Pathname.new(File.dirname(referrent ? referrent.path : "")) + path
       file = file.cleanpath
       # is there a better way to trim a leading / ?
@@ -52,67 +54,56 @@ module SiteStructure
     end
 
     def generate(site)
-      structure_processed_pages = []
-      root_page = find_page_with_path_absolute_or_relative_to(site, SiteStructure::BROOKLYN_WEBSITE_ROOT,
nil, structure_processed_pages)
-      navgroups = root_page.data['navgroups']
-      navgroups.each do |ng|
-        ng['page'] = find_page_with_path_absolute_or_relative_to(site, ng['page'], root_page,
structure_processed_pages)
-        if not ng['title_in_menu']
-          ng['title_in_menu'] = ng['title'].capitalize
-        end
-      end
-      site.data['navgroups'] = navgroups
-      site.data['structure'] = gen_structure(site, SiteStructure::BROOKLYN_WEBSITE_ROOT,
nil, navgroups, structure_processed_pages)
+      site.data.merge!( gen_structure(site, { 'path' => SiteStructure::BROOKLYN_WEBSITE_ROOT
}, nil, [], [], []).data )
+#      puts "ROOT MENU is #{site.data['menu']}"
+#      puts "C1 sub-menu is #{site.data['menu'][0].data['menu'}"
+#but note after processing 'data' on pages is promoted, so you access it like:
+#      puts "C1 sub-menu will be #{site.data['menu'][0]['menu'}"
     end
 
+    # processes liquid tags, e.g. in a link or path object
     def render_liquid(site, page, content)
+      return content unless page
       info = { :filters => [Jekyll::Filters], :registers => { :site => site, :page
=> page } }
       page.render_liquid(content, site.site_payload, info)
     end
         
-    def gen_structure(site, pagename, parent, navgroups, structure_processed_pages)
-      page = find_page_with_path_absolute_or_relative_to(site, pagename, parent, structure_processed_pages)
-      
-      # My navgroup is (first rule matches):
-      # 1. what I have explicitly declared
-      # 2. if I find my path referred to in the global navgroup list
-      # 3. my parent's navgroup
-      unless page.data['navgroup']
-        match = navgroups.detect { |ng| ng['page'] == page }
-        if match
-          page.data['navgroup'] = match['id']
-        elsif parent
-          page.data['navgroup'] = parent.data['navgroup']
-        end
-      end
-            
-      # Figure out second level menu
-      # If there's no parent => I'm at the top level, so no action
-      # If there's a parent, but parent has no parent => I'm at second level, so set second-level
menu
-      # Otherwise, use the parent's second level menu
-      if parent && !parent.data['parent']
-        page.data['menu2parent'] = page
-        page.data['menu2'] = page.data['children']
-      elsif parent && parent.data['parent']
-        page.data['menu2parent'] = parent.data['menu2parent']
-        page.data['menu2'] = parent.data['menu2']
+    def gen_structure(site, item, parent, breadcrumb_pages, breadcrumb_paths, structure_processed_pages)
+#      puts "gen_structure #{item}"
+      breadcrumb_pages = breadcrumb_pages.dup
+      breadcrumb_paths = breadcrumb_paths.dup
+      if (item['path'])      
+        page = find_page_with_path_absolute_or_relative_to(site, render_liquid(site, parent,
item['path']), parent, structure_processed_pages)
+        data = page.data
+        data['path'] = page.path
+        breadcrumb_pages << page
+        breadcrumb_paths << page.path
+      elsif (item['link'])
+        data = { 'link' => render_liquid(site, parent, item['link']) }
+        page = { 'data' => data }
+        breadcrumb_pages << data
+        breadcrumb_paths << item['link']
+      else
+        raise "Link to #{item} in #{parent ? parent.path : nil} must have link or path"
       end
       
-      page.data['parent'] = parent
-      if page.data['children']
-        page.data['children'].each do |c|
-          if c['path']
-            # links to another Jekyll site-structured page
-            c['reference'] = gen_structure(site, render_liquid(site, page, c['path']), page,
navgroups, structure_processed_pages)
-          elsif c['link']
-            # links to a non-site-structured page, on this site or elsewhere
-            # allow title and link to use vars and tags (liquid processing)
-            c['reference'] = { 'url' => render_liquid(site, page, c['link']), 'title'
=> render_liquid(site, page, c['title']) }
-          end
+      data['breadcrumb_pages'] = breadcrumb_pages
+      data['breadcrumb_paths'] = breadcrumb_paths
+      data['menu_parent'] = parent
+      
+      data['title_in_menu'] = item['title_in_menu'] || item['title'] || data['title_in_menu']
|| data['title']
+#      puts "built #{data}, now looking at children"
+      
+      if (data['children'])
+        data['menu'] = []
+        data['children'].each do |child|
+          data['menu'] << gen_structure(site, child, page, breadcrumb_pages, breadcrumb_paths,
structure_processed_pages)
         end
       end
       
       page
     end
+    
   end
+
 end

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/406948f0/docs/style/css/base.scss
----------------------------------------------------------------------
diff --git a/docs/style/css/base.scss b/docs/style/css/base.scss
index 3dd60bd..5912d73 100644
--- a/docs/style/css/base.scss
+++ b/docs/style/css/base.scss
@@ -71,11 +71,71 @@ a[id]:empty, a[name]:empty {
 }
 .navbar-icon-shift { margin-right: -2px; }
 
-/* pop-up menu */
+/* pop-up top-menu */
 ul.nav li.dropdown:hover > ul.dropdown-menu {
     display: block;
 }
 
+/* side menu */
+.side-menu {
+  h4.with_following {
+    margin-bottom: 0;
+  }
+  h4.with_preceding {
+    margin-top: 0;
+  }
+  h4.with_following a {
+    border-bottom-right-radius: 0 !important ;
+    border-bottom-left-radius: 0 !important ;
+    border-bottom: 0;
+  }
+  h4.with_preceding a {
+    border-top-right-radius: 0;
+    border-top-left-radius: 0;
+    border-top: 0;
+  }
+  a, a.breadcrumb.breadcrumb0 { padding-left: 15px; }
+  a.breadcrumb.breadcrumb1 { padding-left: 30px; }
+  a.breadcrumb.breadcrumb2 { padding-left: 45px; }
+  a.breadcrumb.breadcrumb3 { padding-left: 60px; }
+  /* further crumbs all get the same */
+  a.breadcrumb { padding-left: 70px; }
+  
+  div.sub-item {
+    background-color: #48a648;
+    border-left: 1px solid #428bca;
+    /*
+    border-bottom: 1px solid #428bca;
+    border-top: 1px solid #428bca;
+    border-right: 1px solid #428bca;
+    */
+    /*
+    padding-bottom: 6px;
+    padding-right: 6px;
+    */
+  } 
+  div.sub-item:last-child {
+    border-bottom: 1px solid #ddd;
+    border-bottom-left-radius: 4px;
+    border-bottom-right-radius: 4px;
+  }
+  div.sub-item:last-child a.sub-item:last-child {
+    border-bottom-right-radius: 4px !important;
+  }
+  a.with-sub-item {
+    /* border-bottom: 1px solid #ddd; */
+    border-bottom: 0;
+  }
+  a.sub-item { 
+    border-radius: 0 !important;
+    border-bottom: 0;
+    margin-left: 12px;
+    padding-left: 10px; 
+    padding-top: 8px; 
+    padding-bottom: 8px; 
+  }
+}
+
 
 /* FOOTER
    ----------------------------------------------------------------------- */

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/406948f0/docs/website/documentation.md
----------------------------------------------------------------------
diff --git a/docs/website/documentation.md b/docs/website/documentation.md
index 4ad3c8e..9b9edc8 100644
--- a/docs/website/documentation.md
+++ b/docs/website/documentation.md
@@ -2,7 +2,7 @@
 layout: website-normal
 title: Documentation
 children:
-- { link: "{{ site.path.guide }}", title: User Guide }
+- { path: ../guide/index.md, title_in_menu: User Guide }
 - { path: glossary.md }
 - { path: documentation/install-on-server.md }
 ---

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/406948f0/docs/website/index.md
----------------------------------------------------------------------
diff --git a/docs/website/index.md b/docs/website/index.md
index c199f77..481fb84 100644
--- a/docs/website/index.md
+++ b/docs/website/index.md
@@ -1,19 +1,13 @@
 ---
 layout: website-landing
 title: Home
-navgroup: home
+landing: true
 children:
 - { path: learnmore/index.md }
 - { path: download.md }
-- { path: quickstart/index.md }
+- { path: quickstart/index.md, title: Get Started }
 - { path: documentation.md }
 - { path: community/index.md }
-navgroups:
-- { id: learnmore, page: learnmore/index.md, title: learn more, title_in_menu: Learn More
}
-- { id: download, page: download.md, title: download }
-- { id: getstarted, page: quickstart/index.md, title: get started, title_in_menu: Get Started
}
-- { id: documentation, page: documentation.md, title: documentation, title_in_menu: All Documentation
}
-- { id: community, page: community/index.md, title: community, title_in_menu: Community Home
}
 ---
 
 <div class="jumbotron">

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/406948f0/docs/website/learnmore/theory.md
----------------------------------------------------------------------
diff --git a/docs/website/learnmore/theory.md b/docs/website/learnmore/theory.md
index 33d9b18..f1c3899 100644
--- a/docs/website/learnmore/theory.md
+++ b/docs/website/learnmore/theory.md
@@ -1,7 +1,6 @@
 ---
 layout: website-normal
 title: The Theory behind Brooklyn
-navgroup: learnmore
 ---
 
 <div class="jumobotron" markdown="1">

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/406948f0/docs/website/sitemap.md
----------------------------------------------------------------------
diff --git a/docs/website/sitemap.md b/docs/website/sitemap.md
new file mode 100644
index 0000000..efff2b2
--- /dev/null
+++ b/docs/website/sitemap.md
@@ -0,0 +1,19 @@
+---
+layout: website-normal
+title: Site Map
+---
+
+<!-- TODO this is very much work in progress -->
+
+Site map is:
+
+{% for item in site.data.menu %}
+&nbsp;&nbsp;&nbsp; * {{ item['title_in_menu'] }} / {{ item.data['title'] }} -
{{ item.data }}<br/>
+  {% for item2 in item['menu'] %}
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * {{ item2['title_in_menu']
}} / {{ item2['path'] }} / {{ item2['link'] }}<br/>
+    {% for item3 in item2['menu'] %}
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
* {{ item3['title_in_menu'] }} / {{ item3['path'] }} / {{ item3['breadcrumbs'] }}<br/>
+    {% endfor %}
+  {% endfor %}
+{% endfor %}
+


Mime
View raw message