Module: Spacedocs

Defined in:
lib/spacedocs.rb,
lib/spacedocs/version.rb

Constant Summary collapse

VERSION =
"0.0.3"

Class Method Summary collapse

Class Method Details

.doc(file_path, output_dir) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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
70
# File 'lib/spacedocs.rb', line 27

def doc(file_path, output_dir)
  tilt_path = File.dirname(__FILE__)

  # can't use < unless it's a file
  json = `#{File.join tilt_path, 'node_modules/dox/bin/dox'} < #{file_path}`

  doc_json = JSON.parse json

  processed_data = process_data doc_json

  template = Tilt.new(File.join tilt_path, "class.html.haml")
  index_template = Tilt.new(File.join tilt_path, "index.html.haml")

  files = {}

  class_data = processed_data[:docs_data]

  class_data.each_key do |namespace|
    files[namespace] = true
  end

  FileUtils.rm_rf output_dir
  FileUtils.mkdir_p output_dir

  File.open(File.join(output_dir, "index.html"), 'w') do |f|
    f.write(index_template.render self, {
      class_names: files.keys,
    })
  end

  files.each_key do |file_name|
    methods = class_data[file_name]['methods']

    File.open(File.join(output_dir, "#{file_name}.html"), 'w') do |f|
      f.write(template.render self, {
        class_name: file_name,
        method_list: methods.keys,
        methods: methods,
        class_names: files.keys,
        class_summary: class_data[file_name]['summary'],
      })
    end
  end
end

.generate_stylesheet(output_dir) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/spacedocs.rb', line 13

def generate_stylesheet(output_dir)
  tilt_path = File.dirname(__FILE__)

  stylesheets_dir = File.join(output_dir, 'stylesheets')

  FileUtils.mkdir_p stylesheets_dir

  stylesheet_template = Tilt.new(File.join(tilt_path, 'spacedocs.sass'), Compass.configuration.to_sass_engine_options)

  File.open(File.join(stylesheets_dir, 'spacedocs.css'), 'w') do |f|
    f.write(stylesheet_template.render self)
  end
end