module ActionView::Helpers::OutputSafetyHelper

def raw(stringish)

# => 'Jimmy Tables'
raw @user.name

For example:

input.
escape tags. This is not recommended if the data is coming from the user's
now default, this can be used when you don't want \Rails to automatically
This method outputs without escaping a string. Since escaping tags is
def raw(stringish)
  stringish.to_s.html_safe
end

def safe_join(array, sep = $,)


# => "

foo


bar

"
safe_join([raw("

foo

"), raw("

bar

")], raw("
"))

# => "

foo

<br /><p>bar</p>"
safe_join([raw("

foo

"), "

bar

"], "
")

safe, and the returned string is marked as HTML safe.
the supplied separator, are HTML escaped unless they are HTML
would return. The array is flattened, and all items, including
This method returns an HTML safe string similar to what Array#join
def safe_join(array, sep = $,)
  sep = ERB::Util.unwrapped_html_escape(sep)
  array.flatten.map! { |i| ERB::Util.unwrapped_html_escape(i) }.join(sep).html_safe
end

def to_sentence(array, options = {})


ActiveSupport's {Array#to_sentence}[https://api.rubyonrails.org/classes/Array.html#method-i-to_sentence].
joined by the connector word. This is the html_safe-aware version of
Converts the array to a comma-separated sentence where the last element is
def to_sentence(array, options = {})
  options.assert_valid_keys(:words_connector, :two_words_connector, :last_word_connector, :locale)
  default_connectors = {
    words_connector: ", ",
    two_words_connector: " and ",
    last_word_connector: ", and "
  }
  if defined?(I18n)
    i18n_connectors = I18n.translate(:'support.array', locale: options[:locale], default: {})
    default_connectors.merge!(i18n_connectors)
  end
  options = default_connectors.merge!(options)
  case array.length
  when 0
    "".html_safe
  when 1
    ERB::Util.html_escape(array[0])
  when 2
    safe_join([array[0], array[1]], options[:two_words_connector])
  else
    safe_join([safe_join(array[0...-1], options[:words_connector]), options[:last_word_connector], array[-1]], nil)
  end
end