ÿØÿà JFIF ÿÛ „ ( %!1!%*+...983,7(-.- PK |]$+j irb.rbnu [ # # irb.rb - irb main module # $Release Version: 0.9.5 $ # $Revision: 24483 $ # $Date: 2009-08-09 17:44:15 +0900 (Sun, 09 Aug 2009) $ # by Keiju ISHITSUKA(keiju@ruby-lang.org) # # -- # # # require "e2mmap" require "irb/init" require "irb/context" require "irb/extend-command" #require "irb/workspace" require "irb/ruby-lex" require "irb/input-method" require "irb/locale" STDOUT.sync = true module IRB @RCS_ID='-$Id: irb.rb 24483 2009-08-09 08:44:15Z shyouhei $-' class Abort < Exception;end # @CONF = {} def IRB.conf @CONF end # IRB version method def IRB.version if v = @CONF[:VERSION] then return v end require "irb/version" rv = @RELEASE_VERSION.sub(/\.0/, "") @CONF[:VERSION] = format("irb %s(%s)", rv, @LAST_UPDATE_DATE) end def IRB.CurrentContext IRB.conf[:MAIN_CONTEXT] end # initialize IRB and start TOP_LEVEL irb def IRB.start(ap_path = nil) $0 = File::basename(ap_path, ".rb") if ap_path IRB.setup(ap_path) if @CONF[:SCRIPT] irb = Irb.new(nil, @CONF[:SCRIPT]) else irb = Irb.new end @CONF[:IRB_RC].call(irb.context) if @CONF[:IRB_RC] @CONF[:MAIN_CONTEXT] = irb.context trap("SIGINT") do irb.signal_handle end begin catch(:IRB_EXIT) do irb.eval_input end ensure irb_at_exit end # print "\n" end def IRB.irb_at_exit @CONF[:AT_EXIT].each{|hook| hook.call} end def IRB.irb_exit(irb, ret) throw :IRB_EXIT, ret end def IRB.irb_abort(irb, exception = Abort) if defined? Thread irb.context.thread.raise exception, "abort then interrupt!!" else raise exception, "abort then interrupt!!" end end # # irb interpriter main routine # class Irb def initialize(workspace = nil, input_method = nil, output_method = nil) @context = Context.new(self, workspace, input_method, output_method) @context.main.extend ExtendCommandBundle @signal_status = :IN_IRB @scanner = RubyLex.new @scanner.exception_on_syntax_error = false end attr_reader :context attr_accessor :scanner def eval_input @scanner.set_prompt do |ltype, indent, continue, line_no| if ltype f = @context.prompt_s elsif continue f = @context.prompt_c elsif indent > 0 f = @context.prompt_n else @context.prompt_i f = @context.prompt_i end f = "" unless f if @context.prompting? @context.io.prompt = p = prompt(f, ltype, indent, line_no) else @context.io.prompt = p = "" end if @context.auto_indent_mode unless ltype ind = prompt(@context.prompt_i, ltype, indent, line_no)[/.*\z/].size + indent * 2 - p.size ind += 2 if continue @context.io.prompt = p + " " * ind if ind > 0 end end end @scanner.set_input(@context.io) do signal_status(:IN_INPUT) do if l = @context.io.gets print l if @context.verbose? else if @context.ignore_eof? and @context.io.readable_atfer_eof? l = "\n" if @context.verbose? printf "Use \"exit\" to leave %s\n", @context.ap_name end end end l end end @scanner.each_top_level_statement do |line, line_no| signal_status(:IN_EVAL) do begin line.untaint @context.evaluate(line, line_no) output_value if @context.echo? exc = nil rescue Interrupt => exc rescue SystemExit, SignalException raise rescue Exception => exc end if exc print exc.class, ": ", exc, "\n" if exc.backtrace[0] =~ /irb(2)?(\/.*|-.*|\.rb)?:/ && exc.class.to_s !~ /^IRB/ irb_bug = true else irb_bug = false end messages = [] lasts = [] levels = 0 for m in exc.backtrace m = @context.workspace.filter_backtrace(m) unless irb_bug if m if messages.size < @context.back_trace_limit messages.push "\tfrom "+m else lasts.push "\tfrom "+m if lasts.size > @context.back_trace_limit lasts.shift levels += 1 end end end end print messages.join("\n"), "\n" unless lasts.empty? printf "... %d levels...\n", levels if levels > 0 print lasts.join("\n") end print "Maybe IRB bug!!\n" if irb_bug end if $SAFE > 2 abort "Error: irb does not work for $SAFE level higher than 2" end end end end def suspend_name(path = nil, name = nil) @context.irb_path, back_path = path, @context.irb_path if path @context.irb_name, back_name = name, @context.irb_name if name begin yield back_path, back_name ensure @context.irb_path = back_path if path @context.irb_name = back_name if name end end def suspend_workspace(workspace) @context.workspace, back_workspace = workspace, @context.workspace begin yield back_workspace ensure @context.workspace = back_workspace end end def suspend_input_method(input_method) back_io = @context.io @context.instance_eval{@io = input_method} begin yield back_io ensure @context.instance_eval{@io = back_io} end end def suspend_context(context) @context, back_context = context, @context begin yield back_context ensure @context = back_context end end def signal_handle unless @context.ignore_sigint? print "\nabort!!\n" if @context.verbose? exit end case @signal_status when :IN_INPUT print "^C\n" raise RubyLex::TerminateLineInput when :IN_EVAL IRB.irb_abort(self) when :IN_LOAD IRB.irb_abort(self, LoadAbort) when :IN_IRB # ignore else # ignore other cases as well end end def signal_status(status) return yield if @signal_status == :IN_LOAD signal_status_back = @signal_status @signal_status = status begin yield ensure @signal_status = signal_status_back end end def prompt(prompt, ltype, indent, line_no) p = prompt.dup p.gsub!(/%([0-9]+)?([a-zA-Z])/) do case $2 when "N" @context.irb_name when "m" @context.main.to_s when "M" @context.main.inspect when "l" ltype when "i" if $1 format("%" + $1 + "d", indent) else indent.to_s end when "n" if $1 format("%" + $1 + "d", line_no) else line_no.to_s end when "%" "%" end end p end def output_value if @context.inspect? printf @context.return_format, @context.last_value.inspect else printf @context.return_format, @context.last_value end end def inspect ary = [] for iv in instance_variables case iv when "@signal_status" ary.push format("%s=:%s", iv, @signal_status.id2name) when "@context" ary.push format("%s=%s", iv, eval(iv).__to_s__) else ary.push format("%s=%s", iv, eval(iv)) end end format("#<%s: %s>", self.class, ary.join(", ")) end end # Singleton method def @CONF.inspect IRB.version unless self[:VERSION] array = [] for k, v in sort{|a1, a2| a1[0].id2name <=> a2[0].id2name} case k when :MAIN_CONTEXT, :__TMP__EHV__ array.push format("CONF[:%s]=...myself...", k.id2name) when :PROMPT s = v.collect{ |kk, vv| ss = vv.collect{|kkk, vvv| ":#{kkk.id2name}=>#{vvv.inspect}"} format(":%s=>{%s}", kk.id2name, ss.join(", ")) } array.push format("CONF[:%s]={%s}", k.id2name, s.join(", ")) else array.push format("CONF[:%s]=%s", k.id2name, v.inspect) end end array.join("\n") end end PK |]\ rdoc/usage.rbnu [ # = Synopsis # # This library allows command-line tools to encapsulate their usage # as a comment at the top of the main file. Calling RDoc::usage # then displays some or all of that comment, and optionally exits # the program with an exit status. We always look for the comment # in the main program file, so it is safe to call this method # from anywhere in the executing program. # # = Usage # # RDoc::usage( [ exit_status ], [ section, ...]) # RDoc::usage_no_exit( [ section, ...]) # # where: # # exit_status:: # the integer exit code (default zero). RDoc::usage will exit # the calling program with this status. # # section:: # an optional list of section names. If specified, only the # sections with the given names as headings will be output. # For example, this section is named 'Usage', and the next # section is named 'Examples'. The section names are case # insensitive. # # = Examples # # # Comment block describing usage # # with (optional) section headings # # . . . # # require 'rdoc/usage' # # # Display all usage and exit with a status of 0 # # RDoc::usage # # # Display all usage and exit with a status of 99 # # RDoc::usage(99) # # # Display usage in the 'Summary' section only, then # # exit with a status of 99 # # RDoc::usage(99, 'Summary') # # # Display information in the Author and Copyright # # sections, then exit 0. # # RDoc::usage('Author', 'Copyright') # # # Display information in the Author and Copyright # # sections, but don't exit # # RDoc::usage_no_exit('Author', 'Copyright') # # = Author # # Dave Thomas, The Pragmatic Programmers, LLC # # = Copyright # # Copyright (c) 2004 Dave Thomas. # Licensed under the same terms as Ruby # require 'rdoc/markup/simple_markup' require 'rdoc/markup/simple_markup/to_flow' require 'rdoc/ri/ri_formatter' require 'rdoc/ri/ri_options' module RDoc # Display usage information from the comment at the top of # the file. String arguments identify specific sections of the # comment to display. An optional integer first argument # specifies the exit status (defaults to 0) def RDoc.usage(*args) exit_code = 0 if args.size > 0 status = args[0] if status.respond_to?(:to_int) exit_code = status.to_int args.shift end end # display the usage and exit with the given code usage_no_exit(*args) exit(exit_code) end # Display usage def RDoc.usage_no_exit(*args) main_program_file = caller[-1].sub(/:\d+$/, '') comment = File.open(main_program_file) do |file| find_comment(file) end comment = comment.gsub(/^\s*#/, '') markup = SM::SimpleMarkup.new flow_convertor = SM::ToFlow.new flow = markup.convert(comment, flow_convertor) format = "plain" unless args.empty? flow = extract_sections(flow, args) end options = RI::Options.instance if args = ENV["RI"] options.parse(args.split) end formatter = options.formatter.new(options, "") formatter.display_flow(flow) end ###################################################################### private # Find the first comment in the file (that isn't a shebang line) # If the file doesn't start with a comment, report the fact # and return empty string def RDoc.gets(file) if (line = file.gets) && (line =~ /^#!/) # shebang throw :exit, find_comment(file) else line end end def RDoc.find_comment(file) catch(:exit) do # skip leading blank lines 0 while (line = gets(file)) && (line =~ /^\s*$/) comment = [] while line && line =~ /^\s*#/ comment << line line = gets(file) end 0 while line && (line = gets(file)) return no_comment if comment.empty? return comment.join end end ##### # Given an array of flow items and an array of section names, extract those # sections from the flow which have headings corresponding to # a section name in the list. Return them in the order # of names in the +sections+ array. def RDoc.extract_sections(flow, sections) result = [] sections.each do |name| name = name.downcase copy_upto_level = nil flow.each do |item| case item when SM::Flow::H if copy_upto_level && item.level >= copy_upto_level copy_upto_level = nil else if item.text.downcase == name result << item copy_upto_level = item.level end end else if copy_upto_level result << item end end end end if result.empty? puts "Note to developer: requested section(s) [#{sections.join(', ')}] " + "not found" result = flow end result end ##### # Report the fact that no doc comment count be found def RDoc.no_comment $stderr.puts "No usage information available for this program" "" end end if $0 == __FILE__ RDoc::usage(*ARGV) end PK |]w4, , rdoc/markup/test/TestParse.rbnu [ require 'test/unit' $:.unshift "../../.." require 'rdoc/markup/simple_markup' include SM class TestParse < Test::Unit::TestCase class MockOutput def start_accepting @res = [] end def end_accepting @res end def accept_paragraph(am, fragment) @res << fragment.to_s end def accept_verbatim(am, fragment) @res << fragment.to_s end def accept_list_start(am, fragment) @res << fragment.to_s end def accept_list_end(am, fragment) @res << fragment.to_s end def accept_list_item(am, fragment) @res << fragment.to_s end def accept_blank_line(am, fragment) @res << fragment.to_s end def accept_heading(am, fragment) @res << fragment.to_s end def accept_rule(am, fragment) @res << fragment.to_s end end def basic_conv(str) sm = SimpleMarkup.new mock = MockOutput.new sm.convert(str, mock) sm.content end def line_types(str, expected) p = SimpleMarkup.new mock = MockOutput.new p.convert(str, mock) assert_equal(expected, p.get_line_types.map{|type| type.to_s[0,1]}.join('')) end def line_groups(str, expected) p = SimpleMarkup.new mock = MockOutput.new block = p.convert(str, mock) if block != expected rows = (0...([expected.size, block.size].max)).collect{|i| [expected[i]||"nil", block[i]||"nil"] } printf "\n\n%35s %35s\n", "Expected", "Got" rows.each {|e,g| printf "%35s %35s\n", e.dump, g.dump } end assert_equal(expected, block) end def test_tabs str = "hello\n dave" assert_equal(str, basic_conv(str)) str = "hello\n\tdave" assert_equal("hello\n dave", basic_conv(str)) str = "hello\n \tdave" assert_equal("hello\n dave", basic_conv(str)) str = "hello\n \tdave" assert_equal("hello\n dave", basic_conv(str)) str = "hello\n \tdave" assert_equal("hello\n dave", basic_conv(str)) str = "hello\n \tdave" assert_equal("hello\n dave", basic_conv(str)) str = "hello\n \tdave" assert_equal("hello\n dave", basic_conv(str)) str = "hello\n \tdave" assert_equal("hello\n dave", basic_conv(str)) str = "hello\n \tdave" assert_equal("hello\n dave", basic_conv(str)) str = "hello\n \tdave" assert_equal("hello\n dave", basic_conv(str)) str = ".\t\t." assert_equal(". .", basic_conv(str)) end def test_whitespace assert_equal("hello", basic_conv("hello")) assert_equal("hello", basic_conv(" hello ")) assert_equal("hello", basic_conv(" \t \t hello\t\t")) assert_equal("1\n 2\n 3", basic_conv("1\n 2\n 3")) assert_equal("1\n 2\n 3", basic_conv(" 1\n 2\n 3")) assert_equal("1\n 2\n 3\n1\n 2", basic_conv("1\n 2\n 3\n1\n 2")) assert_equal("1\n 2\n 3\n1\n 2", basic_conv(" 1\n 2\n 3\n 1\n 2")) assert_equal("1\n 2\n\n 3", basic_conv(" 1\n 2\n\n 3")) end def test_types str = "now is the time" line_types(str, 'P') str = "now is the time\nfor all good men" line_types(str, 'PP') str = "now is the time\n code\nfor all good men" line_types(str, 'PVP') str = "now is the time\n code\n more code\nfor all good men" line_types(str, 'PVVP') str = "now is\n---\nthe time" line_types(str, 'PRP') str = %{\ now is * l1 * l2 the time} line_types(str, 'PLLP') str = %{\ now is * l1 l1+ * l2 the time} line_types(str, 'PLPLP') str = %{\ now is * l1 * l1.1 * l2 the time} line_types(str, 'PLLLP') str = %{\ now is * l1 * l1.1 text code code text * l2 the time} line_types(str, 'PLLPVVBPLP') str = %{\ now is 1. l1 * l1.1 2. l2 the time} line_types(str, 'PLLLP') str = %{\ now is [cat] l1 * l1.1 [dog] l2 the time} line_types(str, 'PLLLP') str = %{\ now is [cat] l1 continuation [dog] l2 the time} line_types(str, 'PLPLP') end def test_groups str = "now is the time" line_groups(str, ["L0: Paragraph\nnow is the time"] ) str = "now is the time\nfor all good men" line_groups(str, ["L0: Paragraph\nnow is the time for all good men"] ) str = %{\ now is the time code _line_ here for all good men} line_groups(str, [ "L0: Paragraph\nnow is the time", "L0: Verbatim\n code _line_ here\n", "L0: Paragraph\nfor all good men" ] ) str = "now is the time\n code\n more code\nfor all good men" line_groups(str, [ "L0: Paragraph\nnow is the time", "L0: Verbatim\n code\n more code\n", "L0: Paragraph\nfor all good men" ] ) str = %{\ now is * l1 * l2 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L1: ListStart\n", "L1: ListItem\nl1", "L1: ListItem\nl2", "L1: ListEnd\n", "L0: Paragraph\nthe time" ]) str = %{\ now is * l1 l1+ * l2 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L1: ListStart\n", "L1: ListItem\nl1 l1+", "L1: ListItem\nl2", "L1: ListEnd\n", "L0: Paragraph\nthe time" ]) str = %{\ now is * l1 * l1.1 * l2 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L1: ListStart\n", "L1: ListItem\nl1", "L2: ListStart\n", "L2: ListItem\nl1.1", "L2: ListEnd\n", "L1: ListItem\nl2", "L1: ListEnd\n", "L0: Paragraph\nthe time" ]) str = %{\ now is * l1 * l1.1 text code code text * l2 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L1: ListStart\n", "L1: ListItem\nl1", "L2: ListStart\n", "L2: ListItem\nl1.1 text", "L2: Verbatim\n code\n code\n", "L2: Paragraph\ntext", "L2: ListEnd\n", "L1: ListItem\nl2", "L1: ListEnd\n", "L0: Paragraph\nthe time" ]) str = %{\ now is 1. l1 * l1.1 2. l2 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L1: ListStart\n", "L1: ListItem\nl1", "L2: ListStart\n", "L2: ListItem\nl1.1", "L2: ListEnd\n", "L1: ListItem\nl2", "L1: ListEnd\n", "L0: Paragraph\nthe time" ]) str = %{\ now is [cat] l1 * l1.1 [dog] l2 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L1: ListStart\n", "L1: ListItem\nl1", "L2: ListStart\n", "L2: ListItem\nl1.1", "L2: ListEnd\n", "L1: ListItem\nl2", "L1: ListEnd\n", "L0: Paragraph\nthe time" ]) str = %{\ now is [cat] l1 continuation [dog] l2 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L1: ListStart\n", "L1: ListItem\nl1 continuation", "L1: ListItem\nl2", "L1: ListEnd\n", "L0: Paragraph\nthe time" ]) end def test_verbatim_merge str = %{\ now is code the time} line_groups(str, [ "L0: Paragraph\nnow is", "L0: Verbatim\n code\n", "L0: Paragraph\nthe time" ]) str = %{\ now is code code1 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L0: Verbatim\n code\n code1\n", "L0: Paragraph\nthe time" ]) str = %{\ now is code code1 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L0: Verbatim\n code\n\n code1\n", "L0: Paragraph\nthe time" ]) str = %{\ now is code code1 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L0: Verbatim\n code\n\n code1\n", "L0: Paragraph\nthe time" ]) str = %{\ now is code code1 code2 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L0: Verbatim\n code\n\n code1\n\n code2\n", "L0: Paragraph\nthe time" ]) # Folds multiple blank lines str = %{\ now is code code1 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L0: Verbatim\n code\n\n code1\n", "L0: Paragraph\nthe time" ]) end def test_list_split str = %{\ now is * l1 1. n1 2. n2 * l2 the time} line_groups(str, [ "L0: Paragraph\nnow is", "L1: ListStart\n", "L1: ListItem\nl1", "L1: ListEnd\n", "L1: ListStart\n", "L1: ListItem\nn1", "L1: ListItem\nn2", "L1: ListEnd\n", "L1: ListStart\n", "L1: ListItem\nl2", "L1: ListEnd\n", "L0: Paragraph\nthe time" ]) end def test_headings str = "= heading one" line_groups(str, [ "L0: Heading\nheading one" ]) str = "=== heading three" line_groups(str, [ "L0: Heading\nheading three" ]) str = "text\n === heading three" line_groups(str, [ "L0: Paragraph\ntext", "L0: Verbatim\n === heading three\n" ]) str = "text\n code\n === heading three" line_groups(str, [ "L0: Paragraph\ntext", "L0: Verbatim\n code\n === heading three\n" ]) str = "text\n code\n=== heading three" line_groups(str, [ "L0: Paragraph\ntext", "L0: Verbatim\n code\n", "L0: Heading\nheading three" ]) end end PK |]Z / / rdoc/markup/test/AllTests.rbnu [ require 'TestParse.rb' require 'TestInline.rb' PK |]= rdoc/markup/test/TestInline.rbnu [ require "test/unit" $:.unshift "../../.." require "rdoc/markup/simple_markup/inline" class TestInline < Test::Unit::TestCase def setup @am = SM::AttributeManager.new @bold_on = @am.changed_attribute_by_name([], [:BOLD]) @bold_off = @am.changed_attribute_by_name([:BOLD], []) @tt_on = @am.changed_attribute_by_name([], [:TT]) @tt_off = @am.changed_attribute_by_name([:TT], []) @em_on = @am.changed_attribute_by_name([], [:EM]) @em_off = @am.changed_attribute_by_name([:EM], []) @bold_em_on = @am.changed_attribute_by_name([], [:BOLD] | [:EM]) @bold_em_off = @am.changed_attribute_by_name([:BOLD] | [:EM], []) @em_then_bold = @am.changed_attribute_by_name([:EM], [:EM] | [:BOLD]) @em_to_bold = @am.changed_attribute_by_name([:EM], [:BOLD]) @am.add_word_pair("{", "}", :WOMBAT) @wombat_on = @am.changed_attribute_by_name([], [:WOMBAT]) @wombat_off = @am.changed_attribute_by_name([:WOMBAT], []) end def crossref(text) [ @am.changed_attribute_by_name([], [:CROSSREF] | [:_SPECIAL_]), SM::Special.new(33, text), @am.changed_attribute_by_name([:CROSSREF] | [:_SPECIAL_], []) ] end def test_special # class names, variable names, file names, or instance variables @am.add_special(/( \b([A-Z]\w+(::\w+)*) | \#\w+[!?=]? | \b\w+([_\/\.]+\w+)+[!?=]? )/x, :CROSSREF) assert_equal(["cat"], @am.flow("cat")) assert_equal(["cat ", crossref("#fred"), " dog"].flatten, @am.flow("cat #fred dog")) assert_equal([crossref("#fred"), " dog"].flatten, @am.flow("#fred dog")) assert_equal(["cat ", crossref("#fred")].flatten, @am.flow("cat #fred")) end def test_basic assert_equal(["cat"], @am.flow("cat")) assert_equal(["cat ", @bold_on, "and", @bold_off, " dog"], @am.flow("cat *and* dog")) assert_equal(["cat ", @bold_on, "AND", @bold_off, " dog"], @am.flow("cat *AND* dog")) assert_equal(["cat ", @em_on, "And", @em_off, " dog"], @am.flow("cat _And_ dog")) assert_equal(["cat *and dog*"], @am.flow("cat *and dog*")) assert_equal(["*cat and* dog"], @am.flow("*cat and* dog")) assert_equal(["cat *and ", @bold_on, "dog", @bold_off], @am.flow("cat *and *dog*")) assert_equal(["cat ", @em_on, "and", @em_off, " dog"], @am.flow("cat _and_ dog")) assert_equal(["cat_and_dog"], @am.flow("cat_and_dog")) assert_equal(["cat ", @tt_on, "and", @tt_off, " dog"], @am.flow("cat +and+ dog")) assert_equal(["cat ", @bold_on, "a_b_c", @bold_off, " dog"], @am.flow("cat *a_b_c* dog")) assert_equal(["cat __ dog"], @am.flow("cat __ dog")) assert_equal(["cat ", @em_on, "_", @em_off, " dog"], @am.flow("cat ___ dog")) end def test_combined assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off], @am.flow("cat _and_ *dog*")) assert_equal(["cat ", @em_on, "a__nd", @em_off, " ", @bold_on, "dog", @bold_off], @am.flow("cat _a__nd_ *dog*")) end def test_html_like assert_equal(["cat ", @tt_on, "dog", @tt_off], @am.flow("cat dog")) assert_equal(["cat ", @em_on, "and", @em_off, " ", @bold_on, "dog", @bold_off], @am.flow("cat and dog")) assert_equal(["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off], @am.flow("cat and dog")) assert_equal(["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off], @am.flow("cat and dog")) assert_equal(["cat ", @em_on, "and ", @em_to_bold, "dog", @bold_off], @am.flow("cat and dog")) assert_equal([@tt_on, "cat", @tt_off, " ", @em_on, "and ", @em_to_bold, "dog", @bold_off], @am.flow("cat and dog")) assert_equal(["cat ", @em_on, "and ", @em_then_bold, "dog", @bold_em_off], @am.flow("cat and dog")) assert_equal(["cat ", @bold_em_on, "and", @bold_em_off, " dog"], @am.flow("cat and dog")) end def test_protect assert_equal(['cat \\ dog'], @am.flow('cat \\ dog')) assert_equal(["cat dog"], @am.flow("cat \\dog")) assert_equal(["cat ", @em_on, "and", @em_off, " dog"], @am.flow("cat and \\dog")) assert_equal(["*word* or text"], @am.flow("\\*word* or \\text")) assert_equal(["_cat_", @em_on, "dog", @em_off], @am.flow("\\_cat_dog")) end def test_adding assert_equal(["cat ", @wombat_on, "and", @wombat_off, " dog" ], @am.flow("cat {and} dog")) # assert_equal(["cat {and} dog" ], @am.flow("cat \\{and} dog")) end end PK |]8a U~ ~ $ rdoc/markup/simple_markup/to_flow.rbnu [ require 'rdoc/markup/simple_markup/fragments' require 'rdoc/markup/simple_markup/inline' require 'cgi' module SM module Flow P = Struct.new(:body) VERB = Struct.new(:body) RULE = Struct.new(:width) class LIST attr_reader :type, :contents def initialize(type) @type = type @contents = [] end def <<(stuff) @contents << stuff end end LI = Struct.new(:label, :body) H = Struct.new(:level, :text) end class ToFlow LIST_TYPE_TO_HTML = { SM::ListBase::BULLET => [ "
") + "\n" @res << wrap(convert_flow(am.flow(fragment.txt))) @res << annotate("
") + "\n" end def accept_verbatim(am, fragment) @res << annotate("") + "\n"
@res << CGI.escapeHTML(fragment.txt)
@res << annotate("") << "\n"
end
def accept_rule(am, fragment)
size = fragment.param
size = 10 if size > 10
@res << "