Author: assaf
Date: Thu Jan 3 13:50:48 2008
New Revision: 608645
URL: http://svn.apache.org/viewvc?rev=608645&view=rev
Log:
Now using YAML for nested ToC.
Modified:
incubator/buildr/docter/trunk/CHANGELOG
incubator/buildr/docter/trunk/Rakefile
incubator/buildr/docter/trunk/lib/docter.rb
incubator/buildr/docter/trunk/lib/docter/collection.rb
incubator/buildr/docter/trunk/lib/docter/common.rb
incubator/buildr/docter/trunk/lib/docter/page.rb
incubator/buildr/docter/trunk/lib/docter/server.rb
incubator/buildr/docter/trunk/lib/docter/template.rb
incubator/buildr/docter/trunk/lib/docter/ultraviolet.rb
Modified: incubator/buildr/docter/trunk/CHANGELOG
URL:
http://svn.apache.org/viewvc/incubator/buildr/docter/trunk/CHANGELOG?rev=608645&r1=608644&r2=608645&view=diff
==============================================================================
--- incubator/buildr/docter/trunk/CHANGELOG (original)
+++ incubator/buildr/docter/trunk/CHANGELOG Thu Jan 3 13:50:48 2008
@@ -1,10 +1,11 @@
-1.0.2 (Pending)
+1.1.0 (2007-01-03)
+* Changed: Now using YAML for nested ToC.
* Fixed: Sleek upload with changelog for each release courtesy of Anatol
Pomozov.
-1.0.1 (6/6/2007)
+1.0.1 (2007-06-06)
* Added: renumber_footnotes to template for handling footnote numbering when
creating a single page.
* Changed: Ultraviolet no longer used as default syntax highlighting, must
require separately.
* Changed: footnote_links is now list_links and the new method eliminates
duplicates (based on URL), sorts alphabetically (the text component) and
capitalizes the text description.
-1.0.0 (6/3/2007)
+1.0.0 (2007-06-03)
* First release of working code.
Modified: incubator/buildr/docter/trunk/Rakefile
URL:
http://svn.apache.org/viewvc/incubator/buildr/docter/trunk/Rakefile?rev=608645&r1=608644&r2=608645&view=diff
==============================================================================
--- incubator/buildr/docter/trunk/Rakefile (original)
+++ incubator/buildr/docter/trunk/Rakefile Thu Jan 3 13:50:48 2008
@@ -10,8 +10,8 @@
spec = Gem::Specification.new do |spec|
spec.name = "docter"
spec.version =
File.read(__FILE__.pathmap("%d/lib/docter.rb")).scan(/VERSION\s*=\s*(['"])(.*)\1/)[0][1]
- spec.author = "Apache Software Foundation"
- #spec.email = ""
+ spec.author = "Apache Buildr"
+ spec.email = "[EMAIL PROTECTED]"
spec.homepage = "http://incubator.apache.org/buildr/"
spec.summary = "We has docs"
spec.files = FileList["lib/**/*", "CHANGELOG", "README", "LICENSE",
"Rakefile", "html/**/*"].collect
@@ -93,7 +93,7 @@
namespace :upload do
task :packages=>["rake:package"] do |task|
# Read the changes for this release.
- pattern = /(^(\d+\.\d+(?:\.\d+)?)\s+\(\d+\/\d+\/\d+\)\s*((:?^[^\n]+\n)*))/
+ pattern =
/(^(\d+\.\d+(?:\.\d+)?)\s+\(\d{4}-\d{2}-\d{2}\)\s*((:?^[^\n]+\n)*))/
changelog = File.read(__FILE__.pathmap("%d/CHANGELOG"))
changes = changelog.scan(pattern).inject({}) { |hash, set| hash[set[1]] =
set[2] ; hash }
current = changes[spec.version.to_s]
Modified: incubator/buildr/docter/trunk/lib/docter.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/docter/trunk/lib/docter.rb?rev=608645&r1=608644&r2=608645&view=diff
==============================================================================
--- incubator/buildr/docter/trunk/lib/docter.rb (original)
+++ incubator/buildr/docter/trunk/lib/docter.rb Thu Jan 3 13:50:48 2008
@@ -1,32 +1,32 @@
# &:symbol goodness.
-require "facet/symbol/to_proc"
+require 'facet/symbol/to_proc'
# blank? on string and nil
-require "facet/string/blank"
-require "facet/nilclass/blank"
+require 'facet/string/blank'
+require 'facet/nilclass/blank'
# x.in?(y) is better than y.include?(x)
-require "facet/string/starts_with"
-require "facets/core/kernel/tap"
-require "facet/kernel/__DIR__"
+require 'facet/string/starts_with'
+require 'facets/core/kernel/tap'
+require 'facet/kernel/__DIR__'
module Docter
- VERSION = "1.0.2".freeze
+ VERSION = '1.1.0'.freeze
end
$LOAD_PATH.unshift __DIR__
-require "cgi"
-require "erb"
+require 'cgi'
+require 'erb'
# All these Gems are optional.
-["redcloth", "haml", "mongrel", "uv"].each do |gem|
+['redcloth', 'haml', 'mongrel', 'uv'].each do |gem|
begin
require gem
rescue LoadError
end
end
-require "docter/common.rb"
-require "docter/page.rb"
-require "docter/template.rb"
-require "docter/collection.rb"
-require "docter/server.rb" if defined?(Mongrel)
-require "docter/rake.rb" if defined?(Rake)
+require 'docter/common.rb'
+require 'docter/page.rb'
+require 'docter/template.rb'
+require 'docter/collection.rb'
+require 'docter/server.rb' if defined?(Mongrel)
+require 'docter/rake.rb' if defined?(Rake)
Modified: incubator/buildr/docter/trunk/lib/docter/collection.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/docter/trunk/lib/docter/collection.rb?rev=608645&r1=608644&r2=608645&view=diff
==============================================================================
--- incubator/buildr/docter/trunk/lib/docter/collection.rb (original)
+++ incubator/buildr/docter/trunk/lib/docter/collection.rb Thu Jan 3 13:50:48
2008
@@ -14,18 +14,22 @@
@collection.page(path)
end
- def toc()
+ def toc
load
@toc
end
- def title()
+ def title
load
@title
end
protected
+ def create_from_yaml(yaml, options)
+ @toc = ToC.from_yaml(yaml, @collection)
+ end
+
if defined?(::RedCloth)
def create_from_textile(text, options)
html = RedCloth.new(erb_this(text, binding),
[:no_span_caps]).to_html(:textile)
@@ -45,27 +49,27 @@
def create_from_html(html, options)
@toc = ToC.new.tap do |toc|
- html.scan(regexp_element("ol")).each do |tag, attrs, list|
- list.scan(regexp_element("li")).each do |tag, attrs, item|
- if item[regexp_element("a")]
+ html.scan(regexp_element('ol')).each do |tag, attrs, list|
+ list.scan(regexp_element('li')).each do |tag, attrs, item|
+ if item[regexp_element('a')]
attrs, title = $2, $3
- url = $3 if attrs =~ regexp_attribute("href")
+ url = $3 if attrs =~ regexp_attribute('href')
if page = page(url)
toc.add page.toc_entry
else
- toc.add url, inner_text_from(title)
+ toc.add inner_text_from(title), url
end
else
- url, title = "#", inner_text_from(item)
- if page = page(item.strip.gsub(/\s+/, " ").downcase + ".html")
+ url, title = '#', inner_text_from(item)
+ if page = page(item.strip.gsub(/\s+/, ' ').downcase + '.html')
toc.add page.toc_entry
else
- toc.add url, inner_text_from(title)
+ toc.add inner_text_from(title), url
end
end
end
end
- @title = inner_text_from($3) if html =~ regexp_element("h1")
+ @title = inner_text_from($3) if html =~ regexp_element('h1')
end
end
@@ -80,18 +84,18 @@
end
# The collection title (HTML encoded).
- def title()
+ def title
@title || if @toc_resource
@toc_resource.reload if @toc_resource.modified?
@toc_resource.title
- end || ""
+ end || ''
end
# :call-seq:
- # toc() => ToC
+ # toc => ToC
#
# Returns the collection's ToC.
- def toc()
+ def toc
if @toc_resource
@toc_resource.reload if @toc_resource.modified?
@toc_resource.toc
@@ -152,19 +156,19 @@
# Returns a page based on its path.
#
# For example:
- # collection.include("doc/pages")
- # collection.page("index.html")
- # Will return a page generated from "doc/pages/index.textile".
+ # collection.include('doc/pages')
+ # collection.page('index.html')
+ # Will return a page generated from 'doc/pages/index.textile'.
def page(path)
pages.find { |page| page.path == path }
end
# :call-seq:
- # pages() => Pages
+ # pages => Pages
#
# Returns all the pages in this collection/
- def pages()
- @pages = @sources.map { |path| File.directory?(path) ?
FileList[File.join(path, "**/*")] : path }.flatten.
+ def pages
+ @pages = @sources.map { |path| File.directory?(path) ?
FileList[File.join(path, '**/*')] : path }.flatten.
inject(@pages || {}) { |pages, file| pages[file] ||= Page.new(file,
:collection=>self) ; pages }
@pages.values
end
@@ -172,27 +176,28 @@
def prev(page)
pages = toc.map { |entry| page(entry.url) }.compact
index = pages.index(page)
- pages[index - 1] if index > 0
+ pages[index - 1] if index && index > 0
end
def next(page)
pages = toc.map { |entry| page(entry.url) }.compact
- pages[pages.index(page) + 1]
+ index = pages.index(page)
+ pages[index + 1] if index
end
# :call-seq:
# file(path) => filename
#
# Returns the full path based on the relative path. For example:
- # collection.include("pages", "LICENSE")
- # collection.find("index.textile") => "pages/index.textile"
- # collection.find("LICENSE") => "LICENSE"
+ # collection.include('pages', 'LICENSE')
+ # collection.find('index.textile') => 'pages/index.textile'
+ # collection.find('LICENSE') => 'LICENSE'
def file(path)
@sources.inject(nil) do |found, file|
break found if found
if File.directory?(file)
- base = file + "/"
- FileList[File.join(file, "**/*")].find { |file| file.sub(base, "")
== path }
+ base = file + '/'
+ FileList[File.join(file, '**/*')].find { |file| file.sub(base, '')
== path }
else
file if File.basename(file) == path
end
@@ -224,8 +229,8 @@
html = template.render(options.merge(:collection=>self, :pages=>pages,
:one_page=>true))
url_map = pages.inject({}) { |map, page| map[page.path] =
"##{page.id}" ; map }
- html.gsub(regexp_element("a")) do |link|
- link.gsub(regexp_attribute("href")) do |href|
+ html.gsub(regexp_element('a')) do |link|
+ link.gsub(regexp_attribute('href')) do |href|
url = $3
url = url_map[url] || url.gsub(/^(.*?)#(.*?)$/) { |path|
url_map[$1] ? "##{$2}" : path }
%{href="#{url}"}
@@ -256,10 +261,10 @@
template.copy_resources to_dir
elsif args.first == :one_page
mkpath to_dir
- File.join(to_dir, "index.html").tap do |filename|
+ File.join(to_dir, 'index.html').tap do |filename|
puts "Generating #{filename}" if verbose
html = render(template, options)
- File.open(filename, "w") { |file| file.write html }
+ File.open(filename, 'w') { |file| file.write html }
end
template.copy_resources to_dir
else
@@ -268,7 +273,7 @@
File.join(to_dir, page.path).tap do |filename|
puts "Generating #{filename}" if verbose
html = render(template, page, options)
- File.open(filename, "w") { |file| file.write html }
+ File.open(filename, 'w') { |file| file.write html }
end
end
end
@@ -278,8 +283,8 @@
#
# Returns a list of dependencies (resource files, the template file, etc).
Useful when creating
# a Rake task based on this template.
- def dependencies() #:nodoc:
- files = @sources.map { |path| File.directory?(path) ? FileList[path,
File.join(path, "**/*")] : path }.flatten +
+ def dependencies #:nodoc:
+ files = @sources.map { |path| File.directory?(path) ? FileList[path,
File.join(path, '**/*')] : path }.flatten +
(@toc_resource ? [EMAIL PROTECTED] : [])
end
Modified: incubator/buildr/docter/trunk/lib/docter/common.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/docter/trunk/lib/docter/common.rb?rev=608645&r1=608644&r2=608645&view=diff
==============================================================================
--- incubator/buildr/docter/trunk/lib/docter/common.rb (original)
+++ incubator/buildr/docter/trunk/lib/docter/common.rb Thu Jan 3 13:50:48 2008
@@ -10,11 +10,11 @@
# Returns the inner text from some HTML text, effectively stripping the
tags, normalizing whitespaces
# and stripping leading/trailing spaces.
def inner_text_from(html)
- html.gsub(/<(\w*).*?>(.*?)<\/\1\s*>/m, "\\2").strip.gsub(/\s+/m, " ")
+ html.gsub(/<(\w*).*?>(.*?)<\/\1\s*>/m, "\\2").strip.gsub(/\s+/m, ' ')
end
def regexp_element(name)
- Regexp.new("<(#{name})\\s*(.*?)>(.*?)<\\/\\1\\s*>", Regexp::MULTILINE +
Regexp::IGNORECASE)
+ Regexp.new("<(#{name})(?:>|\s+(.*?)>)(.*?)<\\/\\1\\s*>",
Regexp::MULTILINE + Regexp::IGNORECASE)
end
def regexp_attribute(name)
@@ -34,8 +34,8 @@
module Resource
# Maps various filename extensions to the appropriate format. You only
need to use this when the filename
- # extension is not the same as the format, e.g. map ".txt" to :plain, but
not necessary to map ".textile".
- EXTENSIONS = { ""=>:plain, ".txt"=>:plain, ".text"=>:plain,
".thtml"=>:textile, ".mhtml"=>:markdown }
+ # extension is not the same as the format, e.g. map '.txt' to :plain, but
not necessary to map '.textile'.
+ EXTENSIONS = { ''=>:plain, '.txt'=>:plain, '.text'=>:plain,
'.thtml'=>:textile, '.mhtml'=>:markdown }
class << self
@@ -58,35 +58,35 @@
attr_reader :filename
# :call-seq:
- # modified() => time
+ # modified => time
#
# Returns the date/time this resource was last modified. If the resource
comes from a file,
# the timestamp of the file, otherwise the when the resource was created.
- def modified()
+ def modified
@filename ? File.stat(@filename).mtime : @modified
end
# :call-seq:
- # modified?() => boolean
+ # modified? => boolean
#
# Returns true if the resource was modified since it was lase
(re)loaded. Only applies to resources
# created from a file, all other resources return false.
- def modified?()
+ def modified?
@filename ? File.stat(@filename).mtime > @modified : false
end
# :call-seq:
- # reload()
+ # reload
#
# Reloads the resource. Only applies to resources created from a file,
otherwise acts like load.
# You can safely call it for all resources, for example:
# page.reload if page.modified?
- def reload()
+ def reload
@loaded = false if @filename
load
end
- def to_s() #:nodoc:
+ def to_s #:nodoc:
@filename || super
end
@@ -98,7 +98,7 @@
case args.first
when String
@filename = args.shift
- raise ArgumentError, "Expecting file name and options, found too may
arguments." unless args.empty?
+ raise ArgumentError, 'Expecting file name and options, found too may
arguments.' unless args.empty?
# We'll load the file later, but we need to known the mtime in case
someone calls modified?/reload first.
@modified = File.stat(@filename).mtime
@load_using = lambda do
@@ -112,28 +112,28 @@
when Symbol
@modified = Time.now # Best guess
format, content = args.shift, args.shift
- raise ArgumentError, "Expecting format (as symbol) followed by
content (string), found too many arguments." unless args.empty?
+ raise ArgumentError, 'Expecting format (as symbol) followed by
content (string), found too many arguments.' unless args.empty?
@load_using = lambda { create format, content, options }
else
if args.empty? && block
@modified = Time.now # Best guess
@load_using = lambda { block.call options }
else
- raise ArgumentError, "Expecting file name, or (format, content),
not sure what to do with these arguments."
+ raise ArgumentError, 'Expecting file name, or (format, content),
not sure what to do with these arguments.'
end
end
end
# :call-seq:
- # load()
+ # load
#
# Loads the resource. Call this method before anything that depends on
the content of the resource,
# for example:
- # def title()
+ # def title
# load
# @title # Created by load
# end
- def load()
+ def load
unless @loaded
@load_using.call
@loaded = true
@@ -184,7 +184,7 @@
#
# The second form creates this resource from content in the specified
format. This one you cannot reload.
# For example:
- # Page.new(:plain, "HAI")
+ # Page.new(:plain, 'HAI')
#
# The third form creates this resource by calling the block with the
supplied options.
def initialize(*args, &block)
@@ -206,23 +206,36 @@
# Use #to_html to transform to an HTML ordered list.
class ToC
+ class << self
+
+ # Loads the ToC from a YAML file.
+ def from_yaml(yaml, collection = nil)
+ new.send(:initialize_from, YAML.load(yaml), collection)
+ end
+
+ end
+
include Enumerable
+ # The title of this entry (optional)
+ attr_reader :title
+
# Array of entries.
attr_reader :entries
# Create new ToC with no entries.
- def initialize()
+ def initialize(title = nil)
+ @title = title
@entries = []
end
- ARRAY_METHODS = ["each", "first", "last", "size", "empty?", "include?",
"index", "[]"]
- (Enumerable.instance_methods + ARRAY_METHODS - ["entries"]).each do
|method|
+ ARRAY_METHODS = ['each', 'first', 'last', 'size', 'empty?', 'include?',
'index', '[]']
+ (Enumerable.instance_methods + ARRAY_METHODS - ['entries']).each do
|method|
class_eval "def #{method}(*args, &block) ; entries.send(:#{method},
*args, &block) ; end", __FILE__, __LINE__
end
# :call-seq:
- # add(url, title) => entry
+ # add(title, url?) => entry
# add(entry) => entry
#
# Adds (and returns) a new entry. The first form creates an entry with a
link (must be a valid URL,
@@ -231,7 +244,7 @@
def add(*args)
if ToCEntry === args.first
entry = args.shift
- raise ArgumentError, "Can only accept a ToCEntry argument." unless
args.empty?
+ raise ArgumentError, 'Can only accept a ToCEntry argument.' unless
args.empty?
else
entry = ToCEntry.new(*args)
end
@@ -251,9 +264,9 @@
#
# The +options+ argument can take the form of a Hash, list of symbols or
both. Symbols are
# treated as +true+ for example:
- # to_html(:nested, :class=>"toc")
+ # to_html(:nested, :class=>'toc')
# Is the same as:
- # to_html(:nested=>true, :class=>"toc")
+ # to_html(:nested=>true, :class=>'toc')
def to_html(*args)
options = Hash === args.last ? args.pop.clone : {}
args.each { |arg| options[arg.to_sym] = true }
@@ -261,6 +274,32 @@
%{<ol #{cls}>#{map { |entry| entry.to_html(options) }}</ol>}
end
+ protected
+
+ def initialize_from(entry, collection = nil) #:nodoc:
+ case entry
+ when Array
+ entry.each { |item| initialize_from(item, collection) }
+ when Hash
+ entry.each do |title, entry|
+ if String === entry
+ if collection && page = collection.page(entry)
+ add page.toc_entry
+ else
+ add title, entry
+ end
+ else
+ add ToCEntry.new(title).initialize_from(entry, collection)
+ end
+ end
+ when String
+ add entry
+ else
+ fail "Don't know how to populate ToC from #{entry.inspect}"
+ end
+ self
+ end
+
end
@@ -270,17 +309,14 @@
# The URL for this entry.
attr_reader :url
- # The title of this entry.
- attr_reader :title
-
# :call-seq:
- # new(url, title)
+ # new(title, url)
#
# URL links to the ToC entry, and must be a valid URL (use CGI.escape is
necessary). The title must
# be HTML-encoded (use CGI.escapeHTML if necessary).
- def initialize(url, title)
- super()
- @url, @title = url, title
+ def initialize(title, url = nil)
+ super title
+ @url = url
end
# :call-seq:
@@ -292,10 +328,17 @@
options = Hash === args.last ? args.pop.clone : {}
args.each { |arg| options[arg.to_sym] = true }
if options[:nested] && !empty?
- nested = options[:nested].respond_to?(:to_i) && options[:nested].to_i
> 0 ?
- super(options.merge(:nested=>options[:nested] - 1)) : super(options)
+ if Integer === options[:nested]
+ nested = super(options.merge(:nested=>options[:nested] - 1)) if
options[:nested] > 0
+ else
+ nested = super(options)
+ end
+ end
+ if url
+ %{<li><a href="#{url}">#{title}</a>#{nested}</li>}
+ else
+ %{<li>#{title}#{nested}</li>}
end
- %{<li><a href="#{url}">#{title}</a>#{nested}</li>}
end
end
Modified: incubator/buildr/docter/trunk/lib/docter/page.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/docter/trunk/lib/docter/page.rb?rev=608645&r1=608644&r2=608645&view=diff
==============================================================================
--- incubator/buildr/docter/trunk/lib/docter/page.rb (original)
+++ incubator/buildr/docter/trunk/lib/docter/page.rb Thu Jan 3 13:50:48 2008
@@ -34,7 +34,7 @@
# TITLE and H1 are used, they must match.
#
# If none of these options are available (e.g. for :plain) the title comes
from the filename, treating
- # underscore as space and capitalizing first letter, e.g. change_log.txt
becomes "Change Log".
+ # underscore as space and capitalizing first letter, e.g. change_log.txt
becomes 'Change Log'.
#
# *ToC* The table of contents is constructed from H2 and H3 headers. H2
headers provide the top-level sections,
# and H3 headers are nested inside H2 headers.
@@ -43,7 +43,7 @@
# one is created using the header title, for example:
# h2. Getting Started
# becomes:
- # <h2 id="getting_started">Getting Started</h2>
+ # <h2 id='getting_started'>Getting Started</h2>
# You can rely on these IDs to link inside the page and across pages.
#
# *Filters* Runs the default chain of filters, or those specified by the
:filters option. See Filter
@@ -59,25 +59,25 @@
@page = page
end
- def title()
+ def title
@page.title
end
- def url()
+ def url
@page.path
end
- def entries()
+ def entries
@page.toc.entries
end
end
# :call-seq:
- # title() => string
+ # title => string
#
# Returns the page title.
- def title()
+ def title
load
@title
end
@@ -87,51 +87,51 @@
end
# :call-seq:
- # content() => string
+ # content => string
#
# Returns the page content (HTML).
- def content()
+ def content
load
Filter.process(@content)
end
# :call-seq:
- # toc() => ToC
+ # toc => ToC
#
# Returns the table of contents.
- def toc()
+ def toc
load
@toc
end
# :call-seq:
- # path() => filename
+ # path => filename
#
# Returns the path for this page. You can use this to link to the page
from any other page.
#
- # For example, if the page name is "intro.textile" the path will be
"intro.html".
- def path()
- @path ||= File.basename(@filename).downcase.ext(".html")
+ # For example, if the page name is 'intro.textile' the path will be
'intro.html'.
+ def path
+ @path ||= File.basename(@filename).downcase.ext('.html')
end
# :call-seq;
- # id() => string
+ # id => string
#
# Returns fragment identifier for this page.
- def id()
- @id ||= title.gsub(/\s+/, "_").downcase
+ def id
+ @id ||= title.gsub(/\s+/, '_').downcase
end
- def entries() #:nodoc:
+ def entries #:nodoc:
toc.entries
end
# :call-seq:
- # toc_entry() => ToCEntry
+ # toc_entry => ToCEntry
#
# Returns a ToC entry for this page. Uses the +one_page+ argument to
determine whether to return
# a link to #path of the fragment #id.
- def toc_entry()
+ def toc_entry
@toc_entry ||= ToCEntryForPage.new(self)
end
@@ -142,7 +142,7 @@
end
def create_from_plain(text, options)
- parse(%{<pre class="text">#{CGI.escapeHTML(text)}</pre>}, options)
+ parse(%{<pre class='text'>#{CGI.escapeHTML(text)}</pre>}, options)
end
def create_from_textile(textile, options)
@@ -166,7 +166,7 @@
# Process {{{ ... }}} code sections into pre tags.
text = text.gsub(/^\{\{\{([^\n]*)\n(.*?)\n\}\}\}/m) do
code, spec = $2, $1.scan(/^!(.*?)$/).to_s.strip
- %{<notextile><pre class="#{spec.split(",").join("
")}">#{CGI.escapeHTML(code)}</pre></notextile>}
+ %{<notextile><pre class='#{spec.split(',').join('
')}'>#{CGI.escapeHTML(code)}</pre></notextile>}
end
# Create the HTML.
RedCloth.new(text, [:no_span_caps]).to_html(format)
@@ -185,32 +185,32 @@
def parse(html, options)
# Get the body (in most cases it's just the page). Make sure when we
wreck havoc on the HTML,
# we're not changing any content passed to us.
- body = html[regexp_element("body")] ? $2 : html.clone
+ body = html[regexp_element('body')] ? $2 : html.clone
# The correct structure is to use H1 for the document title (but TITLE
element will also work).
# If both are used, they must both match. Two or more H1 is a sign
you're using H1 instead of H2.
- title = html.scan(regexp_element("title|h1")).map{ |parts|
inner_text_from(parts.last) }.uniq
- raise ArgumentError, "A page can only have one title, you can use the H1
element (preferred) or TITLE element, or both if they're the same. If you want
to title sections, please use the H2 element" if title.size > 1
+ title = html.scan(regexp_element('title|h1')).map{ |parts|
inner_text_from(parts.last) }.uniq
+ raise ArgumentError, 'A page can only have one title, you can use the H1
element (preferred) or TITLE element, or both if they\'re the same. If you want
to title sections, please use the H2 element' if title.size > 1
# Lacking that, we need to derive the title somehow.
- title = title.first || options[:title] || (filename &&
filename.pathmap("%n").gsub("_", " ").capitalize) || "Untitled"
+ title = title.first || options[:title] || (filename &&
filename.pathmap('%n').gsub('_', ' ').capitalize) || 'Untitled'
# Get rid of H1 header.
- body.gsub!(regexp_element("h1"), "")
+ body.gsub!(regexp_element('h1'), '')
# Catalog all the major sections, based on the H2/H3 headers.
toc = ToC.new
- body.gsub!(regexp_element("h[23]")) do |header|
+ body.gsub!(regexp_element('h[23]')) do |header|
tag, attributes, text = $1.downcase, $2.to_s, inner_text_from($3)
# Make sure all H2/H3 headers have a usable ID, create once if
necessary.
- id = CGI.unescape($3) if attributes[regexp_attribute("id")]
+ id = CGI.unescape($3) if attributes[regexp_attribute('id')]
if id.blank?
- id = CGI.unescapeHTML(text.downcase.gsub(" ", "_"))
- header = %{<#{tag} #{attributes} id="#{id}">#{text}</#{tag}>}
+ id = CGI.unescapeHTML(text.downcase.gsub(' ', '_'))
+ header = %{<#{tag} #{attributes} id='#{id}'>#{text}</#{tag}>}
end
- if tag == "h2"
- toc.add "##{id}", text
+ if tag == 'h2'
+ toc.add text, "##{id}"
else
- fail ArgumentError, "H3 section found without any H2 section."
unless toc.last
- toc.last.add "##{id}", text
+ fail ArgumentError, 'H3 section found without any H2 section.'
unless toc.last
+ toc.last.add text, "##{id}"
end
header
end
@@ -228,10 +228,10 @@
class << self
# :call-seq:
- # list() => names
+ # list => names
#
# Return the names of all defined filters.
- def list()
+ def list
@filters.keys
end
Modified: incubator/buildr/docter/trunk/lib/docter/server.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/docter/trunk/lib/docter/server.rb?rev=608645&r1=608644&r2=608645&view=diff
==============================================================================
--- incubator/buildr/docter/trunk/lib/docter/server.rb (original)
+++ incubator/buildr/docter/trunk/lib/docter/server.rb Thu Jan 3 13:50:48 2008
@@ -8,14 +8,14 @@
@collection, @template, @options = collection, template, options || {}
end
- def resources()
+ def resources
@resources ||= Resources.new
end
def process(request, response)
# Absolute path to relative path, default index.
- path = request.params[Mongrel::Const::PATH_INFO].sub(/^\//, "")
- path = "index.html" if path.empty?
+ path = request.params[Mongrel::Const::PATH_INFO].sub(/^\//, '')
+ path = 'index.html' if path.empty?
begin
if file = template.find(path)
@@ -27,32 +27,32 @@
else
puts "Serving #{path}" if verbose
response.start(200) do |head,out|
- head[Mongrel::Const::LAST_MODIFIED] =
CGI.rfc1123_date(File.stat(file).mtime)
+ head['Last-Modified'] = CGI.rfc1123_date(File.stat(file).mtime)
out.write File.read(file)
end
end
- elsif options[:one_page] && path == "index.html"
+ elsif options[:one_page] && path == 'index.html'
puts "Serving #{path}" if verbose
response.start(200) do |head,out|
- head[Mongrel::Const::CONTENT_TYPE] = "text/html"
+ head['Content-Type'] = 'text/html'
out.write collection.render(template, options)
end
elsif page = collection.page(path)
puts "Serving #{path}" if verbose
response.start(200) do |head,out|
- head[Mongrel::Const::CONTENT_TYPE] = "text/html"
+ head['Content-Type'] = 'text/html'
out.write collection.render(template, page, options)
end
else
response.start 404 do |head, out|
- head[Mongrel::Const::CONTENT_TYPE] = "text/html"
+ head['Content-Type'] = 'text/html'
out.write "<h1>Did you accidentally rm #{path}, or did you forget
to :w it?</h1>"
end
end
rescue Exception=>error
response.start(500) do |head, out|
- head["Content-Type"] = "text/plain"
- error = ["#{error.class}: #{error}", error.backtrace.join("\n")]
+ head['Content-Type'] = 'text/plain'
+ error = ["#{error.class}: #{error}", error.backtrace.join('\n')]
out.puts *error
puts *error
end
@@ -78,7 +78,7 @@
def start(wait = true)
puts "Starting Mongrel on port #{port}"
- @mongrel = Mongrel::HttpServer.new("0.0.0.0", port, 4)
+ @mongrel = Mongrel::HttpServer.new('0.0.0.0', port, 4)
@mongrel.register("/", MongrelHandler.new(collection, template, options))
if wait
@mongrel.run.join rescue nil
@@ -87,8 +87,8 @@
end
end
- def stop()
- puts "Stopping Mongrel"
+ def stop
+ puts 'Stopping Mongrel'
@mongrel.stop if @mongrel
end
Modified: incubator/buildr/docter/trunk/lib/docter/template.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/docter/trunk/lib/docter/template.rb?rev=608645&r1=608644&r2=608645&view=diff
==============================================================================
--- incubator/buildr/docter/trunk/lib/docter/template.rb (original)
+++ incubator/buildr/docter/trunk/lib/docter/template.rb Thu Jan 3 13:50:48
2008
@@ -15,8 +15,8 @@
def collect_links(content, mark = false)
@links ||= []
- content.gsub(regexp_element("a")) do |link|
- url = $3 if link =~ regexp_attribute("href")
+ content.gsub(regexp_element('a')) do |link|
+ url = $3 if link =~ regexp_attribute('href')
if url =~ /^\w+:/
unless index = @links.index(url)
index = @links.size
@@ -33,20 +33,20 @@
# Remove duplicate links (same URL), sort by text and convert into
DT/DD pairs.
links = @links.inject({}) { |hash, link| hash[link.first] ||=
link.last ; hash }.
sort { |a,b| a.last <=> b.last }.
- map { |url, text| %{<dt>#{text.capitalize}</dt><dd><a
href="#{url}">#{url}</a></dd>} }
- %{<dl class="#{cls}">#{links.join}</dl>}
+ map { |url, text| %{<dt>#{text.capitalize}</dt><dd><a
href='#{url}'>#{url}</a></dd>} }
+ %{<dl class='#{cls}'>#{links.join}</dl>}
end
def renumber_footnotes(html)
@footnote ||= 0
- html.gsub(/<a href="#fn(\d+)">\1<\/a>/) {
+ html.gsub(/<a href=['"]#fn(\d+)['"]>\1<\/a>/) {
# Renumber footnote references starting from the last footnote
number.
fn = $1.to_i + @footnote
- %{<a href="#fn#{fn}">#{fn}</a>}
- }.gsub(/<p id="fn(\d+)"(.*?)><sup>\1<\/sup>(.*?)<\/p>/m) {
+ %{<a href='#fn#{fn}'>#{fn}</a>}
+ }.gsub(/<p id=['"]fn(\d+)['"](.*?)><sup>\1<\/sup>(.*?)<\/p>/m) {
# Renumber footnotes the same way, and update the last footnote
number.
@footnote += 1
- %{<p id="[EMAIL PROTECTED]"#{$2}><sup>[EMAIL
PROTECTED]</sup>#{$3}</p>}
+ %{<p id='[EMAIL PROTECTED]'#{$2}><sup>[EMAIL
PROTECTED]</sup>#{$3}</p>}
}
end
@@ -113,16 +113,16 @@
# Returns the location of a file on disk based on the request path.
#
# For example:
- # template.include("html/index.html", "images", "css/*")
- # map.find("index.html") => "html/index.html"
- # map.find("images/logo.png") => "images/logo.png"
- # map.find("fancy.css") => "css/fancy.css"
+ # template.include('html/index.html', 'images', 'css/*')
+ # map.find('index.html') => 'html/index.html'
+ # map.find('images/logo.png') => 'images/logo.png'
+ # map.find('fancy.css') => 'css/fancy.css'
def find(path)
@sources.inject(nil) do |found, file|
break found if found
if File.directory?(file)
- base = File.dirname(file) + "/"
- FileList["#{file}/**/*"].find { |file| file.sub(base, "") == path }
+ base = File.dirname(file) + '/'
+ FileList["#{file}/**/*"].find { |file| file.sub(base, '') == path }
else
file if File.basename(file) == path
end
@@ -137,9 +137,9 @@
mkpath to_dir
@sources.each do |file|
if File.directory?(file)
- base = File.dirname(file) + "/"
- FileList[File.join(file, "**/*")].each do |file|
- target = File.join(to_dir, file.sub(base, ""))
+ base = File.dirname(file) + '/'
+ FileList[File.join(file, '**/*')].each do |file|
+ target = File.join(to_dir, file.sub(base, ''))
mkpath File.dirname(target)
cp file, target
end
@@ -154,8 +154,8 @@
#
# Returns a list of dependencies (resource files, the template file, etc).
Useful when creating
# a Rake task based on this template.
- def dependencies()
- @sources.map { |path| File.directory?(path) ? FileList[path,
File.join(path, "**/*")] : path }.flatten +
+ def dependencies
+ @sources.map { |path| File.directory?(path) ? FileList[path,
File.join(path, '**/*')] : path }.flatten +
[EMAIL PROTECTED]
end
Modified: incubator/buildr/docter/trunk/lib/docter/ultraviolet.rb
URL:
http://svn.apache.org/viewvc/incubator/buildr/docter/trunk/lib/docter/ultraviolet.rb?rev=608645&r1=608644&r2=608645&view=diff
==============================================================================
--- incubator/buildr/docter/trunk/lib/docter/ultraviolet.rb (original)
+++ incubator/buildr/docter/trunk/lib/docter/ultraviolet.rb Thu Jan 3 13:50:48
2008
@@ -1,26 +1,26 @@
-require "uv" # gem install ultraviolet
+require 'uv' # gem install ultraviolet
module Docter
- SYNTAX_THEME = "eiffel"
+ SYNTAX_THEME = 'eiffel'
SYNTAX_STYLESHEET = "css/#{SYNTAX_THEME}.css"
- SYNTAX_MAP = { "sh"=>"shell-unix-generic" }
+ SYNTAX_MAP = { 'sh'=>'shell-unix-generic' }
filter_for :syntax do |html|
- html.gsub(HTML.regexp_element("pre")) do |pre|
+ html.gsub(HTML.regexp_element('pre')) do |pre|
attributes, code = $2, $3
- if attributes[HTML.regexp_attribute("class")]
+ if attributes[HTML.regexp_attribute('class')]
classes = $3.split(/\s+/)
lang = classes.first
end
- if lang == "text"
- Uv.parse(CGI.unescapeHTML(code), "xhtml", "plain_text", false,
SYNTAX_THEME).
- gsub(URI.regexp) { |uri| uri =~ /^http(s?):\/\// ? %{<a
href="#{uri}">#{uri}</a>} : uri }
+ if lang == 'text'
+ Uv.parse(CGI.unescapeHTML(code), 'xhtml', 'plain_text', false,
SYNTAX_THEME).
+ gsub(URI.regexp) { |uri| uri =~ /^http(s?):\/\// ? %{<a
href='#{uri}'>#{uri}</a>} : uri }
elsif lang
- syntax = SYNTAX_MAP[lang] || (Uv.syntaxes.include?(lang) ? lang :
"plain_text")
- Uv.parse(CGI.unescapeHTML(code), "xhtml", syntax || "plain_text",
classes.include?("lines"), SYNTAX_THEME)
+ syntax = SYNTAX_MAP[lang] || (Uv.syntaxes.include?(lang) ? lang :
'plain_text')
+ Uv.parse(CGI.unescapeHTML(code), 'xhtml', syntax || 'plain_text',
classes.include?('lines'), SYNTAX_THEME)
else
- Uv.parse(CGI.unescapeHTML(code), "xhtml", "plain_text", false,
SYNTAX_THEME)
+ Uv.parse(CGI.unescapeHTML(code), 'xhtml', 'plain_text', false,
SYNTAX_THEME)
end
end
end