Documentation Editor
This is the mountable Rails application providing the documentation editor of algolia.com/doc.
The goal of this project is to provide an easy & frictionless way to edit an online tech documentation. The sweet spot of this editor is to be able to generate pages containing multiple snippets of highlighted code & conditional sections (which wasn't really available in any other CMS we considered). It also includes a nice image uploader storing the image to Amazon S3, a simple table editor and an automatic table of content generator.
Features
- Widgets
- Text: full markdown support
- Callout: info/warning/danger
- Tables: customizable number of columns & rows
- Code: code snippet with highlighting
- Conditions: ability to display some sections based on some query parameters
- Image: image uploader + ability to store on S3
- Buttons: labeled buttons
- Caching
- Automatic TOC generation (anchors are automatically generated on each title)
- Raw edition mode
- Administration restricted access
- Undo
- Versionning
- Diff
Installation
Dependencies
Your project needs to depend on the following libraries:
- Angular.js,
- ng-file-upload.js,
- Bootstrap 3,
- and Fontawesome 4.
This project depends on:
- rails (> 4.0),
- haml-rails,
- sass-rails,
- kramdown,
- highlight,
- simple_form,
- sass-rails,
- and paperclip.
Setup
To use it in your own Rails project, do the following steps:
Rails.application.routes.draw do
mount DocumentationEditor::Engine => "/doc"
end
- Add the following dependency in your
application.js
:
- Add the following dependency in your
application.css
:
- Run the underlying migrations:
$ rake db:migrate
- Go to
/doc/admin
to create your first page
Configuration
Create a config/initializers/documentation_editor.rb
file to configure the editor:
DocumentationEditor::Config.layout = 'my_custom_layout'
DocumentationEditor::Config.is_admin = :method_checking_if_admin?
DocumentationEditor::Config.before_filter = :my_before_filter
DocumentationEditor::Config.paperclip_options = {
storage: 's3',
s3_credentials: { bucket: 'xxx', access_key_id: 'xxx', secret_access_key: 'xxx' },
s3_host_alias: 'xxxxxxxxxx.cloudfront.net',
url: ':s3_alias_url',
path: ':attachment/:id/:style.:extension'
}
DocumentationEditor::Config.wrap_h1_with_sections = true
DocumentationEditor::Config.lower_title_levels = true
Extensions
Language conditions
You can force a page to only display a specific language. To force the language of a page, you need to set the language
query parameter. We recommend inlining those parameters directly from your routes.rb
file:
Rails.application.routes.draw do
get '/doc/ruby', :controller => 'pages', :action => 'show', slug: 'guide', language: 'ruby'
mount DocumentationEditor::Engine => "/doc"
end
Use [[LANGUAGE]] ... [[/LANGUAGE]]
to only display a piece of text if this is the current language. For instance:
[[ruby]]This will only be displayed if languag=ruby[[/ruby]] but this will be always displayed.
If you want a tab of your code snippet to be displayed whatever the language, you can use the special *
language name. For instance, this JavaScript snippet will be displayed whatever the language specified:
Variables
Rails.application.routes.draw do
get '/doc/ruby', :controller => 'pages', :action => 'show', slug: 'my_page', variables: { name: 'Foo' }
mount DocumentationEditor::Engine => "/doc"
end
Use [[variable:VARIABLE]]
and specify any variables you want to display their values. For instance:
This is the value of the `name` variable: [[variable:name]].
Section Restriction
Rails.application.routes.draw do
get '/doc/ruby(/:section)', :controller => 'pages', :action => 'show', slug: 'my_page'
mount DocumentationEditor::Engine => "/doc"
end
If you're using the wrap_h1_with_sections
option you can use the :section
param to restrict the rendering to a specific section your page. The TOC will still contain everything. That's something you may want to use for SEO reasons. This must be the last part of your URL.
Usage
Create your first page from the /doc/admin
URL.
This is what the previous code generates:
And this is what it looks like once styled:
What the history/diff looks like:
Development
$ bundle install
$ cd test/dummy
$ rake documentation_editor:install:migrations
$ rake db:migrate
$ rails server
$ open http://localhost:3000/doc/admin
Credits
This has originally been inspired by the great readme.io service and adapted to fit Algolia's needs.