-
Notifications
You must be signed in to change notification settings - Fork 2
/
docpad.coffee
242 lines (203 loc) · 7.83 KB
/
docpad.coffee
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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
# The DocPad Configuration File
# It is simply a CoffeeScript Object which is parsed by CSON
docpadConfig =
# Template Data
# =============
# These are variables that will be accessible via our templates
# To access one of these within our templates, refer to the FAQ:
# https://github.com/bevry/docpad/wiki/FAQ
templateData:
# Specify some site properties
site:
# The production url of our website
url: "https://pimatic.org"
# Here are some old site urls that you would like to redirect from
oldUrls: [
'www.pimatic.org'
]
# The default title of our website
title: "pimatic - smart home automation for the raspberry pi"
# The website description (for SEO)
description: """
a home automation server and framework for the raspberry pi running on node.js
"""
# The website keywords (for SEO) separated by commas
keywords: """
pimatic home automation house nodejs Raspberry Pi
"""
# The website author's name
author: "Oliver Schneider"
# The website author's email
email: "[email protected]"
# Your company's name
copyright: "© Oliver Schneider " + new Date().getUTCFullYear()
# Helper Functions
# ----------------
# Get the prepared site/document title
# Often we would like to specify particular formatting to our page's title
# we can apply that formatting here
getPreparedTitle: ->
# if we have a document title, then we should use that and suffix the site's title onto it
if @document.title
"#{@document.title} | #{@site.title}"
# if our document does not have it's own title, then we should just use the site's title
else
@site.title
# Get the prepared site/document description
getPreparedDescription: ->
# if we have a document description, then we should use that,
# otherwise use the site's description
@document.description or @site.description
# Get the prepared site/document keywords
getPreparedKeywords: ->
# Merge the document keywords with the site keywords
@site.keywords.concat(@document.keywords or []).join(', ')
getPlugins: ->
#plugins = require('fs').readdirSync(__dirname + '/src/documents/docs')
#plugins = (p for p in plugins when not (p in ['pimatic-plugin-template']))
return [
"pimatic"
"pimatic-cron",
"pimatic-gpio",
"pimatic-log-reader",
"pimatic-mobile-frontend",
"pimatic-pilight",
"pimatic-ping",
"pimatic-redirect",
"pimatic-shell-execute",
"pimatic-sispmctl",
"pimatic-pushover",
"pimatic-sunrise",
"pimatic-voice-recognition",
]
getAllPlugins: ->
fs = require 'fs'
return JSON.parse(fs.readFileSync 'pluginList.json').filter( (p) -> p.name isnt 'pimatic' )
getAllDevices: -> require('./devices.coffee')
getCore: ->
fs = require 'fs'
return JSON.parse(fs.readFileSync 'pluginList.json').filter( (p) -> p.name is 'pimatic' )[0]
renderActionApi: (section) ->
declapi = require '../node_modules/pimatic/node_modules/decl-api'
api = require './api/pimatic-api.coffee'
return declapi.docs().genDocsForActions(api[section].actions)
require: (file) -> require file
author: (p) ->
name = p.author?.name or p.author_name
url = p.author?.url or p.autor_url
email = p.author?.email or p.autor_email
maintainer = null
for m in p.maintainers
if (email? and email is m.email)
maintainer = m
break
if maintainer?
if name?
name = "#{name} (#{maintainer.name})"
else
name = maintainer.name
return {href: url, name: name}
printConfigShema: (schema) ->
ck = require 'coffeekup'
return ck.render( (->
print = (schema, hidden) ->
if schema.title?
div schema.title
if schema.type is "object" and schema.properties?
if Object.keys(schema.properties).length > 0
table class:"table config-table #{if hidden then 'hidden'}", ->
tr ->
th "Option"
th "Description"
th "Default"
even = false
for k, v of schema.properties
evenClass = if even then 'even' else 'odd'
even = not even
tr class: evenClass, ->
td ->
strong k
br()
em (
if v.type is "array" and v.items?.type
then "array of #{v.items.type}s"
else v.type
)
td v.description
td ->
if v.default?
pre JSON.stringify(v.default, null, " ")
if (v.type is "object" and v.properties?) or
(v.type is "array" and v.items?.type is "object" and
v.items.properties? and Object.keys(v.items.properties).length > 0)
tr class: evenClass, ->
td class:"continue", colspan:3, ->
a class:'toggle-table', ->
i class:'glyphicon glyphicon-chevron-right', ''
if v.type is "object" then em " Properties" else em " Elements"
switch v.type
when "object" then print v, yes
when "array" then print v.items, yes
print @schema, no
), schema: schema)
# Collections
# ===========
# These are special collections that our website makes available to us
collections:
# For instance, this one will fetch in all documents that have pageOrder
# set within their meta data
pages: (database) ->
database.findAllLive({menu: true}, [pageOrder:1,title:1])
guides: (database) ->
database.findAllLive({guideOrder: $exists: true}, [guideOrder:1,title:1])
docs: (database) ->
database.findAllLive({url: $startsWith: '/docs/'}, [pageOrder:1,title:1])
# DocPad Events
# =============
# Here we can define handlers for events that DocPad fires
# You can find a full listing of events on the DocPad Wiki
events:
# Server Extend
# Used to add our own custom routes to the server before the docpad routes are added
serverExtend: (opts) ->
# Extract the server from the options
{server} = opts
docpad = @docpad
# As we are now running in an event,
# ensure we are using the latest copy of the docpad configuraiton
# and fetch our urls from it
latestConfig = docpad.getConfig()
oldUrls = latestConfig.templateData.site.oldUrls or []
newUrl = latestConfig.templateData.site.url
# Redirect any requests accessing one of our sites oldUrls to the new site url
server.use (req,res,next) ->
if req.headers.host in oldUrls
res.redirect 301, newUrl+req.url
else
next()
plugins:
repocloner:
repos: [
name: 'Guide'
path: 'src/documents/guide'
branch: 'master'
url: 'https://github.com/pimatic/pimatic-guide.git'
]
marked:
markedRenderer:
table: (header, body) ->
"""
<table class="table table-bordered">
<thead>
#{header}
</thead>
<tbody>
#{body}
</tbody>
</table>
"""
image: (href, title, text) ->
# TODO: clever handling or relative urls: unless href.match(/https?:\/\//)?
"""<img src="#{href}" alt="#{text}" #{if title? then 'title="'+title+'"' else ''}>"""
# Export our DocPad Configuration
module.exports = docpadConfig