forked from emberjs/website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.rb
191 lines (149 loc) · 4.37 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
require "redcarpet"
require "active_support/core_ext"
require "coderay"
# Debugging
set(:logging, ENV['RACK_ENV'] != 'production')
###
# Blog
###
#activate :blog
#set :blog_sources, "blog/:year-:month-:day-:title.html"
#set :blog_permalink, "blog/:year/:month/:day/:title.html"
#set :blog_layout, 'blog'
###
# Helpers
###
# Methods defined in the helpers block are available in templates
# helpers do
# def some_helper
# "Helping"
# end
# end
class TableOfContents < Redcarpet::Render::Base
def self.anchorify(text)
text.gsub(/&#?\w+;/, '-').gsub(/\W+/, '-').gsub(/^-|-$/, '').downcase
end
def initialize
@current_level = 0
@toc_count = 0
@result = []
super
end
def header(text, level)
@toc_count += 1
return "" if level > 3
link = "<a href=\"#toc_#{TableOfContents.anchorify(text)}\">#{text}</a>"
@result << %Q{<li class="level-#{level}">#{link}</li>}
""
end
def postprocess(text)
"<ol>" + @result.join("") + "</ol>"
end
end
helpers do
def link_to_page name, url
path = request.path
current = path =~ Regexp.new(url)
if path == '/index.html' and name == 'about'
current = true
end
class_name = current ? ' class="active"' : ''
"<li#{class_name}><a href=\"#{url}\">#{name}</a></li>"
end
def table_of_contents
chapters = data.docs.chapters
chapters = chapters.collect_concat do |file|
File.read("source/docs/#{file}.md")+"\n"
end
toc = TableOfContents.new()
markdown = Redcarpet::Markdown.new(toc, fenced_code_blocks: true)
markdown.render(chapters.join(''))
end
def table_of_contents_for(file)
document = File.read("source/#{file}")
toc = TableOfContents.new()
markdown = Redcarpet::Markdown.new(toc, fenced_code_blocks: true)
markdown.render(document)
end
def highlight(language, class_name, &block)
concat %Q{<div class="highlight #{class_name} #{language}">}
concat '<div class="ribbon"></div>'
code = capture(&block)
code.gsub!(/^\n+/, '')
#code.rstrip!
code = CodeRay.scan(code, language)
concat code.div css: :class,
line_numbers: :table,
line_number_anchors: false
concat %Q{</div>}
end
# The default one is buggy as of beta 2
def wrap_layout(layout_name, &block)
# Save current buffer for later
@_out_buf, _buf_was = "", @_out_buf
begin
content = capture(&block) if block_given?
ensure
# Reset stored buffer
@_out_buf = _buf_was
end
layout_path = locate_layout(layout_name, current_engine)
if !@_out_buf
raise "wrap_layout is currently broken for this templating system"
end
@_out_buf.concat render_individual_file(layout_path, @current_locs || {}, @current_opts || {}, self) { content }
end
end
class HighlightedHTML < Redcarpet::Render::HTML
def header(text, level)
"<h#{level} id='toc_#{TableOfContents.anchorify(text)}'>#{text}</h#{level}>"
end
def block_code(code, language)
result = %Q{<div class="highlight #{language}">}
result += '<div class="ribbon"></div>'
code.gsub!(/^\n+/, '')
code.rstrip!
code = CodeRay.scan(code, language)
result += code.div css: :class,
line_numbers: :table,
line_number_anchors: false
result += %Q{</div>}
result
end
end
set :markdown_engine, :redcarpet
set :markdown, :layout_engine => :erb,
:fenced_code_blocks => true,
:lax_html_blocks => true,
:renderer => HighlightedHTML.new()
activate :directory_indexes
page "/doc*" do
@chapters = data.docs.chapters
end
data.guides.each do |guide_name, properties|
page "/guides/#{guide_name}", :proxy => "guide.html" do
@guide = guide_name
end
end
page "community.html" do
@chapters = data.community.chapters
end
page "examples/*", :directory_index => false
page "index.html", :proxy => "about.html"
# Build-specific configuration
configure :build do
# For example, change the Compass output style for deployment
# activate :minify_css
# Minify Javascript on build
# activate :minify_javascript
# Enable cache buster
# activate :cache_buster
# Use relative URLs
# activate :relative_assets
# Compress PNGs after build
# First: gem install middleman-smusher
# require "middleman-smusher"
# activate :smusher
# Or use a different image path
# set :http_path, "/Content/images/"
end