module EvilFront::Russian

Helpers to work with Russian text.

Public Class Methods

auto_flying_quotes(html) click to toggle source

Find quotes in text and make them flying

# File lib/evil-front/russian.rb, line 21
def self.auto_flying_quotes(html)
  process_html(html) do |text|
    text.gsub(/\s«[^»]+»/) { |i| flying_quotes i[2..-2], space: i[0] }.
         gsub(/^«[^»]+»/)  { |i| flying_quotes i[1..-2], space: '' }
  end
end
capitalize_first(text) click to toggle source

Capitalize only first letter (like titles in Russian).

= EvilFront::Russian.capitalize_first(title)
# File lib/evil-front/russian.rb, line 16
def self.capitalize_first(text)
  UnicodeUtils.upcase(text[0]) + text[1..-1]
end
flying_quotes(text, options = { }) click to toggle source

Mark quotes to move first quote before the text line.

# File lib/evil-front/russian.rb, line 29
def self.flying_quotes(text, options = { })
  sp = options[:space] || ' '
  sp = "<span class=\"space-before-quote\">#{sp}</span>" if sp != ''
  "#{ sp }<span class=\"quotes\">«#{ text }»</span>"
end

Private Class Methods

tiny_words() click to toggle source

Small words to insert non-break space before them

# File lib/evil-front/russian.rb, line 38
def self.tiny_words
  @tiny_words ||= begin
    tiny  = %w(ни не и но а или да как из-за про по за для
               на до при меж о у в во с со от ото из без
               безо к ко об обо под подо над перед передо это)
    tiny += tiny.map { |i| capitalize_first(i) }
    tiny.map { |i| Regexp.new("( | )(#{Regexp.quote i}) ") }
  end
end
use_right_symbols(text) click to toggle source

Replace symbols to right ones, like m-dash, quotes, etc.

# File lib/evil-front/russian.rb, line 49
def self.use_right_symbols(text)
  StandaloneTypograf::Typograf.new(text)
    .processor(:dashes, :quotes, :mnemonics, :fractions, :ellipsis)
    .gsub(' —', ' —')                       # nbsp before m-dash
    .gsub(/([а-яА-Я])-([а-яА-Я])/, '\1‑\2') # non-break dash
end