Skip to content

Commit

Permalink
fix merge
Browse files Browse the repository at this point in the history
  • Loading branch information
voloko committed Sep 6, 2011
1 parent 8c54609 commit 125827e
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 44 deletions.
1 change: 0 additions & 1 deletion bin/sdoc-merge
@@ -1,5 +1,4 @@
#!/usr/bin/env ruby -KU

require File.dirname(__FILE__) + '/../lib/sdoc' # add extensions
require 'sdoc/merge'

Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/generator/template/merge/index.rhtml
Expand Up @@ -7,7 +7,7 @@

<title><%= @title %></title>
</head>
<frameset cols="300,*" frameborder="1" border="1" bordercolor="#666666" framespacing="1">
<frameset cols="300,*" frameborder="1" border="1" bordercolor="#999999" framespacing="1">
<frame src="panel/index.html" title="Search" name="panel" />
<frame src="<%= index_path %>" name="docwin" />
</frameset>
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/generator/template/rails/index.rhtml
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=<%= @options.charset %>" />
<title><%= @options.title %></title>
</head>
<frameset cols="300,*" frameborder="1" border="1" bordercolor="#666666" framespacing="1">
<frameset cols="300,*" frameborder="1" border="1" bordercolor="#999999" framespacing="1">
<frame src="panel/index.html" title="Search" name="panel" />
<frame src="<%= index_path %>" name="docwin" />
</frameset>
Expand Down
1 change: 1 addition & 0 deletions lib/rdoc/generator/template/rails/resources/css/panel.css
Expand Up @@ -175,6 +175,7 @@
margin-left: -0.2em;
padding: 0 0.2em;
color: #000;
border-radius: 3px;
}

.panel .result ul li .badge_1
Expand Down
2 changes: 1 addition & 1 deletion lib/rdoc/generator/template/sdoc/index.rhtml
Expand Up @@ -6,7 +6,7 @@
<meta http-equiv="Content-Type" content="text/html; charset=<%= @options.charset %>" />
<title><%= @options.title %></title>
</head>
<frameset cols="300,*" frameborder="1" border="1" bordercolor="#666666" framespacing="1">
<frameset cols="300,*" frameborder="1" border="1" bordercolor="#999999" framespacing="1">
<frame src="panel/index.html" title="Search" name="panel" />
<frame src="<%= index_path %>" name="docwin" />
</frameset>
Expand Down
1 change: 1 addition & 0 deletions lib/rdoc/generator/template/sdoc/resources/css/panel.css
Expand Up @@ -175,6 +175,7 @@
margin-left: -0.2em;
padding: 0 0.2em;
color: #000;
border-radius: 3px;
}

.panel .result ul li .badge_1
Expand Down
79 changes: 39 additions & 40 deletions lib/sdoc/merge.rb
Expand Up @@ -13,24 +13,22 @@

class SDoc::Merge
include SDoc::Templatable

FLAG_FILE = "created.rid"

def initialize()
@names = []
@urls = []
@op_dir = 'doc'
@title = ''
@directories = []
template_dir = RDoc::Generator::SDoc.template_dir_for('merge')
@template_dir = Pathname.new File.expand_path(template_dir)
end

def merge(options)
parse_options options

@outputdir = Pathname.new( @op_dir )

check_directories
setup_output_dir
setup_names
Expand All @@ -40,39 +38,40 @@ def merge(options)
merge_tree
generate_index_file
end

def parse_options(options)
opts = OptionParser.new do |opt|
opts = OptionParser.new do |opt|
opt.banner = "Usage: sdoc-merge [options] directories"

opt.on("-n", "--names [NAMES]", "Names of merged repositories. Comma separated") do |v|
@names = v.split(',').map{|name| name.strip }
end

opt.on("-o", "--op [DIRECTORY]", "Set the output directory") do |v|
@op_dir = v
end

opt.on("-t", "--title [TITLE]", "Set the title of merged file") do |v|
@title = v
end

opt.on("-u", "--urls [URLS]", "Paths to merged docs. If you",
"set this files and classes won't be actualy",
"copied to merged build") do |v|
@urls = v.split(' ').map{|name| name.strip }
end
end
opts.parse! options
@template_dir = Pathname.new(RDoc::Options.new.template_dir_for 'merge')
@directories = options.dup
end

def merge_tree
tree = []
@directories.each_with_index do |dir, i|
name = @names[i]
url = @urls.empty? ? name : @urls[i]
filename = File.join dir, RDoc::Generator::SHtml::TREE_FILE
filename = File.join dir, RDoc::Generator::SDoc::TREE_FILE
data = open(filename).read.sub(/var tree =\s*/, '')
subtree = JSON.parse(data, :max_nesting => 0)
item = [
Expand All @@ -83,33 +82,33 @@ def merge_tree
]
tree << item
end
dst = File.join @op_dir, RDoc::Generator::SHtml::TREE_FILE

dst = File.join @op_dir, RDoc::Generator::SDoc::TREE_FILE
FileUtils.mkdir_p File.dirname(dst)
File.open(dst, "w", 0644) do |f|
f.write('var tree = '); f.write(tree.to_json(:max_nesting => 0))
end
end

def append_path subtree, path
subtree.map do |item|
item[1] = path + '/' + item[1] unless item[1].empty?
item[3] = append_path item[3], path
item
end
end

def merge_search_index
items = []
@indexes = {}
@directories.each_with_index do |dir, i|
name = @names[i]
url = @urls.empty? ? name : @urls[i]
filename = File.join dir, RDoc::Generator::SHtml::SEARCH_INDEX_FILE
filename = File.join dir, RDoc::Generator::SDoc::SEARCH_INDEX_FILE
data = open(filename).read.sub(/var search_data =\s*/, '')
subindex = JSON.parse(data, :max_nesting => 0)
@indexes[name] = subindex

searchIndex = subindex["index"]["searchIndex"]
longSearchIndex = subindex["index"]["longSearchIndex"]
subindex["index"]["info"].each_with_index do |info, j|
Expand All @@ -126,7 +125,7 @@ def merge_search_index
# type (class/method/file) or name or doc part or namespace
[a[:info][5], a[:info][0], a[:info][6], a[:info][1]] <=> [b[:info][5], b[:info][0], b[:info][6], b[:info][1]]
end

index = {
:searchIndex => items.map{|item| item[:searchIndex]},
:longSearchIndex => items.map{|item| item[:longSearchIndex]},
Expand All @@ -136,14 +135,14 @@ def merge_search_index
:index => index,
:badges => @names
}
dst = File.join @op_dir, RDoc::Generator::SHtml::SEARCH_INDEX_FILE

dst = File.join @op_dir, RDoc::Generator::SDoc::SEARCH_INDEX_FILE
FileUtils.mkdir_p File.dirname(dst)
File.open(dst, "w", 0644) do |f|
f.write('var search_data = '); f.write(search_data.to_json(:max_nesting => 0))
end
end

def extract_index_path dir
filename = File.join dir, 'index.html'
content = File.open(filename) { |f| f.read }
Expand All @@ -154,16 +153,16 @@ def extract_index_path dir
''
end
end

def generate_index_file
templatefile = @template_dir + 'index.rhtml'
outfile = @outputdir + 'index.html'
url = @urls.empty? ? @names[0] : @urls[0]
index_path = url + '/' + extract_index_path(@directories[0])

render_template templatefile, binding(), outfile
end

def setup_names
unless @names.size > 0
@directories.each do |dir|
Expand All @@ -173,52 +172,52 @@ def setup_names
end
end
end

def copy_docs
@directories.each_with_index do |dir, i|
name = @names[i]
index_dir = File.dirname(RDoc::Generator::SHtml::TREE_FILE)
index_dir = File.dirname(RDoc::Generator::SDoc::TREE_FILE)
FileUtils.mkdir_p(File.join(@op_dir, name))

Dir.new(dir).each do |item|
if File.directory?(File.join(dir, item)) && item != '.' && item != '..' && item != index_dir
FileUtils.cp_r File.join(dir, item), File.join(@op_dir, name, item), :preserve => true
end
end
end
end

def copy_files
dir = @directories.first
Dir.new(dir).each do |item|
if item != '.' && item != '..' && item != RDoc::Generator::SHtml::FILE_DIR && item != RDoc::Generator::SHtml::CLASS_DIR
if item != '.' && item != '..' && item != RDoc::Generator::SDoc::FILE_DIR && item != RDoc::Generator::SDoc::CLASS_DIR
FileUtils.cp_r File.join(dir, item), @op_dir, :preserve => true
end
end
end

def setup_output_dir
if File.exists? @op_dir
error "#{@op_dir} allready exists"
end
FileUtils.mkdir_p @op_dir
end

def check_directories
@directories.each do |dir|
unless File.exists?(File.join(dir, FLAG_FILE)) &&
File.exists?(File.join(dir, RDoc::Generator::SHtml::TREE_FILE)) &&
File.exists?(File.join(dir, RDoc::Generator::SHtml::SEARCH_INDEX_FILE))
unless File.exists?(File.join(dir, FLAG_FILE)) &&
File.exists?(File.join(dir, RDoc::Generator::SDoc::TREE_FILE)) &&
File.exists?(File.join(dir, RDoc::Generator::SDoc::SEARCH_INDEX_FILE))
error "#{dir} does not seem to be an sdoc directory"
end
end
end

##
# Report an error message and exit

def error(msg)
raise RDoc::Error, msg
end

end

0 comments on commit 125827e

Please sign in to comment.