forked from rom-rb/rom-rb.org
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.rb
205 lines (161 loc) · 4.59 KB
/
config.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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
Encoding.default_internal = "utf-8"
require 'slim'
require 'builder'
set :site_url, 'http://rom-rb.org'
set :page_title, 'Ruby Object Mapper'
set :twitter_handle, '@rom_rb'
set :people, {
'Don Morrison' => 'https://twitter.com/elskwid',
'Piotr Solnica' => 'https://twitter.com/_solnic_',
'Mark Rickerby' => 'https://twitter.com/maetl'
}
set :projects, %w[
rom
rom-sql
rom-yesql
rom-influxdb
rom-event_store
rom-rethinkdb
rom-mongo
rom-redis
rom-csv
rom-yaml
rom-dm
rom-lotus
rom-rails
rom-roda
]
set :markdown_engine, :redcarpet
set :markdown, fenced_code_blocks: true,
smartypants: true,
with_toc_data: true
# blog config
activate :blog do |blog|
blog.prefix = 'blog'
blog.layout = 'blog'
blog.permalink = '{year}/{month}/{day}/{title}'
blog.paginate = true
blog.tag_template = "blog/tag.html"
end
ignore 'doc-pages/*'
page 'blog/*', layout: 'blog_article'
page 'blog/feed.xml', layout: false
configure :build do
activate :minify_javascript
activate :relative_assets
end
# syntax stuff
activate :syntax
set :css_dir, 'stylesheets'
set :js_dir, 'javascripts'
set :images_dir, 'images'
activate :livereload
activate :directory_indexes
doc_pages_root = "#{root}/source/doc-pages"
%w(introduction guides tutorials).each do |type|
Dir["#{doc_pages_root}/#{type}/**/*.md"].each do |full_path|
dir = File.dirname(full_path.gsub("#{doc_pages_root}/", ''))
name = File.basename(full_path, '.md')
path = "#{dir}/#{name}"
proxy "#{path}.html", "doc-page.html", locals: { type: type, doc: path }, ignore: true do
content_for(:page_title) {
name.split('/').unshift(type).map(&:humanize).join(' » ')
}
end
end
end
helpers do
def nav_heading(slug, title)
nav_link(slug, title, "nav-heading")
end
def nav_link(slug, title, class_names = [])
current = page_slug(current_page)
class_names = Array(class_names)
class_names << 'active' if slug == current
content_tag(:li, class: class_names.join(' ')) do
link_to(title, slug, class: class_names.join(' '))
end
end
def introduction_layout(&block)
partial "layouts/introduction", locals: { content: capture_html(&block) }
end
def tutorials_layout(&block)
partial "layouts/tutorials", locals: { content: capture_html(&block) }
end
def guides_layout(&block)
partial "layouts/guides", locals: { content: capture_html(&block) }
end
def within_layout(name, &block)
partial "layouts/#{name}", locals: { content: capture_html(&block) }
end
DOC_PAGES_ROOT = 'https://github.com/rom-rb/rom-rb.org/tree/master/source/doc-pages%{slug}.md'
GEMS = config.projects
def edit_article_link(title = 'Edit')
slug = page_slug(current_page)
link_to title, DOC_PAGES_ROOT % { slug: slug }
end
def page_slug(current_page)
current_page.data.slug || "/#{current_page.metadata[:locals][:doc]}"
end
def api_docs_link(gem)
link_to gem, "http://www.rubydoc.info/gems/#{gem}"
end
def api_docs_nav
html = ""
html << link_to("API <span class='caret'/>", "#",
class: "dropdown-toggle",
role: "button", data: { toggle: "dropdown" })
html << content_tag(:ul, class: "dropdown-menu", role: "menu") do
GEMS.map { |name| content_tag(:li, api_docs_link(name)) }.join
end
html
end
def article_permalink(article)
date = article.date
parts = ['/blog']
parts << date.year
parts << date.month.to_s.rjust(2, '0')
parts << date.day.to_s.rjust(2, '0')
parts << article.slug
parts.join('/')
end
def article_url(article)
"#{config.site_url}#{article_permalink(article)}"
end
def page_title
if is_blog_article?
"ROM » Blog » #{current_article.title}"
else
if yield_content(:page_title)
"ROM » #{yield_content(:page_title)}"
else
"ROM » #{data.page.title}"
end
end
end
def twitter_page_title
"#{page_title} via #{config.twitter_handle}"
end
def article_meta(article)
"Published on %{date} by %{author} under %{tags}" % {
date: article_date(article),
author: article_author(article),
tags: article_tags(article)
}
end
def article_date(article)
I18n.l(article.date.to_date, format: :long)
end
def article_author(article)
author_link(article.data['author'])
end
def article_tags(article)
article.tags.map { |tag| tag_link(tag) }.join(' ')
end
def tag_link(tag)
link_to(tag, tag_path(tag), class: 'tag')
end
def author_link(author)
link_to(author, config.people[author])
end
end