middleman-core 4.1.9 → 4.1.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/features/asset_hash.feature +14 -0
- data/fixtures/asset-hash-prefix/config.rb +7 -0
- data/fixtures/asset-hash-prefix/lib/middleware.rb +16 -0
- data/fixtures/asset-hash-prefix/source/index.html.erb +6 -0
- data/fixtures/asset-hash-prefix/source/javascripts/application.js +2 -0
- data/fixtures/asset-hash-prefix/source/javascripts/application.js.map +1 -0
- data/fixtures/asset-hash-prefix/source/layout.erb +17 -0
- data/lib/middleman-core/extensions/asset_hash.rb +2 -1
- data/lib/middleman-core/extensions/relative_assets.rb +2 -4
- data/lib/middleman-core/renderers/sass_functions.rb +4 -6
- data/lib/middleman-core/sitemap/extensions/redirects.rb +1 -2
- data/lib/middleman-core/sources/source_watcher.rb +1 -1
- data/lib/middleman-core/template_context.rb +10 -12
- data/lib/middleman-core/util/binary.rb +4 -5
- data/lib/middleman-core/util/data.rb +1 -1
- data/lib/middleman-core/util/paths.rb +26 -19
- data/lib/middleman-core/version.rb +1 -1
- metadata +14 -2
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 73f1ee44db78bc2bf335aac0e48af1ccc5915dd0
         | 
| 4 | 
            +
              data.tar.gz: b6b8fae3d1af952639ed6b1c897a4d256f26e698
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 5e206d7f48ffcb3b24d394c4fa9ca52432fab4787bfa8ef64b50498bb45cb1ed19ea7db4aa2164818b9e70aa12bb59a71077f44745c1088c9272eac22462b54c
         | 
| 7 | 
            +
              data.tar.gz: 391d5447bdfd1fcdde64dba7298fcd5085d360c1697b3027eea728eb326b721b5384f7c74c295f0ffd57603fc33dcd6047efdb394c065fca3096100d8ed4f676
         | 
    
        data/features/asset_hash.feature
    CHANGED
    
    | @@ -308,3 +308,17 @@ Feature: Assets get file hashes appended to them and references to them are upda | |
| 308 308 | 
             
                  | javascripts/application.js.map |
         | 
| 309 309 |  | 
| 310 310 | 
             
                And the file "javascripts/application-4553338c.js" should contain "//# sourceMappingURL=application.js-22cc2b5f.map"
         | 
| 311 | 
            +
             | 
| 312 | 
            +
              Scenario: Hashes can contain a prefix
         | 
| 313 | 
            +
                Given a successfully built app at "asset-hash-prefix"
         | 
| 314 | 
            +
                When I cd to "build"
         | 
| 315 | 
            +
                Then the following files should exist:
         | 
| 316 | 
            +
                  | index.html |
         | 
| 317 | 
            +
                  | javascripts/application-myprefix-4553338c.js |
         | 
| 318 | 
            +
                  | javascripts/application.js-myprefix-22cc2b5f.map |
         | 
| 319 | 
            +
                  | index.html |
         | 
| 320 | 
            +
                And the following files should not exist:
         | 
| 321 | 
            +
                  | javascripts/application.js |
         | 
| 322 | 
            +
                  | javascripts/application.js.map |
         | 
| 323 | 
            +
             | 
| 324 | 
            +
                And the file "javascripts/application-myprefix-4553338c.js" should contain "//# sourceMappingURL=application.js-myprefix-22cc2b5f.map"
         | 
| @@ -0,0 +1,16 @@ | |
| 1 | 
            +
            class Middleware
         | 
| 2 | 
            +
              def initialize(app)
         | 
| 3 | 
            +
                @app = app
         | 
| 4 | 
            +
              end
         | 
| 5 | 
            +
             | 
| 6 | 
            +
              def call(env)
         | 
| 7 | 
            +
                status, headers, response = @app.call(env)
         | 
| 8 | 
            +
                body = ''
         | 
| 9 | 
            +
                response.each {|part| body += part }
         | 
| 10 | 
            +
                if (env["PATH_INFO"] =~ /css$/)
         | 
| 11 | 
            +
                  body += "\n/* Added by Rack filter */"
         | 
| 12 | 
            +
                  status, headers, response = Rack::Response.new(body, status, headers).finish
         | 
| 13 | 
            +
                end
         | 
| 14 | 
            +
                [status, headers, response]
         | 
| 15 | 
            +
              end
         | 
| 16 | 
            +
            end
         | 
| @@ -0,0 +1 @@ | |
| 1 | 
            +
            {"version":3,"sources":["source/javascripts/application.js"],"names":["foo","message","para","document","createElement","innerHTML","body","getElementsByTagName","insertBefore","firstChild","window","onload"],"mappings":"AAAA,QAASA,OACP,GAAIC,SAAU,mBACd,IAAIC,MAAOC,SAASC,cAAc,IAClCF,MAAKG,UAAYJ,OACb,IAAIK,MAAOH,SAASI,qBAAqB,QAAQ,EAC/CD,MAAKE,aAAaN,KAAMI,KAAKG,YAGpCC,OAAOC,OAASX"}
         | 
| @@ -0,0 +1,17 @@ | |
| 1 | 
            +
            <!DOCTYPE html>
         | 
| 2 | 
            +
            <html>
         | 
| 3 | 
            +
              <head>
         | 
| 4 | 
            +
                <meta charset="utf-8">
         | 
| 5 | 
            +
             | 
| 6 | 
            +
                <%= javascript_include_tag "application" %>
         | 
| 7 | 
            +
                <%= yield_content :head %>
         | 
| 8 | 
            +
              </head>
         | 
| 9 | 
            +
             | 
| 10 | 
            +
              <body class="<%= page_classes %>">
         | 
| 11 | 
            +
             | 
| 12 | 
            +
                <div id="main" role="main">
         | 
| 13 | 
            +
                  <%= yield %>
         | 
| 14 | 
            +
                </div>
         | 
| 15 | 
            +
             | 
| 16 | 
            +
              </body>
         | 
| 17 | 
            +
            </html>
         | 
| @@ -6,6 +6,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension | |
| 6 6 | 
             
              option :exts, nil, 'List of extensions that get asset hashes appended to them.'
         | 
| 7 7 | 
             
              option :ignore, [], 'Regexes of filenames to skip adding asset hashes to'
         | 
| 8 8 | 
             
              option :rewrite_ignore, [], 'Regexes of filenames to skip processing for path rewrites'
         | 
| 9 | 
            +
              option :prefix, '', 'Prefix for hash'
         | 
| 9 10 |  | 
| 10 11 | 
             
              def initialize(app, options_hash={}, &block)
         | 
| 11 12 | 
             
                super
         | 
| @@ -92,7 +93,7 @@ class Middleman::Extensions::AssetHash < ::Middleman::Extension | |
| 92 93 | 
             
                  ::Digest::SHA1.hexdigest(response.body)[0..7]
         | 
| 93 94 | 
             
                end
         | 
| 94 95 |  | 
| 95 | 
            -
                resource.destination_path = resource.destination_path.sub(/\.(\w+)$/) { |ext| "-#{digest}#{ext}" }
         | 
| 96 | 
            +
                resource.destination_path = resource.destination_path.sub(/\.(\w+)$/) { |ext| "-#{options.prefix}#{digest}#{ext}" }
         | 
| 96 97 | 
             
                resource
         | 
| 97 98 | 
             
              end
         | 
| 98 99 |  | 
| @@ -11,9 +11,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension | |
| 11 11 | 
             
              def initialize(app, options_hash={}, &block)
         | 
| 12 12 | 
             
                super
         | 
| 13 13 |  | 
| 14 | 
            -
                if options[:helpers_only]
         | 
| 15 | 
            -
                  return
         | 
| 16 | 
            -
                end
         | 
| 14 | 
            +
                return if options[:helpers_only]
         | 
| 17 15 |  | 
| 18 16 | 
             
                app.rewrite_inline_urls id: :relative_assets,
         | 
| 19 17 | 
             
                                        url_extensions: options.exts || app.config[:asset_extensions],
         | 
| @@ -53,7 +51,7 @@ class Middleman::Extensions::RelativeAssets < ::Middleman::Extension | |
| 53 51 | 
             
                end
         | 
| 54 52 |  | 
| 55 53 | 
             
                def asset_path(kind, source, options={})
         | 
| 56 | 
            -
                  super(kind, source, | 
| 54 | 
            +
                  super(kind, source, app.extensions[:relative_assets].mark_as_relative(super, options, current_resource))
         | 
| 57 55 | 
             
                end
         | 
| 58 56 | 
             
              end
         | 
| 59 57 |  | 
| @@ -105,10 +105,8 @@ module Middleman | |
| 105 105 | 
             
              end
         | 
| 106 106 | 
             
            end
         | 
| 107 107 |  | 
| 108 | 
            -
             | 
| 109 | 
            -
              ::SassC
         | 
| 110 | 
            -
             | 
| 111 | 
            -
              ::Sass
         | 
| 108 | 
            +
            if defined?(::SassC)
         | 
| 109 | 
            +
              ::SassC::Script::Functions.send :include, ::Middleman::Sass::Functions
         | 
| 110 | 
            +
            elsif defined?(::Sass)
         | 
| 111 | 
            +
              ::Sass::Script::Functions.send :include, ::Middleman::Sass::Functions
         | 
| 112 112 | 
             
            end
         | 
| 113 | 
            -
             | 
| 114 | 
            -
            SASS_MODULE::Script::Functions.send :include, ::Middleman::Sass::Functions
         | 
| @@ -138,18 +138,16 @@ module Middleman | |
| 138 138 | 
             
                    relative_dir_no_underscore = current_dir + Pathname(non_root_no_underscore)
         | 
| 139 139 | 
             
                  end
         | 
| 140 140 |  | 
| 141 | 
            -
             | 
| 142 | 
            -
             | 
| 143 | 
            -
             | 
| 144 | 
            -
             | 
| 145 | 
            -
                  lookup_stack.push [ | 
| 146 | 
            -
             | 
| 147 | 
            -
             | 
| 148 | 
            -
             | 
| 149 | 
            -
             | 
| 150 | 
            -
             | 
| 151 | 
            -
                                      { try_static: try_static }]
         | 
| 152 | 
            -
             | 
| 141 | 
            +
                  lookup_stack.push [relative_dir.to_s,
         | 
| 142 | 
            +
                                     { preferred_engine: resource.file_descriptor[:relative_path]
         | 
| 143 | 
            +
                                       .extname[1..-1].to_sym }] if relative_dir
         | 
| 144 | 
            +
                  lookup_stack.push [non_root]
         | 
| 145 | 
            +
                  lookup_stack.push [non_root,
         | 
| 146 | 
            +
                                     { try_static: try_static }]
         | 
| 147 | 
            +
                  lookup_stack.push [relative_dir_no_underscore.to_s,
         | 
| 148 | 
            +
                                     { try_static: try_static }] if relative_dir_no_underscore
         | 
| 149 | 
            +
                  lookup_stack.push [non_root_no_underscore,
         | 
| 150 | 
            +
                                     { try_static: try_static }]
         | 
| 153 151 |  | 
| 154 152 | 
             
                  lookup_stack.each do |args|
         | 
| 155 153 | 
             
                    partial_file = ::Middleman::TemplateRenderer.resolve_template(@app, *args)
         | 
| @@ -47,14 +47,13 @@ module Middleman | |
| 47 47 | 
             
                # @return [Boolean]
         | 
| 48 48 | 
             
                Contract String => Bool
         | 
| 49 49 | 
             
                def nonbinary_mime?(mime)
         | 
| 50 | 
            -
                   | 
| 51 | 
            -
                  when mime.start_with?('text/')
         | 
| 50 | 
            +
                  if mime.start_with?('text/')
         | 
| 52 51 | 
             
                    true
         | 
| 53 | 
            -
                   | 
| 52 | 
            +
                  elsif mime.include?('xml') && !mime.include?('officedocument')
         | 
| 54 53 | 
             
                    true
         | 
| 55 | 
            -
                   | 
| 54 | 
            +
                  elsif mime.include?('json')
         | 
| 56 55 | 
             
                    true
         | 
| 57 | 
            -
                   | 
| 56 | 
            +
                  elsif mime.include?('javascript')
         | 
| 58 57 | 
             
                    true
         | 
| 59 58 | 
             
                  else
         | 
| 60 59 | 
             
                    false
         | 
| @@ -1,8 +1,8 @@ | |
| 1 1 | 
             
            # Core Pathname library used for traversal
         | 
| 2 2 | 
             
            require 'pathname'
         | 
| 3 3 | 
             
            require 'uri'
         | 
| 4 | 
            -
            require 'memoist'
         | 
| 5 4 | 
             
            require 'addressable'
         | 
| 5 | 
            +
            require 'memoist'
         | 
| 6 6 | 
             
            require 'tilt'
         | 
| 7 7 |  | 
| 8 8 | 
             
            require 'middleman-core/contracts'
         | 
| @@ -32,9 +32,9 @@ module Middleman | |
| 32 32 | 
             
                # @return [String]
         | 
| 33 33 | 
             
                Contract String => String
         | 
| 34 34 | 
             
                def normalize_path(path)
         | 
| 35 | 
            -
             | 
| 35 | 
            +
                 # The tr call works around a bug in Ruby's Unicode handling
         | 
| 36 36 | 
             
                  ::URI.decode(path).sub(%r{^/}, '').tr('', '')
         | 
| 37 | 
            -
             | 
| 37 | 
            +
                 end
         | 
| 38 38 | 
             
                memoize :normalize_path
         | 
| 39 39 |  | 
| 40 40 | 
             
                # This is a separate method from normalize_path in case we
         | 
| @@ -111,7 +111,7 @@ module Middleman | |
| 111 111 | 
             
                    raise ArgumentError, '#asset_url must be run in a context with current_resource if relative: true'
         | 
| 112 112 | 
             
                  end
         | 
| 113 113 |  | 
| 114 | 
            -
                  uri =  | 
| 114 | 
            +
                  uri = ::Middleman::Util.parse_uri(path)
         | 
| 115 115 | 
             
                  path = uri.path
         | 
| 116 116 |  | 
| 117 117 | 
             
                  # Ensure the url we pass into find_resource_by_destination_path is not a
         | 
| @@ -131,9 +131,15 @@ module Middleman | |
| 131 131 | 
             
                    end
         | 
| 132 132 | 
             
                  end
         | 
| 133 133 |  | 
| 134 | 
            -
                  final_result = ::URI.encode( | 
| 134 | 
            +
                  final_result = ::Addressable::URI.encode(
         | 
| 135 | 
            +
                    relative_path_from_resource(
         | 
| 136 | 
            +
                      options[:current_resource],
         | 
| 137 | 
            +
                      result,
         | 
| 138 | 
            +
                      options[:relative]
         | 
| 139 | 
            +
                    )
         | 
| 140 | 
            +
                  )
         | 
| 135 141 |  | 
| 136 | 
            -
                  result_uri =  | 
| 142 | 
            +
                  result_uri = ::Middleman::Util.parse_uri(final_result)
         | 
| 137 143 | 
             
                  result_uri.query = uri.query
         | 
| 138 144 | 
             
                  result_uri.fragment = uri.fragment
         | 
| 139 145 | 
             
                  result_uri.to_s
         | 
| @@ -158,14 +164,10 @@ module Middleman | |
| 158 164 |  | 
| 159 165 | 
             
                  # Try to parse URL
         | 
| 160 166 | 
             
                  begin
         | 
| 161 | 
            -
                    uri =  | 
| 162 | 
            -
                  rescue ::URI::InvalidURIError
         | 
| 163 | 
            -
                     | 
| 164 | 
            -
             | 
| 165 | 
            -
                    rescue ::URI::InvalidURIError
         | 
| 166 | 
            -
                      # Nothing we can do with it, it's not really a URI
         | 
| 167 | 
            -
                      return url
         | 
| 168 | 
            -
                    end
         | 
| 167 | 
            +
                    uri = ::Middleman::Util.parse_uri(url)
         | 
| 168 | 
            +
                  rescue ::Addressable::URI::InvalidURIError
         | 
| 169 | 
            +
                    # Nothing we can do with it, it's not really a URI
         | 
| 170 | 
            +
                    return url
         | 
| 169 171 | 
             
                  end
         | 
| 170 172 |  | 
| 171 173 | 
             
                  relative = options[:relative]
         | 
| @@ -206,7 +208,13 @@ module Middleman | |
| 206 208 |  | 
| 207 209 | 
             
                  if resource
         | 
| 208 210 | 
             
                    uri.path = if this_resource
         | 
| 209 | 
            -
                      ::URI.encode( | 
| 211 | 
            +
                      ::Addressable::URI.encode(
         | 
| 212 | 
            +
                        relative_path_from_resource(
         | 
| 213 | 
            +
                          this_resource,
         | 
| 214 | 
            +
                          resource_url,
         | 
| 215 | 
            +
                          effective_relative
         | 
| 216 | 
            +
                        )
         | 
| 217 | 
            +
                      )
         | 
| 210 218 | 
             
                    else
         | 
| 211 219 | 
             
                      resource_url
         | 
| 212 220 | 
             
                    end
         | 
| @@ -284,16 +292,15 @@ module Middleman | |
| 284 292 | 
             
                # @return [Boolean] Whether the path matches the matcher
         | 
| 285 293 | 
             
                Contract PATH_MATCHER, String => Bool
         | 
| 286 294 | 
             
                def path_match(matcher, path)
         | 
| 287 | 
            -
                   | 
| 288 | 
            -
                  when matcher.is_a?(String)
         | 
| 295 | 
            +
                  if matcher.is_a?(String)
         | 
| 289 296 | 
             
                    if matcher.include? '*'
         | 
| 290 297 | 
             
                      ::File.fnmatch(matcher, path)
         | 
| 291 298 | 
             
                    else
         | 
| 292 299 | 
             
                      path == matcher
         | 
| 293 300 | 
             
                    end
         | 
| 294 | 
            -
                   | 
| 301 | 
            +
                  elsif matcher.respond_to?(:match)
         | 
| 295 302 | 
             
                    !!(path =~ matcher)
         | 
| 296 | 
            -
                   | 
| 303 | 
            +
                  elsif matcher.respond_to?(:call)
         | 
| 297 304 | 
             
                    matcher.call(path)
         | 
| 298 305 | 
             
                  else
         | 
| 299 306 | 
             
                    ::File.fnmatch(matcher.to_s, path)
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: middleman-core
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 4.1. | 
| 4 | 
            +
              version: 4.1.10
         | 
| 5 5 | 
             
            platform: ruby
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Thomas Reynolds
         | 
| @@ -10,7 +10,7 @@ authors: | |
| 10 10 | 
             
            autorequire: 
         | 
| 11 11 | 
             
            bindir: bin
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date: 2016- | 
| 13 | 
            +
            date: 2016-07-11 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              name: bundler
         | 
| @@ -495,6 +495,12 @@ files: | |
| 495 495 | 
             
            - fixtures/asset-hash-minified-app/source/images/100px.jpg
         | 
| 496 496 | 
             
            - fixtures/asset-hash-minified-app/source/javascripts/jquery.min.js
         | 
| 497 497 | 
             
            - fixtures/asset-hash-minified-app/source/stylesheets/test.css
         | 
| 498 | 
            +
            - fixtures/asset-hash-prefix/config.rb
         | 
| 499 | 
            +
            - fixtures/asset-hash-prefix/lib/middleware.rb
         | 
| 500 | 
            +
            - fixtures/asset-hash-prefix/source/index.html.erb
         | 
| 501 | 
            +
            - fixtures/asset-hash-prefix/source/javascripts/application.js
         | 
| 502 | 
            +
            - fixtures/asset-hash-prefix/source/javascripts/application.js.map
         | 
| 503 | 
            +
            - fixtures/asset-hash-prefix/source/layout.erb
         | 
| 498 504 | 
             
            - fixtures/asset-hash-source-map/config.rb
         | 
| 499 505 | 
             
            - fixtures/asset-hash-source-map/lib/middleware.rb
         | 
| 500 506 | 
             
            - fixtures/asset-hash-source-map/source/index.html.erb
         | 
| @@ -1695,6 +1701,12 @@ test_files: | |
| 1695 1701 | 
             
            - fixtures/asset-hash-minified-app/source/images/100px.jpg
         | 
| 1696 1702 | 
             
            - fixtures/asset-hash-minified-app/source/javascripts/jquery.min.js
         | 
| 1697 1703 | 
             
            - fixtures/asset-hash-minified-app/source/stylesheets/test.css
         | 
| 1704 | 
            +
            - fixtures/asset-hash-prefix/config.rb
         | 
| 1705 | 
            +
            - fixtures/asset-hash-prefix/lib/middleware.rb
         | 
| 1706 | 
            +
            - fixtures/asset-hash-prefix/source/index.html.erb
         | 
| 1707 | 
            +
            - fixtures/asset-hash-prefix/source/javascripts/application.js
         | 
| 1708 | 
            +
            - fixtures/asset-hash-prefix/source/javascripts/application.js.map
         | 
| 1709 | 
            +
            - fixtures/asset-hash-prefix/source/layout.erb
         | 
| 1698 1710 | 
             
            - fixtures/asset-hash-source-map/config.rb
         | 
| 1699 1711 | 
             
            - fixtures/asset-hash-source-map/lib/middleware.rb
         | 
| 1700 1712 | 
             
            - fixtures/asset-hash-source-map/source/index.html.erb
         |