11module ChangesHelper
2+ MimeFormat = "application/vnd.github.%s+json" . freeze
23 # Public: Filters the change items out. If a version is given, show only the
34 # items related to that version.
45 #
@@ -17,4 +18,72 @@ def api_changes(version = nil)
1718 attribute_to_time ( y [ :created_at ] ) <=> attribute_to_time ( x [ :created_at ] )
1819 end . first ( 30 )
1920 end
21+
22+ # Public
23+ def current_api
24+ @current_api ||= ( api_versions [ -2 ] || api_versions . first ) . first
25+ end
26+
27+ # Public
28+ def upcoming_api
29+ @upcoming_api ||= begin
30+ version , date = api_versions . last
31+ version unless date
32+ end
33+ end
34+
35+ # Public
36+ def current_api? ( version )
37+ @api_current_checks ||= { }
38+ if @api_current_checks . key? ( version )
39+ @api_current_checks [ version ]
40+ end
41+
42+ @api_current_checks [ version ] = version == current_api
43+ end
44+
45+ # Public
46+ def no_current_api_versions? ( *versions )
47+ versions . none? { |v | current_api? ( v ) }
48+ end
49+
50+ # Public
51+ def api_released_at ( version )
52+ @api_releases ||= { }
53+ if @api_releases . key? ( version )
54+ @api_releases [ version ]
55+ end
56+
57+ @api_releases [ version ] = begin
58+ pair = api_versions . detect do |( name , date ) |
59+ name == version
60+ end
61+ pair ? pair [ 1 ] : nil
62+ end
63+ end
64+
65+ # Public
66+ def api_mimetype_listing ( version )
67+ version_s = version . to_s
68+ mime = mimetype_for version_s
69+ if time = api_released_at ( version_s )
70+ mime << " ("
71+ mime << "Current, " if current_api? ( version_s )
72+ mime << strftime ( time )
73+ mime << ")"
74+ else
75+ mime
76+ end
77+ end
78+
79+ # Internal
80+ def mimetype_for ( version )
81+ MimeFormat % version . to_s
82+ end
83+
84+ # Internal
85+ def api_versions
86+ @api_versions ||= Array ( @site . config [ :api_versions ] )
87+ end
2088end
89+
0 commit comments