Class: Quarry::Document

Inherits:
Object show all
Defined in:
lib/quarry/document.rb

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

Instance Method Summary collapse

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(options)
  options.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

#cssObject

Returns the value of attribute css.



18
19
20
# File 'lib/quarry/document.rb', line 18

def css
  @css
end

#dryrunObject

Returns the value of attribute dryrun.



20
21
22
# File 'lib/quarry/document.rb', line 20

def dryrun
  @dryrun
end

#outputObject

Ouput file.



24
25
26
# File 'lib/quarry/document.rb', line 24

def output
  @output
end

#pathsObject

Returns the value of attribute paths.



19
20
21
# File 'lib/quarry/document.rb', line 19

def paths
  @paths
end

#quietObject

Returns the value of attribute quiet.



21
22
23
# File 'lib/quarry/document.rb', line 21

def quiet
  @quiet
end

#titleObject

Returns the value of attribute title.



17
18
19
# File 'lib/quarry/document.rb', line 17

def title
  @title
end

Instance Method Details

#generateObject

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.

Returns:

  • (Boolean)


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

#templateObject

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