├── .gitignore
├── lib
├── rdoc
│ ├── discover.rb
│ └── generator
│ │ └── template
│ │ ├── sdoc
│ │ ├── resources
│ │ │ ├── favicon.ico
│ │ │ ├── i
│ │ │ │ ├── arrows.png
│ │ │ │ ├── tree_bg.png
│ │ │ │ └── results_bg.png
│ │ │ ├── apple-touch-icon.png
│ │ │ ├── js
│ │ │ │ ├── main.js
│ │ │ │ ├── highlight.pack.js
│ │ │ │ ├── searchdoc.js
│ │ │ │ └── jquery-effect.js
│ │ │ ├── css
│ │ │ │ ├── reset.css
│ │ │ │ ├── github.css
│ │ │ │ ├── main.css
│ │ │ │ └── panel.css
│ │ │ └── panel
│ │ │ │ └── index.html
│ │ ├── se_index.rhtml
│ │ ├── index.rhtml
│ │ ├── _head.rhtml
│ │ ├── file.rhtml
│ │ ├── class.rhtml
│ │ └── _context.rhtml
│ │ ├── rails
│ │ ├── resources
│ │ │ ├── favicon.ico
│ │ │ ├── i
│ │ │ │ ├── arrows.png
│ │ │ │ ├── tree_bg.png
│ │ │ │ └── results_bg.png
│ │ │ ├── apple-touch-icon.png
│ │ │ ├── js
│ │ │ │ ├── main.js
│ │ │ │ ├── highlight.pack.js
│ │ │ │ ├── searchdoc.js
│ │ │ │ └── jquery-effect.js
│ │ │ ├── css
│ │ │ │ ├── reset.css
│ │ │ │ ├── github.css
│ │ │ │ ├── main.css
│ │ │ │ └── panel.css
│ │ │ └── panel
│ │ │ │ └── index.html
│ │ ├── se_index.rhtml
│ │ ├── index.rhtml
│ │ ├── _head.rhtml
│ │ ├── file.rhtml
│ │ ├── class.rhtml
│ │ └── _context.rhtml
│ │ └── merge
│ │ └── index.rhtml
├── sdoc.rb
└── sdoc
│ ├── helpers.rb
│ ├── github.rb
│ ├── templatable.rb
│ ├── merge.rb
│ └── generator.rb
├── Rakefile
├── .rake_tasks~
├── bin
├── sdoc-merge
└── sdoc
├── sdoc.gemspec
├── README.rdoc
└── LICENSE
/.gitignore:
--------------------------------------------------------------------------------
1 | pkg
2 | doc
3 | /test.rb
--------------------------------------------------------------------------------
/lib/rdoc/discover.rb:
--------------------------------------------------------------------------------
1 | begin
2 | gem 'rdoc', '~> 3'
3 | require File.join(File.dirname(__FILE__), '/../sdoc')
4 | rescue Gem::LoadError
5 | end
6 |
--------------------------------------------------------------------------------
/lib/sdoc.rb:
--------------------------------------------------------------------------------
1 | $:.unshift File.dirname(__FILE__)
2 | require "rubygems"
3 | gem 'rdoc', '~> 3'
4 |
5 | module SDoc end
6 |
7 | require 'sdoc/generator'
8 |
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/resources/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/sdoc/master/lib/rdoc/generator/template/sdoc/resources/favicon.ico
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/resources/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/sdoc/master/lib/rdoc/generator/template/rails/resources/favicon.ico
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/resources/i/arrows.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/sdoc/master/lib/rdoc/generator/template/rails/resources/i/arrows.png
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/resources/i/tree_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/sdoc/master/lib/rdoc/generator/template/rails/resources/i/tree_bg.png
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/resources/i/arrows.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/sdoc/master/lib/rdoc/generator/template/sdoc/resources/i/arrows.png
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/resources/i/tree_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/sdoc/master/lib/rdoc/generator/template/sdoc/resources/i/tree_bg.png
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/resources/i/results_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/sdoc/master/lib/rdoc/generator/template/sdoc/resources/i/results_bg.png
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/resources/i/results_bg.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/sdoc/master/lib/rdoc/generator/template/rails/resources/i/results_bg.png
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/resources/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/sdoc/master/lib/rdoc/generator/template/rails/resources/apple-touch-icon.png
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/resources/apple-touch-icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/bloopletech/sdoc/master/lib/rdoc/generator/template/sdoc/resources/apple-touch-icon.png
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/se_index.rhtml:
--------------------------------------------------------------------------------
1 |
2 |
File index
3 |
4 | <% @files.each do |file| %>
5 | <%= file.relative_name %>
6 | <% end %>
7 |
8 |
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/se_index.rhtml:
--------------------------------------------------------------------------------
1 |
2 | File index
3 |
4 | <% @files.each do |file| %>
5 | <%= file.relative_name %>
6 | <% end %>
7 |
8 |
--------------------------------------------------------------------------------
/Rakefile:
--------------------------------------------------------------------------------
1 | require 'rubygems'
2 |
3 | require 'bundler'
4 | Bundler::GemHelper.install_tasks
5 |
6 | gem 'rspec', '>= 2.5.0'
7 | require 'rspec/core/rake_task'
8 |
9 | desc "Run all specs"
10 | RSpec::Core::RakeTask.new(:spec)
11 | task :default => :spec
12 | task :test => :spec
13 |
--------------------------------------------------------------------------------
/.rake_tasks~:
--------------------------------------------------------------------------------
1 | build
2 | check_dependencies
3 | check_dependencies:development
4 | check_dependencies:runtime
5 | gem_file_list
6 | gemspec
7 | gemspec:debug
8 | gemspec:generate
9 | gemspec:validate
10 | ghost
11 | git:release
12 | github:release
13 | install
14 | release
15 | test
16 | version
17 | version:bump:major
18 | version:bump:minor
19 | version:bump:patch
20 | version:write
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/resources/js/main.js:
--------------------------------------------------------------------------------
1 | function toggleSource(id)
2 | {
3 | var src = $('#' + id).toggle();
4 | var isVisible = src.is(':visible');
5 | $('#l_' + id).html(isVisible ? 'hide' : 'show');
6 | }
7 |
8 | window.highlight = function(url) {
9 | var hash = url.match(/#([^#]+)$/)
10 | if(hash) {
11 | $('a[name=' + hash[1] + ']').parent().effect('highlight', {}, 'slow')
12 | }
13 | }
14 |
15 | $(function() {
16 | highlight('#' + location.hash);
17 | $('.description pre').each(function() {
18 | hljs.highlightBlock(this);
19 | });
20 | });
21 |
--------------------------------------------------------------------------------
/bin/sdoc-merge:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby -KU
2 | require File.dirname(__FILE__) + '/../lib/sdoc' # add extensions
3 | require 'sdoc/merge'
4 |
5 | begin
6 | m = SDoc::Merge.new
7 | m.merge(ARGV)
8 | rescue SystemExit
9 | raise
10 | rescue Exception => e
11 | if $DEBUG_RDOC then
12 | $stderr.puts e.message
13 | $stderr.puts "#{e.backtrace.join "\n\t"}"
14 | $stderr.puts
15 | elsif Interrupt === e then
16 | $stderr.puts
17 | $stderr.puts 'Interrupted'
18 | else
19 | $stderr.puts "uh-oh! SDoc merge had a problem:"
20 | $stderr.puts e.message
21 | end
22 | exit 1
23 | end
24 |
25 |
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/merge/index.rhtml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 |
8 | <%= @title %>
9 |
10 |
14 |
15 |
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/index.rhtml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 | <%= @options.title %>
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/index.rhtml:
--------------------------------------------------------------------------------
1 |
4 |
5 |
6 |
7 | <%= @options.title %>
8 |
9 |
13 |
14 |
--------------------------------------------------------------------------------
/bin/sdoc:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env ruby -KU
2 | require 'sdoc'
3 |
4 | begin
5 | ARGV.push('--format=sdoc') if ARGV.grep(/\A(-f|--fmt|--format|-r|-R|--ri|--ri-site)\b/).empty?
6 | r = RDoc::RDoc.new
7 | r.document ARGV
8 | rescue SystemExit
9 | raise
10 | rescue Exception => e
11 | if $DEBUG_RDOC then
12 | $stderr.puts e.message
13 | $stderr.puts "#{e.backtrace.join "\n\t"}"
14 | $stderr.puts
15 | elsif Interrupt === e then
16 | $stderr.puts
17 | $stderr.puts 'Interrupted'
18 | else
19 | $stderr.puts "uh-oh! RDoc had a problem:"
20 | $stderr.puts e.message
21 | $stderr.puts
22 | $stderr.puts "run with --debug for full backtrace"
23 | end
24 |
25 | exit 1
26 | end
27 |
28 |
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/resources/js/main.js:
--------------------------------------------------------------------------------
1 | function toggleSource(id)
2 | {
3 | var src = $('#' + id).toggle();
4 | var isVisible = src.is(':visible');
5 | $('#l_' + id).html(isVisible ? 'hide' : 'show');
6 | if (!src.data('syntax-higlighted')) {
7 | src.data('syntax-higlighted', 1);
8 | hljs.highlightBlock(src[0]);
9 | }
10 | }
11 |
12 | window.highlight = function(url) {
13 | var hash = url.match(/#([^#]+)$/)
14 | if(hash) {
15 | $('a[name=' + hash[1] + ']').parent().effect('highlight', {}, 'slow')
16 | }
17 | }
18 |
19 | $(function() {
20 | highlight('#' + location.hash);
21 | $('.description pre').each(function() {
22 | hljs.highlightBlock(this);
23 | });
24 | });
25 |
--------------------------------------------------------------------------------
/lib/sdoc/helpers.rb:
--------------------------------------------------------------------------------
1 | module SDoc::Helpers
2 | def each_letter_group(methods, &block)
3 | group = {:name => '', :methods => []}
4 | methods.sort{ |a, b| a.name <=> b.name }.each do |method|
5 | gname = group_name method.name
6 | if gname != group[:name]
7 | yield group unless group[:methods].size == 0
8 | group = {
9 | :name => gname,
10 | :methods => []
11 | }
12 | end
13 | group[:methods].push(method)
14 | end
15 | yield group unless group[:methods].size == 0
16 | end
17 |
18 | protected
19 | def group_name name
20 | if match = name.match(/^([a-z])/i)
21 | match[1].upcase
22 | else
23 | '#'
24 | end
25 | end
26 | end
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/_head.rhtml:
--------------------------------------------------------------------------------
1 | " type="text/css" media="screen" />
2 | " type="text/css" media="screen" />
3 | " type="text/css" media="screen" />
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/_head.rhtml:
--------------------------------------------------------------------------------
1 | " type="text/css" media="screen" />
2 | " type="text/css" media="screen" />
3 | " type="text/css" media="screen" />
4 |
5 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/sdoc.gemspec:
--------------------------------------------------------------------------------
1 | # -*- encoding: utf-8 -*-
2 |
3 | Gem::Specification.new do |s|
4 | s.name = "sdoc"
5 | s.version = "0.3.15"
6 |
7 | s.authors = ["Vladimir Kolesnikov"]
8 | s.description = %q{rdoc generator html with javascript search index.}
9 | s.summary = %q{rdoc html with javascript search index.}
10 | s.homepage = %q{http://github.com/voloko/sdoc}
11 | s.email = %q{voloko@gmail.com}
12 |
13 | s.required_rubygems_version = Gem::Requirement.new(">= 1.3.6") if
14 | s.respond_to? :required_rubygems_version=
15 |
16 | s.rdoc_options = ["--charset=UTF-8"]
17 | s.extra_rdoc_files = ["README.rdoc"]
18 |
19 | s.add_runtime_dependency('rdoc', "~> 3.10")
20 | if defined?(JRUBY_VERSION)
21 | s.platform = Gem::Platform.new(['universal', 'java', nil])
22 | s.add_runtime_dependency("json_pure", ">= 1.1.3")
23 | else
24 | s.add_runtime_dependency("json", ">= 1.1.3")
25 | end
26 |
27 | s.files = `git ls-files`.split("\n")
28 | s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
29 | s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
30 | end
31 |
32 |
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/resources/css/reset.css:
--------------------------------------------------------------------------------
1 | /* http://meyerweb.com/eric/tools/css/reset/ */
2 | /* v1.0 | 20080212 */
3 |
4 | html, body, div, span, applet, object, iframe,
5 | h1, h2, h3, h4, h5, h6, p, blockquote, pre,
6 | a, abbr, acronym, address, big, cite, code,
7 | del, dfn, em, font, img, ins, kbd, q, s, samp,
8 | small, strike, strong, sub, sup, tt, var,
9 | b, u, i, center,
10 | dl, dt, dd, ol, ul, li,
11 | fieldset, form, label, legend,
12 | table, caption, tbody, tfoot, thead, tr, th, td {
13 | margin: 0;
14 | padding: 0;
15 | border: 0;
16 | outline: 0;
17 | font-size: 100%;
18 | vertical-align: baseline;
19 | background: transparent;
20 | }
21 | body {
22 | line-height: 1;
23 | }
24 | ol, ul {
25 | list-style: none;
26 | }
27 | blockquote, q {
28 | quotes: none;
29 | }
30 | blockquote:before, blockquote:after,
31 | q:before, q:after {
32 | content: '';
33 | content: none;
34 | }
35 |
36 | /* remember to highlight inserts somehow! */
37 | ins {
38 | text-decoration: none;
39 | }
40 | del {
41 | text-decoration: line-through;
42 | }
43 |
44 | /* tables still need 'cellspacing="0"' in the markup */
45 | table {
46 | border-collapse: collapse;
47 | border-spacing: 0;
48 | }
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/resources/css/reset.css:
--------------------------------------------------------------------------------
1 | /* http://meyerweb.com/eric/tools/css/reset/ */
2 | /* v1.0 | 20080212 */
3 |
4 | html, body, div, span, applet, object, iframe,
5 | h1, h2, h3, h4, h5, h6, p, blockquote, pre,
6 | a, abbr, acronym, address, big, cite, code,
7 | del, dfn, em, font, img, ins, kbd, q, s, samp,
8 | small, strike, strong, sub, sup, tt, var,
9 | b, u, i, center,
10 | dl, dt, dd, ol, ul, li,
11 | fieldset, form, label, legend,
12 | table, caption, tbody, tfoot, thead, tr, th, td {
13 | margin: 0;
14 | padding: 0;
15 | border: 0;
16 | outline: 0;
17 | font-size: 100%;
18 | vertical-align: baseline;
19 | background: transparent;
20 | }
21 | body {
22 | line-height: 1;
23 | }
24 | ol, ul {
25 | list-style: none;
26 | }
27 | blockquote, q {
28 | quotes: none;
29 | }
30 | blockquote:before, blockquote:after,
31 | q:before, q:after {
32 | content: '';
33 | content: none;
34 | }
35 |
36 | /* remember to highlight inserts somehow! */
37 | ins {
38 | text-decoration: none;
39 | }
40 | del {
41 | text-decoration: line-through;
42 | }
43 |
44 | /* tables still need 'cellspacing="0"' in the markup */
45 | table {
46 | border-collapse: collapse;
47 | border-spacing: 0;
48 | }
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/file.rhtml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 | <%= h file.name %>
7 |
8 | <%= include_template '_head.rhtml', {:rel_prefix => rel_prefix} %>
9 |
10 |
11 |
12 |
13 | <% if ENV['HORO_PROJECT_NAME'] %>
14 |
<%= ERB::Util.html_escape(ENV['HORO_PROJECT_NAME']) %> <%= ERB::Util.html_escape(ENV['HORO_PROJECT_VERSION']) %>
15 | <% end %>
16 |
17 | <%= h file.name %>
18 |
19 |
20 | - <%= h file.relative_name %>
21 | - Last modified: <%= file.file_stat.mtime %>
22 |
23 |
24 |
25 |
26 | <%= include_template '_context.rhtml', {:context => file, :rel_prefix => rel_prefix} %>
27 |
28 |
29 |
--------------------------------------------------------------------------------
/README.rdoc:
--------------------------------------------------------------------------------
1 | = SDoc
2 | == What's in?
3 | - shtml - RDoc's generator to build searchable documentation
4 | - sdoc-merge - comand line tool to build merge multiple sdoc documentations
5 | packages into a single one
6 | - sdoc - command line tool to run rdoc with generator=shtml
7 |
8 | == Getting Started
9 | sudo gem install sdoc
10 | sdoc -N projectdir
11 |
12 | == Command line sdoc
13 | sdoc is simply a wrapper to rdoc command line tool. see sdoc --help
14 | for more details. --fmt is set to shtml by default.
15 | Default template -T is shtml. You can also use 'direct' template.
16 | Example:
17 | sdoc -o doc/rails -T direct rails
18 |
19 | == Rake
20 | # Rakefile
21 | require 'sdoc' # and use your RDoc task the same way you used it before
22 |
23 | Rake::RDocTask.new do |rdoc|
24 | rdoc.rdoc_dir = 'doc/rdoc'
25 | rdoc.options << '--fmt' << 'shtml' # explictly set shtml generator
26 | rdoc.template = 'direct' # lighter template used on railsapi.com
27 | ...
28 | end
29 |
30 | == sdoc-merge
31 | Usage: sdoc-merge [options] directories
32 | -n, --names [NAMES] Names of merged repositories. Comma separated
33 | -o, --op [DIRECTORY] Set the output directory
34 | -t, --title [TITLE] Set the title of merged file
35 |
36 | Example:
37 | sdoc-merge --title "Ruby v1.9, Rails v2.3.2.1" --op merged --names "Ruby,Rails" ruby-v1.9 rails-v2.3.2.1
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/file.rhtml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 | <%= h file.name %>
7 |
8 | <%= include_template '_head.rhtml', {:rel_prefix => rel_prefix} %>
9 |
10 |
11 |
12 |
13 | <% if ENV['HORO_PROJECT_NAME'] %>
14 |
<%= ERB::Util.html_escape(ENV['HORO_PROJECT_NAME']) %> <%= ERB::Util.html_escape(ENV['HORO_PROJECT_VERSION']) %>
15 | <% end %>
16 |
17 | <%= h file.name %>
18 |
19 |
20 | <%
21 | github = github_url(file.relative_name) if options.github
22 | %>
23 | -
24 | <%= h file.relative_name %>
25 | <% if github %>
26 | on GitHub
27 | <% end %>
28 |
29 | - Last modified: <%= file.file_stat.mtime %>
30 |
31 |
32 |
33 |
34 | <%= include_template '_context.rhtml', {:context => file, :rel_prefix => rel_prefix} %>
35 |
36 |
37 |
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/rails/class.rhtml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 | <%= h klass.full_name %>
7 |
8 | <%= include_template '_head.rhtml', {:rel_prefix => rel_prefix} %>
9 |
10 |
11 |
12 |
13 | <% if ENV['HORO_PROJECT_NAME'] %>
14 |
<%= ERB::Util.html_escape(ENV['HORO_PROJECT_NAME']) %> <%= ERB::Util.html_escape(ENV['HORO_PROJECT_VERSION']) %>
15 | <% end %>
16 |
17 | <%= klass.module? ? 'Module' : 'Class' %>
18 | <%= h klass.full_name %>
19 | <% if klass.type == 'class' %>
20 | <
21 | <% if String === klass.superclass %>
22 | <%= klass.superclass %>
23 | <% elsif !klass.superclass.nil? %>
24 | <%= h klass.superclass.full_name %>
25 | <% end %>
26 |
27 | <% end %>
28 |
29 |
34 |
35 |
36 | <%= include_template '_context.rhtml', {:context => klass, :rel_prefix => rel_prefix} %>
37 |
38 |
39 |
--------------------------------------------------------------------------------
/lib/rdoc/generator/template/sdoc/class.rhtml:
--------------------------------------------------------------------------------
1 |
2 |
4 |
5 |
6 | <%= h klass.full_name %>
7 |
8 | <%= include_template '_head.rhtml', {:rel_prefix => rel_prefix} %>
9 |
10 |
11 |
12 |
13 | <% if ENV['HORO_PROJECT_NAME'] %>
14 |
<%= ERB::Util.html_escape(ENV['HORO_PROJECT_NAME']) %> <%= ERB::Util.html_escape(ENV['HORO_PROJECT_VERSION']) %>
15 | <% end %>
16 |
17 | <%= klass.module? ? 'Module' : 'Class' %>
18 | <%= h klass.full_name %>
19 | <% if klass.type == 'class' %>
20 | <
21 | <% if String === klass.superclass %>
22 | <%= klass.superclass %>
23 | <% elsif !klass.superclass.nil? %>
24 | <%= h klass.superclass.full_name %>
25 | <% end %>
26 |
27 | <% end %>
28 |
29 |
34 |
35 |
36 | <%= include_template '_context.rhtml', {:context => klass, :rel_prefix => rel_prefix} %>
37 |
38 |
39 |
--------------------------------------------------------------------------------
/lib/sdoc/github.rb:
--------------------------------------------------------------------------------
1 | module SDoc::GitHub
2 | def github_url(path)
3 | unless @github_url_cache.has_key? path
4 | @github_url_cache[path] = false
5 | file = RDoc::TopLevel.find_file_named(path)
6 | if file
7 | base_url = repository_url(path)
8 | if base_url
9 | sha1 = commit_sha1(path)
10 | if sha1
11 | relative_url = path_relative_to_repository(path)
12 | @github_url_cache[path] = "#{base_url}#{sha1}#{relative_url}"
13 | end
14 | end
15 | end
16 | end
17 | @github_url_cache[path]
18 | end
19 |
20 | protected
21 |
22 | def have_git?
23 | @have_git = system('git --version > /dev/null 2>&1') if @have_git.nil?
24 | @have_git
25 | end
26 |
27 | def commit_sha1(path)
28 | return false unless have_git?
29 | name = File.basename(path)
30 | s = Dir.chdir(File.join(basedir, File.dirname(path))) do
31 | `git log -1 --pretty=format:"commit %H" #{name}`
32 | end
33 | m = s.match(/commit\s+(\S+)/)
34 | m ? m[1] : false
35 | end
36 |
37 | def repository_url(path)
38 | return false unless have_git?
39 | s = Dir.chdir(File.join(basedir, File.dirname(path))) do
40 | `git config --get remote.origin.url`
41 | end
42 | m = s.match(%r{github.com[/:](.*)\.git$})
43 | m ? "https://github.com/#{m[1]}/blob/" : false
44 | end
45 |
46 | def path_relative_to_repository(path)
47 | absolute_path = File.join(basedir, path)
48 | root = path_to_git_dir(File.dirname(absolute_path))
49 | absolute_path[root.size..absolute_path.size]
50 | end
51 |
52 | def path_to_git_dir(path)
53 | while !path.empty? && path != '.'
54 | if (File.exists? File.join(path, '.git'))
55 | return path
56 | end
57 | path = File.dirname(path)
58 | end
59 | ''
60 | end
61 | end
62 |
--------------------------------------------------------------------------------
/lib/sdoc/templatable.rb:
--------------------------------------------------------------------------------
1 | require 'erb'
2 | require "sdoc"
3 |
4 | module SDoc::Templatable
5 | ### Load and render the erb template in the given +templatefile+ within the
6 | ### specified +context+ (a Binding object) and return output
7 | ### Both +templatefile+ and +outfile+ should be Pathname-like objects.
8 | def eval_template(templatefile, context)
9 | template_src = templatefile.read
10 | template = ERB.new( template_src, nil, '<>' )
11 | template.filename = templatefile.to_s
12 |
13 | begin
14 | template.result( context )
15 | rescue NoMethodError => err
16 | raise RDoc::Error, "Error while evaluating %s: %s (at %p)" % [
17 | templatefile.to_s,
18 | err.message,
19 | eval( "_erbout[-50,50]", context )
20 | ], err.backtrace
21 | end
22 | end
23 |
24 | ### Load and render the erb template with the given +template_name+ within
25 | ### current context. Adds all +local_assigns+ to context
26 | def include_template(template_name, local_assigns = {})
27 | source = local_assigns.keys.map { |key| "#{key} = local_assigns[:#{key}];" }.join
28 | templatefile = @template_dir + template_name
29 | eval("#{source};eval_template(templatefile, binding)")
30 | end
31 |
32 | ### Load and render the erb template in the given +templatefile+ within the
33 | ### specified +context+ (a Binding object) and write it out to +outfile+.
34 | ### Both +templatefile+ and +outfile+ should be Pathname-like objects.
35 | def render_template( templatefile, context, outfile )
36 | output = eval_template(templatefile, context)
37 |
38 | # TODO delete this dirty hack when documentation for example for GeneratorMethods will not be cutted off by
11 |
12 |
13 |
14 |
15 |
50 |
51 |
52 |
71 | index
72 |
73 |