Class: String

Inherits:
Object
  • Object
show all
Includes:
ForceArray
Defined in:
lib/liquidoc.rb

Instance Method Summary collapse

Methods included from ForceArray

#force_array

Instance Method Details

#indent(options = {}) ⇒ Object



1054
1055
1056
1057
# File 'lib/liquidoc.rb', line 1054

def indent options = {}
  spaces = " " * options.fetch(:spaces, 4)
  self.gsub(/^/, spaces).gsub(/^\s*$/, '')
end

#indent_with_wrap(options = {}) ⇒ Object



1059
1060
1061
1062
1063
1064
# File 'lib/liquidoc.rb', line 1059

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 = {}) ⇒ Object



1046
1047
1048
1049
1050
1051
1052
# File 'lib/liquidoc.rb', line 1046

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