Class: Quarry::Document
Overview
Document
TODO: css and javascripts have fixed location
-
need to make more flexible.
Constant Summary collapse
- DEFAULT_TITLE =
"Specifications"
- DEFAULT_CSS =
“../assets/styles/spec.css”
nil
- DEFAULT_FILE =
"doc/spec/index.html"
- 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
-
#generate ⇒ Object
Generate specification document.
-
#initialize(options) ⇒ Document
constructor
New Spec Document object.
-
#quiet? ⇒ Boolean
Supress output.
-
#save(text) ⇒ Object
Save specification document.
-
#template ⇒ Object
Load specification HTML template.
Constructor Details
#initialize(options) ⇒ Document
New Spec Document object.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/quarry/document.rb', line 27 def initialize() .each do |k,v| __send__("#{k}=", v) end @title ||= DEFAULT_TITLE @css ||= DEFAULT_CSS @output ||= DEFAULT_FILE @paths ||= [] @paths = DEFAULT_PATH if @paths.empty? end |
Instance Attribute Details
#css ⇒ Object
Returns the value of attribute css.
18 19 20 |
# File 'lib/quarry/document.rb', line 18 def css @css end |
#dryrun ⇒ Object
Returns the value of attribute dryrun.
20 21 22 |
# File 'lib/quarry/document.rb', line 20 def dryrun @dryrun end |
#output ⇒ Object
Ouput file.
24 25 26 |
# File 'lib/quarry/document.rb', line 24 def output @output end |
#paths ⇒ Object
Returns the value of attribute paths.
19 20 21 |
# File 'lib/quarry/document.rb', line 19 def paths @paths end |
#quiet ⇒ Object
Returns the value of attribute quiet.
21 22 23 |
# File 'lib/quarry/document.rb', line 21 def quiet @quiet end |
#title ⇒ Object
Returns the value of attribute title.
17 18 19 |
# File 'lib/quarry/document.rb', line 17 def title @title end |
Instance Method Details
#generate ⇒ Object
Generate specification document.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/quarry/document.rb', line 44 def generate text = '' files = [] paths.each do |path| files.concat(Dir.glob(path).select{ |f| File.file?(f) }) end files.sort! files.each do |file| puts file unless quiet? case ext = File.extname(file) when '.rd', '.rdoc' require_rdoc markup = SM::SimpleMarkup.new formatter = SM::ToHtml.new text << markup.convert(File.read(file), formatter) when '.md', '.markdown' # TODO end text << "\n" end temp = Template.new(template, text, title, css) html = temp.parse_template save(html) end |
#quiet? ⇒ Boolean
Supress output.
41 |
# File 'lib/quarry/document.rb', line 41 def quiet? ; @quiet ; end |
#save(text) ⇒ Object
Save specification document.
80 81 82 83 84 85 86 87 88 89 |
# File 'lib/quarry/document.rb', line 80 def save(text) if dryrun puts "\nwrite #{output}" else FileUtils.mkdir_p(File.dirname(output)) File.open(output, 'wb') do |f| f << text end end end |
#template ⇒ Object
Load specification HTML template.
72 73 74 75 76 77 |
# File 'lib/quarry/document.rb', line 72 def template @template ||= ( file = File.join(File.dirname(__FILE__), 'document', 'template.rhtml') File.read(file) ) end |