lib/docurium.rb in docurium-0.0.2 vs lib/docurium.rb in docurium-0.0.3

- old
+ new

@@ -4,11 +4,11 @@ require 'rocco' require 'docurium/layout' require 'pp' class Docurium - Version = VERSION = '0.0.2' + Version = VERSION = '0.0.3' attr_accessor :branch, :output_dir, :data def initialize(config_file) raise "You need to specify a config file" if !config_file @@ -67,17 +67,37 @@ next if !File.file?(file) files << file end files.each do |file| out " # #{file}" + + # highlight, roccoize and link rocco = Rocco.new(file, files, {:language => 'c'}) 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}" rf_path = File.join(outdir, rel_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}\" href=\"../../##{version}/group/#{fdata[:group]}/#{f}\">#{f}</a>#{extra}" + end + end + + # write example to docs directory FileUtils.mkdir_p(File.dirname(rf_path)) File.open(rf_path, 'w+') do |f| @data[:examples] ||= [] @data[:examples] << [file, rel_path] f.write(rf) @@ -237,9 +257,10 @@ group, rest = k.split('_', 2) next if group.empty? if !rest group = value[:file].gsub('.h', '').gsub('/', '_') end + @data[:functions][key][:group] = group func[group] ||= [] func[group] << key func[group].sort! end misc = []