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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0df7b6d2befa8e9db8de24d9e4da6b62c20f3451
4
- data.tar.gz: 9ab21bbdece78ee6e279e684d313d3e3799f9629
3
+ metadata.gz: dc7429cfe473b413857e9bb90a626415c78d3939
4
+ data.tar.gz: 6ec2fb3daa296b19dd87fed400dde69b0beb095d
5
5
  SHA512:
6
- metadata.gz: 5dc1a3a6d97a7ca03b80975464f47c0f8c40c48ce02bb64032454f22d256d9f797275fd476e0815d8e9cbd22475e68e71d614f777d2cd70edcc92a0e727cd283
7
- data.tar.gz: 43e49b07fc1cd23e7faa77e94763ce6195fa6d1249988e01de7d5e2d580e48168047b2952ed21561efdafa71f4aa3fc0e3248b2b3519ffe8605eb61c53232f1e
6
+ metadata.gz: 0334755fa70f7e576af65da353556912838a761ed126c0dce8046900978cf987e18b1dd75b9bea43d77c34a779fcd75fcfd17f04c040b9e6cd97c1a06605ed95
7
+ data.tar.gz: 3750da06b51ec7c6cd3b732c57e2e27620359989fcd7f0aca56d10d7074f8bfa16409f1a15d461a5e693b67f4535690632b192fbd47773e81544aa91824c9c2a
@@ -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
- def releases
41
- releases_controller.releases
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
- def latest_release
45
- releases.first
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
@@ -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
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "middleman-releases"
6
- s.version = "0.2.0"
6
+ s.version = "0.2.1"
7
7
  s.platform = Gem::Platform::RUBY
8
8
  s.authors = ["Matt Millsaps-Brewer"]
9
9
  s.email = ["matt@madebylotus.com"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-releases
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matt Millsaps-Brewer