Class: Docurium

Inherits:
Object
  • Object
show all
Defined in:
lib/docurium.rb,
lib/docurium/cli.rb

Defined Under Namespace

Classes: CLI

Constant Summary collapse

Version =
VERSION = '0.0.1'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config_file) ⇒ Docurium

Returns a new instance of Docurium.



11
12
13
14
15
16
# File 'lib/docurium.rb', line 11

def initialize(config_file)
  raise "You need to specify a config file" if !config_file
  raise "You need to specify a valid config file" if !valid_config(config_file)
  @sigs = {}
  clear_data
end

Instance Attribute Details

#branchObject

Returns the value of attribute branch.



9
10
11
# File 'lib/docurium.rb', line 9

def branch
  @branch
end

#dataObject

Returns the value of attribute data.



9
10
11
# File 'lib/docurium.rb', line 9

def data
  @data
end

#output_dirObject

Returns the value of attribute output_dir.



9
10
11
# File 'lib/docurium.rb', line 9

def output_dir
  @output_dir
end

Instance Method Details

#clear_data(version = 'HEAD') ⇒ Object



18
19
20
21
# File 'lib/docurium.rb', line 18

def clear_data(version = 'HEAD')
  @data = {:files => [], :functions => {}, :globals => {}, :types => {}, :prefix => ''}
  @data[:prefix] = option_version(version, 'input', '')
end

#generate_docsObject



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
71
72
73
74
75
76
77
78
# File 'lib/docurium.rb', line 36

def generate_docs
  puts "generating docs"
  outdir = mkdir_temp
  copy_site(outdir)
  versions = get_versions
  versions << 'HEAD'
  versions.each do |version|
    puts "generating docs for version #{version}"
    workdir = mkdir_temp
    Dir.chdir(workdir) do
      clear_data(version)
      checkout(version, workdir)
      puts "parsing headers"
      parse_headers
      tally_sigs(version)
      File.open(File.join(outdir, "#{version}.json"), 'w+') do |f|
        f.write(@data.to_json)
      end
    end
  end

  Dir.chdir(outdir) do
    project = {
      :versions => versions.reverse,
      :github   => @options['github'],
      :name     => @options['name'],
      :signatures => @sigs
    }
    File.open("project.json", 'w+') do |f|
      f.write(project.to_json)
    end
  end

  if @options['branch']
    write_branch
  else
    final_dir = File.join(@project_dir, @options['output'] || 'docs')
    FileUtils.mkdir_p(final_dir)
    Dir.chdir(final_dir) do
      FileUtils.cp_r(File.join(outdir, '.'), '.') 
    end
  end
end

#get_versionsObject



80
81
82
# File 'lib/docurium.rb', line 80

def get_versions
  VersionSorter.sort(git('tag').split("\n"))
end

#option_version(version, option, default) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/docurium.rb', line 23

def option_version(version, option, default)
  if @options['legacy']
    if valhash = @options['legacy'][option]
      valhash.each do |value, versions|
        return value if versions.include?(version)
      end
    end
  end
  opt = @options[option]
  opt = default if !opt
  opt
end

#parse_headersObject



84
85
86
87
88
89
90
91
# File 'lib/docurium.rb', line 84

def parse_headers
  headers.each do |header|
    parse_header(header)
  end
  @data[:groups] = group_functions
  @data[:types] = @data[:types].sort # make it an assoc array
  find_type_usage
end