Class: MarkdownExec::MenuFilter

Inherits:
Object
  • Object
show all
Defined in:
lib/mdoc.rb

Instance Method Summary collapse

Constructor Details

#initialize(opts) ⇒ MenuFilter

Returns a new instance of MenuFilter.



14
15
16
# File 'lib/mdoc.rb', line 14

def initialize(opts)
  @opts = opts.merge(block_name_hidden_match: nil)
end

Instance Method Details

#fcb_in_menu?(fcb) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
21
22
23
24
25
26
27
# File 'lib/mdoc.rb', line 18

def fcb_in_menu?(fcb)
  in_menu = Filter.fcb_select?(@opts, fcb)
  unless @opts[:menu_include_imported_blocks]
    in_menu = fcb.fetch(:depth, 0).zero?
  end
  if in_menu && @opts[:hide_blocks_by_name]
    in_menu = !hide_menu_block_on_name(fcb)
  end
  in_menu
end

#hide_menu_block_on_name(block) ⇒ Boolean

Checks if a code block should be hidden based on the given options.

:reek:UtilityFunction

Parameters:

  • opts (Hash)

    The options used for hiding code blocks.

  • block (Hash)

    The code block to check for hiding.

Returns:

  • (Boolean)

    True if the code block should be hidden; false otherwise.



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/mdoc.rb', line 36

def hide_menu_block_on_name(block)
  if block.fetch(:chrome, false)
    false
  else
    @opts[:hide_blocks_by_name] &&
      ((@opts[:block_name_hidden_match]&.present? &&
        block.s2title&.match(Regexp.new(@opts[:block_name_hidden_match]))) ||
       (@opts[:block_name_include_match]&.present? &&
        block.s2title&.match(Regexp.new(@opts[:block_name_include_match]))) ||
       (@opts[:block_name_wrapper_match]&.present? &&
        block.s2title&.match(Regexp.new(@opts[:block_name_wrapper_match])))) &&
      (block.s2title&.present? || block[:label]&.present?)
  end
end