简体   繁体   中英

Make Gollum Gem work with Rails 4

I need to add wiki pages to my application and I've just read about the Gollum gem.

Since I'm new to Rails I'm not completely sure about how to integrate gems installed separately with a working project.

What are the next steps after installing the gem? How will it be accessible from a controller? Do I have to create my own controller, view and model?

Plus, where can I find valid examples of how to manage simple wiki pages? The git repository lacks examples

https://github.com/gollum/gollum

@edit

taking this post as an example, what is YourApplication in the accepted answer?

How to properly mount github's gollum wiki inside a Rails App?

After following these steps am I able to use, for example, the markdown syntax in a view and it will be translated to formatted html?

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    

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM