A simple help system using Rails Engine.
Just install the plugin with script/plugin install git://github.com/fnando/need_help.git
.
-
Run the task
rake help:sync
to copy the required migrations. Rundb:migrate
to update the database schema. -
Create the file
config/help/help.yml
. This file will hold all categories and topics. The syntax is quite simple:"Category 1": "Topic 1.1": topic11.textile "Topic 1.2": topic12.textile "Category 2": "Topic 2.1": topic21.textile "Topic 2.2": topic22.textile
-
Create the files you specify (*.textile) on
config/help
directory. -
Import the topics with
rake help:update
-
Start the server
script/server
and go tohttp://localhost:3000/help
to view the help index. -
This plugin has two dependencies: http://github.com/fnando/has_permalink and http://github.com/fnando/has_markup.
This plugins adds 3 routing paths:
/help
: the main help page/help/[category permalink]
: the whole help category page/help/v/[topic permalink]
: the topic page. This action accepts 3 formats:xml
,json
andhtml
; note that thehtml
format will redirect to the category page unlessrequest.xhr?
returnstrue
, which in this case will render theshow.erb.html
template.
If you want to override/localize the routing, use the following snippet (which is added by the plugin):
map.with_options :controller => "help" do |url|
url.help "/help", :action => "index"
url.help_page "/help/v/:permalink", :action => "show"
url.formatted_help_page "/help/v/:permalink.:format", :action => "show"
url.help_category "/help/:permalink", :action => "by_category"
end
As you can see, you have some named routings.
To customize the view, just create two views at app/views/help/index.erb.html
and app/views/help/show.erb.html
. There's three instance variables: @categories
, @category
and @topics
, depending on the view you're working.
You need to set two keys for your locale file (config/locales/en.yml
):
en:
back_to_top: "Back to top"
see_all: "See all"
Here's some CSS:
body {
font-family: Georgia;
font-size: 14px;
margin: 0;
padding: 40px;
}
.help h3,
.help-summary h2 a {
color: #900;
font-size: 18px;
margin-bottom: 0;
}
.help-summary h2 a {
text-decoration: none;
}
.help-summary h2 a:hover {
text-decoration: underline;
}
.help p {
line-height: 160%;
margin: 0;
padding-bottom: 10px;
}
a {
color: rgb(54, 113, 161);
}
p.top a {
font-weight: bold;
}
p.top a:after {
content: "↑";
}
ul.topics {
margin-left: 0;
padding-left: 20px;
}
ul.topics li {
margin: 5px 0;
}
h2#index {
font-size: 24px;
margin: 0;
}
.help {
border-top: 1px dotted #888;
}
- Write specs
Create a new project with Rails 2.3, install the plugin and its dependencies and run the command ruby vendor/plugins/need_help/spec/need_help_spec.rb -c
from the project's root.
Copyright (c) 2009 Nando Vieira
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.