Class: Docurium
- Inherits:
-
Object
- Object
- Docurium
- Defined in:
- lib/docurium.rb,
lib/docurium/cli.rb,
lib/docurium/cparser.rb,
lib/docurium/version.rb
Defined Under Namespace
Constant Summary collapse
- Version =
VERSION = '0.2.0'
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.
15 16 17 18 19 20 21 22 23 |
# File 'lib/docurium.rb', line 15 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.
13 14 15 |
# File 'lib/docurium.rb', line 13 def branch @branch end |
#data ⇒ Object
Returns the value of attribute data.
13 14 15 |
# File 'lib/docurium.rb', line 13 def data @data end |
#output_dir ⇒ Object
Returns the value of attribute output_dir.
13 14 15 |
# File 'lib/docurium.rb', line 13 def output_dir @output_dir end |
Instance Method Details
#clear_data(version = 'HEAD') ⇒ Object
25 26 27 28 |
# File 'lib/docurium.rb', line 25 def clear_data(version = 'HEAD') @data = {:files => [], :functions => {}, :globals => {}, :types => {}, :prefix => ''} @data[:prefix] = option_version(version, 'input', '') end |
#generate_docs ⇒ Object
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 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 |
# File 'lib/docurium.rb', line 43 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 rf_path = File.basename(file).split('.')[0..-2].join('.') + '.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
174 175 176 177 178 |
# File 'lib/docurium.rb', line 174 def get_versions = [] @repo..each { |tag| << tag.gsub(%r(^refs/tags/), '') } VersionSorter.sort() end |
#option_version(version, option, default = nil) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/docurium.rb', line 30 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
180 181 182 183 184 185 186 187 188 189 |
# File 'lib/docurium.rb', line 180 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
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 |
# File 'lib/docurium.rb', line 148 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 |