Class: Docurium
- Inherits:
-
Object
- Object
- Docurium
- Defined in:
- lib/docurium/cli.rb,
lib/docurium/cparser.rb,
lib/docurium/version.rb,
lib/docurium.rb
Defined Under Namespace
Constant Summary collapse
- Version =
VERSION = '0.3.1'
Instance Attribute Summary collapse
-
#branch ⇒ Object
Returns the value of attribute branch.
-
#data ⇒ Object
Returns the value of attribute data.
-
#output_dir ⇒ Object
Returns the value of attribute output_dir.
Instance Method Summary collapse
- #clear_data(version = 'HEAD') ⇒ Object
- #generate_docs ⇒ Object
- #get_versions ⇒ Object
-
#initialize(config_file) ⇒ Docurium
constructor
A new instance of Docurium.
- #option_version(version, option, default = nil) ⇒ Object
- #parse_headers(index) ⇒ Object
- #show_warnings ⇒ Object
Constructor Details
#initialize(config_file) ⇒ Docurium
Returns a new instance of Docurium.
19 20 21 22 23 24 25 26 27 |
# File 'lib/docurium.rb', line 19 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 = {} @groups = {} repo_path = Rugged::Repository.discover('.') @repo = Rugged::Repository.new(repo_path) clear_data end |
Instance Attribute Details
#branch ⇒ Object
Returns the value of attribute branch.
17 18 19 |
# File 'lib/docurium.rb', line 17 def branch @branch end |
#data ⇒ Object
Returns the value of attribute data.
17 18 19 |
# File 'lib/docurium.rb', line 17 def data @data end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
17 18 19 |
# File 'lib/docurium.rb', line 17 def output_dir @output_dir end |
Instance Method Details
#clear_data(version = 'HEAD') ⇒ Object
29 30 31 32 |
# File 'lib/docurium.rb', line 29 def clear_data(version = 'HEAD') @data = {:files => [], :functions => {}, :globals => {}, :types => {}, :prefix => ''} @data[:prefix] = option_version(version, 'input', '') end |
#generate_docs ⇒ Object
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 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 |
# File 'lib/docurium.rb', line 47 def generate_docs out "* generating docs" output_index = Rugged::Index.new write_site(output_index) versions = get_versions versions << 'HEAD' versions.each do |version| out " - processing version #{version}" index = @repo.index index.clear clear_data(version) read_subtree(index, version, @data[:prefix]) parse_headers(index) tally_sigs(version) tf = File.(File.join(File.dirname(__FILE__), 'docurium', 'layout.mustache')) if ex = option_version(version, 'examples') if subtree = find_subtree(version, ex) # check that it exists index.read_tree(subtree) out " - processing examples for #{version}" files = [] index.each do |entry| next unless entry[:path].match(/\.c$/) files << entry[:path] end files.each do |file| out " # #{file}" # highlight, roccoize and link rocco = Rocco.new(file, files, {:language => 'c'}) do ientry = index[file] blob = @repo.lookup(ientry[:oid]) blob.content end rocco_layout = Rocco::Layout.new(rocco, tf) rocco_layout.version = version rf = rocco_layout.render extlen = -(File.extname(file).length + 1) rf_path = file[0..extlen] + '.html' rel_path = "ex/#{version}/#{rf_path}" # look for function names in the examples and link id_num = 0 @data[:functions].each do |f, fdata| rf.gsub!(/#{f}([^\w])/) do |fmatch| extra = $1 id_num += 1 name = f + '-' + id_num.to_s # save data for cross-link @data[:functions][f][:examples] ||= {} @data[:functions][f][:examples][file] ||= [] @data[:functions][f][:examples][file] << rel_path + '#' + name "<a name=\"#{name}\" class=\"fnlink\" href=\"../../##{version}/group/#{fdata[:group]}/#{f}\">#{f}</a>#{extra}" end end # write example to the repo sha = @repo.write(rf, :blob) output_index.add(:path => rel_path, :oid => sha, :mode => 0100644) @data[:examples] ||= [] @data[:examples] << [file, rel_path] end end if version == 'HEAD' show_warnings end end sha = @repo.write(@data.to_json, :blob) output_index.add(:path => "#{version}.json", :oid => sha, :mode => 0100644) end project = { :versions => versions.reverse, :github => @options['github'], :name => @options['name'], :signatures => @sigs, :groups => @groups } sha = @repo.write(project.to_json, :blob) output_index.add(:path => "project.json", :oid => sha, :mode => 0100644) br = @options['branch'] out "* writing to branch #{br}" refname = "refs/heads/#{br}" tsha = output_index.write_tree(@repo) puts "\twrote tree #{tsha}" ref = Rugged::Reference.lookup(@repo, refname) user = { :name => @repo.config['user.name'], :email => @repo.config['user.email'], :time => Time.now } = {} [:tree] = tsha [:author] = user [:committer] = user [:message] = 'generated docs' [:parents] = ref ? [ref.target] : [] [:update_ref] = refname csha = Rugged::Commit.create(@repo, ) puts "\twrote commit #{csha}" puts "\tupdated #{br}" end |
#get_versions ⇒ Object
179 180 181 182 183 |
# File 'lib/docurium.rb', line 179 def get_versions = [] @repo..each { |tag| << tag.gsub(%r(^refs/tags/), '') } VersionSorter.sort() end |
#option_version(version, option, default = nil) ⇒ Object
34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/docurium.rb', line 34 def option_version(version, option, default = nil) 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_headers(index) ⇒ Object
185 186 187 188 189 190 191 192 193 194 |
# File 'lib/docurium.rb', line 185 def parse_headers(index) headers(index).each do |header| records = parse_header(index, header) update_globals(records) end @data[:groups] = group_functions @data[:types] = @data[:types].sort # make it an assoc array find_type_usage end |
#show_warnings ⇒ Object
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 |
# File 'lib/docurium.rb', line 153 def show_warnings out '* checking your api' # check for unmatched paramaters unmatched = [] @data[:functions].each do |f, fdata| unmatched << f if fdata[:comments] =~ /@param/ end if unmatched.size > 0 out ' - unmatched params in' unmatched.sort.each { |p| out ("\t" + p) } end # check for changed signatures sigchanges = [] @sigs.each do |fun, data| if data[:changes]['HEAD'] sigchanges << fun end end if sigchanges.size > 0 out ' - signature changes in' sigchanges.sort.each { |p| out ("\t" + p) } end end |