A wiki engine in Rails 5.
Usage
Add this line to your application's Gemfile:
gem 'railswiki'
# for loading secrets
gem 'figaro'
gem 'dotenv-rails'
And then execute:
$ bundle
Then enable in your application in config/routes.rb
:
Rails.application.routes.draw do
mount Railswiki::Engine, at: "/wiki"
get "/auth/google_login/callback" => "railswiki/sessions#create"
get "/auth/google_login" => "railswiki/sessions#create", as: :login
root to: "railswiki/pages#show", id: "Home"
end
Install and run migrations:
$ rake railties:install:migrations
$ rake db:migrate
Enable config/secrets.yml
to load secrets from ENV (using figaro
):
# config/secrets.yml
# Do not keep production secrets in the repository,
# instead read values from the environment.
production:
secret_key_base: <%= ENV["SECRET_KEY_BASE"] %>
Set your secrets in a .env
file in root (using dotenv-rails
):
SECRET_KEY_BASE: "xyz"
OAUTH_CLIENT_ID: "xyz"
OAUTH_CLIENT_SECRET: "xyz"
Get these values by logging into your Google Developers Console.
Install webpacker, adding railswiki
as a dependency:
$ rails webpacker:install
$ yarn add https://github.com/soundasleep/railswiki
$ yarn install
$ yarn add webpack-cli -D
Add to your app/javascript/packs/application.js
:
// javascripts
import SimpleMDE from 'simplemde'
import Tingle from 'tingle.js'
window.SimpleMDE = SimpleMDE
window.tingle = Tingle
// stylesheets
// I have NO idea why the src/ is broken but debug/ works - it looks like src/
// is missing some extra styles that aren't being included properly. who knows.
// import "simplemde/src/css/simplemde.css"
import "simplemde/debug/simplemde.css"
import 'tingle.js/src/tingle.css'
Run bin/webpack-dev-server
(or ruby bin\webpack-dev-server
on Windows) to compile the webpacker pack with hot reloading.
You can now host locally and visit http://localhost:3000/wiki:
$ rails s
Extending
In your local app, edit the app/assets/javascripts/ and app/assets/stylesheets as normal. They will automatically be picked up.
You can also override individual views from railswiki by creating e.g. app/views/railswiki/pages/show.html.erb
.
Custom page titles
In app/helpers/railswiki/title_helper.rb
:
module Railswiki::TitleHelper
def title(page_title)
page_title = ["My Very First Wiki"] if page_title == ["Home"]
content_for(:title) { page_title.join(" - ") }
end
end
Use slugs (/title) rather than Wiki (/wiki/Title)
Create a new initialiser to enable slugs, rather than wiki pages:
# config/initializers/railswiki_slugs.rb
Railswiki::Engine.use_slugs = true
And add to your routes.rb
, before your root
route:
get "*path", to: 'railswiki/pages#show', via: :get, as: :slug
Deploying
Check out DEPLOY.md for instructions to deploy using Capistrano onto Apache/Passenger/MySQL.
Supported
- Making pages, editing pages
- Assigning permissions to users
- Uploading files and images, images can be scaled and linked to external URLs
- Existing image dialog in wysiwyg editor (uploading images remotely is too hard)
- Existing file dialog in wysiwyg editor
- Invite users
- Prevent navigating/reloading with unsaved changes
- Templates can be included using
{{template}}
- Search with
{{Special:Search}}
template - Rails 5.1
- Uses yarn/webpack for Javascript assets (though it's a bit messy - waiting for webpack support for Rails Engines)
MVP
- A nice default style
- Put dialog Javascript into assets/, not inline
TODO
- Use Ruby 2.4+
- Make site accessible to screen readers (like ChromeVox) by default
- Allow images to have descriptions, which are used for screen readers
- Allow images to be linked as Image:N rather than full paths
- Allow files, images to be renamed (change title)
- All the schemas require null set
- Rspec tests
- Cucumber tests
- Travis-ci integration
- Demo site on Heroku
- Screenshot
- Uploads persist across validations and can be uploaded from remote URLs
- Support strikethrough, pretty code blocks, etc and list in Special:Formatting
- "What Links Here"
- "Page Categories"
- Clicking "sign in" at the bottom of the page redirects to the page you were on
Sites using Railswiki
Contributing
Contribution directions go here.
License
The gem is available as open source under the terms of the MIT License.