Move docs to submodule for multi-module projects

This commit is contained in:
Dave Syer
2014-10-06 14:58:44 +01:00
parent 77ac511c8c
commit b6eda4ba37
11 changed files with 91 additions and 29 deletions

View File

@@ -0,0 +1,19 @@
#!/usr/bin/env ruby
base_dir = File.join(File.dirname(__FILE__),'../../..')
src_dir = File.join(base_dir, "/src/main/asciidoc")
require File.join(File.dirname(__FILE__), 'readme.rb')
require 'optparse'
options = {}
input = "#{src_dir}/README.adoc"
OptionParser.new do |o|
o.on('-o OUTPUT_FILE', 'Output file (default is stdout)') { |file| options[:to_file] = file unless file=='-' }
o.on('-h', '--help') { puts o; exit }
o.parse!
end
input = ARGV[0] if ARGV.length>0
SpringCloud::Build.render_file(input, options)

View File

@@ -0,0 +1,54 @@
require 'open-uri'
module SpringCloud
module Build
IncludeDirectiveRx = /^\\?include::([^\[]+)\[(.*?)\]$/
class << self
def process_include out, src, target, attrs
unless target.include?(':') || target.start_with?('/')
target = File.join(src, target)
end
open(target) do |file|
file.each do |line|
self.process(out, File.dirname(target), line)
end
end
end
def process out, src, line
if ((escaped = line.start_with?('\\include::')) || line.start_with?('include::')) && (match = IncludeDirectiveRx.match(line))
if escaped
out << line[1..-1]
else
self.process_include out, src, match[1], match[2].strip
end
else
out << line
end
end
def render_file file, options = {}
srcDir = File.dirname(file)
out = ["// Do not edit this file (e.g. go instead to src/main/asciidoc)\n","\n"]
File.new(file).each do |line|
self.process(out, srcDir, line)
end
unless options[:to_file]
puts out
else
File.open(options[:to_file],'w+') do |file|
out.each { |line| file.write(line) }
end
end
end
end
end
end