Sha256: 08c7491c4e15394b708d96db63ff92bbefee44a8101a7092f89adc05977fbefe

Contents?: true

Size: 1.18 KB

Versions: 16

Compression:

Stored size: 1.18 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)
              resource.url
            else
              File.join(http_prefix, path)
            end
          end
        end
      end
    end
  end
end

Version data entries

16 entries across 16 versions & 1 rubygems

Version Path
middleman-more-3.0.14 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.13 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.12 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.12.pre.1 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.11 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.10.pre.1 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.9 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.8 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.8.pre.2 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.8.pre.1 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.7 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.6 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.5 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.4 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.2 lib/middleman-more/core_extensions/assets.rb
middleman-more-3.0.1.pre lib/middleman-more/core_extensions/assets.rb