Module: StandaloneTypograf::Nbspaces::Processor

Defined in:
lib/standalone_typograf/nbspaces.rb

Class Method Summary collapse

Class Method Details

.compile(text, mode) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/standalone_typograf/nbspaces.rb', line 22

def self.compile(text, mode)
  # One or three letter word - nbspace to the right
  text.gsub!(/(\s|^)([[:alpha:]]{1,2})(\s)/i, '\1\2'+CHAR[mode])

  # nbspace to the right
  text.gsub!(/(#{PARTICLES.join('|')})(\s)/i, '\1'+CHAR[mode])

  # dash - nbspace to the left
  text.gsub!(/(\s)(-|#{Dashes::CHAR[:html]}|#{Dashes::CHAR[:utf]})/i, CHAR[mode]+'\2')

  return text
end