Class: Nexmo::Markdown::I18n::Smartling::FrontmatterFilter

Inherits:
Banzai::Filter
  • Object
show all
Defined in:
lib/nexmo_markdown_renderer/filters/i18n/smartling/frontmatter_filter.rb

Instance Method Summary collapse

Instance Method Details

#call(input) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/nexmo_markdown_renderer/filters/i18n/smartling/frontmatter_filter.rb', line 6

def call(input)
  input.gsub(/\A\*\*\* \*\* \* \*\* \*\*\*\n*(.*?\n)!?(\*\*\* \*\* \* \*\* \*\*\*|----+)\n*/m) do |_frontmatter|
    front = $1.gsub(/`products: (.*)`\n\n/) do |products|
      "products: #{$1}\n\n"
    end

    front = front.gsub(/`(.*):`(.*)/) do |_config|
      "#{$1}: #{$2}"
    end

    front = front.gsub(/languages: \n\n(.*)\n/m) do |_languages|
      languages = $1.split("\n\n").map do |lang|
        lang.gsub(/\* `(.*)`/) { |_l| "  - #{$1}" }
      end
      <<~LANGUAGES
      languages:
      #{languages.join("\n")}
      LANGUAGES
    end

    <<~FRONTMATTER
      ---
      #{front}
      ---

    FRONTMATTER
  end
end