Created
January 25, 2018 10:08
-
-
Save clintpachl/1807a0a3ba42dfca788bd853f42aa66f to your computer and use it in GitHub Desktop.
My first Syro app: a wiki!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
App = Syro.new do | |
on 'wiki' do | |
if root? | |
run PageRouter, page: 'wiki' | |
else | |
run UtilityRouter | |
end | |
end | |
on :page do | |
run PageRouter, inbox | |
end | |
res.redirect '/wiki', 301 | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
PageRouter = Syro.new(WikiPage) do | |
on (req.path.end_with? '/') do | |
res.redirect req.path.chop, 301 | |
end | |
on page_exists? do | |
get do | |
if req.params.key? 'edit' | |
render :edit, content: fetch_page_markdown | |
else | |
render_page | |
end | |
end | |
delete do | |
delete_page | |
res.redirect '/wiki' | |
end | |
head {} # 200 status for client-side file detection | |
patch do | |
update_page | |
store_uploads | |
reload_page | |
end | |
end | |
get do | |
res.status = 404 | |
render :new | |
end | |
post do | |
create_page | |
store_uploads | |
reload_page | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
UtilityRouter = Syro.new(WikiPage) do | |
on :utility do | |
if root? and req.get? and utility_exists? | |
res.status = 200 | |
if 'search' == inbox[:utility] | |
render('wiki/search', query: req.params['query']) | |
else | |
render('wiki/%s' % inbox[:utility]) | |
end | |
else | |
res.text 'This utility page does not exist.' | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment