From 8dc719ac22c9dddc392d1214813ac7e464ce3486 Mon Sep 17 00:00:00 2001 From: Chris Eppstein Date: Thu, 8 Jul 2010 22:19:11 -0700 Subject: [PATCH] Less buggy import resolver. Closes GH-139. --- doc-src/layouts/blueprint.haml | 2 +- doc-src/layouts/core.haml | 2 +- doc-src/lib/stylesheets.rb | 33 +++++++++++++++++---------------- 3 files changed, 19 insertions(+), 18 deletions(-) diff --git a/doc-src/layouts/blueprint.haml b/doc-src/layouts/blueprint.haml index b17f15a1..e1797ced 100644 --- a/doc-src/layouts/blueprint.haml +++ b/doc-src/layouts/blueprint.haml @@ -1,5 +1,5 @@ - render 'main' do %aside(role="sidebar") %nav#local-nav - %ul=item_tree(reference_item(:stylesheet => "_blueprint.scss"), :depth => 2, :omit_self => false, :heading_level => 2) + %ul=item_tree(reference_item(:stylesheet => "blueprint.scss"), :depth => 2, :omit_self => false, :heading_level => 2) %article= yield \ No newline at end of file diff --git a/doc-src/layouts/core.haml b/doc-src/layouts/core.haml index 15b59b99..b146930d 100644 --- a/doc-src/layouts/core.haml +++ b/doc-src/layouts/core.haml @@ -1,5 +1,5 @@ - render 'main' do - content_for :module_nav do - %ul= item_tree(reference_item(:stylesheet => "_compass.scss"), :depth => 1, :omit_self => true, :headings => false) + %ul= item_tree(reference_item(:stylesheet => "compass.scss"), :depth => 1, :omit_self => true, :headings => false) %aside(role="sidebar")= render 'partials/sidebar', :default_stylesheet => "_compass.scss" %article= yield \ No newline at end of file diff --git a/doc-src/lib/stylesheets.rb b/doc-src/lib/stylesheets.rb index 28c8186f..f22e86e6 100644 --- a/doc-src/lib/stylesheets.rb +++ b/doc-src/lib/stylesheets.rb @@ -30,9 +30,9 @@ end def reference_item(options) stylesheet = options[:stylesheet] - @site.cached("reference/item/#{stylesheet}") do - path = stylesheet_path(stylesheet) - if path + path = stylesheet_path(stylesheet) + if path + @site.cached("reference/item/#{path}") do @items.detect do |i| if i.identifier =~ /^\/reference/ && i[:stylesheet] i[:stylesheet] == path @@ -54,27 +54,28 @@ def reference_path(options) end def import_paths - paths = Compass::Frameworks::ALL.inject([]) {|m, f| m << f.stylesheets_directory} - paths.map!{|p|[p, '']} + paths = [] if @item[:stylesheet] paths << [File.join(Compass::Frameworks[@item[:framework]].stylesheets_directory, - File.dirname(@item[:stylesheet])), File.dirname(@item[:stylesheet])] + File.dirname(@item[:stylesheet])), + @item[:stylesheet]["/"] ? File.dirname(@item[:stylesheet]) : ""] end + + paths += Compass::Frameworks::ALL.inject([]) {|m, f| m << f.stylesheets_directory}.map!{|p|[p, '']} paths end def stylesheet_path(ss) - @site.cached("stylesheet/path/#{ss}") do - possible_names = possible_filenames_for_stylesheet(ss) - import_paths.each do |import_path| - possible_names.each do |filename| - full_path = File.join(import_path.first, filename) - if File.exist?(full_path) - return "#{import_path.last}#{"/" if import_path.last && import_path.last.length > 0}#{filename}" - end + possible_names = possible_filenames_for_stylesheet(ss) + import_paths.each do |import_path| + possible_names.each do |filename| + full_path = File.join(import_path.first, filename) + if File.exist?(full_path) + return "#{import_path.last}#{"/" if import_path.last && import_path.last.length > 0}#{filename}" end end end + nil end def possible_filenames_for_stylesheet(ss) @@ -85,9 +86,9 @@ def possible_filenames_for_stylesheet(ss) extensions = if ext.size > 0 [ext] else - [".sass", ".scss"] + [".scss", ".sass"] end - basenames = [base, "_#{base}"] + basenames = ["_#{base}", base] filenames = [] basenames.each do |basename| extensions.each do |extension|