Class: String
Instance Method Summary
collapse
Methods included from ForceArray
#force_array, #force_array!
Instance Method Details
#contains_liquid? ⇒ Boolean
1254
1255
1256
1257
1258
1259
1260
1261
|
# File 'lib/liquidoc.rb', line 1254
def contains_liquid?
self.each_line do |row|
if row.match(/.*\{\%.*\%\}.*|.*\{\{.*\}\}.*/)
return true
end
end
return false
end
|
#indent(options = {}) ⇒ Object
1247
1248
1249
1250
1251
1252
|
# File 'lib/liquidoc.rb', line 1247
def indent options = {}
syms = options.fetch(:sym, ' ') * options.fetch(:by, 2)
self.gsub!(/^/m, "#{syms}")
self.sub!("#{syms}", "") unless options.fetch(:line1, false)
end
|
#quote_wrap(options = {}) ⇒ Object
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
|
# File 'lib/liquidoc.rb', line 1263
def quote_wrap options = {}
pattern = options.fetch(:pattern, '\s').to_s
return self unless self.strip.match(/\s/)
quotes = options.fetch(:quotes, "single")
case quotes
when "single"
wrap = "''"
when "double"
wrap = '""'
when "backtick"
wrap = "``"
when "bracket"
wrap = "[]"
else
wrap = quotes
end
quotes << wrap[0] unless wrap[1]
return wrap[0] + self.strip + wrap[1]
end
|
#wrap(options = {}) ⇒ Object
1237
1238
1239
1240
1241
1242
1243
1244
1245
|
# File 'lib/liquidoc.rb', line 1237
def wrap options = {}
width = options.fetch(:width, 76) pre = options.fetch(:prepend, '') app = options.fetch(:append, '') chars = pre.size + app.size
self.strip.split("\n").collect do |line|
line.length + chars.size > width ? line.gsub(/(.{1,#{(width - chars)}})(\s+|$)/, "#{pre}\\1#{app}\n") : "#{pre}#{line}#{app}\n"
end.map(&:rstrip).join("\n")
end
|