Added TOC (Table of contents) for wiki pages.
This commit is contained in:
parent
255a4cd6c7
commit
eddf20b063
6 changed files with 53 additions and 3 deletions
|
@ -1,7 +1,8 @@
|
|||
module PagesHelper
|
||||
|
||||
def wikified_body(body)
|
||||
r = RedCloth.new(generate_anchors(body))
|
||||
body = wiki_header(body)
|
||||
r = RedCloth.new(body)
|
||||
r.gsub!(/\[\[(.*?)(\|(.*?))?\]\]/) { wiki_link($1, $3) }
|
||||
sanitize r.to_html
|
||||
r.to_html
|
||||
|
@ -16,6 +17,10 @@ module PagesHelper
|
|||
end
|
||||
end
|
||||
|
||||
def wiki_header(body)
|
||||
body.gsub(/^(={2,6})\s+(.*)\s+={2,6}$/) { "h#{$1.size}. #{$2}" }
|
||||
end
|
||||
|
||||
def generate_toc(body)
|
||||
toc = ""
|
||||
body.gsub(/^\s*h([1-6])\.\s+(.*)/) do
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090325175756
|
||||
#
|
||||
# Table name: pages
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# title :string(255)
|
||||
# body :text
|
||||
# permalink :string(255)
|
||||
# lock_version :integer default(0)
|
||||
# updated_by :integer
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
#
|
||||
|
||||
class Page < ActiveRecord::Base
|
||||
|
||||
belongs_to :user, :foreign_key => 'updated_by'
|
||||
|
|
2
test/fixtures/articles.yml
vendored
2
test/fixtures/articles.yml
vendored
|
@ -1,5 +1,5 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090317175355
|
||||
# Schema version: 20090325175756
|
||||
#
|
||||
# Table name: articles
|
||||
#
|
||||
|
|
15
test/fixtures/pages.yml
vendored
15
test/fixtures/pages.yml
vendored
|
@ -1,3 +1,18 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090325175756
|
||||
#
|
||||
# Table name: pages
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# title :string(255)
|
||||
# body :text
|
||||
# permalink :string(255)
|
||||
# lock_version :integer default(0)
|
||||
# updated_by :integer
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
#
|
||||
|
||||
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
|
||||
|
||||
one:
|
||||
|
|
2
test/fixtures/suppliers.yml
vendored
2
test/fixtures/suppliers.yml
vendored
|
@ -1,5 +1,5 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090317175355
|
||||
# Schema version: 20090325175756
|
||||
#
|
||||
# Table name: suppliers
|
||||
#
|
||||
|
|
|
@ -1,3 +1,18 @@
|
|||
# == Schema Information
|
||||
# Schema version: 20090325175756
|
||||
#
|
||||
# Table name: pages
|
||||
#
|
||||
# id :integer not null, primary key
|
||||
# title :string(255)
|
||||
# body :text
|
||||
# permalink :string(255)
|
||||
# lock_version :integer default(0)
|
||||
# updated_by :integer
|
||||
# created_at :datetime
|
||||
# updated_at :datetime
|
||||
#
|
||||
|
||||
require 'test_helper'
|
||||
|
||||
class PageTest < ActiveSupport::TestCase
|
||||
|
|
Loading…
Reference in a new issue