Skip to content

soundasleep/railswiki

Repository files navigation

Railswiki Gem Version

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

  1. Making pages, editing pages
  2. Assigning permissions to users
  3. Uploading files and images, images can be scaled and linked to external URLs
  4. Existing image dialog in wysiwyg editor (uploading images remotely is too hard)
  5. Existing file dialog in wysiwyg editor
  6. Invite users
  7. Prevent navigating/reloading with unsaved changes
  8. Templates can be included using {{template}}
  9. Search with {{Special:Search}} template
  10. Rails 5.1
  11. Uses yarn/webpack for Javascript assets (though it's a bit messy - waiting for webpack support for Rails Engines)

MVP

  1. A nice default style
  2. Put dialog Javascript into assets/, not inline

TODO

  1. Use Ruby 2.4+
  2. Make site accessible to screen readers (like ChromeVox) by default
  3. Allow images to have descriptions, which are used for screen readers
  4. Allow images to be linked as Image:N rather than full paths
  5. Allow files, images to be renamed (change title)
  6. All the schemas require null set
  7. Rspec tests
  8. Cucumber tests
  9. Travis-ci integration
  10. Demo site on Heroku
  11. Screenshot
  12. Uploads persist across validations and can be uploaded from remote URLs
  13. Support strikethrough, pretty code blocks, etc and list in Special:Formatting
  14. "What Links Here"
  15. "Page Categories"
  16. 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.

About

A wiki engine in Rails 5.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published