Sha256: 6fb532c933e602c12034b8b572c4c1ff1273300101920585c9af98e8e49db8fa

Contents?: true

Size: 1.19 KB

Versions: 3

Compression:

Stored size: 1.19 KB

Contents

module Middleman
  module CoreExtensions
    
    # Base helper to manipulate asset paths
    module Assets
  
      # Extension registered
      class << self
        def registered(app)
          # Disable Padrino cache buster
          app.set :asset_stamp, false
      
          # Include helpers
          app.send :include, InstanceMethod
        end
        alias :included :registered
      end
  
      # Methods to be mixed-in to Middleman::Application
      module InstanceMethod
    
        # Get the URL of an asset given a type/prefix
        #
        # @param [String] path The path (such as "photo.jpg")
        # @param [String] prefix The type prefix (such as "images")
        # @return [String] The fully qualified asset url
        def asset_url(path, prefix="")
          # Don't touch assets which already have a full path
          if path.include?("//")
            path
          else # rewrite paths to use their destination path
            path = File.join(prefix, path)
            if resource = sitemap.find_resource_by_path(path)
              path = resource.destination_path
            end

            File.join(http_prefix, path)
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
middleman-more-3.0.0.rc.2 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.0.rc.1 lib/middleman-more/core_extensions/assets.rb
middleman-core-3.0.0.beta.3 lib/middleman-core/core_extensions/assets.rb