Class: ReeText::SimpleFormat

Inherits:
Object
  • Object
show all
Includes:
Ree::FnDSL
Defined in:
lib/ree_lib/packages/ree_text/package/ree_text/functions/simple_format.rb

Constant Summary collapse

DEFAULTS =
{
  html_options: {},
  wrapper_tag: :p,
  sanitize: false
}

Instance Method Summary collapse

Instance Method Details

#call(text, **opts) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/ree_lib/packages/ree_text/package/ree_text/functions/simple_format.rb', line 69

def call(text, **opts)
  options = DEFAULTS.merge(opts)
  text = sanitize_html(text) if options[:sanitize]
  wrapper_tag = options[:wrapper_tag]
  html_options = options[:html_options]
  paragraphs = split_paragraphs(text)

  if is_blank(paragraphs)
    (wrapper_tag, nil, html_options)
  else
    paragraphs
      .map! { (wrapper_tag, _1, html_options) }
      .join("\n\n")
  end
end