Link imports to their reference documentation.

This commit is contained in:
Chris Eppstein 2010-01-23 23:01:30 -08:00
parent 0fd292b776
commit 3e248176aa
2 changed files with 54 additions and 1 deletions

View File

@ -3,4 +3,8 @@
%ol %ol
- imported_libs.each do |import| - imported_libs.each do |import|
%li= import %li
- if path = reference_path(:stylesheet => import)
%a{:href => path}= import
- else
= import

View File

@ -28,6 +28,55 @@ def imports(item)
imports imports
end end
def reference_path(options)
stylesheet = options[:stylesheet]
path = stylesheet_path(stylesheet)
if path
item = @items.detect do |i|
i[:stylesheet] == path
end
if item
rep = item.reps.find { |r| r.name == :default }
rep.path
end
end
end
def import_paths
Compass::Frameworks::ALL.inject([]) {|m, f| m << f.stylesheets_directory}
end
def stylesheet_path(ss)
possible_filenames_for_stylesheet(ss).each do |filename|
import_paths.each do |import_path|
full_path = File.join(import_path, filename)
puts "Looking for #{full_path}"
if File.exist?(full_path)
return filename
end
end
end
end
def possible_filenames_for_stylesheet(ss)
ext = File.extname(ss)
path = File.dirname(ss)
base = File.basename(ss)[0..-(ext.size+1)]
extensions = if ext.size > 0
[ext]
else
[".sass", ".scss"]
end
basenames = [base, "_#{base}"]
filenames = []
basenames.each do |basename|
extensions.each do |extension|
filenames << "#{path}/#{basename}#{extension}"
end
end
filenames
end
def mixins(item) def mixins(item)
sass_tree = tree(item) sass_tree = tree(item)
mixins = [] mixins = []