lib/docurium.rb in docurium-0.4.0 vs lib/docurium.rb in docurium-0.4.1
- old
+ new
@@ -7,10 +7,11 @@
require 'libdetect'
require 'docurium/docparser'
require 'pp'
require 'rugged'
require 'redcarpet'
+require 'redcarpet/compat'
require 'thread'
# Markdown expects the old redcarpet compat API, so let's tell it what
# to use
Rocco::Markdown = RedcarpetCompat
@@ -24,11 +25,11 @@
@sigs = {}
@repo = repo || Rugged::Repository.discover('.')
end
def init_data(version = 'HEAD')
- data = {:files => [], :functions => {}, :globals => {}, :types => {}, :prefix => ''}
+ data = {:files => [], :functions => {}, :callbacks => {}, :globals => {}, :types => {}, :prefix => ''}
data[:prefix] = option_version(version, 'input', '')
data
end
def option_version(version, option, default = nil)
@@ -62,18 +63,29 @@
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}"
+ rocco_layout = Rocco::Layout.new(rocco, @tf)
+ # find out how deep our file is so we can use the right
+ # number of ../ in the path
+ depth = rel_path.count('/') - 1
+ if depth == 0
+ rocco_layout[:dirsup] = "./"
+ else
+ rocco_layout[:dirsup] = "../"*depth
+ end
+
+ rocco_layout.version = version
+ rf = rocco_layout.render
+
+
# 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
@@ -183,10 +195,14 @@
:signatures => @sigs,
}
sha = @repo.write(project.to_json, :blob)
output_index.add(:path => "project.json", :oid => sha, :mode => 0100644)
+ css = File.read(File.expand_path(File.join(File.dirname(__FILE__), 'docurium', 'css.css')))
+ sha = @repo.write(css, :blob)
+ output_index.add(:path => "ex/css.css", :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}"
@@ -371,20 +387,20 @@
file_map[r[:file]][:lines] = r[:lineto]
end
# process this type of record
case r[:type]
- when :function
- data[:functions][r[:name]] ||= {}
+ when :function, :callback
+ t = r[:type] == :function ? :functions : :callbacks
+ data[t][r[:name]] ||= {}
wanted[:functions].each do |k|
next unless r.has_key? k
- conents = nil
if k == :description || k == :comments
contents = md.render r[k]
else
contents = r[k]
end
- data[:functions][r[:name]][k] = contents
+ data[t][r[:name]][k] = contents
end
file_map[r[:file]][:functions] << r[:name]
when :define, :macro
data[:globals][r[:decl]] ||= {}