Class: String

Inherits:
Object
  • Object
show all
Defined in:
lib/wax_tasks/utils.rb

Overview

Monkey-patched String class

Instance Method Summary collapse

Instance Method Details

#cyanString

Colorizes console output to cyan (messages)

Returns:



143
144
145
# File 'lib/wax_tasks/utils.rb', line 143

def cyan
  "\e[36m#{self}\e[0m"
end

#html_stripString

Cleans YAML front matter + markdown pages for lunr indexing

Returns:



105
106
107
108
109
110
111
112
113
# File 'lib/wax_tasks/utils.rb', line 105

def html_strip
  self.gsub!(/\A---(.|\n)*?---/, '') # remove yaml front matter
  self.gsub!(/{%(.*)%}/, '') # remove functional liquid
  self.gsub!(%r{<\/?[^>]*>}, '') # remove html
  self.gsub!('\\n', '') # remove newlines
  self.gsub!(/\s+/, ' ') # remove extra space
  self.tr!('"', "'") # replace double quotes with single
  self
end

#magentaString

Colorizes console output to magenta (errors)

Returns:



137
138
139
# File 'lib/wax_tasks/utils.rb', line 137

def magenta
  "\e[35m#{self}\e[0m"
end

#normalizeString

Normalizes string without diacritics for lunr indexing

Returns:



131
132
133
# File 'lib/wax_tasks/utils.rb', line 131

def normalize
  self.remove_diacritics
end

#orangeString

Colorizes console output to orange (warnings)

Returns:



149
150
151
# File 'lib/wax_tasks/utils.rb', line 149

def orange
  "\e[33m#{self}\e[0m"
end

#remove_diacriticsString

Normalizes accent marks/diacritics for Lunr indexing

Returns:



117
118
119
120
121
# File 'lib/wax_tasks/utils.rb', line 117

def remove_diacritics
  to_replace  = 'ÀÁÂÃÄÅàáâãäåĀāĂ㥹ÇçĆćĈĉĊċČčÐðĎďĐđÈÉÊËèéêëĒēĔĕĖėĘęĚěĜĝĞğĠġĢģĤĥĦħÌÍÎÏìíîïĨĩĪīĬĭĮįİıĴĵĶķĸĹĺĻļĽľĿŀŁłÑñŃńŅņŇňʼnŊŋÒÓÔÕÖØòóôõöøŌōŎŏŐőŔŕŖŗŘřŚśŜŝŞşŠšſŢţŤťŦŧÙÚÛÜùúûüŨũŪūŬŭŮůŰűŲųŴŵÝýÿŶŷŸŹźŻżŽž'
  replaced_by = 'AAAAAAaaaaaaAaAaAaCcCcCcCcCcDdDdDdEEEEeeeeEeEeEeEeEeGgGgGgGgHhHhIIIIiiiiIiIiIiIiIiJjKkkLlLlLlLlLlNnNnNnNnnNnOOOOOOooooooOoOoOoRrRrRrSsSsSsSssTtTtTtUUUUuuuuUuUuUuUuUuUuWwYyyYyYZzZzZz'
  self.tr(to_replace, replaced_by)
end

#remove_yamlString

Removes YAML front matter from a string

Returns:



99
100
101
# File 'lib/wax_tasks/utils.rb', line 99

def remove_yaml
  self.gsub!(/\A---(.|\n)*?---/, '')
end

#slugString

Converts string to snake case and swaps out special chars

Returns:



125
126
127
# File 'lib/wax_tasks/utils.rb', line 125

def slug
  self.downcase.tr(' ', '_').gsub(/[^\w-]/, '')
end