Skip to content

Commit

Permalink
fix broken code formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
voloko committed Aug 29, 2011
1 parent e953c8d commit 663e92c
Show file tree
Hide file tree
Showing 10 changed files with 181 additions and 32 deletions.
16 changes: 9 additions & 7 deletions lib/rdoc/generator/template/rails/_context.rhtml
Expand Up @@ -121,7 +121,7 @@
<div class="sectiontitle"><%= type.capitalize %> <%= visibility.to_s.capitalize %> methods</div>
<% methods.each do |method| %>
<div class="method">
<div class="title" id="<%= method.aref %>">
<div class="title method-title" id="<%= method.aref %>">
<% if method.call_seq %>
<a name="<%= method.aref %>"></a><b><%= method.call_seq.gsub(/->/, '&rarr;') %></b>
<% else %>
Expand All @@ -142,24 +142,26 @@
</div>
<% end %>
<% if method.token_stream %>
<% markup = method.markup_code %>
<% markup = method.sdoc_markup_code %>
<div class="sourcecode">
<p class="source-link">
Source: <a href="javascript:toggleSource('<%= method.aref %>_source')" id="l_<%= method.aref %>_source">show</a>
<%
if options.github
if markup =~ /File\s(\S+), line (\d+)/
path = $1
line = $2.to_i
end
github = github_url(path)
if github
%>
<%
if options.github && path
github = github_url(path)
if github
%>
| <a href="<%= "#{github}#L#{line}" %>" target="_blank" class="github_url">on GitHub</a>
<% end end %>
</p>
<div id="<%= method.aref %>_source" class="dyn-source x">
<pre><%= method.markup_code %></pre>
<div id="<%= method.aref %>_source" class="dyn-source">
<pre><%= markup %></pre>
</div>
</div>
<% end %>
Expand Down
45 changes: 42 additions & 3 deletions lib/rdoc/generator/template/rails/resources/css/main.css
Expand Up @@ -147,7 +147,7 @@ ol li
margin-bottom: 0;
}

pre
pre
{
margin-bottom: 1em;
}
Expand Down Expand Up @@ -261,7 +261,7 @@ tt {
font-size: 1.1em;
color:#333;
}
.method .title {
.method .method-title {
border-bottom: 1px dotted #666;
padding: 0 0 0.15em 0;
margin: 0 0 0.5em 0;
Expand All @@ -284,4 +284,43 @@ tt {
.method .source-link
{
font-size: 0.85em;
}
}

.ruby-constant {
color: teal;
}
.ruby-keyword {
color: #000;
font-weight: bold
}
.ruby-title {
color: #900;
font-weight: bold;
}
.ruby-ivar {
color: teal;
}
.ruby-operator {
color: #000;
font-weight: bold
}
.ruby-identifier {
color: #000;
}
.ruby-string,
.ruby-node {
color: #D14;
}
.ruby-comment {
color: #998;
font-style: italic;
}
.ruby-regexp {
color: #009926;
}
.ruby-value {
color: #990073;
}
.ruby-number {
color: #40A070;
}
4 changes: 2 additions & 2 deletions lib/rdoc/generator/template/rails/resources/css/panel.css
Expand Up @@ -51,7 +51,7 @@
font-size: 12px;
line-height: 29px;
margin-left: 3px;
color: #999;
color: #777;
cursor: text;
}

Expand Down Expand Up @@ -127,7 +127,7 @@
.panel .result ul li h1 i,
.panel .result ul li p.snippet
{
color: #999;
color: #777;
}

.panel .result ul li b
Expand Down
6 changes: 1 addition & 5 deletions lib/rdoc/generator/template/rails/resources/js/main.js
@@ -1,12 +1,8 @@
function toggleSource( id )
function toggleSource(id)
{
var src = $('#' + id).toggle();
var isVisible = src.is(':visible');
$('#l_' + id).html(isVisible ? 'hide' : 'show');
if (!src.data('syntax-higlighted')) {
src.data('syntax-higlighted', 1);
hljs.highlightBlock(src[0]);
}
}

window.highlight = function(url) {
Expand Down
16 changes: 9 additions & 7 deletions lib/rdoc/generator/template/sdoc/_context.rhtml
Expand Up @@ -121,7 +121,7 @@
<div class="sectiontitle"><%= type.capitalize %> <%= visibility.to_s.capitalize %> methods</div>
<% methods.each do |method| %>
<div class="method">
<div class="title" id="<%= method.aref %>">
<div class="title method-title" id="<%= method.aref %>">
<% if method.call_seq %>
<a name="<%= method.aref %>"></a><b><%= method.call_seq.gsub(/->/, '&rarr;') %></b>
<% else %>
Expand All @@ -142,24 +142,26 @@
</div>
<% end %>
<% if method.token_stream %>
<% markup = method.markup_code %>
<% markup = method.sdoc_markup_code %>
<div class="sourcecode">
<p class="source-link">
Source: <a href="javascript:toggleSource('<%= method.aref %>_source')" id="l_<%= method.aref %>_source">show</a>
<%
if options.github
if markup =~ /File\s(\S+), line (\d+)/
path = $1
line = $2.to_i
end
github = github_url(path)
if github
%>
<%
if options.github && path
github = github_url(path)
if github
%>
| <a href="<%= "#{github}#L#{line}" %>" target="_blank" class="github_url">on GitHub</a>
<% end end %>
</p>
<div id="<%= method.aref %>_source" class="dyn-source x">
<pre><%= method.markup_code %></pre>
<div id="<%= method.aref %>_source" class="dyn-source">
<pre><%= markup %></pre>
</div>
</div>
<% end %>
Expand Down
43 changes: 41 additions & 2 deletions lib/rdoc/generator/template/sdoc/resources/css/main.css
Expand Up @@ -252,7 +252,7 @@ tt {
font-size: 1.1em;
color:#333;
}
.method .title {
.method .method-title {
border-bottom: 1px dotted #666;
padding: 0 0 0.15em 0;
margin: 0 0 0.5em 0;
Expand All @@ -275,4 +275,43 @@ tt {
.method .source-link
{
font-size: 0.85em;
}
}

.ruby-constant {
color: teal;
}
.ruby-keyword {
color: #000;
font-weight: bold
}
.ruby-title {
color: #900;
font-weight: bold;
}
.ruby-ivar {
color: teal;
}
.ruby-operator {
color: #000;
font-weight: bold
}
.ruby-identifier {
color: #000;
}
.ruby-string,
.ruby-node {
color: #D14;
}
.ruby-comment {
color: #998;
font-style: italic;
}
.ruby-regexp {
color: #009926;
}
.ruby-value {
color: #990073;
}
.ruby-number {
color: #40A070;
}
2 changes: 1 addition & 1 deletion lib/rdoc/generator/template/sdoc/resources/js/main.js
@@ -1,4 +1,4 @@
function toggleSource( id )
function toggleSource(id)
{
var src = $('#' + id).toggle();
var isVisible = src.is(':visible');
Expand Down
75 changes: 73 additions & 2 deletions lib/sdoc/generator.rb
Expand Up @@ -31,6 +31,77 @@ class RDoc::Options
attr_accessor :se_index
end

class RDoc::AnyMethod

TITLE_AFTER = %w(def class module)

##
# Turns the method's token stream into HTML.
#
# Prepends line numbers if +add_line_numbers+ is true.

def sdoc_markup_code
return '' unless @token_stream

src = ""
starting_title = false

@token_stream.each do |t|
next unless t

style = case t
when RDoc::RubyToken::TkFLOAT then 'ruby-number'
when RDoc::RubyToken::TkINTEGER then 'ruby-number'
when RDoc::RubyToken::TkCONSTANT then 'ruby-constant'
when RDoc::RubyToken::TkKW then 'ruby-keyword'
when RDoc::RubyToken::TkIVAR then 'ruby-ivar'
when RDoc::RubyToken::TkOp then 'ruby-operator'
when RDoc::RubyToken::TkId then 'ruby-identifier'
when RDoc::RubyToken::TkNode then 'ruby-node'
when RDoc::RubyToken::TkCOMMENT then 'ruby-comment'
when RDoc::RubyToken::TkREGEXP then 'ruby-regexp'
when RDoc::RubyToken::TkSTRING then 'ruby-string'
when RDoc::RubyToken::TkVal then 'ruby-value'
end

if RDoc::RubyToken::TkId === t && starting_title
starting_title = false
style = 'ruby-keyword ruby-title'
end

if RDoc::RubyToken::TkKW === t && TITLE_AFTER.include?(t.text)
starting_title = true
end

text = CGI.escapeHTML t.text

if style then
src << "<span class=\"#{style}\">#{text}</span>"
else
src << text
end
end

# dedent the source
indent = src.length
lines = src.lines.to_a
lines.shift if src =~ /\A.*#\ *File/i # remove '# File' comment
lines.each do |line|
if line =~ /^ *(?=\S)/
n = $&.length
indent = n if n < indent
break if n == 0
end
end
src.gsub!(/^#{' ' * indent}/, '') if indent > 0

add_line_numbers(src) if self.class.add_line_numbers

src
end

end

class RDoc::Generator::SDoc
RDoc::RDoc.add_generator self

Expand Down Expand Up @@ -85,7 +156,7 @@ def self.setup_options(options)
options.se_index = false
end
opt.separator nil

end

def initialize(options)
Expand All @@ -94,7 +165,7 @@ def initialize(options)
@options.diagram = false
end
@github_url_cache = {}

@template_dir = Pathname.new(options.template_dir)
@basedir = Pathname.pwd.expand_path
end
Expand Down
2 changes: 1 addition & 1 deletion lib/sdoc/github.rb
Expand Up @@ -40,7 +40,7 @@ def repository_url(path)
`git config --get remote.origin.url`
end
m = s.match(%r{github.com[/:](.*)\.git$})
m ? "http://github.com/#{m[1]}/blob/" : false
m ? "https://github.com/#{m[1]}/blob/" : false
end

def path_relative_to_repository(path)
Expand Down
4 changes: 2 additions & 2 deletions sdoc.gemspec
Expand Up @@ -2,11 +2,11 @@

Gem::Specification.new do |s|
s.name = "sdoc"
s.version = "0.3.3"
s.version = "0.3.5"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Vladimir Kolesnikov"]
s.date = %q{2011-09-24}
s.date = %q{2011-09-27}
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 Down

0 comments on commit 663e92c

Please sign in to comment.