From 466d40ed15bc057ff786e73fde58a1ee48effabe Mon Sep 17 00:00:00 2001 From: drbrain Date: Mon, 7 Jan 2008 10:40:50 +0000 Subject: [PATCH] Use ERB instead of custom template language for RDoc. Remove old_html template. Convert all templates to ERB. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14935 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 8 + lib/rdoc/generators/chm_generator.rb | 8 +- lib/rdoc/generators/template/chm/chm.rb | 45 +- lib/rdoc/generators/template/html/hefss.rb | 194 ++--- lib/rdoc/generators/template/html/html.rb | 350 ++++----- lib/rdoc/generators/template/html/kilmer.rb | 242 +++--- lib/rdoc/generators/template/html/old_html.rb | 728 ------------------ .../generators/template/html/one_page_html.rb | 163 ++-- lib/rdoc/generators/template/xml/rdf.rb | 135 ++-- lib/rdoc/generators/template/xml/xml.rb | 141 ++-- lib/rdoc/template.rb | 251 +----- 11 files changed, 690 insertions(+), 1575 deletions(-) delete mode 100644 lib/rdoc/generators/template/html/old_html.rb diff --git a/ChangeLog b/ChangeLog index 11e1acfc17..97161338df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +Mon Jan 7 19:39:50 2008 Eric Hodel + + * lib/rdoc/template.rb: Use ERB instead of custom template language. + + * lib/rdoc/generators/template/html/old_html.rb: Remove. + + * lib/rdoc/generators/template/*: Convert to ERB. + Mon Jan 7 19:11:30 2008 Yukihiro Matsumoto * string.c (Init_String): sym_match arity spec was wrong. a patch diff --git a/lib/rdoc/generators/chm_generator.rb b/lib/rdoc/generators/chm_generator.rb index b4a5167a5c..c3272c9af3 100644 --- a/lib/rdoc/generators/chm_generator.rb +++ b/lib/rdoc/generators/chm_generator.rb @@ -27,8 +27,6 @@ class RDoc::Generators::CHMGenerator < RDoc::Generators::HTMLGenerator "\n\nYou can download a copy for free from:\n\n" << " http://msdn.microsoft.com/library/default.asp?" << "url=/library/en-us/htmlhelp/html/hwMicrosoftHTMLHelpDownloads.asp\n\n" - - exit 99 end ## @@ -54,7 +52,7 @@ class RDoc::Generators::CHMGenerator < RDoc::Generators::HTMLGenerator # files that go to make up the help. def create_project_file - template = TemplatePage.new(RDoc::Page::HPP_FILE) + template = RDoc::TemplatePage.new RDoc::Page::HPP_FILE values = { "title" => @options.title, "opname" => @op_name } files = [] @files.each do |f| @@ -92,13 +90,13 @@ class RDoc::Generators::CHMGenerator < RDoc::Generators::HTMLGenerator end values = { "contents" => contents } - template = TemplatePage.new(RDoc::Page::CONTENTS) + template = RDoc::TemplatePage.new RDoc::Page::CONTENTS File.open("contents.hhc", "w") do |f| template.write_html_on(f, values) end values = { "index" => index } - template = TemplatePage.new(RDoc::Page::CHM_INDEX) + template = RDoc::TemplatePage.new RDoc::Page::CHM_INDEX File.open("index.hhk", "w") do |f| template.write_html_on(f, values) end diff --git a/lib/rdoc/generators/template/chm/chm.rb b/lib/rdoc/generators/template/chm/chm.rb index 4a89c26520..1932023416 100644 --- a/lib/rdoc/generators/template/chm/chm.rb +++ b/lib/rdoc/generators/template/chm/chm.rb @@ -1,5 +1,4 @@ -module RDoc -module Page +module RDoc::Page require "rdoc/generators/template/html/html" @@ -13,17 +12,17 @@ HPP_FILE = %{ [OPTIONS] Auto Index = Yes Compatibility=1.1 or later -Compiled file=%opname%.chm +Compiled file=<%= values["opname"] %>.chm Contents file=contents.hhc Full-text search=Yes Index file=index.hhk Language=0x409 English(United States) -Title=%title% +Title=<%= values["title"] %> [FILES] -START:all_html_files -%html_file_name% -END:all_html_files +<% values["all_html_files"].each do |all_html_files| %> +<%= all_html_files["html_file_name"] %> +<% end # values["all_html_files"] %> } CONTENTS = %{ @@ -39,28 +38,27 @@ CONTENTS = %{
    -START:contents +<% values["contents"].each do |contents| %>
  • - - + "> + "> -IF:methods +<% if contents["methods"] then %>
      -START:methods +<% contents["methods"].each do |methods| %>
    • - - + "> + "> -END:methods +<% end # contents["methods"] %>
    -ENDIF:methods +<% end %>
  • -END:contents +<% end # values["contents"] %>
} - CHM_INDEX = %{ @@ -74,14 +72,15 @@ CHM_INDEX = %{
    -START:index +<% values["index"].each do |index| %>
  • - - + "> + "> -END:index +<% end # values["index"] %>
} + end -end + diff --git a/lib/rdoc/generators/template/html/hefss.rb b/lib/rdoc/generators/template/html/hefss.rb index e68ca85823..a7baac6fd3 100644 --- a/lib/rdoc/generators/template/html/hefss.rb +++ b/lib/rdoc/generators/template/html/hefss.rb @@ -112,9 +112,9 @@ td { font-family: Verdana, Arial, Helvetica, sans-serif; BODY = %{ - %title% - - + <%= values["title"] %> + "> + " type="text/css" media="screen" /> -} +EOF ##################################################################### @@ -300,308 +300,308 @@ CONTEXT_CONTENT = %{ ##################################################################### ### F O O T E R T E M P L A T E ##################################################################### -FOOTER = %{ +FOOTER = <<-EOF -} +EOF ##################################################################### ### F I L E P A G E H E A D E R T E M P L A T E ##################################################################### -FILE_PAGE = %{ +FILE_PAGE = <<-EOF
-

%short_name%

+

<%= values["short_name"] %>

- - +
Path:%full_path% -IF:cvsurl -  (CVS) -ENDIF:cvsurl + <%= values["full_path"] %> +<% if values["cvsurl"] then %> +  (">CVS) +<% end %>
Last Update:%dtm_modified%<%= values["dtm_modified"] %>
-} +EOF ##################################################################### ### C L A S S P A G E H E A D E R T E M P L A T E ##################################################################### -CLASS_PAGE = %{ +CLASS_PAGE = <<-EOF
- - + + -IF:parent +<% if values["parent"] then %> -ENDIF:parent +<% end %>
%classmod%%full_name%<%= values["classmod"] %><%= values["full_name"] %>
In: -START:infiles -IF:full_path_url - -ENDIF:full_path_url - %full_path% -IF:full_path_url +<% values["infiles"].each do |infiles| %> +<% if infiles["full_path_url"] then %> + "> +<% end %> + <%= infiles["full_path"] %> +<% if infiles["full_path_url"] then %> -ENDIF:full_path_url -IF:cvsurl -  (CVS) -ENDIF:cvsurl +<% end %> +<% if infiles["cvsurl"] then %> +  (">CVS) +<% end %>
-END:infiles +<% end # values["infiles"] %>
Parent: -IF:par_url - -ENDIF:par_url - %parent% -IF:par_url +<% if values["par_url"] then %> + "> +<% end %> + <%= values["parent"] %> +<% if values["par_url"] then %> -ENDIF:par_url +<% end %>
-} +EOF ##################################################################### ### M E T H O D L I S T T E M P L A T E ##################################################################### -METHOD_LIST = %{ +METHOD_LIST = <<-EOF
-IF:diagram +<% if values["diagram"] then %>
- %diagram% + <%= values["diagram"] %>
-ENDIF:diagram +<% end %> -IF:description +<% if values["description"] then %>
- %description% + <%= values["description"] %>
-ENDIF:description +<% end %> -IF:requires +<% if values["requires"] then %>

Required files

-START:requires - HREF:aref:name:   -END:requires +<% values["requires"].each do |requires| %> + <%= href requires["aref"], requires["name"] %>   +<% end # values["requires"] %>
-ENDIF:requires +<% end %> -IF:toc +<% if values["toc"] then %>

Contents

-ENDIF:toc +<% end %>
-IF:methods +<% if values["methods"] then %>

Methods

-START:methods - HREF:aref:name:   -END:methods +<% values["methods"].each do |methods| %> + <%= href methods["aref"], methods["name"] %>   +<% end # values["methods"] %>
-ENDIF:methods +<% end %>
-IF:includes +<% if values["includes"] then %>

Included Modules

-START:includes - HREF:aref:name: -END:includes +<% values["includes"].each do |includes| %> + <%= href includes["aref"], includes["name"] %> +<% end # values["includes"] %>
-ENDIF:includes +<% end %> -START:sections +<% values["sections"].each do |sections| %>
-IF:sectitle -

%sectitle%

-IF:seccomment +<% if sections["sectitle"] then %> +

"><%= sections["sectitle"] %>

+<% if sections["seccomment"] then %>
- %seccomment% -
-ENDIF:seccomment -ENDIF:sectitle + <%= sections["seccomment"] %> +
+<% end %> +<% end %> -IF:classlist +<% if values["classlist"] then %>

Classes and Modules

- %classlist% + <%= values["classlist"] %>
-ENDIF:classlist +<% end %> -IF:constants +<% if values["constants"] then %>

Constants

-START:constants +<% values["constants"].each do |constants| $stderr.puts({ :constants => constants }.inspect) %> - + - -IF:desc + +<% if values["desc"] then %> - -ENDIF:desc + +<% end %> -END:constants +<% end # values["constants"] %>
%name%<%= values["name"] %> =%value%<%= values["value"] %> %desc%<%= values["desc"] %>
-ENDIF:constants +<% end %> -IF:aliases +<% if values["aliases"] then %>

External Aliases

-START:aliases +<% values["aliases"].each do |aliases| $stderr.puts({ :aliases => aliases }.inspect) %> - + - + -IF:desc +<% if values["desc"] then %> - + -ENDIF:desc -END:aliases -
%old_name%<%= values["old_name"] %> ->%new_name%<%= values["new_name"] %>
 %desc%<%= values["desc"] %>
+<% end %> +<% end # values["aliases"] %> +
-ENDIF:aliases +<% end %> -IF:attributes +<% if values["attributes"] then %>

Attributes

-START:attributes +<% values["attributes"].each do |attributes| $stderr.puts({ :attributes => attributes }.inspect) %> - -IF:rw - -ENDIF:rw -IFNOT:rw + +<% if values["rw"] then %> + +<% end %> +<% unless values["rw"] then %> -ENDIF:rw - +<% end %> + -END:attributes +<% end # values["attributes"] %>
%name% [%rw%] <%= values["name"] %> [<%= values["rw"] %>]   %a_desc%<%= values["a_desc"] %>
-ENDIF:attributes +<% end %> -IF:method_list +<% if sections["method_list"] then %>
-START:method_list -IF:methods -

%type% %category% methods

+<% sections["method_list"].each do |method_list| %> +<% if method_list["methods"] then %> +

<%= method_list["type"] %> <%= method_list["category"] %> methods

-START:methods -
- +<% method_list["methods"].each do |methods| %> +
" class="method-detail"> + "> - +
-IF:m_desc - %m_desc% -ENDIF:m_desc -IF:sourcecode +<% if methods["m_desc"] then %> + <%= methods["m_desc"] %> +<% end %> +<% if methods["sourcecode"] then %>

[Source]

-
+ onclick="toggleCode('<%= methods["aref"] %>-source');return false;">[Source]

+
-source">
-%sourcecode%
+<%= methods["sourcecode"] %>
 
-ENDIF:sourcecode +<% end %>
-END:methods -ENDIF:methods -END:method_list +<% end # method_list["methods"] %> +<% end %> +<% end # sections["method_list"] %>
-ENDIF:method_list -END:sections -} +<% end %> +<% end # values["sections"] %> +EOF ##################################################################### @@ -610,7 +610,7 @@ END:sections BODY = HEADER + %{ -!INCLUDE! +<%= template_include %>
@@ -626,18 +626,18 @@ BODY = HEADER + %{ ### S O U R C E C O D E T E M P L A T E ##################################################################### -SRC_PAGE = XHTML_PREAMBLE + %{ +SRC_PAGE = XHTML_PREAMBLE + <<-EOF - %title% - - + <%= values["title"] %> + " /> + " type="text/css" media="screen" /> -
%code%
+
<%= values["code"] %>
-} +EOF ##################################################################### @@ -645,29 +645,29 @@ SRC_PAGE = XHTML_PREAMBLE + %{ ##################################################################### FR_INDEX_BODY = %{ -!INCLUDE! +<%= template_include %> } FILE_INDEX = XHTML_PREAMBLE + %{ - %list_title% - - + <%= values["list_title"] %> + " /> + " type="text/css" />
-

%list_title%

+

<%= values["list_title"] %>

-START:entries - %name%
-END:entries +<% values["entries"].each do |entries| %> + "><%= entries["name"] %>
+<% end # values["entries"] %>
@@ -677,20 +677,20 @@ END:entries CLASS_INDEX = FILE_INDEX METHOD_INDEX = FILE_INDEX -INDEX = %{ -"?> + - %title% - + <%= values["title"] %> + " /> @@ -698,7 +698,7 @@ INDEX = %{ - + " name="docwin" /> } diff --git a/lib/rdoc/generators/template/html/kilmer.rb b/lib/rdoc/generators/template/html/kilmer.rb index 55071fc026..64687ff3cd 100644 --- a/lib/rdoc/generators/template/html/kilmer.rb +++ b/lib/rdoc/generators/template/html/kilmer.rb @@ -5,7 +5,7 @@ module Page FONTS = "Verdana, Arial, Helvetica, sans-serif" STYLE = %{ -body,td,p { font-family: %fonts%; +body,td,p { font-family: <%= values["fonts"] %>; color: #000040; } @@ -18,20 +18,20 @@ body,td,p { font-family: %fonts%; .big-title-font { color: black; font-weight: bold; - font-family: %fonts%; + font-family: <%= values["fonts"] %>; font-size: large; height: 60px; padding: 10px 3px 10px 3px; } .small-title-font { color: black; - font-family: %fonts%; + font-family: <%= values["fonts"] %>; font-size:10; } .aqua { color: black } .method-name, .attr-name { - font-family: font-family: %fonts%; + font-family: font-family: <%= values["fonts"] %>; font-weight: bold; font-size: small; margin-left: 20px; @@ -92,9 +92,9 @@ body,td,p { font-family: %fonts%; BODY = %{ - %title% - - + <%= values["title"] %> + "> + " type="text/css" media="screen" /> - -} - - -################################################################### - -METHOD_LIST = %{ -IF:includes - - -
Included modules
-
-START:includes - HREF:aref:name: -END:includes -
-ENDIF:includes - -IF:method_list -START:method_list -IF:methods - - -
%type% %category% methods
-START:methods - - -
- -IF:codeurl - -ENDIF:codeurl -IF:callseq -%callseq% -ENDIF:callseq -IFNOT:callseq -%name%%params% -ENDIF:callseq -IF:codeurl - -ENDIF:codeurl -
-IF:m_desc -
-%m_desc% -
-ENDIF:m_desc -IF:aka -
-This method is also aliased as -START:aka -%name% -END:aka -
-ENDIF:aka -IF:sourcecode -
-%sourcecode%
-
-ENDIF:sourcecode -END:methods -ENDIF:methods -END:method_list -ENDIF:method_list -} - -################################################################### - -CONTEXT_CONTENT = %{ -IF:diagram - -
-%diagram% -
-ENDIF:diagram - - -IF:description -
%description%
-ENDIF:description - -IF:requires - - -
Required files
-
-START:requires -HREF:aref:name:    -END:requires -
-ENDIF:requires - -IF:methods - - -
Methods
-
-START:methods -HREF:aref:name:    -END:methods -
-ENDIF:methods - -IF:constants - - -
Constants
- -START:constants - -IF:desc - -ENDIF:desc -END:constants -
%name%=%value%
%desc%
-ENDIF:constants - -IF:aliases - - -
External Aliases
-
-START:aliases -%old_name% -> %new_name%
-END:aliases -
-ENDIF:aliases - -IF:attributes - - -
Attributes
- -START:attributes - - -IF:rw - -ENDIF:rw -IFNOT:rw - -ENDIF:rw - - -END:attributes -
%name% [%rw%] %a_desc%
-ENDIF:attributes - -IF:classlist - - -
Classes and Modules
-
-%classlist% -
-ENDIF:classlist -} - -############################################################################### - -BODY = HEADER + %{ - -!INCLUDE! -} + -CONTEXT_CONTENT + METHOD_LIST + -%{ - - -} - - -############################################################################### - -FILE_PAGE = <<_FILE_PAGE_ - - - - -
- -
%short_name% - - - - - - - - -
Path:%full_path% -IF:cvsurl -  (CVS) -ENDIF:cvsurl -
Modified:%dtm_modified%
-
-_FILE_PAGE_ - -################################################################### - -CLASS_PAGE = %{ - - - - - -
- %classmod% %full_name% - - - - - - -IF:parent - - - - -ENDIF:parent -
In: -START:infiles -IF:full_path_url - -ENDIF:full_path_url -%full_path% -IF:full_path_url - -ENDIF:full_path_url -IF:cvsurl -  (CVS) -ENDIF:cvsurl -
-END:infiles -
Parent: -IF:par_url - -ENDIF:par_url -%parent% -IF:par_url - -ENDIF:par_url -
-
-} - -=begin -=end - -########################## Source code ########################## - -SRC_PAGE = %{ - - - - -%title% - - - -
%code%
- - -} - -########################## Index ################################ - -FR_INDEX_BODY = %{ -!INCLUDE! -} - -FILE_INDEX = %{ - - - - -%list_title% - - - - - -START:entries -%name%
-END:entries - -} - -CLASS_INDEX = FILE_INDEX -METHOD_INDEX = FILE_INDEX - -INDEX = %{ - - - - -%title% - - - - - - - - - - <body bgcolor="white"> - Sorry, RDoc currently only generates HTML using frames. - </body> - - - - -} - -###################################################################### -# -# The following is used for the -1 option -# - -CONTENTS_XML = %{ -IF:description -%description% -ENDIF:description - -IF:requires -

Requires:

-
    -START:requires -IF:aref -
  • %name%
  • -ENDIF:aref -IFNOT:aref -
  • %name%
  • -ENDIF:aref -END:requires -
-ENDIF:requires - -IF:attributes -

Attributes

- -START:attributes - -END:attributes -
%name%%rw%%a_desc%
-ENDIF:attributes - -IF:includes -

Includes

-
    -START:includes -IF:aref -
  • %name%
  • -ENDIF:aref -IFNOT:aref -
  • %name%
  • -ENDIF:aref -END:includes -
-ENDIF:includes - -IF:method_list -

Methods

-START:method_list -IF:methods -START:methods -

%type% %category% method: %name%%params%

- -IF:m_desc -%m_desc% -ENDIF:m_desc - -IF:sourcecode -
-%sourcecode%
-
-ENDIF:sourcecode -END:methods -ENDIF:methods -END:method_list -ENDIF:method_list -} - - -end -end - -require 'rdoc/generators/template/html/one_page_html' diff --git a/lib/rdoc/generators/template/html/one_page_html.rb b/lib/rdoc/generators/template/html/one_page_html.rb index 19441f4725..170bbf23c8 100644 --- a/lib/rdoc/generators/template/html/one_page_html.rb +++ b/lib/rdoc/generators/template/html/one_page_html.rb @@ -1,78 +1,77 @@ -module RDoc -module Page -###################################################################### -# -# The following is used for the -1 option -# +module RDoc::Page CONTENTS_XML = %{ -IF:description -%description% -ENDIF:description +<% if defined? classes and classes["description"] then %> +<%= classes["description"] %> +<% end %> -IF:requires +<% if defined? files and files["requires"] then %>

Requires:

    -START:requires -IF:aref -
  • %name%
  • -ENDIF:aref -IFNOT:aref -
  • %name%
  • -ENDIF:aref -END:requires +<% files["requires"].each do |requires| %> +<% if requires["aref"] then %> +
  • "><%= requires["name"] %>
  • +<% end %> +<% unless requires["aref"] then %> +
  • <%= requires["name"] %>
  • +<% end %> +<% end # files["requires"] %>
-ENDIF:requires +<% end %> -IF:attributes -

Attributes

- -START:attributes - -END:attributes -
%name%%rw%%a_desc%
-ENDIF:attributes - -IF:includes +<% if defined? classes and classes["includes"] then %>

Includes

    -START:includes -IF:aref -
  • %name%
  • -ENDIF:aref -IFNOT:aref -
  • %name%
  • -ENDIF:aref -END:includes +<% classes["includes"].each do |includes| %> +<% if includes["aref"] then %> +
  • "><%= includes["name"] %>
  • +<% end %> +<% unless includes["aref"] then %> +
  • <%= includes["name"] %>
  • +<% end %> +<% end # classes["includes"] %>
-ENDIF:includes +<% end %> -IF:method_list +<% if defined? classes and classes["sections"] then %> +<% classes["sections"].each do |sections| %> +<% if sections["attributes"] then %> +

Attributes

+ +<% sections["attributes"].each do |attributes| %> + +<% end # sections["attributes"] %> +
<%= attributes["name"] %><%= attributes["rw"] %><%= attributes["a_desc"] %>
+<% end %> + +<% if sections["method_list"] then %>

Methods

-START:method_list -IF:methods -START:methods -

%type% %category% method: -IF:callseq -%callseq% -ENDIF:callseq -IFNOT:callseq -%name%%params%

-ENDIF:callseq +<% sections["method_list"].each do |method_list| %> +<% if method_list["methods"] then %> +<% method_list["methods"].each do |methods| %> +

<%= methods["type"] %> <%= methods["category"] %> method: +<% if methods["callseq"] then %> +"><%= methods["callseq"] %> +<% end %> +<% unless methods["callseq"] then %> +"><%= methods["name"] %><%= methods["params"] %>

+<% end %> -IF:m_desc -%m_desc% -ENDIF:m_desc +<% if methods["m_desc"] then %> +<%= methods["m_desc"] %> +<% end %> -IF:sourcecode +<% if methods["sourcecode"] then %>
-%sourcecode%
+<%= methods["sourcecode"] %>
 
-ENDIF:sourcecode -END:methods -ENDIF:methods -END:method_list -ENDIF:method_list +<% end %> +<% end # method_list["methods"] %> +<% end %> +<% end # sections["method_list"] %> +<% end %> +<% end # classes["sections"] %> +<% end %> } ######################################################################## @@ -81,42 +80,42 @@ ONE_PAGE = %{ - %title% - + <%= values["title"] %> + " /> -START:files -

File: %short_name%

+<% values["files"].each do |files| %> +

File: <%= files["short_name"] %>

- - + +
Path:%full_path%
Modified:%dtm_modified%
Path:<%= files["full_path"] %>
Modified:<%= files["dtm_modified"] %>
} + CONTENTS_XML + %{ -END:files +<% end # values["files"] %> -IF:classes +<% if values["classes"] then %>

Classes

-START:classes -IF:parent -

%classmod% %full_name% < HREF:par_url:parent:

-ENDIF:parent -IFNOT:parent -

%classmod% %full_name%

-ENDIF:parent +<% values["classes"].each do |classes| %> +<% if classes["parent"] then %> +

<%= classes["classmod"] %> <%= classes["full_name"] %> < <%= href classes["par_url"], classes["parent"] %>

+<% end %> +<% unless classes["parent"] then %> +

<%= classes["classmod"] %> <%= classes["full_name"] %>

+<% end %> -IF:infiles +<% if classes["infiles"] then %> (in files -START:infiles -HREF:full_path_url:full_path: -END:infiles +<% classes["infiles"].each do |infiles| %> +<%= href infiles["full_path_url"], infiles["full_path"] %> +<% end # classes["infiles"] %> ) -ENDIF:infiles +<% end %> } + CONTENTS_XML + %{ -END:classes -ENDIF:classes +<% end # values["classes"] %> +<% end %> } end -end + diff --git a/lib/rdoc/generators/template/xml/rdf.rb b/lib/rdoc/generators/template/xml/rdf.rb index 1545d81a2f..fbeb599ce6 100644 --- a/lib/rdoc/generators/template/xml/rdf.rb +++ b/lib/rdoc/generators/template/xml/rdf.rb @@ -1,67 +1,68 @@ -module RDoc -module Page - - +module RDoc::Page CONTENTS_RDF = %{ -IF:description +<% if defined? classes and classes["description"] then %> -%description% +<%= classes["description"] %> -ENDIF:description +<% end %> -IF:requires -START:requires - -END:requires -ENDIF:requires +<% if defined? files and files["requires"] then %> +<% files["requires"].each do |requires| %> + " /> +<% end # files["requires"] %> +<% end %> -IF:attributes -START:attributes +<% if defined? classes and classes["includes"] then %> + +<% classes["includes"].each do |includes| %> + " /> +<% end # includes["includes"] %> + +<% end %> + +<% if defined? classes and classes["sections"] then %> +<% classes["sections"].each do |sections| %> +<% if sections["attributes"] then %> +<% sections["attributes"].each do |attributes| %> - -IF:rw - %rw% -ENDIF:rw - %a_desc% + "> +<% if attributes["rw"] then %> + <%= attributes["rw"] %> +<% end %> + <%= attributes["a_desc"] %> -END:attributes -ENDIF:attributes +<% end # sections["attributes"] %> +<% end %> -IF:includes - -START:includes - -END:includes - -ENDIF:includes - -IF:method_list -START:method_list -IF:methods -START:methods +<% if sections["method_list"] then %> +<% sections["method_list"].each do |method_list| %> +<% if method_list["methods"] then %> +<% method_list["methods"].each do |methods| %> - - %params% -IF:m_desc + " rd:visibility="<%= methods["type"] %>" + rd:category="<%= methods["category"] %>" rd:id="<%= methods["aref"] %>"> + <%= methods["params"] %> +<% if methods["m_desc"] then %> -%m_desc% +<%= methods["m_desc"] %> -ENDIF:m_desc -IF:sourcecode +<% end %> +<% if methods["sourcecode"] then %> -%sourcecode% +<%= methods["sourcecode"] %> -ENDIF:sourcecode +<% end %> -END:methods -ENDIF:methods -END:method_list -ENDIF:method_list +<% end # method_list["methods"] %> +<% end %> +<% end # sections["method_list"] %> +<% end %> +<% end # classes["sections"] %> +<% end %> } ######################################################################## @@ -72,41 +73,39 @@ ONE_PAGE = %{ xmlns:rd="http://pragprog.com/rdoc/rdoc.rdf#"> -START:files - - %full_path% - %dtm_modified% +<% values["files"].each do |files| %> + " rd:id="<%= files["href"] %>"> + <%= files["full_path"] %> + <%= files["dtm_modified"] %> } + CONTENTS_RDF + %{ -END:files -START:classes - <%classmod% rd:name="%full_name%" rd:id="%full_name%"> +<% end # values["files"] %> +<% values["classes"].each do |classes| %> + <<%= values["classmod"] %> rd:name="<%= classes["full_name"] %>" rd:id="<%= classes["full_name"] %>"> -IF:infiles +<% if classes["infiles"] then %> -START:infiles +<% classes["infiles"].each do |infiles| %> - " +<% if infiles["full_path_url"] then %> + rdf:about="<%= infiles["full_path_url"] %>" +<% end %> /> -END:infiles +<% end # classes["infiles"] %> -ENDIF:infiles -IF:parent - HREF:par_url:parent: -ENDIF:parent +<% end %> +<% if classes["parent"] then %> + <%= href classes["par_url"], classes["parent"] %> +<% end %> } + CONTENTS_RDF + %{ - -END:classes + > +<% end # values["classes"] %> } - -end end diff --git a/lib/rdoc/generators/template/xml/xml.rb b/lib/rdoc/generators/template/xml/xml.rb index 4a0c8c9ac4..ab6355a1c5 100644 --- a/lib/rdoc/generators/template/xml/xml.rb +++ b/lib/rdoc/generators/template/xml/xml.rb @@ -1,73 +1,74 @@ -module RDoc -module Page - - +module RDoc::Page CONTENTS_XML = %{ -IF:description +<% if defined? classes and classes["description"] then %> -%description% +<%= classes["description"] %> -ENDIF:description +<% end %> -IF:requires +<% if defined? files and files["requires"] then %> -START:requires - + " +<% if requires["aref"] then %> + href="<%= requires["aref"] %>" +<% end %> /> -END:requires +<% end # files["requires"] %> -ENDIF:requires -IF:attributes +<% end %> +<% if defined? classes and classes["sections"] then %> +<% classes["sections"].each do |sections| %> +<% if sections["attributes"] then %> -START:attributes - -IF:rw - %rw% -ENDIF:rw - %a_desc% +<% sections["attributes"].each do |attributes| %> + "> +<% if attributes["rw"] then %> + <%= attributes["rw"] %> +<% end %> + <%= attributes["a_desc"] %> -END:attributes +<% end # sections["attributes"] %> -ENDIF:attributes -IF:includes - -START:includes - -END:includes - -ENDIF:includes -IF:method_list +<% end %> +<% if sections["method_list"] then %> -START:method_list -IF:methods -START:methods - - %params% -IF:m_desc +<% sections["method_list"].each do |method_list| %> +<% if method_list["methods"] then %> +<% method_list["methods"].each do |methods| %> + " type="<%= methods["type"] %>" category="<%= methods["category"] %>" id="<%= methods["aref"] %>"> + <%= methods["params"] %> +<% if methods["m_desc"] then %> -%m_desc% +<%= methods["m_desc"] %> -ENDIF:m_desc -IF:sourcecode +<% end %> +<% if methods["sourcecode"] then %> -%sourcecode% +<%= methods["sourcecode"] %> -ENDIF:sourcecode +<% end %> -END:methods -ENDIF:methods -END:method_list +<% end # method_list["methods"] %> +<% end %> +<% end # sections["method_list"] %> -ENDIF:method_list - +<% end %> +<% end # classes["sections"] %> +<% end %> +<% if defined? classes and classes["includes"] then %> + +<% classes["includes"].each do |includes| %> + " +<% if includes["aref"] then %> + href="<%= includes["aref"] %>" +<% end %> + /> +<% end # classes["includes"] %> + +<% end %> + } ######################################################################## @@ -75,38 +76,36 @@ ENDIF:method_list ONE_PAGE = %{ -START:files - +<% values["files"].each do |files| %> + " id="<%= files["href"] %>"> - %full_path% - %dtm_modified% + <%= files["full_path"] %> + <%= files["dtm_modified"] %> } + CONTENTS_XML + %{ -END:files +<% end # values["files"] %> -START:classes - <%classmod% name="%full_name%" id="%full_name%"> +<% values["classes"].each do |classes| %> + <<%= classes["classmod"] %> name="<%= classes["full_name"] %>" id="<%= classes["full_name"] %>"> -IF:infiles +<% if classes["infiles"] then %> -START:infiles - HREF:full_path_url:full_path: -END:infiles +<% classes["infiles"].each do |infiles| %> + <%= href infiles["full_path_url"], infiles["full_path"] %> +<% end # classes["infiles"] %> -ENDIF:infiles -IF:parent - HREF:par_url:parent: -ENDIF:parent +<% end %> +<% if classes["parent"] then %> + <%= href classes["par_url"], classes["parent"] %> +<% end %> } + CONTENTS_XML + %{ - -END:classes + > +<% end # values["classes"] %> } - -end end diff --git a/lib/rdoc/template.rb b/lib/rdoc/template.rb index dcbccea30e..09fe1e8d24 100644 --- a/lib/rdoc/template.rb +++ b/lib/rdoc/template.rb @@ -1,233 +1,62 @@ -# Cheap-n-cheerful HTML page template system. You create a -# template containing: +require 'erb' + +## +# An ERB wrapper. # -# * variable names between percent signs (%fred%) -# * blocks of repeating stuff: +# This TemplatePage operates similarly to RDoc 1.x's TemplatePage, but uses +# ERB instead of a custom template language. # -# START:key -# ... stuff -# END:key +# Converting from a RDoc 1.x template to an RDoc 2.x template is fairly easy. # -# You feed the code a hash. For simple variables, the values -# are resolved directly from the hash. For blocks, the hash entry -# corresponding to +key+ will be an array of hashes. The block will -# be generated once for each entry. Blocks can be nested arbitrarily -# deeply. +# * %blah% becomes <%= values["blah"] %> +# * !INCLUDE! becomes <%= template_include %> +# * HREF:aref:name becomes <%= href values["aref"], values["name"] %> +# * IF:blah becomes <% if values["blah"] then %> +# * IFNOT:blah becomes <% unless values["blah"] then %> +# * ENDIF:blah becomes <% end %> +# * START:blah becomes <% values["blah"].each do |blah| %> +# * END:blah becomes <% end %> # -# The template may also contain -# -# IF:key -# ... stuff -# ENDIF:key -# -# _stuff_ will only be included in the output if the corresponding -# key is set in the value hash. -# -# Usage: Given a set of templates T1, T2, etc -# -# values = { "name" => "Dave", state => "TX" } -# -# t = TemplatePage.new(T1, T2, T3) -# File.open(name, "w") {|f| t.write_html_on(f, values)} -# or -# res = '' -# t.write_html_on(res, values) +# To make nested loops easier to convert, start by converting START statements +# to: # +# <% values["blah"].each do |blah| $stderr.puts blah.keys %> # +# So you can see what is being used inside which loop. class RDoc::TemplatePage - ########## - # A context holds a stack of key/value pairs (like a symbol - # table). When asked to resolve a key, it first searches the top of - # the stack, then the next level, and so on until it finds a match - # (or runs out of entries) - - class Context - def initialize - @stack = [] - end - - def push(hash) - @stack.push(hash) - end - - def pop - @stack.pop - end - - # Find a scalar value, throwing an exception if not found. This - # method is used when substituting the %xxx% constructs - - def find_scalar(key) - @stack.reverse_each do |level| - if val = level[key] - return val unless val.kind_of? Array - end - end - raise "Template error: can't find variable '#{key}'" - end - - # Lookup any key in the stack of hashes - - def lookup(key) - @stack.reverse_each do |level| - val = level[key] - return val if val - end - nil - end - end - - ######### - # Simple class to read lines out of a string - - class LineReader - # we're initialized with an array of lines - def initialize(lines) - @lines = lines - end - - # read the next line - def read - @lines.shift - end - - # Return a list of lines up to the line that matches - # a pattern. That last line is discarded. - def read_up_to(pattern) - res = [] - while line = read - if pattern.match(line) - return LineReader.new(res) - else - res << line - end - end - raise "Missing end tag in template: #{pattern.source}" - end - - # Return a copy of ourselves that can be modified without - # affecting us - def dup - LineReader.new(@lines.dup) - end - end - - - - # +templates+ is an array of strings containing the templates. - # We start at the first, and substitute in subsequent ones - # where the string !INCLUDE! occurs. For example, - # we could have the overall page template containing - # - # - #

Master

- # !INCLUDE! - # - # - # and substitute subpages in to it by passing [master, sub_page]. - # This gives us a cheap way of framing pages + ## + # Create a new TemplatePage that will use +templates+. def initialize(*templates) - result = "!INCLUDE!" - templates.each do |content| - result.sub!(/!INCLUDE!/, content) + @templates = templates + end + + ## + # Returns "#{name}" + + def href(ref, name) + if ref then + "#{name}" + else + name end - @lines = LineReader.new(result.split($/)) end - # Render the templates into HTML, storing the result on +op+ - # using the method <<. The value_hash contains - # key/value pairs used to drive the substitution (as described above) + ## + # Process the template using +values+, writing the result to +io+. - def write_html_on(op, value_hash) - @context = Context.new - op << substitute_into(@lines, value_hash).tr("\000", '\\') - end + def write_html_on(io, values) + template_include = "" + b = binding - # Substitute a set of key/value pairs into the given template. - # Keys with scalar values have them substituted directly into - # the page. Those with array values invoke substitute_array - # (below), which examples a block of the template once for each - # row in the array. - # - # This routine also copes with the IF:_key_ directive, - # removing chunks of the template if the corresponding key - # does not appear in the hash, and the START: directive, which - # loops its contents for each value in an array - - def substitute_into(lines, values) - @context.push(values) - skip_to = nil - result = [] - - while line = lines.read - - case line - - when /^IF:(\w+)/ - lines.read_up_to(/^ENDIF:#$1/) unless @context.lookup($1) - - when /^IFNOT:(\w+)/ - lines.read_up_to(/^ENDIF:#$1/) if @context.lookup($1) - - when /^ENDIF:/ - ; - - when /^START:(\w+)/ - tag = $1 - body = lines.read_up_to(/^END:#{tag}/) - inner_values = @context.lookup(tag) - raise "unknown tag: #{tag}" unless inner_values - raise "not array: #{tag}" unless inner_values.kind_of?(Array) - inner_values.each do |vals| - result << substitute_into(body.dup, vals) - end - else - result << expand_line(line.dup) - end + @templates.reverse_each do |template| + template_include = ERB.new(template).result b end - @context.pop - - result.join("\n") - end - - # Given an individual line, we look for %xxx% constructs and - # HREF:ref:name: constructs, substituting for each. - - def expand_line(line) - # Generate a cross reference if a reference is given, - # otherwise just fill in the name part - - line.gsub!(/HREF:(\w+?):(\w+?):/) { - ref = @context.lookup($1) - name = @context.find_scalar($2) - - if ref and !ref.kind_of?(Array) - "#{name}" - else - name - end - } - - # Substitute in values for %xxx% constructs. This is made complex - # because the replacement string may contain characters that are - # meaningful to the regexp (like \1) - - line = line.gsub(/%([a-zA-Z]\w*)%/) { - val = @context.find_scalar($1) - val.tr('\\', "\000") - } - - - line - rescue Exception => e - $stderr.puts "Error in template: #{e}" - $stderr.puts "Original line: #{line}" - exit + io.write template_include end end