# File lib/staticmatic/helpers.rb, line 10
    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
        # no specific files requested so include all in no particular order
        stylesheet_dir = File.join(@staticmatic.src_dir, 'stylesheets')
        stylesheet_directories = Dir[File.join(stylesheet_dir, '**','*.sass')]
        
        # Bit of a hack here - adds any stylesheets that exist in the site/ dir that haven't been generated from source sass
        Dir[File.join(@staticmatic.site_dir, 'stylesheets', '*.css')].each do |filename|
          search_filename = File.basename(filename).chomp(File.extname(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.base_dir}\/(src|site)\//, "").
                                 gsub(/#{filename_without_extension}\.(sass|css)/, "")
          
            options[:href] = "#{relative_path}#{path}#{filename_without_extension}.css"
            output << tag(:link, options)
          end
        end
      else
        #specific files requested and in a specific order
        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] = "#{relative_path}stylesheets/#{file}.css"
            output << tag(:link, options)
          end
        end
      end
      
      output
    end