Completed
Push — master ( f38e39...3e86b8 )
by
unknown
10s
created

ApplicationHelper.markdown()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
1
# Methods added to this helper will be available to all templates in the application.
2
module ApplicationHelper
3
4
  def edit(obj, &blk)
5
    return unless logged_in?
6
    if obj == current_participant || obj.try(:participant_id) == current_participant.id
7
      concat(capture(&blk))
8
    end
9
  end
10
11
  def markdown(str)
12
    return '' unless str
13
    @markdown ||= Redcarpet::Markdown.new(
14
        Redcarpet::Render::HTML.new,
15
        autolink: true,
16
        space_after_headers: true)
17
    sanitize_html(close_tags(@markdown.render(str))).html_safe
18
  end
19
20
  def close_tags(html)
21
    Nokogiri::HTML::DocumentFragment.parse(html).to_html
22
  end
23
24
  def sanitize_html(html)
25
    sanitize html,
26
      tags: %w(a img b i em strong p br ul ol li),
27
      attributes: %w(href src height width alt)
28
  end
29
30
  def add_sessions_button
31
    link_to image_tag('button-add-session.png', :title => 'Add session', :size => "215x43", :border=>"0"), new_session_path, class: 'add-sessions-button', title: "Add Session"
32
  end
33
34
  def toggle_attendance_button(session)
35
    content_tag(:button, "Attending", class: "toggle-attendance", 'data-session-id': session.id)
0 ignored issues
show
Bug introduced by
The Ruby parser could not interpret the code. It reported: unexpected token tCOLON (Using Ruby 2.0 p...meter, under `AllCops`).
Loading history...
Bug introduced by
The Ruby parser could not interpret the code. It reported: unexpected token tRPAREN (Using Ruby 2.0 ...meter, under `AllCops`).
Loading history...
36
  end
37
end
38