From 7acd09b1a02ea9d4178809c12213cd06bbd5a3ed Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Mon, 3 May 2010 19:08:15 -0700 Subject: [PATCH] [Docs] Move some markup from a helper to partials. --- .../layouts/partials/sidebar/container.haml | 1 + doc-src/layouts/partials/sidebar/heading.haml | 3 +++ doc-src/layouts/partials/sidebar/item.haml | 2 ++ doc-src/lib/default.rb | 24 +++++++++---------- 4 files changed, 18 insertions(+), 12 deletions(-) create mode 100644 doc-src/layouts/partials/sidebar/container.haml create mode 100644 doc-src/layouts/partials/sidebar/heading.haml create mode 100644 doc-src/layouts/partials/sidebar/item.haml diff --git a/doc-src/layouts/partials/sidebar/container.haml b/doc-src/layouts/partials/sidebar/container.haml new file mode 100644 index 00000000..71611ba4 --- /dev/null +++ b/doc-src/layouts/partials/sidebar/container.haml @@ -0,0 +1 @@ +%ul= @contents \ No newline at end of file diff --git a/doc-src/layouts/partials/sidebar/heading.haml b/doc-src/layouts/partials/sidebar/heading.haml new file mode 100644 index 00000000..d03ee8a3 --- /dev/null +++ b/doc-src/layouts/partials/sidebar/heading.haml @@ -0,0 +1,3 @@ +%li{:class => ("selected" if @selected)} + - haml_tag(@heading) do + %a{:href => default_path(@current_item), :class => ("selected" if @selected)}= @crumb diff --git a/doc-src/layouts/partials/sidebar/item.haml b/doc-src/layouts/partials/sidebar/item.haml new file mode 100644 index 00000000..3fcd05f6 --- /dev/null +++ b/doc-src/layouts/partials/sidebar/item.haml @@ -0,0 +1,2 @@ +%li{:class => ("selected" if @selected)} + %a{:href => default_path(@current_item), :class => ("selected" if @selected)}= @crumb diff --git a/doc-src/lib/default.rb b/doc-src/lib/default.rb index 79f5fc8a..4e9ec540 100644 --- a/doc-src/lib/default.rb +++ b/doc-src/lib/default.rb @@ -69,7 +69,6 @@ def item_tree(item, options = {}) child_html = "" if options.fetch(:depth,1) > 0 if item.children.any? - child_html << "" - end + end else options.delete(:heading_level) end + child_html = render("partials/sidebar/container", :contents => child_html) unless child_html.size == 0 css_class = nil - prefix = nil - suffix = nil - if item.identifier == @item.identifier - css_class = %Q{class="selected"} - end contents = unless options[:omit_self] - hl = if options[:heading_level] - "h#{options[:heading_level]}" + item_opts = { + :current_item => item, + :selected => item.identifier == @item.identifier, + :crumb => item[:crumb] || item[:title] + } + if options[:heading_level] + render("partials/sidebar/heading", + item_opts.merge(:heading => "h#{options[:heading_level]}") + ) else - "span" + render("partials/sidebar/item", item_opts) end - %Q{
  • <#{hl}>#{crumb}
  • } end %Q{#{contents}#{child_html}} end