Recently, I've tried to mount Gollum onto my app. Here are the codes for my routes.rb
require 'gollum/app'
Rails.application.routes.draw do
wiki_options = {:universal_toc => false}
Precious::App.set(:gollum_path, Rails.root.join('wiki').to_s)
Precious::App.set(:default_markup, :markdown) # set your favorite markup language
Precious::App.set(:wiki_options, wiki_options)
mount Precious::App, at:'gollum'
end
I can access to the whole gollum using http://localhost:3000/gollum/.
I have to create a 'wiki' directory from root and do a git init .
there to get gollum working
$ mkdir wiki
$ cd wiki
$ git init .
The issue I'm having right now is that this is a simple mounting of gollum without all the other features in my app like authentication and layout. Still working on how to reflect which user performs which commit.
As of now, it's all under the server git account. On the side note, it seems a bit easier to integrate gollum to my app using gollum-lib but my have to reimplement the front end features.
Edit: So I get authentication working by using Devise in my routes.
authenticate :user do
mount Precious::App, at: 'gollum'
end
But this comes with a small issue that it keeps getting redirect_loop because Devise tries to route to the root of gollum which has not yet been authenticated. I'm trying to fix it so that it will redirect to the sign in page. Until then, it still serves my use case as I do not want unauthenticated users to come to the wiki.
I also add a way to get the correct author for each commit in gollum by using session["gollum.author"]
to pass in the info. I did this by create a session controller from Devise following Configuring Custom Controllers
class Users::SessionsController < Devise::SessionsController
# POST /resource/sign_in
def create
super do |resource|
session['gollum.author'] = { name: resource.name, email: resource.email }
end
end
# DELETE /resource/sign_out
def destroy
super { session['gollum.author'] = nil }
end
end
But for some reasons the session['gollum.author'] Hash changes the keys into string. So I have to do 1 final hack to get session['gollum.author'] Hash with symbol keys.
I follow this post and create an App class that inherits Previous::App and just do the changing in my routes.rb
# config/routes.rb
require 'gollum/app'
class App < Precious::App
before { assign_author }
helpers do
def assign_author
session["gollum.author"].symbolize_keys!
end
end
end
Rails.application.routes.draw do
wiki_options = {:universal_toc => false}
App.set(:gollum_path, Rails.root.join('wiki').to_s)
App.set(:default_markup, :markdown)
App.set(:wiki_options, wiki_options)
authenticate :user do
mount App, at:'gollum'
end
end