Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3361898
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:12:29+00:00 2026-05-18T03:12:29+00:00

How do I include a ruby code file, as is, into RDoc? I have

  • 0

How do I include a ruby code file, as is, into RDoc?

I have an example.rb file that documents how to use my gem and I would like to include that as one of the files like the README.rdoc and HISTORY.rdoc.

I’ve already figured out how to convert the ruby source code into HTML using the Syntax gem but I can’t figure out how to make RDoc include the file without parsing it.

When I tell RDoc to include the html file it isn’t listed and if I fake it out by using rdoc or txt as the file extension it doesn’t display properly (the file is still actually html).

I’ve got a solution that works it’s just incredibly ugly. There has got to be a better way to do this that’s native to rdoc but I don’t see it.

Here’s what I have in my Rakefile:

# Build rdocs
require 'rake/rdoctask'
require 'syntax/convertors/html'
rdoc_dir = 'rdoc'
# This is rdoc1 but it doesn't work unless you DON'T wrap it in a task
# Generate html files from example ruby files
convertor = Syntax::Convertors::HTML.for_syntax "ruby"
replacement_key = "REPLACE_THIS_TEXT_WITH_PROPER_HTML"
# Create dummy files
Dir.glob('examples/*.rb').each do |file|
  File.open("#{file}.txt", "w") do |dummy_file|
    dummy_file.write(replacement_key)
  end
end

# Call the rdoc task
Rake::RDocTask.new(:rdoc2) do |rdoc|
  rdoc.rdoc_dir = rdoc_dir
  rdoc.title = "pickled_optparse #{version}"
  rdoc.rdoc_files.include('README*')
  rdoc.rdoc_files.include('HISTORY*')
  rdoc.rdoc_files.include('examples/*.txt')
  rdoc.rdoc_files.include('lib/**/*.rb')
end

task :rdoc3 do
  # Now use a hammer to replace the dummy text with the
  # html we want to use in our ruby example code file.
  html_header = File.read('rake_reqs/html_header.html')
  Dir.glob('examples/*.rb').each do |file|
    html_ruby = convertor.convert(File.read(file))
    rdoc_file = "#{rdoc_dir}/examples/#{File.basename(file,".rb")}_rb_txt.html"
    fixed_html = File.read(rdoc_file).gsub!(replacement_key, "#{html_header}#{html_ruby}")
    File.open(rdoc_file, "w") {|f| f.write(fixed_html)}
    File.delete("#{file}.txt")
  end
end

task :rdoc => [:rdoc2, :rdoc3]
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T03:12:30+00:00Added an answer on May 18, 2026 at 3:12 am

    Sorry I can’t give you an actual answer but I’m looking at sdoc myself.
    You can install the gem from ruby gems.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a small code snippet that I'm trying to get to work in
I'm trying to include a source code file when I run irb but irb
include 'header.php'; // ... some code header('Location:index.php'); exit; The above code keeps giving me
I'd like to be able to compile a ruby program to a java JAR
So: I quite like using Haml in ruby projects, and was testing it out
I've been working on a small page in PHP, one that doesn't need the
#include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits
#include <iostream> using namespace std; int main() { double u = 0; double w
#include <vector> std::vector<long int> as; long int a(size_t n){ if(n==1) return 1; if(n==2) return
include(conn.php); $result = mysql_query(SELECT * FROM sggame); while($row = mysql_fetch_assoc($result)); { $id = $row['id'];

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.