class QED::Document
Document
¶ ↑
TODO: css and javascripts have fixed location need to make more flexible. TODO: Have option to run documents through the runner and color code output; need htmlreporter.
Constants
- DEFAULT_CSS
- DEFAULT_OUTPUT
- DEFAULT_PATH
- DEFAULT_TITLE
Attributes
css[RW]
dryrun[RW]
format[RW]
Format of output file, either ‘html’ or ‘plain’. Defaults to extension of output file.
output[RW]
Ouput file.
paths[R]
Files to document.
quiet[RW]
title[RW]
Public Class Methods
cli(*argv)
click to toggle source
Command line interface for generating qedocs.
# File lib/qed/cli/qedoc.rb, line 9 def self.cli(*argv) options = {} parser = OptionParser.new do |usage| usage.banner = "Usage: qedoc [OPTIONS] <QEDFile1> [ <QEDFile2> ... ]" usage.on("-o", "--output [DIR]", "Output directory") do |dir| options[:output]= dir end usage.on("-t", "--title [TITLE]", "Title of Document") do |title| options[:title]= title end usage.on("--css [URI]", "Specify a URI for a CSS file add to HTML header.") do |uri| options[:css] = uri end usage.on("--dryrun", "") do options[:dryrun] = true end usage.on("-q", "--quiet", "") do options[:quiet] = true end usage.on_tail("-h", "--help", "display this help message") do puts usage exit end end parser.parse!(argv) options[:paths] = argv.dup #opts[:output] = cli.options[:file] #opts[:dryrun] = cli.options[:dryrun] #opts[:quiet] = cli.options[:quiet] #opts[:css] = cli.options[:css] #opts[:title] = cli.options[:title] doc = QED::Document.new(options) doc.generate end
new(options={})
click to toggle source
New Spec Document
object.
# File lib/qed/document.rb, line 43 def initialize(options={}) options.each do |k,v| __send__("#{k}=", v) end @paths ||= [] @output ||= DEFAULT_OUTPUT @title ||= DEFAULT_TITLE @css ||= DEFAULT_CSS if File.directory?(@output) @output = File.join(@output, 'qed.html') end @format ||= File.extname(@output).sub('.','') if @paths.empty? #dir = Dir['{test/demos,demos,demo}'].first || DEFAULT_PATH #@paths = File.join(dir, '**', '*') abort "No files to document." end end
Public Instance Methods
demo_files()
click to toggle source
Demo
files.
# File lib/qed/document.rb, line 68 def demo_files @demo_files ||= ( files = [] paths.each do |f| if File.directory?(f) files.concat Dir[File.join(f,'**','*')] else files.concat Dir[f] end end files = files.reject{ |f| File.directory?(f) } files = files.reject{ |f| File.extname(f) == '.rb' } files = files.reject{ |f| /(fixtures|helpers)\// =~ f } # doesn't include .rb applique but does markup applique applique, files = files.partition{ |f| /applique\// =~ f } applique.sort + files.sort ) end
generate()
click to toggle source
Generate specification document.
# File lib/qed/document.rb, line 99 def generate #copy_support_files out = '' files = [] #paths.each do |path| # files.concat(Dir.glob(path).select{ |f| File.file?(f) }) #end #files.sort! if dryrun or $DEBUG puts demo_files.sort.join(" ") end demo_files.each do |file| #strio = StringIO.new('') #reporter = Reporter::Html.new(strio) #runner = Runner.new([file], reporter) #runner.check #iotext = strio.string #strio.close ext = File.extname(file) txt = File.read(file) if ext == '.qed' ext = file_type(txt) end #text = Tilt.new(file).render #html = Nokogiri::HTML(text) #body = html.css("body") text = "" case ext #when '.qed' # require_qedoc # markup = Markup.new(File.read(file)) # text << markup.to_html when '.rd', '.rdoc' require_rdoc require_qedoc if html? markup = Markup.new(txt) text << markup.to_html #text << markup.convert(iotext, formatter) else text << txt end when '.md', '.markdown' require_rdiscount if html? markdown = RDiscount.new(txt) text << markdown.to_html else text << txt end end # TODO: Use Nokogiri to find all <pre>'s with preceeding <p>'s that have text ending in `:`, and # add the class `no-highlight`. If no preceeding `:` add class ruby. out << "#{text}\n" end if html? temp = Template.new(template, out, title, css) html = temp.parse_template save(html) else save(out) end end
html?()
click to toggle source
# File lib/qed/document.rb, line 175 def html? format == 'html' end
make_output_directory()
click to toggle source
# File lib/qed/document.rb, line 209 def make_output_directory dir = File.dirname(output) FileUtils.mkdir_p(dir) unless File.directory?(dir) end
paths=(paths)
click to toggle source
# File lib/qed/document.rb, line 38 def paths=(paths) @paths = [paths].flatten end
quiet?()
click to toggle source
Supress output.
# File lib/qed/document.rb, line 90 def quiet? @quiet end
save(text)
click to toggle source
Save specification document.
# File lib/qed/document.rb, line 197 def save(text) if dryrun puts "[dry-run] Write #{output}" unless quiet else make_output_directory File.open(output, 'wb') do |f| f << text end puts "Write #{output}" unless quiet end end
template()
click to toggle source
Load specification HTML template.
# File lib/qed/document.rb, line 189 def template @template ||= ( file = File.join(File.dirname(__FILE__), 'document', 'template.rhtml') File.read(file) ) end
Private Instance Methods
file_type(text)
click to toggle source
# File lib/qed/document.rb, line 217 def file_type(text) rdoc = text.index(/^\=/) markdown = text.index(/^\#/) if markdown && rdoc rdoc < markdown ? '.rdoc' : '.markdown' elsif rdoc '.rdoc' elsif markdown '.markdown' else # fallback to rdoc '.rdoc' end end
require_qedoc()
click to toggle source
# File lib/qed/document.rb, line 232 def require_qedoc @require_qedoc ||= ( require 'qed/document/markup' true ) end
require_rdiscount()
click to toggle source
# File lib/qed/document.rb, line 254 def require_rdiscount @require_rdiscount ||= ( require 'rdiscount' true ) end
require_rdoc()
click to toggle source
# File lib/qed/document.rb, line 240 def require_rdoc @require_rdoc ||= ( begin require 'rdoc/markup/to_html' rescue LoadError require 'rubygems' gem 'rdoc' retry end true ) end