Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
*.gem
.bundle
pkg
doc
/test.rb
/test.rb
Gemfile.lock
3 changes: 3 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
source "https://rubygems.org"

gemspec
13 changes: 7 additions & 6 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/rdoc/discover.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
begin
gem 'rdoc', '~> 3'
gem 'rdoc', '~> 4.0.0'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you think about allowing ~> 4.0 ? All the tests are green locally with ruby/rdoc#279

By the way thanks for your work, everything seems fine on Rails' master with your branch! ❤️

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could do ~> 4.0 and < 5.0

I'll work out the version dependency soon

require File.join(File.dirname(__FILE__), '/../sdoc')
rescue Gem::LoadError
end
4 changes: 2 additions & 2 deletions lib/rdoc/generator/template/sdoc/file.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
</h1>
<ul class="files">
<li><%= h file.relative_name %></li>
<li>Last modified: <%= file.file_stat.mtime %></li>
<li>Last modified: <%= file.last_modified %></li>
</ul>
</div>

<div id="bodyContent">
<%= include_template '_context.rhtml', {:context => file, :rel_prefix => rel_prefix} %>
</div>
</body>
</html>
</html>
4 changes: 2 additions & 2 deletions lib/sdoc.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
$:.unshift File.dirname(__FILE__)
require "rubygems"
gem 'rdoc', '~> 3'
gem 'rdoc'

module SDoc end

require 'sdoc/generator'
33 changes: 20 additions & 13 deletions lib/sdoc/generator.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions lib/sdoc/github.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +16,7 @@ def github_url(path)
end
@github_url_cache[path]
end

protected

def have_git?
Expand All @@ -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
Expand All @@ -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)
Expand Down
14 changes: 7 additions & 7 deletions lib/sdoc/templatable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,21 @@ 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 = {})
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 <script> tag
begin
if output.respond_to? :force_encoding
Expand All @@ -44,9 +44,9 @@ def render_template( templatefile, context, outfile )
output = output.gsub('<script>', '&lt;script&gt;')
end
rescue Exception => e

end

unless $dryrun
outfile.dirname.mkpath
outfile.open( 'w', 0644 ) do |file|
Expand All @@ -56,5 +56,5 @@ def render_template( templatefile, context, outfile )
debug_msg " would have written %d bytes to %s" %
[ output.length, outfile ]
end
end
end
end
end
12 changes: 8 additions & 4 deletions sdoc.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

Gem::Specification.new do |s|
s.name = "sdoc"
s.version = "0.3.20"
s.version = "0.4.0"

s.authors = ["Vladimir Kolesnikov", "Nathan Broadbent"]
s.authors = ["Vladimir Kolesnikov", "Nathan Broadbent", "Jean Mertz"]
s.description = %q{rdoc generator html with javascript search index.}
s.summary = %q{rdoc html with javascript search index.}
s.homepage = %q{http://github.com/voloko/sdoc}
Expand All @@ -16,16 +16,20 @@ Gem::Specification.new do |s|
s.rdoc_options = ["--charset=UTF-8"]
s.extra_rdoc_files = ["README.md"]

s.add_runtime_dependency('rdoc', "~> 3.10")
s.add_runtime_dependency('rdoc', "~> 4.0", "< 5.0")

if defined?(JRUBY_VERSION)
s.platform = Gem::Platform.new(['universal', 'java', nil])
s.add_runtime_dependency("json_pure", ">= 1.1.3")
else
s.add_runtime_dependency("json", ">= 1.1.3")
end

s.add_development_dependency "bundler", "~> 1.3"
s.add_development_dependency "rake"
s.add_development_dependency "minitest"

s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
end

62 changes: 62 additions & 0 deletions spec/rdoc_generator_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
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
8 changes: 8 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'rubygems'
require 'bundler/setup'

require 'sdoc'

require 'rdoc/test_case'

require 'minitest/autorun'