def stylesheets(*params)
options = {}
if params.last.is_a?(Hash)
options = params.last
params.slice!(-1, 1)
end
options[:media] = 'all' unless options.has_key?(:media)
options[:rel] = 'stylesheet'; options[:type] = 'text/css'
relative_path = current_page_relative_path
output = ""
if params.length == 0
stylesheet_dir = File.join(@staticmatic.src_dir, 'stylesheets')
stylesheet_directories = Dir[File.join(stylesheet_dir, '**','*.{sass,scss}')]
Dir[File.join(@staticmatic.site_dir, 'stylesheets', '*.css')].each do |filename|
search_filename = File.basename(filename).chomp(File.extname(filename))
puts search_filename
already_included = false
stylesheet_directories.each do |path|
if File.basename(path).include?(search_filename)
already_included = true
break
end
end
stylesheet_directories << filename unless already_included
end
stylesheet_directories.each do |path|
filename_without_extension = File.basename(path).chomp(File.extname(path))
if !filename_without_extension.match(/^\_/)
path = path.gsub(/#{@staticmatic.src_dir}/, "").
gsub(/#{@staticmatic.site_dir}/, "").
gsub(/#{filename_without_extension}\.(sass|scss|css)/, "")
options[:href] = File.join(relative_path, path, "#{filename_without_extension}.css")
output << tag(:link, options)
end
end
else
params.each do |file|
if File.exist?(File.join(@staticmatic.src_dir, 'stylesheets', "#{file}.sass")) ||
File.exist?(File.join(@staticmatic.site_dir, 'stylesheets', "#{file}.css"))
options[:href] = File.join(relative_path, "stylesheets", "#{file}.css")
output << tag(:link, options)
end
end
end
output
end