module Headjs
  
  module TagHelper

    def headjs_include_tag(*sources)
      keys = []
      content_tag :script, { :type => Mime::JS }, false do
        "head.js( #{javascript_include_tag(*sources).scan(/src="([^"]+)"/).flatten.map { |src| 
          key = URI.parse(src).path[%r{[^/]+\z}].gsub(/\.js$/,'').gsub(/\.min$/,'')
          while keys.include?(key) do
            key += '_' + key
          end
          keys << key
          "{ '#{key}': '#{src}' }"
        }.join(', ')} );"
      end
    end

  end

end

module Headjs
  
  module TagHelper

    def headjs_include_tag(*sources)
      content_tag :script, { :type => Mime::JS }, false do
        headjs_include_js(*sources)
      end
    end

    def headjs_include_js(*sources)
      keys = []
      "head.js( #{javascript_include_tag(*sources).scan(/src="([^"]+)"/).flatten.map { |src| 
        key = URI.parse(src).path[%r{[^/]+\z}].gsub(/\.js$/,'').gsub(/\.min$/,'')
        while keys.include?(key) do
          key += '_' + key
        end
        keys << key
        "{ '#{key}': '#{src}' }"
      }.join(', ')} );"
    end

  end

end

Refactor the tag stuff slightly to allow more custom loading.
Refactor the tag stuff slightly to allow more custom loading.
