Sha256: 95dffb894f12017c553ca66b515e9708a3be9895f13dc4c5040113109c3cbd08

Contents?: true

Size: 1.17 KB

Versions: 40

Compression:

Stored size: 1.17 KB

Contents

require 'middleman-core/sitemap/resource'
require 'middleman-core/core_extensions/collections/step_context'

module Middleman
  module Sitemap
    module Extensions
      # Manages the list of proxy configurations and manipulates the sitemap
      # to include new resources based on those configurations
      class MoveFile < ConfigExtension
        self.resource_list_manipulator_priority = 101

        # Expose `move_file`
        expose_to_config :move_file

        MoveFileDescriptor = Struct.new(:from, :to) do
          def execute_descriptor(_app, resources)
            resources.each do |r|
              r.destination_path = to if from == r.path || from == r.destination_path
            end

            resources
          end
        end

        # Setup a move from one path to another
        # @param [String] from The original path.
        # @param [String] to The new path.
        # @return [void]
        Contract String, String => MoveFileDescriptor
        def move_file(from, to)
          MoveFileDescriptor.new(
            ::Middleman::Util.normalize_path(from),
            ::Middleman::Util.normalize_path(to)
          )
        end
      end
    end
  end
end

Version data entries

40 entries across 40 versions & 3 rubygems

Version Path
middleman-core-with-external-sources-watch-fix-4.1.10 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-with-external-sources-watch-fix-4.1.0 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.3.0.rc.1 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.2.1 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.2.0 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.14 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.13 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.12 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.11 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.10 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.9 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.8 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.7 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.6 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.5 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.3 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.2 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.1 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.0 lib/middleman-core/sitemap/extensions/move_file.rb
middleman-core-4.1.0.rc.2 lib/middleman-core/sitemap/extensions/move_file.rb