Loading spec/doc_formatter_spec.rb +12 −35 Original line number Diff line number Diff line require "jsduck/doc_formatter" class String # Removes beginning-whitespace from each line of a string. # But only as many whitespace as the first line has. # # Ment to be used with heredoc strings like so: # # text = <<-EOS.heredoc # This line has no indentation # This line has 2 spaces of indentation # This line is also not indented # EOS # def unindent lines = [] each_line {|ln| lines << ln } first_line_ws = lines[0].match(/^\s+/)[0] re = Regexp.new('^\s{0,' + first_line_ws.length.to_s + '}') lines.collect {|line| line.sub(re, "") }.join end end describe JsDuck::DocFormatter do before do Loading Loading @@ -85,12 +62,12 @@ describe JsDuck::DocFormatter do describe "<pre>" do before do @html = @formatter.format(<<-EOS.unindent) Some code<pre> if (condition) { doSomething(); } </pre> @html = @formatter.format(<<-EOS.gsub(/^ *\|/, "")) |Some code<pre> |if (condition) { | doSomething(); |} |</pre> EOS end Loading @@ -103,12 +80,12 @@ describe JsDuck::DocFormatter do describe "<pre><code>" do before do @html = @formatter.format(<<-EOS.unindent) Some code<pre><code> if (condition) { doSomething(); } </code></pre> @html = @formatter.format(<<-EOS.gsub(/^ *\|/, "")) |Some code<pre><code> |if (condition) { | doSomething(); |} |</code></pre> EOS end Loading Loading
spec/doc_formatter_spec.rb +12 −35 Original line number Diff line number Diff line require "jsduck/doc_formatter" class String # Removes beginning-whitespace from each line of a string. # But only as many whitespace as the first line has. # # Ment to be used with heredoc strings like so: # # text = <<-EOS.heredoc # This line has no indentation # This line has 2 spaces of indentation # This line is also not indented # EOS # def unindent lines = [] each_line {|ln| lines << ln } first_line_ws = lines[0].match(/^\s+/)[0] re = Regexp.new('^\s{0,' + first_line_ws.length.to_s + '}') lines.collect {|line| line.sub(re, "") }.join end end describe JsDuck::DocFormatter do before do Loading Loading @@ -85,12 +62,12 @@ describe JsDuck::DocFormatter do describe "<pre>" do before do @html = @formatter.format(<<-EOS.unindent) Some code<pre> if (condition) { doSomething(); } </pre> @html = @formatter.format(<<-EOS.gsub(/^ *\|/, "")) |Some code<pre> |if (condition) { | doSomething(); |} |</pre> EOS end Loading @@ -103,12 +80,12 @@ describe JsDuck::DocFormatter do describe "<pre><code>" do before do @html = @formatter.format(<<-EOS.unindent) Some code<pre><code> if (condition) { doSomething(); } </code></pre> @html = @formatter.format(<<-EOS.gsub(/^ *\|/, "")) |Some code<pre><code> |if (condition) { | doSomething(); |} |</code></pre> EOS end Loading