doculab 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (65) hide show
  1. data/.gitignore +6 -0
  2. data/Gemfile +13 -0
  3. data/Gemfile.lock +133 -0
  4. data/MIT-LICENSE +20 -0
  5. data/README.rdoc +3 -0
  6. data/Rakefile +74 -0
  7. data/VERSION +1 -0
  8. data/app/controllers/doculab/docs_controller.rb +50 -0
  9. data/app/helpers/doculab/docs_helper.rb +15 -0
  10. data/app/helpers/doculab/table_of_contents_helper.rb +34 -0
  11. data/app/models/doculab/doc.rb +61 -0
  12. data/app/models/doculab/table_of_contents.rb +88 -0
  13. data/app/sweepers/doculab/cache_sweeper.rb +17 -0
  14. data/config/cucumber.yml +8 -0
  15. data/config/rails_template.rb +0 -0
  16. data/config/routes.rb +6 -0
  17. data/doculab.gemspec +145 -0
  18. data/features/step_definitions/doc_steps.rb +16 -0
  19. data/features/step_definitions/web_steps.rb +219 -0
  20. data/features/support/env.rb +34 -0
  21. data/features/support/paths.rb +28 -0
  22. data/features/viewing_docs.feature +10 -0
  23. data/lib/doculab/engine.rb +43 -0
  24. data/lib/doculab.rb +53 -0
  25. data/lib/tasks/doculab.rake +15 -0
  26. data/spec/controllers/docs_controller_spec.rb +62 -0
  27. data/spec/dummy/Rakefile +7 -0
  28. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  29. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  30. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  31. data/spec/dummy/config/application.rb +45 -0
  32. data/spec/dummy/config/boot.rb +10 -0
  33. data/spec/dummy/config/database.yml +22 -0
  34. data/spec/dummy/config/environment.rb +5 -0
  35. data/spec/dummy/config/environments/development.rb +22 -0
  36. data/spec/dummy/config/environments/production.rb +49 -0
  37. data/spec/dummy/config/environments/test.rb +35 -0
  38. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/spec/dummy/config/initializers/doculab.rb +1 -0
  40. data/spec/dummy/config/initializers/inflections.rb +10 -0
  41. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  42. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  43. data/spec/dummy/config/initializers/session_store.rb +8 -0
  44. data/spec/dummy/config/locales/en.yml +5 -0
  45. data/spec/dummy/config/routes.rb +58 -0
  46. data/spec/dummy/config.ru +4 -0
  47. data/spec/dummy/doculab/docs/overview.textile +1 -0
  48. data/spec/dummy/doculab/layouts/custom.html.erb +17 -0
  49. data/spec/dummy/doculab/layouts/docs.html.erb +17 -0
  50. data/spec/dummy/public/404.html +26 -0
  51. data/spec/dummy/public/422.html +26 -0
  52. data/spec/dummy/public/500.html +26 -0
  53. data/spec/dummy/public/favicon.ico +0 -0
  54. data/spec/dummy/public/javascripts/application.js +2 -0
  55. data/spec/dummy/public/javascripts/controls.js +965 -0
  56. data/spec/dummy/public/javascripts/dragdrop.js +974 -0
  57. data/spec/dummy/public/javascripts/effects.js +1123 -0
  58. data/spec/dummy/public/javascripts/prototype.js +6001 -0
  59. data/spec/dummy/public/javascripts/rails.js +175 -0
  60. data/spec/dummy/public/stylesheets/.gitkeep +0 -0
  61. data/spec/dummy/script/rails +6 -0
  62. data/spec/integration/navigation_spec.rb +9 -0
  63. data/spec/models/doc_spec.rb +47 -0
  64. data/spec/spec_helper.rb +58 -0
  65. metadata +265 -0
data/.gitignore ADDED
@@ -0,0 +1,6 @@
1
+ .bundle/
2
+ log/*.log
3
+ pkg/
4
+ spec/dummy/db/*.sqlite3
5
+ spec/dummy/log/*.log
6
+ spec/dummy/tmp/
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gem "tilt"
4
+ gem "RedCloth", :require => 'redcloth'
5
+
6
+ group :development do
7
+ gem "rails", "3.0.0.rc"
8
+ gem 'jeweler'
9
+ gem "rspec-rails", ">= 2.0.0.beta"
10
+ gem 'cucumber'
11
+ gem 'cucumber-rails'
12
+ gem 'capybara'
13
+ end
data/Gemfile.lock ADDED
@@ -0,0 +1,133 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ RedCloth (4.2.3)
5
+ abstract (1.0.0)
6
+ actionmailer (3.0.0.rc)
7
+ actionpack (= 3.0.0.rc)
8
+ mail (~> 2.2.5)
9
+ actionpack (3.0.0.rc)
10
+ activemodel (= 3.0.0.rc)
11
+ activesupport (= 3.0.0.rc)
12
+ builder (~> 2.1.2)
13
+ erubis (~> 2.6.6)
14
+ i18n (~> 0.4.1)
15
+ rack (~> 1.2.1)
16
+ rack-mount (~> 0.6.9)
17
+ rack-test (~> 0.5.4)
18
+ tzinfo (~> 0.3.22)
19
+ activemodel (3.0.0.rc)
20
+ activesupport (= 3.0.0.rc)
21
+ builder (~> 2.1.2)
22
+ i18n (~> 0.4.1)
23
+ activerecord (3.0.0.rc)
24
+ activemodel (= 3.0.0.rc)
25
+ activesupport (= 3.0.0.rc)
26
+ arel (~> 0.4.0)
27
+ tzinfo (~> 0.3.22)
28
+ activeresource (3.0.0.rc)
29
+ activemodel (= 3.0.0.rc)
30
+ activesupport (= 3.0.0.rc)
31
+ activesupport (3.0.0.rc)
32
+ arel (0.4.0)
33
+ activesupport (>= 3.0.0.beta)
34
+ builder (2.1.2)
35
+ capybara (0.3.9)
36
+ culerity (>= 0.2.4)
37
+ mime-types (>= 1.16)
38
+ nokogiri (>= 1.3.3)
39
+ rack (>= 1.0.0)
40
+ rack-test (>= 0.5.4)
41
+ selenium-webdriver (>= 0.0.3)
42
+ cucumber (0.8.5)
43
+ builder (~> 2.1.2)
44
+ diff-lcs (~> 1.1.2)
45
+ gherkin (~> 2.1.4)
46
+ json_pure (~> 1.4.3)
47
+ term-ansicolor (~> 1.0.4)
48
+ cucumber-rails (0.3.2)
49
+ cucumber (>= 0.8.0)
50
+ culerity (0.2.10)
51
+ diff-lcs (1.1.2)
52
+ erubis (2.6.6)
53
+ abstract (>= 1.0.0)
54
+ ffi (0.6.3)
55
+ rake (>= 0.8.7)
56
+ gemcutter (0.6.1)
57
+ gherkin (2.1.5)
58
+ trollop (~> 1.16.2)
59
+ git (1.2.5)
60
+ i18n (0.4.1)
61
+ jeweler (1.4.0)
62
+ gemcutter (>= 0.1.0)
63
+ git (>= 1.2.5)
64
+ rubyforge (>= 2.0.0)
65
+ json_pure (1.4.6)
66
+ mail (2.2.5)
67
+ activesupport (>= 2.3.6)
68
+ mime-types
69
+ treetop (>= 1.4.5)
70
+ mime-types (1.16)
71
+ nokogiri (1.4.3.1)
72
+ polyglot (0.3.1)
73
+ rack (1.2.1)
74
+ rack-mount (0.6.9)
75
+ rack (>= 1.0.0)
76
+ rack-test (0.5.4)
77
+ rack (>= 1.0)
78
+ rails (3.0.0.rc)
79
+ actionmailer (= 3.0.0.rc)
80
+ actionpack (= 3.0.0.rc)
81
+ activerecord (= 3.0.0.rc)
82
+ activeresource (= 3.0.0.rc)
83
+ activesupport (= 3.0.0.rc)
84
+ bundler (>= 1.0.0.rc.1)
85
+ railties (= 3.0.0.rc)
86
+ railties (3.0.0.rc)
87
+ actionpack (= 3.0.0.rc)
88
+ activesupport (= 3.0.0.rc)
89
+ rake (>= 0.8.3)
90
+ thor (~> 0.14.0)
91
+ rake (0.8.7)
92
+ rspec (2.0.0.beta.19)
93
+ rspec-core (= 2.0.0.beta.19)
94
+ rspec-expectations (= 2.0.0.beta.19)
95
+ rspec-mocks (= 2.0.0.beta.19)
96
+ rspec-core (2.0.0.beta.19)
97
+ rspec-expectations (2.0.0.beta.19)
98
+ diff-lcs (>= 1.1.2)
99
+ rspec-mocks (2.0.0.beta.19)
100
+ rspec-rails (2.0.0.beta.19)
101
+ rspec (= 2.0.0.beta.19)
102
+ webrat (>= 0.7.2.beta.1)
103
+ rubyforge (2.0.4)
104
+ json_pure (>= 1.1.7)
105
+ rubyzip (0.9.4)
106
+ selenium-webdriver (0.0.27)
107
+ ffi (>= 0.6.1)
108
+ json_pure
109
+ rubyzip
110
+ term-ansicolor (1.0.5)
111
+ thor (0.14.0)
112
+ tilt (1.0.1)
113
+ treetop (1.4.8)
114
+ polyglot (>= 0.3.1)
115
+ trollop (1.16.2)
116
+ tzinfo (0.3.22)
117
+ webrat (0.7.2.beta.1)
118
+ nokogiri (>= 1.2.0)
119
+ rack (>= 1.0)
120
+ rack-test (>= 0.5.3)
121
+
122
+ PLATFORMS
123
+ ruby
124
+
125
+ DEPENDENCIES
126
+ RedCloth
127
+ capybara
128
+ cucumber
129
+ cucumber-rails
130
+ jeweler
131
+ rails (= 3.0.0.rc)
132
+ rspec-rails (>= 2.0.0.beta)
133
+ tilt
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2010 YOURNAME
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.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = Doculab
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,74 @@
1
+ # encoding: UTF-8
2
+ require 'rubygems'
3
+ require 'bundler'
4
+ Bundler.setup(:default, :development)
5
+
6
+ require 'rake'
7
+ require 'rake/rdoctask'
8
+ require 'rake/gempackagetask'
9
+
10
+ require 'rspec/core'
11
+ require 'rspec/core/rake_task'
12
+
13
+ require 'cucumber/rake/task'
14
+
15
+ require 'jeweler'
16
+
17
+ # Specs #######################################################################
18
+ Rspec::Core::RakeTask.new(:spec)
19
+
20
+ task :default => :spec
21
+
22
+ Rake::RDocTask.new(:rdoc) do |rdoc|
23
+ rdoc.rdoc_dir = 'rdoc'
24
+ rdoc.title = 'Doculab'
25
+ rdoc.options << '--line-numbers' << '--inline-source'
26
+ rdoc.rdoc_files.include('README.rdoc')
27
+ rdoc.rdoc_files.include('lib/**/*.rb')
28
+ end
29
+
30
+ # Cucumber ####################################################################
31
+ namespace :cucumber do
32
+ Cucumber::Rake::Task.new(:ok, 'Run features that should pass') do |t|
33
+ t.fork = true # You may get faster startup if you set this to false
34
+ t.profile = 'default'
35
+ end
36
+
37
+ Cucumber::Rake::Task.new(:wip, 'Run features that are being worked on') do |t|
38
+ t.fork = true # You may get faster startup if you set this to false
39
+ t.profile = 'wip'
40
+ end
41
+
42
+ Cucumber::Rake::Task.new(:rerun, 'Record failing features and run only them if any exist') do |t|
43
+ t.fork = true # You may get faster startup if you set this to false
44
+ t.profile = 'rerun'
45
+ end
46
+
47
+ desc 'Run all features'
48
+ task :all => [:ok, :wip]
49
+ end
50
+ task :cucumber => 'cucumber:ok'
51
+ task :features => :cucumber do
52
+ STDERR.puts "*** The 'features' task is deprecated. See rake -T cucumber ***"
53
+ end
54
+
55
+ # Gem #########################################################################
56
+
57
+ Jeweler::Tasks.new do |gem|
58
+ gem.name = "doculab"
59
+ gem.summary = "A Rails Engine for creating a simple documentation site"
60
+ gem.description = "A Rails Engine for a simple file-based CMS, suitable for a documentation site. Originally created to power the Chargify documentation at http://docs.chargify.com"
61
+ gem.email = "michael@webadvocate.com"
62
+ gem.homepage = "http://github.com/grasshopperlabs/doculab"
63
+ gem.authors = ["Michael Klett"]
64
+ gem.add_dependency "tilt"
65
+ gem.add_dependency "RedCloth"
66
+ gem.add_development_dependency "rails", ">= 3.0.0.rc"
67
+ gem.add_development_dependency "rspec-rails", ">= 2.0.0.beta"
68
+ gem.add_development_dependency 'jeweler'
69
+ gem.add_development_dependency 'cucumber'
70
+ gem.add_development_dependency 'cucumber-rails'
71
+ gem.add_development_dependency 'capybara'
72
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
73
+ end
74
+ Jeweler::GemcutterTasks.new
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
@@ -0,0 +1,50 @@
1
+ module Doculab
2
+ class DocsController < ApplicationController
3
+ rescue_from Doc::FileNotFound, :with => :handle_file_not_found
4
+ layout :select_layout
5
+ helper TableOfContentsHelper
6
+ caches_page :index, :show
7
+
8
+ def index
9
+ find('index')
10
+ render :text => @doc.render, :layout => true
11
+ end
12
+
13
+ def show
14
+ find(params[:permalink])
15
+ render :text => @doc.render, :layout => true
16
+ end
17
+
18
+ protected
19
+ def find(permalink)
20
+ @doc = Doc.find(permalink)
21
+ @page = lookup_page(permalink)
22
+ end
23
+
24
+ def handle_file_not_found(e)
25
+ @doc = Doc.new(:title => "File Not Found", :content => e.message)
26
+ @page = TableOfContents::Page.new("File Not Found")
27
+ render :text => e.message, :layout => true
28
+ end
29
+
30
+ def lookup_page(permalink)
31
+ if permalink == 'index'
32
+ TableOfContents::Page.new(Doculab.title)
33
+ elsif page = TableOfContents.lookup(permalink)
34
+ page
35
+ else
36
+ TableOfContents::Page.new(permalink.titleize)
37
+ end
38
+ end
39
+
40
+ def select_layout
41
+ case params[:permalink]
42
+ when 'index', NilClass
43
+ Doculab.index_layout
44
+ else
45
+ Doculab.main_layout
46
+ end
47
+ end
48
+ # end protected
49
+ end
50
+ end
@@ -0,0 +1,15 @@
1
+ module Doculab
2
+ module DocsHelper
3
+ def doc_content
4
+ content_for?(:doc_content) ? yield(:doc_content) : yield
5
+ end
6
+
7
+ def doc
8
+ @doc
9
+ end
10
+
11
+ def sections
12
+ Doculab::TableOfContents.sections
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,34 @@
1
+ module Doculab
2
+ module TableOfContentsHelper
3
+ def page_title
4
+ parts = []
5
+
6
+ if @page
7
+ parts << @page.title
8
+ end
9
+
10
+ parts << "Chargify Documentation"
11
+
12
+ parts.join(" - ")
13
+ end
14
+
15
+
16
+ def toc_link(page)
17
+ if page.doc
18
+ link_to page.title, doculab_doc_path(page.permalink), :class => current_page?(page) ? 'current' : nil
19
+ else
20
+ page.title
21
+ end
22
+ end
23
+
24
+ def page
25
+ @page
26
+ end
27
+
28
+ private
29
+
30
+ def current_page?(page)
31
+ page && (page == @page)
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,61 @@
1
+ module Doculab
2
+ class Doc
3
+ cattr_reader :valid_attributes
4
+ @@valid_attributes = [:permalink, :file, :title, :content, :section]
5
+
6
+ cattr_writer :directory
7
+
8
+ attr_accessor *@@valid_attributes
9
+
10
+ def initialize(attributes = {})
11
+ attributes.assert_valid_keys(@@valid_attributes)
12
+ attributes.each do |field, value|
13
+ send("#{field}=", value)
14
+ end
15
+ end
16
+
17
+ def render
18
+ template = ::Tilt.new(file)
19
+ template.render(self)
20
+ end
21
+
22
+ def self.find(permalink)
23
+ file = file_for_permalink(permalink)
24
+
25
+ unless file && File.exist?(file)
26
+ raise FileNotFound, "No file found for '#{permalink}'"
27
+ end
28
+
29
+ content = File.read(file)
30
+ self.new(:permalink => permalink, :file => file, :content => content)
31
+ end
32
+
33
+ def self.directory
34
+ @@directory ||= Rails.root.join('doculab', 'docs')
35
+ Pathname.new(@@directory)
36
+ end
37
+
38
+ # Returns an array of filenames for all files in the docs directory
39
+ def self.filenames
40
+ filepaths.collect {|fn| File.basename(fn) }
41
+ end
42
+
43
+ def self.filepaths
44
+ Dir.glob(directory.join("*.{#{extensions.join(',')}}"))
45
+ end
46
+
47
+ class FileNotFound < StandardError; end
48
+
49
+ private
50
+
51
+ # Returns an array of available extensions
52
+ def self.extensions
53
+ %w(textile md)
54
+ end
55
+
56
+ def self.file_for_permalink(permalink)
57
+ filepaths.detect {|fn| File.basename(fn).split('.').first == permalink }
58
+ end
59
+
60
+ end
61
+ end
@@ -0,0 +1,88 @@
1
+ module Doculab
2
+ module TableOfContents
3
+ mattr_reader :sections
4
+ mattr_reader :pages
5
+
6
+ def self.define(&block)
7
+ @@sections = []
8
+ @@pages = []
9
+ self.instance_eval(&block)
10
+ return self
11
+ end
12
+
13
+ def self.section(title, &block)
14
+ section = Section.new(title)
15
+ @@sections << section
16
+ section.build(block)
17
+ end
18
+
19
+ def self.add_page(page)
20
+ @@pages << page
21
+ end
22
+
23
+ def self.lookup(permalink)
24
+ pages.detect { |p| p.permalink == permalink }
25
+ end
26
+
27
+ class Section
28
+ attr_reader :title, :pages
29
+
30
+ def initialize(title)
31
+ @title = title
32
+ @pages = []
33
+ end
34
+
35
+ def build(block)
36
+ instance_eval(&block)
37
+ end
38
+
39
+ def page(title, options = {})
40
+ add_page(Page.new(title, self, options))
41
+ end
42
+
43
+ private
44
+
45
+ def add_page(page)
46
+ @pages << page
47
+ TableOfContents.add_page(page)
48
+ end
49
+
50
+ end
51
+
52
+ class Page
53
+ attr_reader :parent, :title, :permalink, :doc
54
+
55
+ def initialize(title, parent = nil, options = {})
56
+ @parent = parent
57
+ @title = title
58
+ @permalink = options[:permalink] || title.parameterize
59
+ @doc = begin
60
+ Doc.find(permalink)
61
+ rescue
62
+ nil
63
+ end
64
+ end
65
+
66
+ def filename(extension = "textile")
67
+ Doc.directory.join("#{permalink}.#{extension}")
68
+ end
69
+
70
+ def next_page
71
+ return nil if index.nil?
72
+ TableOfContents.pages[index+1]
73
+ end
74
+
75
+ def previous_page
76
+ fetch_index = (index || 0)-1
77
+ return nil if fetch_index < 0
78
+ TableOfContents.pages[fetch_index]
79
+ end
80
+
81
+ private
82
+
83
+ def index
84
+ TableOfContents.pages.index(self)
85
+ end
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,17 @@
1
+ module Doculab
2
+ class CacheSweeper
3
+
4
+ def self.sweep!
5
+ File.delete(*cached_file_list)
6
+ end
7
+
8
+ private
9
+
10
+ def self.cached_file_list
11
+ list = Dir.glob(File.join(Rails.public_path, "**", "*.html"))
12
+ list.reject {|file| File.basename(file) =~ /^\d{3}.html$/ }
13
+ end
14
+
15
+ # end private
16
+ end
17
+ end
@@ -0,0 +1,8 @@
1
+ <%
2
+ rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
3
+ rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
4
+ std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} --strict --tags ~@wip"
5
+ %>
6
+ default: <%= std_opts %> features
7
+ wip: --tags @wip:3 --wip features
8
+ rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
File without changes
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ Rails.application.routes.draw do
2
+ scope Doculab.route_base, :module => "doculab" do
3
+ match ':permalink' => 'docs#show', :as => "doculab_doc"
4
+ root :to => 'docs#index', :as => "doculab_root"
5
+ end
6
+ end