diff --git a/.gitignore b/.gitignore index cc4adf63..bf7e55b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +*.gem +.bundle pkg doc -/test.rb \ No newline at end of file +/test.rb +Gemfile.lock diff --git a/Gemfile b/Gemfile new file mode 100644 index 00000000..b4e2a20b --- /dev/null +++ b/Gemfile @@ -0,0 +1,3 @@ +source "https://rubygems.org" + +gemspec diff --git a/Rakefile b/Rakefile index 0113d85b..c7dc917d 100644 --- a/Rakefile +++ b/Rakefile @@ -3,10 +3,11 @@ require 'rubygems' require 'bundler' Bundler::GemHelper.install_tasks -gem 'rspec', '>= 2.5.0' -require 'rspec/core/rake_task' +require 'rake/testtask' -desc "Run all specs" -RSpec::Core::RakeTask.new(:spec) -task :default => :spec -task :test => :spec +Rake::TestTask.new do |t| + t.pattern = "spec/*_spec.rb" +end + +task :default => :test +task :spec => :test diff --git a/lib/rdoc/discover.rb b/lib/rdoc/discover.rb index 11a5ff5c..520cb09e 100644 --- a/lib/rdoc/discover.rb +++ b/lib/rdoc/discover.rb @@ -1,5 +1,5 @@ begin - gem 'rdoc', '~> 3' + gem 'rdoc', '~> 4.0.0' require File.join(File.dirname(__FILE__), '/../sdoc') rescue Gem::LoadError end diff --git a/lib/rdoc/generator/template/rails/se_index.rhtml b/lib/rdoc/generator/template/rails/search_index.rhtml similarity index 100% rename from lib/rdoc/generator/template/rails/se_index.rhtml rename to lib/rdoc/generator/template/rails/search_index.rhtml diff --git a/lib/rdoc/generator/template/sdoc/file.rhtml b/lib/rdoc/generator/template/sdoc/file.rhtml index efda7c01..e99d9ce1 100755 --- a/lib/rdoc/generator/template/sdoc/file.rhtml +++ b/lib/rdoc/generator/template/sdoc/file.rhtml @@ -18,7 +18,7 @@ @@ -26,4 +26,4 @@ <%= include_template '_context.rhtml', {:context => file, :rel_prefix => rel_prefix} %> - \ No newline at end of file + diff --git a/lib/rdoc/generator/template/sdoc/se_index.rhtml b/lib/rdoc/generator/template/sdoc/search_index.rhtml similarity index 100% rename from lib/rdoc/generator/template/sdoc/se_index.rhtml rename to lib/rdoc/generator/template/sdoc/search_index.rhtml diff --git a/lib/sdoc.rb b/lib/sdoc.rb index 331096fe..8aef0116 100644 --- a/lib/sdoc.rb +++ b/lib/sdoc.rb @@ -1,7 +1,7 @@ $:.unshift File.dirname(__FILE__) require "rubygems" -gem 'rdoc', '~> 3' +gem 'rdoc' module SDoc end - + require 'sdoc/generator' diff --git a/lib/sdoc/generator.rb b/lib/sdoc/generator.rb index 144b9630..1e564635 100644 --- a/lib/sdoc/generator.rb +++ b/lib/sdoc/generator.rb @@ -22,7 +22,7 @@ def with_documentation? class RDoc::Options attr_accessor :github - attr_accessor :se_index + attr_accessor :search_index end class RDoc::AnyMethod @@ -120,9 +120,14 @@ class RDoc::Generator::SDoc attr_reader :options + ## + # The RDoc::Store that is the source of the generated content + + attr_reader :store + def self.setup_options(options) @github = false - options.se_index = true + options.search_index = true opt = options.option_parser opt.separator nil @@ -134,25 +139,27 @@ def self.setup_options(options) end opt.separator nil - opt.on("--no-se-index", "-ns", + opt.on("--without-search", "-s", "Do not generated index file for search engines.", "SDoc uses javascript to refrence individual documentation pages.", "Search engine crawlers are not smart enough to find all the", "referenced pages.", "To help them SDoc generates a static file with links to every", "documentation page. This file is not shown to the user." - ) do |value| - options.se_index = false + ) do + options.search_index = false end opt.separator nil end - def initialize(options) + def initialize(store, options) + @store = store @options = options if @options.respond_to?('diagram=') @options.diagram = false end + @options.pipe = true @github_url_cache = {} @template_dir = Pathname.new(options.template_dir) @@ -161,19 +168,19 @@ def initialize(options) @json_index = RDoc::Generator::JsonIndex.new self, options end - def generate(top_levels) + def generate @outputdir = Pathname.new(@options.op_dir).expand_path(@base_dir) - @files = top_levels.sort - @classes = RDoc::TopLevel.all_classes_and_modules.sort + @files = @store.all_files.sort + @classes = @store.all_classes_and_modules.sort # Now actually write the output copy_resources generate_class_tree - @json_index.generate top_levels + @json_index.generate generate_file_files generate_class_files generate_index_file - generate_se_index if @options.se_index + generate_search_index if @options.search_index end def class_dir @@ -352,9 +359,9 @@ def generate_index_file end ### Generate file with links for the search engine - def generate_se_index + def generate_search_index debug_msg "Generating search engine index in #@outputdir" - templatefile = @template_dir + 'se_index.rhtml' + templatefile = @template_dir + 'search_index.rhtml' outfile = @outputdir + 'panel/links.html' self.render_template( templatefile, binding(), outfile ) unless @options.dry_run diff --git a/lib/sdoc/github.rb b/lib/sdoc/github.rb index 37c149be..7cab6e85 100644 --- a/lib/sdoc/github.rb +++ b/lib/sdoc/github.rb @@ -2,7 +2,7 @@ module SDoc::GitHub def github_url(path) unless @github_url_cache.has_key? path @github_url_cache[path] = false - file = RDoc::TopLevel.find_file_named(path) + file = @store.find_file_named(path) if file base_url = repository_url(path) if base_url @@ -16,7 +16,7 @@ def github_url(path) end @github_url_cache[path] end - + protected def have_git? @@ -33,7 +33,7 @@ def commit_sha1(path) 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 @@ -51,7 +51,7 @@ def path_relative_to_repository(path) def path_to_git_dir(path) while !path.empty? && path != '.' - if (File.exists? File.join(path, '.git')) + if (File.exists? File.join(path, '.git')) return path end path = File.dirname(path) diff --git a/lib/sdoc/templatable.rb b/lib/sdoc/templatable.rb index 0e2a376c..fea11381 100644 --- a/lib/sdoc/templatable.rb +++ b/lib/sdoc/templatable.rb @@ -20,7 +20,7 @@ def eval_template(templatefile, 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 = {}) @@ -28,13 +28,13 @@ def include_template(template_name, local_assigns = {}) 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