summaryrefslogtreecommitdiff
path: root/lib/page_tag.rb
blob: 03c15d209b7b259da9ff66c4e48347d9cecef2cc (plain)
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
60
# coding: utf-8
require 'category'
require 'page_index'
require 'page_remote'
require 'sitegen'

class TagPage < IndexPage
	def initialize(abbr)
		@category = Category::new(abbr)
		super("src/tags/#{@category.abbr}.phony")
	end
	def index_title
		return "Tag: #{@category.name}"
	end
	def index_pages
		return Sitegen::pages
				   .select{|p|!p.is_a?(IndexPage)}
				   .select{|p|p.atom_categories.any?{|c|c.abbr == @category.abbr}}
				   .to_set
	end
	def local_outfile
		return "out/tags/#{@category.abbr}.html"
	end
	def index_depends
		if @depends.nil?
			deps = Set['config.yaml']
			Sitegen::pages.select{|p|!p.is_a?(RemotePage)}.each{|p|deps.merge(p.local_depends[''])}
			@depends = deps
		end
		@depends
	end
	def local_depends
		return {
			'' => index_depends,
			local_outfile => index_depends.clone.merge(["tmpl/index.md.erb", "tmpl/page.html.erb"]),
		}
	end
end

class TagIndexPage < IndexPage
	def initialize
		super("src/tags")
	end
	def index_title
		return "Tags"
	end
	def index_pages
		return Sitegen::pages
				   .select{|p|p.is_a?(TagPage)}
				   .to_set
	end
	def index_depends
		if @depends.nil?
			deps = Set[]
			Sitegen::pages.select{|p|p.is_a?(LocalPage)}.each{|p|deps.merge(p.local_depends[''])}
			@depends = deps
		end
		@depends
	end
end