Greg Martin
Greg Martin

Reputation: 23

Ruby Yard Doc: preformatted code

I've been trying to get yard doc to output preformatted code. I've tried @example but that isn't parsed. ++code++:: will create a code section but formatting is not preserved.

I'm using the default settings so I presume RDoc. Yard version: yard 0.8.7.6, Ruby version: ruby 1.9.3p484 (2013-11-22 revision 43786) [x86_64-linux]

This is the section of comment:

# == Example
#       emitter = AsyncEmitter.new
#       emitter.on :error, lambda { |e| puts "Error: #{e}" }
#       emitter.on :data, lambda { |data| puts "Data: #{data}" }
#
#       begin
#               data = get_data_from_somewhere
#               emitter.emit :data, data
#       rescue Exception => e
#               emitter.emit :error, e
#       end

Upvotes: 2

Views: 352

Answers (1)

vgoff
vgoff

Reputation: 11323


If this is the goal:

Screen Shot

This is is how the file looks to create this:

# Example
#     emitter = AsyncEmitter.new
#     emitter.on :error, lambda { |e| puts "Error: #{e}" }
#     emitter.on :data, lambda { |data| puts "Data: #{data}" }
class AsyncEmitter

# Description and example
#     begin
#       data = get_data_from_somewhere
#       emitter.emit :data, data
#     rescue Exception => e
#       emitter.emit :error, e
#     end
  def get_data_from_somewhere
    # Your Code Here
  end
end

I used Bundler to get the environment set up, and this is the contents of the Gemfile:

source "https://rubygems.org"
ruby '1.9.3'
gem 'yard', '0.8.7.6'
gem 'redcarpet'

I used 4 spaces for indentation, not tabs. And I ensured that the blank line also includes the 4 spaces.

Upvotes: 1

Related Questions