Class: QED::Document
- Inherits:
-
Object
- Object
- QED::Document
- Defined in:
- lib/qed/document.rb,
lib/qed/document/markup.rb
Overview
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.
Defined Under Namespace
Classes: Markup
Constant Summary collapse
- DEFAULT_TITLE =
"Demonstration"
- DEFAULT_CSS =
“../assets/styles/spec.css”
nil
- DEFAULT_OUTPUT =
"doc/spec"
- DEFAULT_PATH =
["spec/**/*"]
Instance Attribute Summary collapse
-
#css ⇒ Object
Returns the value of attribute css.
-
#dryrun ⇒ Object
Returns the value of attribute dryrun.
-
#output ⇒ Object
Ouput file.
-
#paths ⇒ Object
Returns the value of attribute paths.
-
#quiet ⇒ Object
Returns the value of attribute quiet.
-
#title ⇒ Object
Returns the value of attribute title.
Instance Method Summary collapse
- #copy_support_files ⇒ Object
-
#generate ⇒ Object
Generate specification document.
-
#initialize(options = {}) ⇒ Document
constructor
New Spec Document object.
- #make_output_directory ⇒ Object
-
#quiet? ⇒ Boolean
Supress output.
-
#save(text) ⇒ Object
Save specification document.
-
#spec_files ⇒ Object
Specification files.
-
#template ⇒ Object
Load specification HTML template.
Constructor Details
#initialize(options = {}) ⇒ Document
New Spec Document object.
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/qed/document.rb', line 28 def initialize(={}) .each do |k,v| __send__("#{k}=", v) end @title ||= DEFAULT_TITLE @css ||= DEFAULT_CSS @output ||= DEFAULT_OUTPUT @paths ||= [] @paths = DEFAULT_PATH if @paths.empty? end |
Instance Attribute Details
#css ⇒ Object
Returns the value of attribute css.
19 20 21 |
# File 'lib/qed/document.rb', line 19 def css @css end |
#dryrun ⇒ Object
Returns the value of attribute dryrun.
21 22 23 |
# File 'lib/qed/document.rb', line 21 def dryrun @dryrun end |
#output ⇒ Object
Ouput file.
25 26 27 |
# File 'lib/qed/document.rb', line 25 def output @output end |
#paths ⇒ Object
Returns the value of attribute paths.
20 21 22 |
# File 'lib/qed/document.rb', line 20 def paths @paths end |
#quiet ⇒ Object
Returns the value of attribute quiet.
22 23 24 |
# File 'lib/qed/document.rb', line 22 def quiet @quiet end |
#title ⇒ Object
Returns the value of attribute title.
18 19 20 |
# File 'lib/qed/document.rb', line 18 def title @title end |
Instance Method Details
#copy_support_files ⇒ Object
104 105 106 107 108 109 110 |
# File 'lib/qed/document.rb', line 104 def copy_support_files make_output_directory %w{jquery.js}.each do |fname| file = File.join(File.dirname(__FILE__), 'document', fname) FileUtils.cp(file, output) end end |
#generate ⇒ Object
Generate specification document.
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/qed/document.rb', line 56 def generate copy_support_files text = '' files = [] #paths.each do |path| # files.concat(Dir.glob(path).select{ |f| File.file?(f) }) #end #files.sort! #TODO: load .config/qedrc.rb spec_files.each do |file| puts file unless quiet? #strio = StringIO.new('') #reporter = Reporter::Html.new(strio) #runner = Runner.new([file], reporter) #runner.check #iotext = strio.string #strio.close case ext = File.extname(file) #when '.qed' # require_qedoc # markup = Markup.new(File.read(file)) # text << markup.to_html when '.rd', '.rdoc', '.qed' require_rdoc markup = RDoc::Markup::ToHtml.new text << markup.convert(File.read(file)) #text << markup.convert(iotext, formatter) when '.md', '.markdown' require_rdiscount markdown = RDiscount.new(File.read(file)) text << markdown.to_html end text << "\n" end temp = Template.new(template, text, title, css) html = temp.parse_template save(html) end |
#make_output_directory ⇒ Object
132 133 134 |
# File 'lib/qed/document.rb', line 132 def make_output_directory FileUtils.mkdir_p(output) end |
#quiet? ⇒ Boolean
Supress output.
53 |
# File 'lib/qed/document.rb', line 53 def quiet? ; @quiet ; end |
#save(text) ⇒ Object
Save specification document.
121 122 123 124 125 126 127 128 129 130 |
# File 'lib/qed/document.rb', line 121 def save(text) if dryrun puts "\nwrite #{output}" else make_output_directory File.open(output + '/index.html', 'wb') do |f| f << text end end end |
#spec_files ⇒ Object
Specification files.
42 43 44 45 46 47 48 49 50 |
# File 'lib/qed/document.rb', line 42 def spec_files @spec_files ||= ( glob = paths.map{ |f| File.directory?(f) ? Dir["#{f}/**/*"] : Dir[f] }.flatten glob = glob.select do |f| File.file?(f) && f !~ /fixtures\/|helpers\// && f !~ /\.rb$/ end glob.sort ) end |
#template ⇒ Object
Load specification HTML template.
113 114 115 116 117 118 |
# File 'lib/qed/document.rb', line 113 def template @template ||= ( file = File.join(File.dirname(__FILE__), 'document', 'template.rhtml') File.read(file) ) end |