middleman-releases 0.2.0 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/releases/extension.rb +33 -4
- data/lib/releases/instance.rb +4 -4
- data/middleman-releases.gemspec +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dc7429cfe473b413857e9bb90a626415c78d3939
|
4
|
+
data.tar.gz: 6ec2fb3daa296b19dd87fed400dde69b0beb095d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0334755fa70f7e576af65da353556912838a761ed126c0dce8046900978cf987e18b1dd75b9bea43d77c34a779fcd75fcfd17f04c040b9e6cd97c1a06605ed95
|
7
|
+
data.tar.gz: 3750da06b51ec7c6cd3b732c57e2e27620359989fcd7f0aca56d10d7074f8bfa16409f1a15d461a5e693b67f4535690632b192fbd47773e81544aa91824c9c2a
|
data/lib/releases/extension.rb
CHANGED
@@ -3,6 +3,8 @@ module Releases
|
|
3
3
|
option :layout, 'release', 'Layout for rendering an individual release'
|
4
4
|
option :releases_dir, 'releases', 'Directory containing releases'
|
5
5
|
|
6
|
+
expose_to_template :releases, :latest_release
|
7
|
+
|
6
8
|
def initialize(app, options_hash={}, &block)
|
7
9
|
super
|
8
10
|
end
|
@@ -15,6 +17,10 @@ module Releases
|
|
15
17
|
@_releases.sort_by(&:date).reverse
|
16
18
|
end
|
17
19
|
|
20
|
+
def latest_release
|
21
|
+
releases.first
|
22
|
+
end
|
23
|
+
|
18
24
|
def manipulate_resource_list(resources)
|
19
25
|
@_releases = []
|
20
26
|
|
@@ -26,6 +32,8 @@ module Releases
|
|
26
32
|
@_releases << Instance.from(resource, self)
|
27
33
|
end
|
28
34
|
end
|
35
|
+
|
36
|
+
resources + [ latest_release_resource ] + latest_release_asset_resources
|
29
37
|
end
|
30
38
|
|
31
39
|
helpers do
|
@@ -36,13 +44,34 @@ module Releases
|
|
36
44
|
def current_release
|
37
45
|
Releases::Instance.from(current_resource, self)
|
38
46
|
end
|
47
|
+
end
|
48
|
+
|
49
|
+
private
|
50
|
+
|
51
|
+
def latest_release_resource
|
52
|
+
return unless latest_release
|
39
53
|
|
40
|
-
|
41
|
-
|
54
|
+
Middleman::Sitemap::ProxyResource.new(app.sitemap, "#{ options[:releases_dir] }/latest/index.html", latest_release.path).tap do |p|
|
55
|
+
layout = options[:layout].to_s
|
56
|
+
p.add_metadata(options: { layout: layout }, locals: { latest: true })
|
42
57
|
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def assets_for_release(release)
|
61
|
+
dir = latest_release.path.gsub('index.html', '')
|
62
|
+
|
63
|
+
app.sitemap.resources.select do |resource|
|
64
|
+
resource.path.start_with?(dir) && !resource.path.end_with?('index.html')
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
def latest_release_asset_resources
|
69
|
+
return [] unless latest_release
|
43
70
|
|
44
|
-
|
45
|
-
|
71
|
+
assets = assets_for_release(latest_release)
|
72
|
+
assets.map do |asset|
|
73
|
+
target = asset.path.gsub("/#{ latest_release.tag }/", '/latest/')
|
74
|
+
Middleman::Sitemap::ProxyResource.new(app.sitemap, target, asset.path)
|
46
75
|
end
|
47
76
|
end
|
48
77
|
end
|
data/lib/releases/instance.rb
CHANGED
@@ -1,7 +1,11 @@
|
|
1
1
|
module Releases
|
2
2
|
class Instance
|
3
|
+
extend Forwardable
|
4
|
+
|
3
5
|
attr_accessor :controller, :resource, :tag
|
4
6
|
|
7
|
+
def_delegators :resource, :path, :data
|
8
|
+
|
5
9
|
def self.from(resource, controller)
|
6
10
|
tag = resource.data[:tag]
|
7
11
|
|
@@ -17,10 +21,6 @@ module Releases
|
|
17
21
|
end
|
18
22
|
end
|
19
23
|
|
20
|
-
def data
|
21
|
-
resource.data
|
22
|
-
end
|
23
|
-
|
24
24
|
def title
|
25
25
|
data[:title].presence || tag
|
26
26
|
end
|
data/middleman-releases.gemspec
CHANGED