-
Notifications
You must be signed in to change notification settings - Fork 82
Task-oriented documentation #64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 11 commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
06d6696
Doc for specific tasks
BurdetteLamar e03baff
Doc for specific tasks
BurdetteLamar a639f3c
Doc for specific tasks
BurdetteLamar f976393
Doc for specific tasks
BurdetteLamar a7e15a5
Doc for specific tasks
BurdetteLamar c48e210
Doc for specific tasks
BurdetteLamar 4b66d8b
Revert "Doc for specific tasks"
BurdetteLamar 58ca9ac
Doc for specific tasks
BurdetteLamar 805ea1f
Doc for specific tasks
BurdetteLamar ad75633
Doc for specific tasks
BurdetteLamar a3aa9a3
Doc for specific tasks
BurdetteLamar e8670d1
Doc for specific tasks
BurdetteLamar e7f3218
Doc for specific tasks
BurdetteLamar 341010e
Doc for specific tasks
BurdetteLamar 871a7e3
Move Rake task related codes to tasks/
kou f073d37
Doc for specific tasks
BurdetteLamar b482627
Merge branch 'tasks' of https://github.com/BurdetteLamar/rexml into t…
BurdetteLamar 72d41c4
Doc for specific tasks
BurdetteLamar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
Dir.chdir(File.dirname(__FILE__)) do | ||
|
||
# Get the correct links from actual (temporary) rdoc html. | ||
toc_lis_by_name = {} | ||
require 'tmpdir' | ||
Dir.mktmpdir do |tmpdir| | ||
system("rdoc --op #{tmpdir} --force-output rdoc") | ||
Dir.chdir("#{tmpdir}/rdoc") do | ||
Dir.new('.').entries.each do |html_file_path| | ||
next if html_file_path.start_with?('.') | ||
toc_lis = [] | ||
File.open(html_file_path, 'r') do |file| | ||
in_toc = false | ||
file.each_line do |line| | ||
unless in_toc | ||
if line.include?('<ul class="link-list" role="directory">') | ||
in_toc = true | ||
next | ||
end | ||
end | ||
if in_toc | ||
break if line.include?('</ul>') | ||
toc_lis.push(line.chomp) | ||
end | ||
end | ||
end | ||
key = html_file_path.sub('_rdoc.html', '') | ||
toc_lis_by_name[key] = toc_lis | ||
end | ||
end | ||
end | ||
|
||
File.open('tocs/master_toc.rdoc', 'w') do |master_toc_file| | ||
master_toc_file.write("== Table of Contents\n\n") | ||
Dir.chdir('tocs') do | ||
entries = Dir.entries('.') | ||
entries.delete_if {|entry| entry.start_with?('.') } | ||
entries.delete_if {|entry| entry == 'master_toc.rdoc' } | ||
toc_lis_by_name.each_pair do |name, lis| | ||
toc_file_name = name + '_toc.rdoc' | ||
entries.delete(toc_file_name) | ||
File.open(toc_file_name, 'w') do |class_file| | ||
class_file.write("Tasks on this page:\n\n") | ||
lis.each_with_index do |li, i| | ||
_, temp = li.split('"', 2) | ||
link, temp = temp.split('">', 2) | ||
text = temp.sub('</a>', '') | ||
indentation = text.start_with?('Task') ? ' ' : '' | ||
toc_entry = "#{indentation}- {#{text}}[#{link}]\n" | ||
if i == 0 | ||
text = text.split(' ')[1] | ||
link = "../../tasks/rdoc/#{text.downcase}_rdoc.html" | ||
master_toc_file.write("=== {#{text}}[#{link}]\n") | ||
next | ||
end | ||
master_link = "../../tasks/rdoc/#{toc_file_name.sub('_toc.rdoc', '_rdoc.html')}#{link}" | ||
master_toc_entry = "#{indentation}- {#{text}}[#{master_link}]\n" | ||
master_toc_file.write(master_toc_entry) | ||
class_file.write(toc_entry) | ||
end | ||
master_toc_file.write("\n") | ||
class_file.write("\n") | ||
end | ||
end | ||
unless entries.empty? | ||
message = "Some entries not updated: #{entries}" | ||
fail message | ||
end | ||
end | ||
end | ||
|
||
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
== Class Child | ||
|
||
Class Child includes module Node; | ||
see {Tasks for Node}[node_rdoc.html]. | ||
|
||
:include: ../tocs/child_toc.rdoc | ||
|
||
=== Relationships | ||
|
||
==== Task: Set the Parent | ||
|
||
Use method {Child#parent=}[../../../../REXML/Parent.html#method-i-parent-3D] | ||
to set the parent: | ||
|
||
e0 = REXML::Element.new('foo') | ||
e1 = REXML::Element.new('bar') | ||
e1.parent # => nil | ||
e1.parent = e0 | ||
e1.parent # => <foo/> | ||
|
||
==== Task: Insert Previous Sibling | ||
|
||
Use method {Child#previous_sibling=}[../../../../REXML/Parent.html#method-i-previous_sibling-3D] | ||
to insert a previous sibling: | ||
|
||
xml_string = '<root><a/><c/></root>' | ||
d = REXML::Document.new(xml_string) | ||
d.root.to_a # => [<a/>, <c/>] | ||
c = d.root[1] # => <c/> | ||
b = REXML::Element.new('b') | ||
c.previous_sibling = b | ||
d.root.to_a # => [<a/>, <b/>, <c/>] | ||
|
||
==== Task: Insert Next Sibling | ||
|
||
Use method {Child#next_sibling=}[../../../../REXML/Parent.html#method-i-next-sibling-3D] | ||
to insert a previous sibling: | ||
|
||
xml_string = '<root><a/><c/></root>' | ||
d = REXML::Document.new(xml_string) | ||
d.root.to_a # => [<a/>, <c/>] | ||
a = d.root[0] # => <a/> | ||
b = REXML::Element.new('b') | ||
a.next_sibling = b | ||
d.root.to_a # => [<a/>, <b/>, <c/>] | ||
|
||
=== Removal or Replacement | ||
|
||
==== Task: Remove Child from Parent | ||
|
||
Use method {Child#remove}[../../../../REXML/Parent.html#method-i-remove] | ||
to remove a child from its parent; returns the removed child: | ||
|
||
xml_string = '<root><a/><b/><c/></root>' | ||
d = REXML::Document.new(xml_string) | ||
d.root.to_a # => [<a/>, <b/>, <c/>] | ||
b = d.root[1] # => <b/> | ||
b.remove # => <b/> | ||
d.root.to_a # => [<a/>, <c/>] | ||
|
||
==== Task: Replace Child | ||
|
||
Use method {Child#replace_with}[../../../../REXML/Parent.html#method-i-replace] | ||
to replace a child; | ||
returns the replaced child: | ||
|
||
xml_string = '<root><a/><b/><c/></root>' | ||
d = REXML::Document.new(xml_string) | ||
d.root.to_a # => [<a/>, <b/>, <c/>] | ||
b = d.root[1] # => <b/> | ||
d = REXML::Element.new('d') | ||
b.replace_with(d) # => <b/> | ||
d.root.to_a # => [<a/>, <d/>, <c/>] | ||
|
||
=== Document | ||
|
||
==== Task: Get the Document | ||
|
||
Use method {Child#document}[../../../../REXML/Parent.html#method-i-document] | ||
to get the document for the child: | ||
|
||
xml_string = '<root><a/><b/><c/></root>' | ||
d = REXML::Document.new(xml_string) | ||
d.root.to_a # => [<a/>, <b/>, <c/>] | ||
b = d.root[1] # => <b/> | ||
b.document == d # => true | ||
REXML::Child.new.document # => nil |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you define this as a
rdoc:toc:generate
Rake task inRakefile
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I meant to say more (and better). My initial question is Do we want this sort of thing?
If yes, everything else can come later: correctness, robustness of TOC build, etc.
Also, Element is not completed, so there are some hanging issues there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's acceptable.
It's better that RDoc provides the TOC feature as a build-in feature. For example,
[:toc:]
is expanded to TOC on rendering phase. But it seems that RDoc doesn't provide the TOC feature. (Could you request the feature to RDoc?)So it's reasonable that we have TOC generator for us for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a lot of work, so needs to be much more than 'acceptable.' Do you like the 'task' concept?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes. I like the concept.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rakefile updated with task tocs:generate.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@kou, I have created the feature request: ruby/rdoc#801
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!