docent 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 Aaron Sumner
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,60 @@
1
+ # Docent: Contextual support for Rails applications
2
+
3
+ Docent is a friendly guide who points your application's users to the proper support documentation, as hosted in some external knowledge base like Desk.com, Zendesk, Confluence, and so on. It does so based on a table of URLs with controller-action combos, then supplies the link based on that view in your application.
4
+
5
+ Docent is a proof-of-concept, based on something I baked into a Rails 2-point-something app back in 2008 and recently realized I could use again. It operates as a mountable Rails engine and is still pretty raw right now.
6
+
7
+ ## Setup
8
+
9
+ 1. Add Docent to your Gemfile and install with Bundler.
10
+
11
+ 2. Mount the engine in your application:
12
+
13
+ mount Docent::Engine => "/docent"
14
+
15
+ 3. Add the Docent-specific tables to your database:
16
+
17
+ rake docent:install:migrations
18
+ rake db:migrate
19
+
20
+ 4. Create an initializer in `config/initializers/docent.rb`. This establishes a default link (top level of your knowledge base, support form, whatever) for views without support documents in Docent; it also provides a username and password for authentication via HTTP Basic:
21
+
22
+ Docent.default_link = 'http://yourhelpsite.com/docs'
23
+ Docent.username = 'docent_admin'
24
+ Docent.password = 'secret'
25
+
26
+ ## Usage
27
+
28
+ 1. Load Docent's admin panel at `http://yourapp.com/docent`
29
+
30
+ 2. Enter links to support documents. You can enter links specific to a controller#action combination, as well as catch-all links to controllers. Docent looks for links in the following order:
31
+
32
+ 1. The controller#action combination (e.g., `posts#new`)
33
+ 2. The controller only
34
+ 3. The default, set above in the initializer
35
+
36
+ 3. Provide links to your application's users by adding the following in your application's layout file:
37
+
38
+ <%= link_to_docent %>
39
+
40
+ By default, Docent labels the link *Help*; you can add your own and any options you could otherwise pass to Rails' `link_to` helper:
41
+
42
+ <%= link_to_docent 'Support', {target: 'new' } %>
43
+
44
+ ## To Do
45
+
46
+ - add a generator to do most of the setup automatically
47
+ - replace HTTP basic authentication with something integrated with the host application
48
+ - add support for self-hosted documents (I'd link to be able to post documents directly from ScreenSteps into Docent via XMLRPC, for example).
49
+
50
+ ## Contributing
51
+
52
+ I'd love to see your ideas and improvements. Fork the project on GitHub, make your changes (with specs!), and submit a pull request. **A note on specs:** I used Capybara feature specs to build Docent; the specs related to end-user access to links currently relies on a non-Rack::Test driver due to the need to check for redirection to an external site. I stuck with Selenium to minimize dependencies, at the expense of speed.
53
+
54
+ StatBoard is released under the [MIT License][mit]. See MIT-LICENSE for further details.
55
+
56
+ [mit]: http://www.opensource.org/licenses/MIT
57
+
58
+ ## Thanks
59
+
60
+ Having not messed with mountable engines in Rails much in the past, I took inspiration from [StatBoard](https://github.com/vigetlabs/stat_board) by Viget Labs (in particular the initializer setup and testing setup).
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Docent'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
@@ -0,0 +1,15 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // the compiled file.
9
+ //
10
+ // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD
11
+ // GO AFTER THE REQUIRES BELOW.
12
+ //
13
+ //= require jquery
14
+ //= require jquery_ujs
15
+ //= require_tree .
@@ -0,0 +1,13 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -0,0 +1,120 @@
1
+ body {
2
+ background-color: #fff;
3
+ color: #333;
4
+ margin: 0;
5
+ padding: 0;
6
+ }
7
+
8
+ body, p, ol, ul, td {
9
+ font-family: helvetica, arial, sans-serif;
10
+ font-size: 13px;
11
+ line-height: 18px;
12
+ }
13
+
14
+ pre {
15
+ background-color: #eee;
16
+ padding: 10px;
17
+ font-size: 11px;
18
+ }
19
+
20
+ a { color: #026; }
21
+
22
+ a.button {
23
+ color: #fff;
24
+ text-decoration: none;
25
+ background-color: #026;
26
+ padding: 4px;
27
+ -mozilla-border-radius: 3px;
28
+ -webkit-border-radius: 3px;
29
+ border-radius: 3px;
30
+ }
31
+
32
+ div.field, div.actions {
33
+ margin-bottom: 10px;
34
+ }
35
+
36
+ header {
37
+ background-color: #ccc;
38
+ color: #fff;
39
+ padding: 5px 20px;
40
+ }
41
+
42
+ header h1 {
43
+ font-weight: normal;
44
+ }
45
+
46
+ header a {
47
+ color: #fff;
48
+ text-decoration: none;
49
+ }
50
+
51
+ #content {
52
+ margin: 20px;
53
+ }
54
+
55
+ table {
56
+ width: 100%;
57
+ border-collapse: collapse;
58
+ }
59
+
60
+ th {
61
+ text-align: left;
62
+ }
63
+
64
+ tr {
65
+ height: 40px;
66
+ }
67
+
68
+ th, td {
69
+ padding: 10px;
70
+ }
71
+
72
+ tr td:last-child {
73
+ text-align: right;
74
+ }
75
+
76
+ .odd { background-color: #eee; }
77
+ .even { background-color: #fff; }
78
+
79
+ footer {
80
+ color: #ccc;
81
+ border-top: 1px solid #ccc;
82
+ margin-top: 25px;
83
+ padding-top: 25px;
84
+ text-align: center;
85
+ }
86
+
87
+ #notice {
88
+ color: green;
89
+ }
90
+
91
+ .field_with_errors {
92
+ padding: 2px;
93
+ background-color: red;
94
+ display: table;
95
+ }
96
+
97
+ #error_explanation {
98
+ width: 450px;
99
+ border: 2px solid red;
100
+ padding: 7px;
101
+ padding-bottom: 0;
102
+ margin-bottom: 20px;
103
+ background-color: #f0f0f0;
104
+ }
105
+
106
+ #error_explanation h2 {
107
+ text-align: left;
108
+ font-weight: bold;
109
+ padding: 5px 5px 5px 15px;
110
+ font-size: 12px;
111
+ margin: -7px;
112
+ margin-bottom: 0px;
113
+ background-color: #c00;
114
+ color: #fff;
115
+ }
116
+
117
+ #error_explanation ul li {
118
+ font-size: 12px;
119
+ list-style: square;
120
+ }
@@ -0,0 +1,13 @@
1
+ module Docent
2
+ class ApplicationController < ActionController::Base
3
+ before_filter :basic_authenticate, if: lambda { Docent.username and Docent.password }
4
+
5
+ private
6
+
7
+ def basic_authenticate
8
+ authenticate_or_request_with_http_basic do |name, password|
9
+ name == Docent.username and password == Docent.password
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,45 @@
1
+ require_dependency "docent/application_controller"
2
+
3
+ module Docent
4
+ class LinksController < ApplicationController
5
+
6
+ def index
7
+ @links = Link.all
8
+ end
9
+
10
+ def new
11
+ @link = Link.new
12
+ end
13
+
14
+ def edit
15
+ @link = Link.find(params[:id])
16
+ end
17
+
18
+ def create
19
+ @link = Link.new(params[:link])
20
+
21
+ if @link.save
22
+ redirect_to links_url, notice: 'Successfully created link.'
23
+ else
24
+ render action: "new"
25
+ end
26
+ end
27
+
28
+ def update
29
+ @link = Link.find(params[:id])
30
+
31
+ if @link.update_attributes(params[:link])
32
+ redirect_to links_url, notice: 'Successfully updated link.'
33
+ else
34
+ render action: "edit"
35
+ end
36
+ end
37
+
38
+ def destroy
39
+ @link = Link.find(params[:id])
40
+ @link.destroy
41
+
42
+ redirect_to links_url, notice: 'Successfully deleted link.'
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ module Docent
2
+ module ApplicationHelper
3
+ def link_to_docent(label="Help", options={})
4
+ link_to label, Docent::Link.link_for(controller.controller_name, controller.action_name), options
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ module Docent
2
+ class Link < ActiveRecord::Base
3
+ attr_accessible :action, :controller, :url
4
+
5
+ def shortcut
6
+ "#{controller}##{action}"
7
+ end
8
+
9
+ def self.link_for(controller=nil, action=nil)
10
+ if link = self.where(controller: controller).
11
+ where(action: action).
12
+ first
13
+ link.url
14
+ elsif link = self.where(controller: controller).first
15
+ link.url
16
+ else
17
+ Docent.default_link
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,29 @@
1
+ <%= form_for(@link) do |f| %>
2
+ <% if @link.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@link.errors.count, "error") %> prohibited this link from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @link.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :controller %><br />
16
+ <%= f.text_field :controller %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :action %><br />
20
+ <%= f.text_field :action %>
21
+ </div>
22
+ <div class="field">
23
+ <%= f.label :url, 'URL' %><br />
24
+ <%= f.text_field :url %>
25
+ </div>
26
+ <div class="actions">
27
+ <%= f.submit %>
28
+ </div>
29
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing link</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', @link %> |
6
+ <%= link_to 'Back', links_path %>
@@ -0,0 +1,20 @@
1
+ <h1>Links</h1>
2
+
3
+ <%= link_to 'New Link', new_link_path, class: 'button' %>
4
+
5
+ <table>
6
+ <tr>
7
+ <th>controller#action</th>
8
+ <th>URL</th>
9
+ <th></th>
10
+ </tr>
11
+
12
+ <% @links.each do |link| %>
13
+ <tr id="link_<%= link.id %>" class="<%= cycle('odd','even') %>">
14
+ <td><%= link_to link.shortcut, edit_link_path(link) %></td>
15
+ <td><%= link_to link.url, link.url %></td>
16
+ <td><%= link_to 'Delete', link, method: :delete, data: { confirm: 'Are you sure?' }, class: 'button' %></td>
17
+ </tr>
18
+ <% end %>
19
+ </table>
20
+
@@ -0,0 +1,5 @@
1
+ <h1>New link</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', links_path %>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Docent</title>
5
+ <%= stylesheet_link_tag "docent/application", :media => "all" %>
6
+ <%= javascript_include_tag "docent/application" %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+ <header>
11
+ <h1><%= link_to 'Docent', root_path %></h1>
12
+ </header>
13
+
14
+ <div id="content">
15
+ <p id="notice"><%= notice %></p>
16
+ <%= yield %>
17
+ </div>
18
+
19
+ <footer>
20
+ Powered by
21
+ <%= link_to 'Docent', 'https://github.com/ruralocity/docent' %>
22
+ <%= Docent::VERSION %>
23
+ </footer>
24
+ </body>
25
+ </html>
data/config/routes.rb ADDED
@@ -0,0 +1,5 @@
1
+ Docent::Engine.routes.draw do
2
+ resources :links
3
+
4
+ root to: 'links#index'
5
+ end
@@ -0,0 +1,11 @@
1
+ class CreateDocentLinks < ActiveRecord::Migration
2
+ def change
3
+ create_table :docent_links do |t|
4
+ t.string :controller
5
+ t.string :action
6
+ t.string :url
7
+
8
+ t.timestamps
9
+ end
10
+ end
11
+ end
data/lib/docent.rb ADDED
@@ -0,0 +1,5 @@
1
+ require "docent/engine"
2
+
3
+ module Docent
4
+ mattr_accessor :default_link, :username, :password
5
+ end
@@ -0,0 +1,18 @@
1
+ module Docent
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Docent
4
+
5
+ initializer 'contextual_help.action_controller' do |app|
6
+ ActiveSupport.on_load :action_controller do
7
+ helper Docent::ApplicationHelper
8
+ end
9
+ end
10
+
11
+ config.generators do |g|
12
+ g.test_framework :rspec, :fixture => false
13
+ g.fixture_replacement :factory_girl, :dir => 'spec/factories'
14
+ g.assets false
15
+ g.helper false
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Docent
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :docent do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,186 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: docent
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Aaron Sumner
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-12-26 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '3.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '3.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: sqlite3
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: sqlite3
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rspec-rails
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: 2.12.0
70
+ type: :development
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: 2.12.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: capybara
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: 2.0.1
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: 2.0.1
94
+ - !ruby/object:Gem::Dependency
95
+ name: factory_girl_rails
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ~>
100
+ - !ruby/object:Gem::Version
101
+ version: 4.1.0
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ~>
108
+ - !ruby/object:Gem::Version
109
+ version: 4.1.0
110
+ - !ruby/object:Gem::Dependency
111
+ name: database_cleaner
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ description: Docent is a mountable Rails engine to provide your app's users with links
127
+ to proper support documentation.
128
+ email:
129
+ - asumner@mac.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - app/assets/javascripts/docent/application.js
135
+ - app/assets/stylesheets/docent/application.css
136
+ - app/assets/stylesheets/docent/scaffold.css
137
+ - app/controllers/docent/application_controller.rb
138
+ - app/controllers/docent/links_controller.rb
139
+ - app/helpers/docent/application_helper.rb
140
+ - app/models/docent/link.rb
141
+ - app/views/docent/links/_form.html.erb
142
+ - app/views/docent/links/edit.html.erb
143
+ - app/views/docent/links/index.html.erb
144
+ - app/views/docent/links/new.html.erb
145
+ - app/views/layouts/docent/application.html.erb
146
+ - config/routes.rb
147
+ - db/migrate/20121223020016_create_docent_links.rb
148
+ - lib/docent/engine.rb
149
+ - lib/docent/version.rb
150
+ - lib/docent.rb
151
+ - lib/tasks/docent_tasks.rake
152
+ - MIT-LICENSE
153
+ - Rakefile
154
+ - README.markdown
155
+ homepage: https://github.com/ruralocity/docent
156
+ licenses:
157
+ - MIT
158
+ post_install_message:
159
+ rdoc_options: []
160
+ require_paths:
161
+ - lib
162
+ required_ruby_version: !ruby/object:Gem::Requirement
163
+ none: false
164
+ requirements:
165
+ - - ! '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ segments:
169
+ - 0
170
+ hash: 3064965182523156662
171
+ required_rubygems_version: !ruby/object:Gem::Requirement
172
+ none: false
173
+ requirements:
174
+ - - ! '>='
175
+ - !ruby/object:Gem::Version
176
+ version: '0'
177
+ segments:
178
+ - 0
179
+ hash: 3064965182523156662
180
+ requirements: []
181
+ rubyforge_project:
182
+ rubygems_version: 1.8.23
183
+ signing_key:
184
+ specification_version: 3
185
+ summary: Contextually-aware links to externally-hosted support docs.
186
+ test_files: []