sdoc-0.4.1/ 0000755 0000041 0000041 00000000000 12377325624 012507 5 ustar www-data www-data sdoc-0.4.1/Rakefile 0000644 0000041 0000041 00000000312 12377325624 014150 0 ustar www-data www-data require 'rubygems' require 'bundler' Bundler::GemHelper.install_tasks require 'rake/testtask' Rake::TestTask.new do |t| t.pattern = "spec/*_spec.rb" end task :default => :test task :spec => :test sdoc-0.4.1/bin/ 0000755 0000041 0000041 00000000000 12377325624 013257 5 ustar www-data www-data sdoc-0.4.1/bin/sdoc 0000755 0000041 0000041 00000001122 12377325624 014131 0 ustar www-data www-data #!/usr/bin/env ruby -KU require 'sdoc' begin ARGV.unshift('--format=sdoc') if ARGV.grep(/\A(-f|--fmt|--format|-r|-R|--ri|--ri-site)\b/).empty? r = RDoc::RDoc.new r.document ARGV rescue SystemExit raise rescue Exception => e if $DEBUG_RDOC then $stderr.puts e.message $stderr.puts "#{e.backtrace.join "\n\t"}" $stderr.puts elsif Interrupt === e then $stderr.puts $stderr.puts 'Interrupted' else $stderr.puts "uh-oh! RDoc had a problem:" $stderr.puts e.message $stderr.puts $stderr.puts "run with --debug for full backtrace" end exit 1 end sdoc-0.4.1/bin/sdoc-merge 0000755 0000041 0000041 00000000761 12377325624 015236 0 ustar www-data www-data #!/usr/bin/env ruby -KU require File.dirname(__FILE__) + '/../lib/sdoc' # add extensions require 'sdoc/merge' begin m = SDoc::Merge.new m.merge(ARGV) rescue SystemExit raise rescue Exception => e if $DEBUG_RDOC then $stderr.puts e.message $stderr.puts "#{e.backtrace.join "\n\t"}" $stderr.puts elsif Interrupt === e then $stderr.puts $stderr.puts 'Interrupted' else $stderr.puts "uh-oh! SDoc merge had a problem:" $stderr.puts e.message end exit 1 end sdoc-0.4.1/Gemfile 0000644 0000041 0000041 00000000047 12377325624 014003 0 ustar www-data www-data source "https://rubygems.org" gemspec sdoc-0.4.1/spec/ 0000755 0000041 0000041 00000000000 12377325624 013441 5 ustar www-data www-data sdoc-0.4.1/spec/spec_helper.rb 0000644 0000041 0000041 00000000161 12377325624 016255 0 ustar www-data www-data require 'rubygems' require 'bundler/setup' require 'sdoc' require 'rdoc/test_case' require 'minitest/autorun' sdoc-0.4.1/spec/rdoc_generator_spec.rb 0000644 0000041 0000041 00000002610 12377325624 017774 0 ustar www-data www-data require File.join(File.dirname(__FILE__), '/spec_helper') describe RDoc::Generator::SDoc do before :each do @options = RDoc::Options.new @options.setup_generator 'sdoc' @parser = @options.option_parser end it "should find sdoc generator" do RDoc::RDoc::GENERATORS.must_include 'sdoc' end it "should use sdoc generator" do @options.generator.must_equal RDoc::Generator::SDoc @options.generator_name.must_equal 'sdoc' end it "should parse github option" do assert !@options.github out, err = capture_io do @parser.parse %w[--github] end err.wont_match /^invalid options/ @options.github.must_equal true end it "should parse github short-hand option" do assert !@options.github out, err = capture_io do @parser.parse %w[-g] end err.wont_match /^invalid options/ @options.github.must_equal true end it "should parse no search engine index option" do @options.search_index.must_equal true out, err = capture_io do @parser.parse %w[--without-search] end err.wont_match /^invalid options/ @options.search_index.must_equal false end it "should parse search-index shorthand option" do @options.search_index.must_equal true out, err = capture_io do @parser.parse %w[-s] end err.wont_match /^invalid options/ @options.search_index.must_equal false end end sdoc-0.4.1/.travis.yml 0000644 0000041 0000041 00000000233 12377325624 014616 0 ustar www-data www-data --- rvm: - 1.8.7 - 1.9.3 - 2.0.0 - 2.1.0 - ruby-head - jruby-19mode - jruby-head notifications: recipients: - zachary@zacharyscott.net sdoc-0.4.1/lib/ 0000755 0000041 0000041 00000000000 12377325624 013255 5 ustar www-data www-data sdoc-0.4.1/lib/sdoc/ 0000755 0000041 0000041 00000000000 12377325624 014205 5 ustar www-data www-data sdoc-0.4.1/lib/sdoc/github.rb 0000644 0000041 0000041 00000003061 12377325624 016014 0 ustar www-data www-data module SDoc::GitHub def github_url(path) unless @github_url_cache.has_key? path @github_url_cache[path] = false file = @store.find_file_named(path) if file base_url = repository_url(path) if base_url sha1 = commit_sha1(path) if sha1 relative_url = path_relative_to_repository(path) @github_url_cache[path] = "#{base_url}#{sha1}#{relative_url}" end end end end @github_url_cache[path] end protected def have_git? @have_git = system('git --version > /dev/null 2>&1') if @have_git.nil? @have_git end def commit_sha1(path) return false unless have_git? name = File.basename(path) s = Dir.chdir(File.join(base_dir, File.dirname(path))) do `git log -1 --pretty=format:"commit %H" #{name}` end m = s.match(/commit\s+(\S+)/) m ? m[1] : false end def repository_url(path) return false unless have_git? s = Dir.chdir(File.join(base_dir, File.dirname(path))) do `git config --get remote.origin.url` end m = s.match(%r{github.com[/:](.*)\.git$}) m ? "https://github.com/#{m[1]}/blob/" : false end def path_relative_to_repository(path) absolute_path = File.join(base_dir, path) root = path_to_git_dir(File.dirname(absolute_path)) absolute_path[root.size..absolute_path.size] end def path_to_git_dir(path) while !path.empty? && path != '.' if (File.exists? File.join(path, '.git')) return path end path = File.dirname(path) end '' end end sdoc-0.4.1/lib/sdoc/helpers.rb 0000644 0000041 0000041 00000001135 12377325624 016174 0 ustar www-data www-data module SDoc::Helpers def each_letter_group(methods, &block) group = {:name => '', :methods => []} methods.sort{ |a, b| a.name <=> b.name }.each do |method| gname = group_name method.name if gname != group[:name] yield group unless group[:methods].size == 0 group = { :name => gname, :methods => [] } end group[:methods].push(method) end yield group unless group[:methods].size == 0 end protected def group_name name if match = name.match(/^([a-z])/i) match[1].upcase else '#' end end end sdoc-0.4.1/lib/sdoc/version.rb 0000644 0000041 0000041 00000000044 12377325624 016215 0 ustar www-data www-data module SDoc VERSION = '0.4.1' end sdoc-0.4.1/lib/sdoc/merge.rb 0000644 0000041 0000041 00000014041 12377325624 015631 0 ustar www-data www-data require 'optparse' require 'pathname' require 'fileutils' if Gem::Specification.respond_to?(:find_by_name) ? Gem::Specification::find_by_name("json") : Gem.available?("json") gem "json", ">= 1.1.3" else gem "json_pure", ">= 1.1.3" end require 'json' require 'sdoc/templatable' class SDoc::Merge include SDoc::Templatable FLAG_FILE = "created.rid" def initialize() @names = [] @urls = [] @op_dir = 'doc' @title = '' @directories = [] end def merge(options) parse_options options @outputdir = Pathname.new( @op_dir ) check_directories setup_output_dir setup_names copy_files copy_docs if @urls.empty? merge_search_index merge_tree generate_index_file end def parse_options(options) 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::SDoc::TREE_FILE data = open(filename).read.sub(/var tree =\s*/, '') subtree = JSON.parse(data, :max_nesting => 0) item = [ name, url + '/' + extract_index_path(dir), '', append_path(subtree, url) ] tree << item end 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::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| info[2] = url + '/' + info[2] info[6] = i items << { :info => info, :searchIndex => searchIndex[j], :longSearchIndex => name + ' ' + longSearchIndex[j] } end end items.sort! do |a, b| # 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]}, :info => items.map{|item| item[:info]} } search_data = { :index => index, :badges => @names } 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 } match = content.match(/ 0 @directories.each do |dir| name = File.basename dir name = File.basename File.dirname(dir) if name == 'doc' @names << name end end end def copy_docs @directories.each_with_index do |dir, i| name = @names[i] 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::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} already 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::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 sdoc-0.4.1/lib/sdoc/templatable.rb 0000644 0000041 0000041 00000004131 12377325624 017023 0 ustar www-data www-data require 'erb' require "sdoc" module SDoc::Templatable ### Load and render the erb template in the given +templatefile+ within the ### specified +context+ (a Binding object) and return output ### Both +templatefile+ and +outfile+ should be Pathname-like objects. def eval_template(templatefile, context) template_src = templatefile.read template = ERB.new( template_src, nil, '<>' ) template.filename = templatefile.to_s begin template.result( context ) rescue NoMethodError => err raise RDoc::Error, "Error while evaluating %s: %s (at %p)" % [ templatefile.to_s, err.message, eval( "_erbout[-50,50]", context ) ], err.backtrace end end ### Load and render the erb template with the given +template_name+ within ### current context. Adds all +local_assigns+ to context def include_template(template_name, local_assigns = {}) source = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join templatefile = @template_dir + template_name eval("#{source};eval_template(templatefile, binding)") end ### Load and render the erb template in the given +templatefile+ within the ### specified +context+ (a Binding object) and write it out to +outfile+. ### Both +templatefile+ and +outfile+ should be Pathname-like objects. def render_template( templatefile, context, outfile ) output = eval_template(templatefile, context) # TODO delete this dirty hack when documentation for example for GeneratorMethods will not be cutted off by