Class: String
- Inherits:
-
Object
- Object
- String
- Defined in:
- lib/wax_tasks/utils.rb
Overview
Monkey-patched String class
Instance Method Summary collapse
-
#cyan ⇒ String
Colorizes console output to cyan (messages).
-
#html_strip ⇒ String
Cleans YAML front matter + markdown pages for lunr indexing.
-
#magenta ⇒ String
Colorizes console output to magenta (errors).
-
#normalize ⇒ String
Normalizes string without diacritics for lunr indexing.
-
#orange ⇒ String
Colorizes console output to orange (warnings).
-
#remove_diacritics ⇒ String
Normalizes accent marks/diacritics for Lunr indexing.
-
#remove_yaml ⇒ String
Removes YAML front matter from a string.
-
#slug ⇒ String
Converts string to snake case and swaps out special chars.
Instance Method Details
#cyan ⇒ String
Colorizes console output to cyan (messages)
143 144 145 |
# File 'lib/wax_tasks/utils.rb', line 143 def cyan "\e[36m#{self}\e[0m" end |
#html_strip ⇒ String
Cleans YAML front matter + markdown pages for lunr indexing
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 |
#magenta ⇒ String
Colorizes console output to magenta (errors)
137 138 139 |
# File 'lib/wax_tasks/utils.rb', line 137 def magenta "\e[35m#{self}\e[0m" end |
#normalize ⇒ String
Normalizes string without diacritics for lunr indexing
131 132 133 |
# File 'lib/wax_tasks/utils.rb', line 131 def normalize self.remove_diacritics end |
#orange ⇒ String
Colorizes console output to orange (warnings)
149 150 151 |
# File 'lib/wax_tasks/utils.rb', line 149 def orange "\e[33m#{self}\e[0m" end |
#remove_diacritics ⇒ String
Normalizes accent marks/diacritics for Lunr indexing
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_yaml ⇒ String
Removes YAML front matter from a string
99 100 101 |
# File 'lib/wax_tasks/utils.rb', line 99 def remove_yaml self.gsub!(/\A---(.|\n)*?---/, '') end |
#slug ⇒ String
Converts string to snake case and swaps out special chars
125 126 127 |
# File 'lib/wax_tasks/utils.rb', line 125 def slug self.downcase.tr(' ', '_').gsub(/[^\w-]/, '') end |