class String
Public Instance Methods
indent(options = {})
click to toggle source
# File lib/liquidoc.rb, line 1224 def indent options = {} spaces = " " * options.fetch(:spaces, 4) self.gsub(/^/, spaces).gsub(/^\s*$/, '') end
indent_with_wrap(options = {})
click to toggle source
# File lib/liquidoc.rb, line 1229 def indent_with_wrap options = {} spaces = options.fetch(:spaces, 4) width = options.fetch(:width, 80) width = width > spaces ? width - spaces : 1 self.wrap(width: width).indent(spaces: spaces) end
wrap(options = {})
click to toggle source
Adapted from Nikhil Gupta nikhgupta.com/code/wrapping-long-lines-in-ruby-for-display-in-source-files/
# File lib/liquidoc.rb, line 1216 def wrap options = {} width = options.fetch(:width, 76) commentchar = options.fetch(:commentchar, '') self.strip.split("\n").collect do |line| line.length > width ? line.gsub(/(.{1,#{width}})(\s+|$)/, "\\1\n#{commentchar}") : line end.map(&:strip).join("\n#{commentchar}") end