Sha256: b0d9fd1196dd8f25ec9ba7772272d4d50a1040901bdcea7096abf837225cbdb0

Contents?: true

Size: 1.66 KB

Versions: 18

Compression:

Stored size: 1.66 KB

Contents

module ApplicationHelper
  include WithStudentPathNavigation

  # html-escapes an string even if it is html-safe
  def html_rescape(html)
    html_escape html.to_str
  end

  def profile_picture_for(user, **options)
    default_options = { height: 40, onError: "this.onerror = null; this.src = '#{image_url(user.placeholder_image_url)}'" }
    avatar_image(user.profile_picture, default_options.merge(options))
  end

  def avatar_image(avatar_url, **options)
    options.merge!(class: "rounded-circle #{options[:class]}")
    image_tag(image_url(avatar_url), options)
  end

  def paginate(object, options = {})
    super(object, {theme: 'bootstrap-5', pagination_class: 'flex-wrap justify-content-center'}.merge(options))
  end

  def last_box_class(trailing_boxes)
    trailing_boxes ? '' : 'mu-last-box'
  end

  def corollary_box(with_corollary, trailing_boxes = false)
    if with_corollary.corollary.present?
      %Q{
        <div class="#{last_box_class trailing_boxes}">
          <p>#{with_corollary.corollary_html}</p>
        </div>
      }.html_safe
    end
  end

  def chapter_finished(chapter)
    t :chapter_finished_html, chapter: link_to_path_element(chapter) if chapter
  end

  def btn_toggle(hidden_text, active_text, active, **options)
    %Q{
      <button class="btn btn-complementary #{'d-none' if active} #{options[:class]}" onclick="#{options[:onclick]}">#{hidden_text}</button>
      <button class="btn btn-secondary #{'d-none' unless active} #{options[:class]}" onclick="#{options[:onclick]}">#{active_text}</button>
    }.html_safe
  end

  def notification_preview_for(target)
    render "notifications/#{target.class.name.underscore}", { target: target }
  end
end

Version data entries

18 entries across 18 versions & 1 rubygems

Version Path
mumuki-laboratory-9.8.2 app/helpers/application_helper.rb
mumuki-laboratory-9.8.1 app/helpers/application_helper.rb
mumuki-laboratory-9.8.0 app/helpers/application_helper.rb
mumuki-laboratory-9.7.2 app/helpers/application_helper.rb
mumuki-laboratory-9.7.1 app/helpers/application_helper.rb
mumuki-laboratory-9.7.0 app/helpers/application_helper.rb
mumuki-laboratory-9.6.0 app/helpers/application_helper.rb
mumuki-laboratory-9.5.1 app/helpers/application_helper.rb
mumuki-laboratory-9.5.0 app/helpers/application_helper.rb
mumuki-laboratory-9.4.1 app/helpers/application_helper.rb
mumuki-laboratory-9.4.0 app/helpers/application_helper.rb
mumuki-laboratory-9.3.1 app/helpers/application_helper.rb
mumuki-laboratory-9.3.0 app/helpers/application_helper.rb
mumuki-laboratory-9.2.0 app/helpers/application_helper.rb
mumuki-laboratory-9.1.3 app/helpers/application_helper.rb
mumuki-laboratory-9.1.2 app/helpers/application_helper.rb
mumuki-laboratory-9.1.1 app/helpers/application_helper.rb
mumuki-laboratory-9.1.0 app/helpers/application_helper.rb