Sha256: 841d8e47b13841cd0d5fcff0a3a2540b59d45d1fbbee632083faba6fa81c0f5f

Contents?: true

Size: 1.8 KB

Versions: 13

Compression:

Stored size: 1.8 KB

Contents

module Middleman
  module Sprockets
    module AssetTagHelpers

      # extend padrinos javascript_include_tag with debug functionality
      # splits up script dependencies in individual files when
      # configuration variable :debug_assets is set to true
      def javascript_include_tag(*sources)
        if sprockets.debug_assets
          options = sources.extract_options!.symbolize_keys
          sources.map do |source|
            super(dependencies_paths('.js', source), options)
          end.join("").gsub("body=1.js", "body=1")
        else
          super
        end
      end

      # extend padrinos stylesheet_link_tag with debug functionality
      # splits up stylesheets dependencies in individual files when
      # configuration variable :debug_assets is set to true
      def stylesheet_link_tag(*sources)
        if sprockets.debug_assets
          options = sources.extract_options!.symbolize_keys
          sources.map do |source|
            super(dependencies_paths('.css', source), options)
          end.join("").gsub("body=1.css", "body=1")
        else
          super
        end
      end

      private

      # Find the paths for all the dependencies of a given source file.
      def dependencies_paths(extension, source)
        source_file_name = source.to_s

        if source_file_name.start_with?('//', 'http')
          # Don't touch external sources
          source_file_name
        else
          source_file_name << extension unless source_file_name.end_with?(extension)

          dependencies_paths = sprockets[source_file_name].to_a.map do |dependency|
            # if sprockets sees "?body=1" it only gives back the body
            # of the script without the dependencies included
            dependency.logical_path + "?body=1"
          end
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 2 rubygems

Version Path
middleman-sprockets-3.5.0 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-4.0.0.beta.1 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-3.4.2 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-3.4.1 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-3.3.10 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-3.3.9 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-3.3.8 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-3.3.7 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-cj-3.3.6 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-3.3.6 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-3.3.4 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-3.3.3 lib/middleman-sprockets/asset_tag_helpers.rb
middleman-sprockets-3.3.2 lib/middleman-sprockets/asset_tag_helpers.rb