static_docs 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/app/assets/javascripts/static_docs/pages.js +2 -0
- data/app/assets/stylesheets/static_docs/pages.css +4 -0
- data/app/controllers/static_docs/application_controller.rb +1 -1
- data/app/controllers/static_docs/pages_controller.rb +9 -0
- data/app/helpers/static_docs/application_helper.rb +11 -0
- data/app/helpers/static_docs/pages_helper.rb +4 -0
- data/app/models/static_docs/page.rb +30 -0
- data/app/views/static_docs/pages/show.html.erb +3 -0
- data/config/routes.rb +4 -0
- data/db/migrate/20130502102206_create_static_docs_pages.rb +16 -0
- data/lib/static_docs/importer.rb +44 -0
- data/lib/static_docs/version.rb +1 -1
- data/lib/static_docs.rb +30 -0
- data/lib/tasks/static_docs_tasks.rake +11 -4
- data/test/dummy/app/helpers/application_helper.rb +3 -0
- data/test/dummy/config/environments/test.rb +1 -1
- data/test/dummy/config/initializers/static_docs.rb +13 -0
- data/test/dummy/config/routes.rb +1 -1
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20130502133441_create_static_docs_pages.static_docs.rb +17 -0
- data/test/dummy/db/schema.rb +29 -0
- data/test/dummy/db/test.sqlite3 +0 -0
- data/test/dummy/log/development.log +56 -0
- data/test/dummy/log/production.log +0 -0
- data/test/dummy/log/test.log +8879 -0
- data/test/dummy/sources/namespace/home.html +1 -0
- data/test/dummy/sources/namespace/index.yml +9 -0
- data/test/dummy/sources/namespace/page.html +1 -0
- data/test/dummy/sources/root/getting_started.html +1 -0
- data/test/dummy/sources/root/home.html +1 -0
- data/test/dummy/sources/root/index.yml +13 -0
- data/test/dummy/sources/root/page.html +1 -0
- data/test/fixtures/static_docs/pages.yml +51 -0
- data/test/functional/static_docs/pages_controller_test.rb +9 -0
- data/test/integration/navigation_test.rb +22 -4
- data/test/static_docs_test.rb +7 -0
- data/test/test_helper.rb +0 -2
- data/test/unit/helpers/static_docs/pages_helper_test.rb +6 -0
- data/test/unit/static_docs/importer_test.rb +52 -0
- data/test/unit/static_docs/page_test.rb +46 -0
- metadata +52 -5
- data/app/views/layouts/static_docs/application.html.erb +0 -14
@@ -1,4 +1,15 @@
|
|
1
1
|
module StaticDocs
|
2
2
|
module ApplicationHelper
|
3
|
+
def respond_to?(method)
|
4
|
+
super || main_app.respond_to?(method)
|
5
|
+
end
|
6
|
+
|
7
|
+
def method_missing(method, *args, &block)
|
8
|
+
if main_app.respond_to?(method)
|
9
|
+
main_app.send(method, *args, &block)
|
10
|
+
else
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
3
14
|
end
|
4
15
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module StaticDocs
|
2
|
+
class Page < ActiveRecord::Base
|
3
|
+
attr_accessor :meta
|
4
|
+
|
5
|
+
class << self
|
6
|
+
def matched(path)
|
7
|
+
namespace, _, namespaced_path = path.partition('/')
|
8
|
+
namespaced_matched(namespaced_path, namespace) || namespaced_matched(path) || raise(ActiveRecord::RecordNotFound)
|
9
|
+
end
|
10
|
+
|
11
|
+
def namespaced_matched(path, namespace = nil)
|
12
|
+
if path.present? && StaticDocs.namespaces.include?(namespace)
|
13
|
+
where(:namespace => namespace, :path => path).first
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def meta
|
19
|
+
@meta ||= {}
|
20
|
+
end
|
21
|
+
|
22
|
+
def renderer
|
23
|
+
@renderer ||= StaticDocs.renderers[namespace].try(:fetch, extension) || StaticDocs.renderers[:default][extension]
|
24
|
+
end
|
25
|
+
|
26
|
+
def rendered_body(context)
|
27
|
+
context.instance_exec(body, self, &renderer)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/config/routes.rb
CHANGED
@@ -0,0 +1,16 @@
|
|
1
|
+
class CreateStaticDocsPages < ActiveRecord::Migration
|
2
|
+
def change
|
3
|
+
create_table :static_docs_pages do |t|
|
4
|
+
t.string :title
|
5
|
+
t.string :path
|
6
|
+
t.string :namespace
|
7
|
+
t.text :body, :limit => 64.kilobytes + 1
|
8
|
+
t.string :extension
|
9
|
+
|
10
|
+
t.timestamps
|
11
|
+
end
|
12
|
+
|
13
|
+
add_index :static_docs_pages, :path
|
14
|
+
add_index :static_docs_pages, :namespace
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module StaticDocs
|
2
|
+
class Importer
|
3
|
+
attr_accessor :namespace
|
4
|
+
|
5
|
+
def self.import(namespace)
|
6
|
+
new(namespace).import
|
7
|
+
end
|
8
|
+
|
9
|
+
def initialize(namespace)
|
10
|
+
@namespace = namespace
|
11
|
+
end
|
12
|
+
|
13
|
+
def source
|
14
|
+
@source ||= Rails.root.join StaticDocs.sources[namespace]
|
15
|
+
end
|
16
|
+
|
17
|
+
def config
|
18
|
+
@config ||= YAML.load IO.read File.join source, 'index.yml'
|
19
|
+
end
|
20
|
+
|
21
|
+
def import
|
22
|
+
cleanup
|
23
|
+
import_collection config['special'], false
|
24
|
+
import_collection config['pages']
|
25
|
+
end
|
26
|
+
|
27
|
+
def import_collection(pages, show = true)
|
28
|
+
return if pages.empty?
|
29
|
+
pages.each_with_index do |data, index|
|
30
|
+
page = Page.where(:namespace => namespace, :path => data['path']).first_or_initialize
|
31
|
+
page.extension = data['file'][/([^\.]+)$/]
|
32
|
+
page.position = show ? index : nil if page.attributes.include?('position')
|
33
|
+
page.title = data['title']
|
34
|
+
page.body = File.read File.join(source, data['file'])
|
35
|
+
page.save
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
def cleanup
|
40
|
+
actual_page_urls = (config['pages'] + config['special']).map{ |page| page['path'] }
|
41
|
+
Page.where(:namespace => namespace).where('path not in (?)', actual_page_urls).destroy_all
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/static_docs/version.rb
CHANGED
data/lib/static_docs.rb
CHANGED
@@ -1,4 +1,34 @@
|
|
1
1
|
require "static_docs/engine"
|
2
2
|
|
3
3
|
module StaticDocs
|
4
|
+
mattr_accessor :sources
|
5
|
+
@@sources = {}.with_indifferent_access
|
6
|
+
|
7
|
+
mattr_accessor :renderers
|
8
|
+
@@renderers = {
|
9
|
+
:default => {
|
10
|
+
:html => proc{ |body| body.html_safe },
|
11
|
+
:txt => proc{ |body| body }
|
12
|
+
}.with_indifferent_access
|
13
|
+
}.with_indifferent_access
|
14
|
+
|
15
|
+
def self.source(src, options = {})
|
16
|
+
namespace = options[:namespace] || options[:to]
|
17
|
+
@@sources[namespace] = src
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.renderer(format, options = {}, &block)
|
21
|
+
namespace = options[:namespace] || :default
|
22
|
+
@@renderers[namespace] ||= {}.with_indifferent_access
|
23
|
+
@@renderers[namespace][format] = block
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.setup(&block)
|
27
|
+
instance_eval(&block)
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.namespaces
|
31
|
+
@namespaces ||= sources.keys
|
32
|
+
end
|
33
|
+
|
4
34
|
end
|
@@ -1,4 +1,11 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
require "static_docs/importer"
|
2
|
+
|
3
|
+
namespace :static_docs do
|
4
|
+
desc "Import pages to database. Use `namespace=xxx` or `namespaces=xxx,yyy` to point what namespace to import. Use keyword `root` to point on root namespace."
|
5
|
+
task :import => :environment do
|
6
|
+
namespaces = (ENV['namespace'] || ENV['namespaces']).try(:split, ',')
|
7
|
+
(namespaces ? namespaces.map{ |n| n == 'root' ? nil : n } & c.namespaces : StaticDocs.namespaces).each do |namespace|
|
8
|
+
StaticDocs::Importer.import(namespace)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -19,7 +19,7 @@ Dummy::Application.configure do
|
|
19
19
|
config.action_controller.perform_caching = false
|
20
20
|
|
21
21
|
# Raise exceptions instead of rendering exception templates
|
22
|
-
config.action_dispatch.show_exceptions =
|
22
|
+
config.action_dispatch.show_exceptions = true
|
23
23
|
|
24
24
|
# Disable request forgery protection in test environment
|
25
25
|
config.action_controller.allow_forgery_protection = false
|
data/test/dummy/config/routes.rb
CHANGED
Binary file
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# This migration comes from static_docs (originally 20130502102206)
|
2
|
+
class CreateStaticDocsPages < ActiveRecord::Migration
|
3
|
+
def change
|
4
|
+
create_table :static_docs_pages do |t|
|
5
|
+
t.string :title
|
6
|
+
t.string :path
|
7
|
+
t.string :namespace
|
8
|
+
t.text :body, :limit => 64.kilobytes + 1
|
9
|
+
t.string :extension
|
10
|
+
|
11
|
+
t.timestamps
|
12
|
+
end
|
13
|
+
|
14
|
+
add_index :static_docs_pages, :path
|
15
|
+
add_index :static_docs_pages, :namespace
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
# This file is auto-generated from the current state of the database. Instead
|
3
|
+
# of editing this file, please use the migrations feature of Active Record to
|
4
|
+
# incrementally modify your database, and then regenerate this schema definition.
|
5
|
+
#
|
6
|
+
# Note that this schema.rb definition is the authoritative source for your
|
7
|
+
# database schema. If you need to create the application database on another
|
8
|
+
# system, you should be using db:schema:load, not running all the migrations
|
9
|
+
# from scratch. The latter is a flawed and unsustainable approach (the more migrations
|
10
|
+
# you'll amass, the slower it'll run and the greater likelihood for issues).
|
11
|
+
#
|
12
|
+
# It's strongly recommended to check this file into your version control system.
|
13
|
+
|
14
|
+
ActiveRecord::Schema.define(:version => 20130502133441) do
|
15
|
+
|
16
|
+
create_table "static_docs_pages", :force => true do |t|
|
17
|
+
t.string "title"
|
18
|
+
t.string "path"
|
19
|
+
t.string "namespace"
|
20
|
+
t.text "body", :limit => 65537
|
21
|
+
t.string "extension"
|
22
|
+
t.datetime "created_at", :null => false
|
23
|
+
t.datetime "updated_at", :null => false
|
24
|
+
end
|
25
|
+
|
26
|
+
add_index "static_docs_pages", ["namespace"], :name => "index_static_docs_pages_on_namespace"
|
27
|
+
add_index "static_docs_pages", ["path"], :name => "index_static_docs_pages_on_path"
|
28
|
+
|
29
|
+
end
|
Binary file
|
@@ -0,0 +1,56 @@
|
|
1
|
+
Connecting to database specified by database.yml
|
2
|
+
[1m[36m (0.2ms)[0m [1mselect sqlite_version(*)[0m
|
3
|
+
[1m[35m (1.0ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
4
|
+
[1m[36m (1.4ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
5
|
+
[1m[35m (2.8ms)[0m SELECT "schema_migrations"."version" FROM "schema_migrations"
|
6
|
+
Migrating to CreateStaticDocsPages (20130502133441)
|
7
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
8
|
+
[1m[35m (0.4ms)[0m CREATE TABLE "static_docs_pages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "path" varchar(255), "body" text(65537), "extension" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
|
9
|
+
[1m[36m (0.1ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ('20130502133441')[0m
|
10
|
+
[1m[35m (0.9ms)[0m commit transaction
|
11
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
12
|
+
Connecting to database specified by database.yml
|
13
|
+
[1m[36m (1.3ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
14
|
+
[1m[35m (0.2ms)[0m select sqlite_version(*)
|
15
|
+
[1m[36m (1.5ms)[0m [1mCREATE TABLE "static_docs_pages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "path" varchar(255), "body" text(65537), "extension" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) [0m
|
16
|
+
[1m[35m (1.0ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
17
|
+
[1m[36m (1.1ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
18
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
19
|
+
[1m[36m (0.8ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20130502133441')[0m
|
20
|
+
Connecting to database specified by database.yml
|
21
|
+
[1m[36m (4.0ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
22
|
+
[1m[35m (0.1ms)[0m SELECT "schema_migrations"."version" FROM "schema_migrations"
|
23
|
+
Migrating to CreateStaticDocsPages (20130502133441)
|
24
|
+
[1m[36m (0.0ms)[0m [1mselect sqlite_version(*)[0m
|
25
|
+
[1m[35m (0.0ms)[0m begin transaction
|
26
|
+
[1m[36m (1.4ms)[0m [1mDROP TABLE "static_docs_pages"[0m
|
27
|
+
[1m[35m (0.1ms)[0m DELETE FROM "schema_migrations" WHERE "schema_migrations"."version" = '20130502133441'
|
28
|
+
[1m[36m (0.8ms)[0m [1mcommit transaction[0m
|
29
|
+
[1m[35m (0.1ms)[0m SELECT "schema_migrations"."version" FROM "schema_migrations"
|
30
|
+
Connecting to database specified by database.yml
|
31
|
+
[1m[36m (1.3ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
32
|
+
Migrating to CreateStaticDocsPages (20130502133441)
|
33
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
34
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
35
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
36
|
+
Connecting to database specified by database.yml
|
37
|
+
[1m[36m (21.8ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
38
|
+
Migrating to CreateStaticDocsPages (20130502133441)
|
39
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
40
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
41
|
+
[1m[35m (1.6ms)[0m CREATE TABLE "static_docs_pages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "path" varchar(255), "namespace" varchar(255), "body" text(65537), "extension" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
|
42
|
+
[1m[36m (0.5ms)[0m [1mCREATE INDEX "index_static_docs_pages_on_path" ON "static_docs_pages" ("path")[0m
|
43
|
+
[1m[35m (0.2ms)[0m CREATE INDEX "index_static_docs_pages_on_namespace" ON "static_docs_pages" ("namespace")
|
44
|
+
[1m[36m (0.2ms)[0m [1mINSERT INTO "schema_migrations" ("version") VALUES ('20130502133441')[0m
|
45
|
+
[1m[35m (1.1ms)[0m commit transaction
|
46
|
+
[1m[36m (0.1ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
47
|
+
Connecting to database specified by database.yml
|
48
|
+
[1m[36m (20.9ms)[0m [1mSELECT "schema_migrations"."version" FROM "schema_migrations" [0m
|
49
|
+
[1m[35m (0.5ms)[0m select sqlite_version(*)
|
50
|
+
[1m[36m (1.4ms)[0m [1mCREATE TABLE "static_docs_pages" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "title" varchar(255), "path" varchar(255), "namespace" varchar(255), "body" text(65537), "extension" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL) [0m
|
51
|
+
[1m[35m (1.0ms)[0m CREATE INDEX "index_static_docs_pages_on_namespace" ON "static_docs_pages" ("namespace")
|
52
|
+
[1m[36m (0.9ms)[0m [1mCREATE INDEX "index_static_docs_pages_on_path" ON "static_docs_pages" ("path")[0m
|
53
|
+
[1m[35m (1.1ms)[0m CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
|
54
|
+
[1m[36m (1.0ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
55
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
56
|
+
[1m[36m (1.1ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('20130502133441')[0m
|
File without changes
|