/
archive_index_tags_and_methods.rb
executable file
·59 lines (46 loc) · 1.27 KB
/
archive_index_tags_and_methods.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
module ArchiveIndexTagsAndMethods
include Radiant::Taggable
tag "archive" do |tag|
tag.expand
end
[:title, :breadcrumb].each do |method|
tag method.to_s do |tag|
setup_date_parts
page = tag.locals.page
unless @year.nil?
Date.new((@year || 1).to_i, (@month || 1).to_i, (@day || 1).to_i).strftime(page.send(method))
else
page.send(method)
end
end
end
tag "archive:year" do |tag|
setup_date_parts
@year.to_i unless @year.nil?
end
tag "archive:month" do |tag|
setup_date_parts
Date.new(@year.to_i, @month.to_i, 1).strftime('%B') rescue ''
end
tag "archive:day" do |tag|
setup_date_parts
@day.to_i unless @day.nil?
end
tag "archive:day_of_week" do |tag|
setup_date_parts
Date.new(@year.to_i, @month.to_i, @day.to_i).strftime('%A') rescue ''
end
tag("archive:children:first") { "unimplemented" }
tag("archive:children:last" ) { "unimplemented" }
tag("archive:children:count") { "unimplemented" }
def virtual?
true
end
private
def request_uri
request.request_uri unless request.nil?
end
def setup_date_parts
@year, @month, @day = $1, $2, $3 if request_uri =~ %r{/(\d{4})(?:/(\d{2})(?:/(\d{2}))?)?/?$}
end
end