Class: Quarry::Spec::Document
Overview
Document
TODO: css and javascripts have fixed location
-
need to make more flexible.
Constant Summary collapse
- DEFAULT_TITLE =
"Specifictions"
- DEFAULT_CSS =
"../assets/styles/spec.css"
- 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.
29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/quarry/spec/document.rb', line 29 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.
20 21 22 |
# File 'lib/quarry/spec/document.rb', line 20 def css @css end |
#dryrun ⇒ Object
Returns the value of attribute dryrun.
22 23 24 |
# File 'lib/quarry/spec/document.rb', line 22 def dryrun @dryrun end |
#output ⇒ Object
Ouput file.
26 27 28 |
# File 'lib/quarry/spec/document.rb', line 26 def output @output end |
#paths ⇒ Object
Returns the value of attribute paths.
21 22 23 |
# File 'lib/quarry/spec/document.rb', line 21 def paths @paths end |
#quiet ⇒ Object
Returns the value of attribute quiet.
23 24 25 |
# File 'lib/quarry/spec/document.rb', line 23 def quiet @quiet end |
#title ⇒ Object
Returns the value of attribute title.
19 20 21 |
# File 'lib/quarry/spec/document.rb', line 19 def title @title end |
Instance Method Details
#generate ⇒ Object
Generate specification document.
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/quarry/spec/document.rb', line 46 def generate files = [] paths.each do |path| files.concat(Dir.glob(path).select{ |f| File.file?(f) }) end text = '' 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.
43 |
# File 'lib/quarry/spec/document.rb', line 43 def quiet? ; @quiet ; end |
#save(text) ⇒ Object
Save specification document.
82 83 84 85 86 87 88 89 90 91 |
# File 'lib/quarry/spec/document.rb', line 82 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.
74 75 76 77 78 79 |
# File 'lib/quarry/spec/document.rb', line 74 def template @template ||= ( file = File.join(File.dirname(__FILE__), 'template.rhtml') File.read(file) ) end |