• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

MarkUsProject / Markus / 12665252158

08 Jan 2025 06:25AM UTC coverage: 91.73% (-0.002%) from 91.732%
12665252158

Pull #7374

github

web-flow
Merge 8cb619e5c into 16128fccc
Pull Request #7374: Refactor Contributors List to Dynamically Read from File

624 of 1365 branches covered (45.71%)

Branch coverage included in aggregate %.

4 of 5 new or added lines in 1 file covered. (80.0%)

1 existing line in 1 file now uncovered.

41184 of 44212 relevant lines covered (93.15%)

120.5 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

96.97
/app/helpers/application_helper.rb
1
# Methods added to this helper will be available to all templates in the application.
2
module ApplicationHelper
2✔
3
  # A more robust flash method. Easier to add multiple messages of each type:
4
  # :error, :success, :warning and :notice
5
  def flash_message(type, text = '', flash_type = flash, **kwargs)
2✔
6
    return if text.nil?
702✔
7

8
    available_types = [:error, :success, :warning, :notice]
702✔
9
    # If type isn't one of the four above, we display it as :notice.
10
    # We don't want to suppress the message, which is why we pick a
11
    # type, and :notice is the most neutral of the four
12
    type = :notice unless available_types.include?(type)
702✔
13
    # If a flash with that type doesn't exist, create a new array
14
    flash_type[type] ||= []
702✔
15
    content = kwargs.empty? ? "<p>#{text.to_s.gsub("\n", '<br/>')}</p>" : render_to_string(**kwargs).split("\n").join
702✔
16
    # If the message doesn't already exist, add it
17
    flash_type[type].push(content) unless flash_type[type].include?(content)
702✔
18
  end
19

20
  # A version of flash_message using flash.now instead. This makes the flash
21
  # available only for the current action.
22
  def flash_now(type, text = '', **kwargs)
2✔
23
    flash_message(type, text, flash.now, **kwargs)
205✔
24
  end
25

26
  # A version of flash_message that accepts an ActionPolicy authorization result
27
  # instead of a message. The result is used to get failure messages and those
28
  # messages are added to the flash hash. If +most_specific+ is true, then only
29
  # the last error message is added to the flash hash.
30
  #
31
  # If the result is a success, this method does nothing. The result is then returned.
32
  def flash_allowance(type, result, flash_type = flash, most_specific: false)
2✔
33
    full_messages = result.reasons.full_messages
36✔
34
    full_messages = [full_messages.last] if most_specific
36✔
35
    message = full_messages.join("\n")
36✔
36
    message = result.message if message.blank?
36✔
37
    flash_message(type, message, flash_type) unless result.value
36✔
38
    result
36✔
39
  end
40

41
  def flash_csv_result(result)
2✔
42
    flash_message(:error, result[:invalid_lines]) unless result[:invalid_lines].empty?
68✔
43
    flash_message(:success, result[:valid_lines]) unless result[:valid_lines].empty?
68✔
44
  end
45

46
  def markdown(text)
2✔
47
    options = { filter_html: false, hard_wrap: true,
16✔
48
                link_attributes: { rel: 'nofollow', target: '_blank' },
49
                space_after_headers: true, fenced_code_blocks: true,
50
                escape_html: true }
51
    extensions = { autolink: true }
16✔
52
    renderer = Redcarpet::Render::HTML.new(options)
16✔
53
    markdown = Redcarpet::Markdown.new(renderer, extensions)
16✔
54
    sanitize markdown.render(text) unless text.nil?
16✔
55
  end
56

57
  def yield_content!(content_key)
2✔
58
    view_flow.content.delete(content_key)
3,248✔
59
  end
60

61
  def read_contributors
2✔
62
    contributors_file = Rails.root.join('doc/markus-contributors.txt')
1✔
63
    if File.exist?(contributors_file)
1✔
64
      File.read(contributors_file).split("\n")
1✔
65
    else
NEW
UNCOV
66
      []
×
67
    end
68
  end
69
end
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc