Module: LiquiDocFilters
Overview
Extending Liquid filters/text manipulation
Instance Method Summary
collapse
-
#asciidocify(input) ⇒ Object
-
#commentwrap(input, width = 80, prepend = '# ') ⇒ Object
-
#encode_entities(input) ⇒ Object
-
#hash_to_array(input, op = nil) ⇒ Object
-
#holds_liquid(input) ⇒ Object
-
#indent_lines(input, by = 2, sym = ' ', line1 = false) ⇒ Object
-
#match(input, regex, multiline = true, global = true) ⇒ Object
-
#plainwrap(input, width = 80) ⇒ Object
-
#quote_wrap(input, quotes = "''", pattern = "\s") ⇒ Object
-
#regexreplace(input, regex, replacement = '') ⇒ Object
-
#replace_regex(input, regex, replacement = '', multiline = true, global = true) ⇒ Object
-
#slugify(input, delim = '-', snip = false) ⇒ Object
-
#smart_format(input) ⇒ Object
-
#sterilize(input) ⇒ Object
-
#store_list_concat(input, property = String) ⇒ Object
-
#store_list_dupes(input, property = String) ⇒ Object
-
#store_list_uniq(input, property = nil) ⇒ Object
-
#strip_tags(input) ⇒ Object
-
#titlecase(input) ⇒ Object
-
#to_cli_args(input, template = "paramequal", delim = " ") ⇒ Object
-
#to_json(input) ⇒ Object
-
#to_slug(input, delim = '-') ⇒ Object
-
#to_yaml(input) ⇒ Object
-
#transliterate(input) ⇒ Object
-
#unwrap(input, token1 = '&g59h%j1k;', token2 = '&ru8sf%df;') ⇒ Object
-
#where_uniq(input, property, value) ⇒ Object
-
#wrap(input, width = 80, prepend = '', append = '', vent = false) ⇒ Object
#array_to_serial, #cgi_escape, #inspect, #jsonify, #normalize_whitespace, #number_of_words, #pop, #push, #sample, #shift, #sort, #to_integer, #unshift, #uri_escape, #where, #where_exp, #xml_escape
Instance Method Details
#asciidocify(input) ⇒ Object
1517
1518
1519
|
# File 'lib/liquidoc.rb', line 1517
def asciidocify input
Asciidoctor.convert(input, doctype: "inline")
end
|
1490
1491
1492
|
# File 'lib/liquidoc.rb', line 1490
def input, width=80, prepend='# '
input.wrap(:width => width, :pre => prepend)
end
|
#encode_entities(input) ⇒ Object
1451
1452
1453
1454
|
# File 'lib/liquidoc.rb', line 1451
def encode_entities input
o = input.dup
o.encode_entities
end
|
#hash_to_array(input, op = nil) ⇒ Object
1529
1530
1531
1532
|
# File 'lib/liquidoc.rb', line 1529
def hash_to_array input, op=nil
o = input.dup
o.to_array(op)
end
|
#holds_liquid(input) ⇒ Object
1534
1535
1536
1537
1538
|
# File 'lib/liquidoc.rb', line 1534
def holds_liquid input
o = false
o = true if input.contains_liquid?
o
end
|
#indent_lines(input, by = 2, sym = ' ', line1 = false) ⇒ Object
1500
1501
1502
|
# File 'lib/liquidoc.rb', line 1500
def indent_lines input, by=2, sym=' ', line1=false
input.indent(:by => by, :sym => "#{sym}", :line1 => line1)
end
|
#match(input, regex, multiline = true, global = true) ⇒ Object
1565
1566
1567
1568
1569
1570
|
# File 'lib/liquidoc.rb', line 1565
def match input, regex, multiline=true, global=true
pattern = Regexp.new(regex, Regexp::MULTILINE) if multiline
pattern = Regexp.new(regex) unless multiline
return true if input.to_s.match(pattern)
return false
end
|
#plainwrap(input, width = 80) ⇒ Object
1486
1487
1488
|
# File 'lib/liquidoc.rb', line 1486
def plainwrap input, width=80
input.wrap(:width => width)
end
|
#quote_wrap(input, quotes = "''", pattern = "\s") ⇒ Object
1521
1522
1523
|
# File 'lib/liquidoc.rb', line 1521
def quote_wrap input, quotes="''", pattern="\s"
input.quote_wrap(:quotes => quotes, :pattern => pattern)
end
|
#regexreplace(input, regex, replacement = '') ⇒ Object
1552
1553
1554
1555
|
# File 'lib/liquidoc.rb', line 1552
def regexreplace input, regex, replacement=''
input.to_s.gsub(Regexp.new(regex), replacement.to_s)
end
|
#replace_regex(input, regex, replacement = '', multiline = true, global = true) ⇒ Object
1557
1558
1559
1560
1561
1562
1563
|
# File 'lib/liquidoc.rb', line 1557
def replace_regex input, regex, replacement='', multiline=true, global=true
pattern = Regexp.new(regex, Regexp::MULTILINE) if multiline
pattern = Regexp.new(regex) unless multiline
o = input.to_s.gsub(pattern, replacement.to_s) if global
o = input.to_s.sub(pattern, replacement.to_s) unless global
o
end
|
#slugify(input, delim = '-', snip = false) ⇒ Object
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
|
# File 'lib/liquidoc.rb', line 1504
def slugify input, delim='-', snip=false
s = input.to_s.downcase
s.gsub!(/[^a-z0-9]/, delim)
if snip
while s.match("#{delim}#{delim}")
s.gsub!("#{delim}#{delim}", "#{delim}")
end
s.gsub!(/^#{delim}+(.*)$/, "\\1")
s.gsub!(/^(.*)#{delim}+$/, "\\1")
end
s
end
|
1446
1447
1448
1449
|
# File 'lib/liquidoc.rb', line 1446
def smart_format input
o = input.dup
o.smart_format
end
|
#sterilize(input) ⇒ Object
1466
1467
1468
1469
|
# File 'lib/liquidoc.rb', line 1466
def sterilize input
o = input.dup
o.sterilize
end
|
#store_list_concat(input, property = String) ⇒ Object
1544
1545
1546
|
# File 'lib/liquidoc.rb', line 1544
def store_list_concat input, property=String
input.concatenate_property_instances(property)
end
|
#store_list_dupes(input, property = String) ⇒ Object
1548
1549
1550
|
# File 'lib/liquidoc.rb', line 1548
def store_list_dupes input, property=String
input.repeated_property_values(property)
end
|
#store_list_uniq(input, property = nil) ⇒ Object
1540
1541
1542
|
# File 'lib/liquidoc.rb', line 1540
def store_list_uniq input, property=nil
input.unique_property_values(property)
end
|
1461
1462
1463
1464
|
# File 'lib/liquidoc.rb', line 1461
def strip_tags input
o = input.dup
o.strip_tags
end
|
#titlecase(input) ⇒ Object
1456
1457
1458
1459
|
# File 'lib/liquidoc.rb', line 1456
def titlecase input
o = input.dup
o.titlecase
end
|
#to_cli_args(input, template = "paramequal", delim = " ") ⇒ Object
1525
1526
1527
|
# File 'lib/liquidoc.rb', line 1525
def to_cli_args input, template="paramequal", delim=" "
input.argify(:template => template, :delim => delim)
end
|
#to_json(input) ⇒ Object
1578
1579
1580
1581
|
# File 'lib/liquidoc.rb', line 1578
def to_json input
o = input.to_json
o
end
|
#to_slug(input, delim = '-') ⇒ Object
1435
1436
1437
1438
1439
|
# File 'lib/liquidoc.rb', line 1435
def to_slug input, delim='-'
o = input.dup
opts = {:delimiter=>delim}
o.to_slug(opts)
end
|
#to_yaml(input) ⇒ Object
1572
1573
1574
1575
1576
|
# File 'lib/liquidoc.rb', line 1572
def to_yaml input
o = input.to_yaml
o = o.gsub(/^\-\-\-$\n/, "")
o
end
|
#transliterate(input) ⇒ Object
1441
1442
1443
1444
|
# File 'lib/liquidoc.rb', line 1441
def transliterate input
o = input.dup
o.transliterate
end
|
#unwrap(input, token1 = '&g59h%j1k;', token2 = '&ru8sf%df;') ⇒ Object
1494
1495
1496
1497
1498
|
# File 'lib/liquidoc.rb', line 1494
def unwrap input, token1='&g59h%j1k;', token2='&ru8sf%df;'
if input
input.gsub(/(.)\n\n/, "\\1#{token1}").gsub(/([\."'])$\n([A-Z\(\_"'])/,"\\1#{token2}\\2").gsub(/\n/, '').gsub(token2,"\n").gsub(token1, "\n\n")
end
end
|
#where_uniq(input, property, value) ⇒ Object
1475
1476
1477
1478
1479
1480
|
# File 'lib/liquidoc.rb', line 1475
def where_uniq input, property, value
o = input.where(input, property, value)
o[0] if o.size == 1
"No result" unless o.size
"Multiple results" if o.size > 1
end
|
#wrap(input, width = 80, prepend = '', append = '', vent = false) ⇒ Object
1482
1483
1484
|
# File 'lib/liquidoc.rb', line 1482
def wrap input, width=80, prepend='', append='', vent=false
input.wrap(:width => width, :prepend => prepend, :append => append)
end
|