Less buggy import resolver. Closes GH-139.

This commit is contained in:
Chris Eppstein 2010-07-08 22:19:11 -07:00
parent 7d9ab20be0
commit 8dc719ac22
3 changed files with 19 additions and 18 deletions

View File

@ -1,5 +1,5 @@
- render 'main' do - render 'main' do
%aside(role="sidebar") %aside(role="sidebar")
%nav#local-nav %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 %article= yield

View File

@ -1,5 +1,5 @@
- render 'main' do - render 'main' do
- content_for :module_nav 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" %aside(role="sidebar")= render 'partials/sidebar', :default_stylesheet => "_compass.scss"
%article= yield %article= yield

View File

@ -30,9 +30,9 @@ end
def reference_item(options) def reference_item(options)
stylesheet = options[:stylesheet] stylesheet = options[:stylesheet]
@site.cached("reference/item/#{stylesheet}") do path = stylesheet_path(stylesheet)
path = stylesheet_path(stylesheet) if path
if path @site.cached("reference/item/#{path}") do
@items.detect do |i| @items.detect do |i|
if i.identifier =~ /^\/reference/ && i[:stylesheet] if i.identifier =~ /^\/reference/ && i[:stylesheet]
i[:stylesheet] == path i[:stylesheet] == path
@ -54,27 +54,28 @@ def reference_path(options)
end end
def import_paths def import_paths
paths = Compass::Frameworks::ALL.inject([]) {|m, f| m << f.stylesheets_directory} paths = []
paths.map!{|p|[p, '']}
if @item[:stylesheet] if @item[:stylesheet]
paths << [File.join(Compass::Frameworks[@item[:framework]].stylesheets_directory, 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 end
paths += Compass::Frameworks::ALL.inject([]) {|m, f| m << f.stylesheets_directory}.map!{|p|[p, '']}
paths paths
end end
def stylesheet_path(ss) def stylesheet_path(ss)
@site.cached("stylesheet/path/#{ss}") do possible_names = possible_filenames_for_stylesheet(ss)
possible_names = possible_filenames_for_stylesheet(ss) import_paths.each do |import_path|
import_paths.each do |import_path| possible_names.each do |filename|
possible_names.each do |filename| full_path = File.join(import_path.first, filename)
full_path = File.join(import_path.first, filename) if File.exist?(full_path)
if File.exist?(full_path) return "#{import_path.last}#{"/" if import_path.last && import_path.last.length > 0}#{filename}"
return "#{import_path.last}#{"/" if import_path.last && import_path.last.length > 0}#{filename}"
end
end end
end end
end end
nil
end end
def possible_filenames_for_stylesheet(ss) def possible_filenames_for_stylesheet(ss)
@ -85,9 +86,9 @@ def possible_filenames_for_stylesheet(ss)
extensions = if ext.size > 0 extensions = if ext.size > 0
[ext] [ext]
else else
[".sass", ".scss"] [".scss", ".sass"]
end end
basenames = [base, "_#{base}"] basenames = ["_#{base}", base]
filenames = [] filenames = []
basenames.each do |basename| basenames.each do |basename|
extensions.each do |extension| extensions.each do |extension|