middleman-cdn 0.1.11 → 0.1.13

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4aa1ea493606bab17daddd55eafc4a092b3e36ae
4
- data.tar.gz: c1bd19c00e6049f9c0061be48fceb9837d1b91e7
3
+ metadata.gz: 8550558e8e045e9d7f82f7b54b44a8a41dca5077
4
+ data.tar.gz: bbf9bf9ee078a2f6ed00edf5e5461abf3ff183aa
5
5
  SHA512:
6
- metadata.gz: fe34df0d332ba27dabd93aa024cc83d7fa62e3b1ed07384266b4c88c29f4d561ce72d2580b57da4bd08d79469c0a6b2a20ce577cafc345954ab2372a43c51928
7
- data.tar.gz: 4855e0686dc2541e467ac27484e6f19daac2a4b3f3c24ef8d57c6a156160190226bfe2203f8261a59faa08b28a77177d802b14c0478c99013c5e97e925f9e205
6
+ metadata.gz: 459ed7ed549ffead8d05e497d2b1036d48416efaf5cce161fa8ed51ce773a6ad4a69711c51aecfb26649fb4efad7c66183113008f51ca365f7ea32476231ccc0
7
+ data.tar.gz: dcef7018c3c2141b8f36baae317272931b250886c3d17ffbbfc07d7be2102f72971f251db38503d972372c3965417af3ac42448794f97a332bcf5f3f72de6791
data/README.md CHANGED
@@ -1,4 +1,6 @@
1
1
  # Middleman CDN
2
+
3
+ [![Gitter](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/leighmcculloch/middleman-cdn?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
2
4
  [![Gem Version](https://badge.fury.io/rb/middleman-cdn.svg)](http://badge.fury.io/rb/middleman-cdn) [![Build Status](https://travis-ci.org/leighmcculloch/middleman-cdn.svg)](https://travis-ci.org/leighmcculloch/middleman-cdn) [![Coverage Status](https://img.shields.io/coveralls/leighmcculloch/middleman-cdn.svg)](https://coveralls.io/r/leighmcculloch/middleman-cdn) [![Dependency Status](https://gemnasium.com/leighmcculloch/middleman-cdn.png)](https://gemnasium.com/leighmcculloch/middleman-cdn)
3
5
 
4
6
  A [middleman](http://middlemanapp.com/) deploy tool for invalidating resources cached
@@ -23,8 +23,15 @@ module Middleman
23
23
  end
24
24
 
25
25
  desc "cdn:cdn_invalidate", "Invalidate your CloudFlare or CloudFront cache"
26
- def cdn_invalidate(options = nil)
26
+ def cdn_invalidate(*args)
27
27
  begin
28
+ if args.first && args.first.respond_to?(:filter)
29
+ options = args.first
30
+ files = args.drop(1)
31
+ else
32
+ files = args
33
+ end
34
+
28
35
  if options.nil?
29
36
  app_instance = ::Middleman::Application.server.inst
30
37
  unless app_instance.respond_to?(:cdn_options)
@@ -40,9 +47,16 @@ module Middleman
40
47
  raise
41
48
  end
42
49
 
43
- files = list_files(options.filter)
44
- self.class.say_status(nil, "Invalidating #{files.count} files with filter: " + "#{options.filter.source}")
50
+ unless files.empty?
51
+ files = normalize_files(files)
52
+ message = "Invalidating #{files.count} files:"
53
+ else
54
+ files = normalize_files(list_files(options.filter))
55
+ message = "Invalidating #{files.count} files with filter: #{options.filter.source}"
56
+ end
57
+ self.class.say_status(nil, message)
45
58
  files.each { |file| self.class.say_status(nil, " • #{file}") }
59
+
46
60
  return if files.empty?
47
61
 
48
62
  invalidate_all = does_filter_match_all(options.filter)
@@ -106,20 +120,21 @@ end
106
120
 
107
121
  # Remove files that do not match filter
108
122
  files.reject! { |f| f !~ filter }
109
-
110
- # Add directories of index.html files since they have to be
111
- # invalidated as well if :directory_indexes is active
112
- files.each do |file|
113
- file_dir = file.sub(/\bindex\.html\z/, '')
114
- files << file_dir if file_dir != file
115
- end
116
-
117
- # Add leading slash
118
- files.map! { |f| f.start_with?('/') ? f : "/#{f}" }
119
123
  end
120
124
  end
121
125
  end
122
126
 
127
+ def normalize_files(files)
128
+ # Add directories of index.html files since they have to be
129
+ # invalidated as well if :directory_indexes is active
130
+ files.each do |file|
131
+ file_dir = file.sub(/\bindex\.html\z/, '')
132
+ files << file_dir if file_dir != file
133
+ end
134
+
135
+ # Add leading slash
136
+ files.map! { |f| f.start_with?('/') ? f : "/#{f}" }
137
+ end
123
138
  end
124
139
 
125
140
  Base.map({"cdn" => "cdn_invalidate"})
@@ -3,6 +3,10 @@ require 'middleman-core'
3
3
  module Middleman
4
4
  module CDN
5
5
  module Helpers
6
+ def cdn_invalidate(files = nil)
7
+ ::Middleman::Cli::CDN.new.cdn_invalidate(cdn_options, *files)
8
+ end
9
+
6
10
  def cdn_options
7
11
  ::Middleman::CDN::CDNExtension.options
8
12
  end
@@ -24,7 +28,7 @@ module Middleman
24
28
 
25
29
  app.after_configuration do
26
30
  app.after_build do
27
- ::Middleman::Cli::CDN.new.cdn_invalidate(@@cdn_options) if @@cdn_options.after_build
31
+ cdn_invalidate if cdn_options.after_build
28
32
  end
29
33
  end
30
34
 
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module CDN
3
- VERSION = '0.1.11'
3
+ VERSION = '0.1.13'
4
4
  end
5
5
  end
@@ -112,5 +112,61 @@ describe Middleman::Cli::CDN do
112
112
  subject.cdn_invalidate(options)
113
113
  end
114
114
  end
115
+
116
+ context "list of files provided at runtime" do
117
+ context "invalidate files given and not the filter" do
118
+ let(:options) do
119
+ OpenStruct.new({
120
+ cloudflare: {},
121
+ cloudfront: {},
122
+ fastly: {},
123
+ filter: /\.htm$/
124
+ })
125
+ end
126
+
127
+ it "should invalidate the files with all cdns" do
128
+ expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to receive(:invalidate).with(options.cloudflare, ["/image.png"], all: false)
129
+ expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to receive(:invalidate).with(options.cloudfront, ["/image.png"], all: false)
130
+ expect_any_instance_of(::Middleman::Cli::FastlyCDN).to receive(:invalidate).with(options.cloudfront, ["/image.png"], all: false)
131
+ subject.cdn_invalidate(options, "image.png")
132
+ end
133
+ end
134
+
135
+ context "invalidate multiple files given and not the filter" do
136
+ let(:options) do
137
+ OpenStruct.new({
138
+ cloudflare: {},
139
+ cloudfront: {},
140
+ fastly: {},
141
+ filter: /\.htm$/
142
+ })
143
+ end
144
+
145
+ it "should invalidate the files with all cdns" do
146
+ expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to receive(:invalidate).with(options.cloudflare, ["/image.png", "/index.html", "/"], all: false)
147
+ expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to receive(:invalidate).with(options.cloudfront, ["/image.png", "/index.html", "/"], all: false)
148
+ expect_any_instance_of(::Middleman::Cli::FastlyCDN).to receive(:invalidate).with(options.cloudfront, ["/image.png", "/index.html", "/"], all: false)
149
+ subject.cdn_invalidate(options, "image.png", "index.html")
150
+ end
151
+ end
152
+
153
+ context "invalidate files and still expand index.html's to directories too" do
154
+ let(:options) do
155
+ OpenStruct.new({
156
+ cloudflare: {},
157
+ cloudfront: {},
158
+ fastly: {},
159
+ filter: /\.htm$/
160
+ })
161
+ end
162
+
163
+ it "should invalidate the files with all cdns" do
164
+ expect_any_instance_of(::Middleman::Cli::CloudFlareCDN).to receive(:invalidate).with(options.cloudflare, ["/index.html", "/"], all: false)
165
+ expect_any_instance_of(::Middleman::Cli::CloudFrontCDN).to receive(:invalidate).with(options.cloudfront, ["/index.html", "/"], all: false)
166
+ expect_any_instance_of(::Middleman::Cli::FastlyCDN).to receive(:invalidate).with(options.cloudfront, ["/index.html", "/"], all: false)
167
+ subject.cdn_invalidate(options, "index.html")
168
+ end
169
+ end
170
+ end
115
171
  end
116
172
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-cdn
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.11
4
+ version: 0.1.13
5
5
  platform: ruby
6
6
  authors:
7
7
  - Leigh McCulloch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-03 00:00:00.000000000 Z
11
+ date: 2015-03-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fog