From faf769cd39408805f02e897907cdce49cd069518 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Tue, 4 Jan 2011 10:42:05 -0800 Subject: [PATCH] Better index structure for vars, mixins, and functions. --- doc-src/content/index/functions.haml | 9 ++++--- doc-src/content/index/mixins.haml | 10 +++---- doc-src/content/index/variables.haml | 10 +++---- doc-src/lib/default.rb | 6 +++++ doc-src/lib/stylesheets.rb | 40 +++++++++------------------- 5 files changed, 34 insertions(+), 41 deletions(-) diff --git a/doc-src/content/index/functions.haml b/doc-src/content/index/functions.haml index 6f918437..423d5000 100644 --- a/doc-src/content/index/functions.haml +++ b/doc-src/content/index/functions.haml @@ -6,11 +6,12 @@ body_id: home %article %h1#logo Sass Based Functions - - all_functions.sort_by{|i| i.first.identifier}.each do |item, functions| - %h3= link_to item[:title], item + - all_functions.sorted_and_grouped_by_name{|f| f.last.name }.each do |(group, functions)| + %h3= group %ul - - functions.sort_by{|f| f.name}.each do |f| - %li= f.sass_signature(:html) + - functions.each do |(i, f)| + %li + %a{:href=>"#{i.path}#function-#{f.name}"}= f.sass_signature(:html) %h1#logo All Ruby Based Functions %ul diff --git a/doc-src/content/index/mixins.haml b/doc-src/content/index/mixins.haml index 4dc8a10b..1743fe8f 100644 --- a/doc-src/content/index/mixins.haml +++ b/doc-src/content/index/mixins.haml @@ -6,9 +6,9 @@ body_id: home %article %h1#logo Compass Mixins - - all_mixins.sort_by{|i| i.first.identifier}.each do |item, mixins| - %h3= link_to item[:title], item + - all_mixins.sorted_and_grouped_by_name{|m| m.last.name }.each do |(group, mixins)| + %h3= group %ul - - mixins.sort_by{|m| m.name}.each do |m| - %li= m.sass_signature(:none, :html) - + - mixins.each do |(i, m)| + %li + %a{:href=>"#{i.path}#mixin-#{m.name}"}= m.sass_signature(:none, :html) diff --git a/doc-src/content/index/variables.haml b/doc-src/content/index/variables.haml index dcb78594..cffd3731 100644 --- a/doc-src/content/index/variables.haml +++ b/doc-src/content/index/variables.haml @@ -6,10 +6,10 @@ body_id: home %article %h1#logo Compass Variables - - all_constants.sort_by{|i| i.first.identifier}.each do |item, constants| - %h3= link_to item[:title], item + - all_constants.sorted_and_grouped_by_name{|v| v.last.name }.each do |(group, variables)| + %h3= group %ul - - constants.sort_by{|c| c.name}.each do |c| - %li $#{c.name} - + - variables.each do |(i, v)| + %li + %a{:href=>"#{i.path}#const-#{v.name}"}= "$" + v.name \ No newline at end of file diff --git a/doc-src/lib/default.rb b/doc-src/lib/default.rb index 39b25dec..46b98745 100644 --- a/doc-src/lib/default.rb +++ b/doc-src/lib/default.rb @@ -28,6 +28,12 @@ def body_attributes(item) } end +module Enumerable + def sorted_and_grouped_by_name + sort_by{|i| yield(i)}.group_by{|i| yield(i).sub(/^[^\w]/,"")[0..0].upcase} + end +end + class Recycler attr_accessor :values attr_accessor :index diff --git a/doc-src/lib/stylesheets.rb b/doc-src/lib/stylesheets.rb index bd15624b..24921c1e 100644 --- a/doc-src/lib/stylesheets.rb +++ b/doc-src/lib/stylesheets.rb @@ -160,42 +160,28 @@ def constants(item) end def all_constants - variables = [] - @items.each do |item| - next unless item.identifier =~ %r{/reference} - next unless item[:stylesheet] - vars = constants(item) - if vars.any? - variables << [item, vars] - end + @items.inject([]) do |variables, item| + next variables unless item.identifier =~ %r{/reference} + next variables unless item[:stylesheet] + variables += constants(item).map{|v| [item, v] } end - variables end def all_mixins - all_mixins = [] - @items.each do |item| - next unless item.identifier =~ %r{/reference} - next unless item[:stylesheet] - ms = mixins(item) - if ms.any? - all_mixins << [item, ms] - end + @items.inject([]) do |all_mixins, item| + next all_mixins unless item.identifier =~ %r{/reference} + next all_mixins unless item[:stylesheet] + all_mixins += mixins(item).map{|m| [item, m] } end - all_mixins end def all_functions - all_functions = [] - @items.each do |item| - next unless item.identifier =~ %r{/reference} - next unless item[:stylesheet] - fns = functions(item) - if fns.any? - all_functions << [item, fns] - end + rv = @items.inject([]) do |all_functions, item| + next all_functions unless item.identifier =~ %r{/reference} + next all_functions unless item[:stylesheet] + all_functions += functions(item).map{|f| [item, f] } end - all_functions + rv end def example_items