Sha256: 2ae8c1d5d61c4f786e3d7750f7f839547bc9f250edb9d40154a96da9c8177028

Contents?: true

Size: 820 Bytes

Versions: 1

Compression:

Stored size: 820 Bytes

Contents

module RailsToastifyHelper
  def rails_toastify_container
    content_tag :div, '', id: 'toast-container', class: "toast-container #{RailsToastify.configuration.position}"
  end

  def rails_toastify_script
    javascript_tag do
      <<-JS.html_safe
        document.addEventListener('DOMContentLoaded', function() {
          window.RailsToastify = {
            config: #{RailsToastify.configuration.to_h.to_json},
            show: function(message, options) {
              options = Object.assign({}, this.config, options || {});
              showToast(message, options);
            }
          };
        });
      JS
    end
  end

  def show_toast(message, options = {})
    javascript_tag do
      <<-JS.html_safe
        RailsToastify.show(#{message.to_json}, #{options.to_json});
      JS
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rails_toastify-1.1.1 app/helpers/rails_toastify_helper.rb