This repository has been archived by the owner on Apr 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
custom.rb
86 lines (74 loc) · 2 KB
/
custom.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# -*- coding: utf-8 -*-
module PageModelViewAddons
def greeting
"Hello there! How are you?"
end
def raw_code(sub_context)
code = sub_context.gsub('{', '{').gsub('}', '}').gsub('<', '<').gsub('>', '>')
"<pre><code>#{code}</code></pre>"
end
def to_what(sub_context)
puts sub_context
end
def breadcrumb
path = []
id = pointer['id']
id.split('/').reduce{|s,p|
path << @ruhoh.db.notes[s]
s = "#{s}/#{p}"
}
path
end
def toc
# @ruhoh.config['toc']['friendly_anchor']
content = __getobj__.content # 这个方法在 model_view 调用来获取正在的model.content 才是未经处理的
html_render = Ruhoh::TOC::TOCRender.new
html_render.setup(content) #[content , id]
html_render.toc
end
def post_next
if pointer['resource'] != '_root'
self.next
else
nil
end
end
def post_previous
if pointer['resource'] != '_root'
self.previous
else
nil
end
end
end
Ruhoh.model('pages').send(:include, PageModelViewAddons)
Ruhoh.model('diary').send(:include, PageModelViewAddons)
module PageCollectionViewAddons
# 分类文章列表应该根据日期排序
def categories_sorted
categories_url = nil
[ruhoh.to_url("categories"), ruhoh.to_url("categories.html")].each { |url|
categories_url = url and break if ruhoh.routes.find(url)
}
dict = {}
dictionary.values.sort{|a,b| b["date"] <=> a["date"]}.each do |model|
Array(model.data['categories']).each do |cat|
cat = Array(cat).join('/')
if dict[cat]
dict[cat]['count'] += 1
else
dict[cat] = {
'count' => 1,
'name' => cat,
resource_name => [],
'url' => "#{categories_url}##{cat}-ref"
}
end
dict[cat][resource_name] << model.id
end
end
dict["all"] = dict.each_value.map { |cat| cat }
dict
end
end
Ruhoh.collection('pages').send(:include, PageCollectionViewAddons)