lib/mdoc.rb in markdown_exec-1.8.7 vs lib/mdoc.rb in markdown_exec-1.8.8

- old
+ new

@@ -74,29 +74,32 @@ name_block = get_block_by_anyname(name) if name_block.nil? || name_block.keys.empty? raise "Named code block `#{name}` not found. (@#{__LINE__})" end - dependencies = collect_dependencies(name_block[:oname]) + nickname = name_block[:nickname] || name_block[:oname] + dependencies = collect_dependencies(nickname) # &bc 'dependencies.count:',dependencies.count - all_dependency_names = collect_unique_names(dependencies).push(name_block[:oname]).uniq + all_dependency_names = collect_unique_names(dependencies).push(nickname).uniq # &bc 'all_dependency_names.count:',all_dependency_names.count # select non-chrome blocks in order of appearance in source documents # blocks = @table.select do |fcb| - !fcb.fetch(:chrome, false) && all_dependency_names.include?(fcb.fetch(:oname)) + !fcb.fetch(:chrome, + false) && all_dependency_names.include?(fcb.fetch(:nickname, + nil) || fcb.fetch(:oname)) end # &bc 'blocks.count:',blocks.count ## add cann key to blocks, calc unmet_dependencies # unmet_dependencies = all_dependency_names.dup blocks = blocks.map do |fcb| - unmet_dependencies.delete(fcb[:oname]) # may not exist if block name is duplicated + unmet_dependencies.delete(fcb[:nickname] || fcb[:oname]) # may not exist if block name is duplicated if (call = fcb[:call]) - [get_block_by_oname("[#{call.match(/^%\((\S+) |\)/)[1]}]") + [get_block_by_anyname("[#{call.match(/^%\((\S+) |\)/)[1]}]") .merge({ cann: call })] else [] end + [fcb] end.flatten(1) @@ -119,11 +122,11 @@ if block_search[:blocks] blocks = collect_wrapped_blocks(block_search[:blocks]) # &bc 'blocks.count:',blocks.count block_search.merge( - { block_names: blocks.map { |block| block[:oname] }, + { block_names: blocks.map { |block| block[:nickname] || block[:oname] }, code: blocks.map do |fcb| if fcb[:cann] collect_block_code_cann(fcb) elsif fcb[:stdout] collect_block_code_stdout(fcb) @@ -131,15 +134,16 @@ BlockType::VARS].include? fcb[:shell] nil elsif fcb[:shell] == BlockType::PORT collect_block_code_shell(fcb) elsif label_body + block_name_for_bash_comment = (fcb[:nickname] || fcb[:oname]).gsub(/\s+/, '_') [label_format_above && format(label_format_above, - block_source.merge({ block_name: fcb[:oname] }))] + + block_source.merge({ block_name: block_name_for_bash_comment }))] + fcb[:body] + [label_format_below && format(label_format_below, - block_source.merge({ block_name: fcb[:oname] }))] + block_source.merge({ block_name: block_name_for_bash_comment }))] else # raw body fcb[:body] end end.compact.flatten(1).compact } ) @@ -192,13 +196,19 @@ Filter.fcb_select? options, fcb_title_groups end ### hide rows correctly + if !options[:menu_include_imported_blocks] + selrows = selrows.reject do |block| + block.fetch(:depth, 0).positive? + end + end + if opts[:hide_blocks_by_name] selrows = selrows.reject do |block| - hide_menu_block_per_options opts, block + hide_menu_block_on_name opts, block end end # remove # . empty chrome between code; edges are same as blanks @@ -214,34 +224,23 @@ # @param default [Hash] The default value to return if the code block is not found. # @return [Hash] The code block as a hash or the default value if not found. # def get_block_by_anyname(name, default = {}) @table.select do |fcb| - fcb.fetch(:dname, '') == name || fcb.fetch(:oname, '') == name + fcb.fetch(:nickname, + '') == name || fcb.fetch(:dname, '') == name || fcb.fetch(:oname, '') == name end.fetch(0, default) end - def get_block_by_dname(name, default = {}) - @table.select do |fcb| - fcb.fetch(:dname, '') == name - end.fetch(0, default) - end - - def get_block_by_oname(name, default = {}) - @table.select do |fcb| - fcb.fetch(:oname, '') == name - end.fetch(0, default) - end - # Checks if a code block should be hidden based on the given options. # # @param opts [Hash] The options used for hiding code blocks. # @param block [Hash] The code block to check for hiding. # @return [Boolean] True if the code block should be hidden; false otherwise. # # :reek:UtilityFunction - def hide_menu_block_per_options(opts, block) + def hide_menu_block_on_name(opts, block) if block.fetch(:chrome, false) false else (opts[:hide_blocks_by_name] && ((opts[:block_name_hidden_match]&.present? && @@ -268,11 +267,11 @@ while rem && rem.count.positive? rem = rem.map do |req| next if memo.include? req memo += [req] - get_block_by_oname(req).fetch(:reqs, []) + get_block_by_anyname(req).fetch(:reqs, []) end .compact .flatten(1) end memo @@ -443,14 +442,14 @@ # expected_result = @table[0][:body] + @table[1][:body] # assert_equal expected_result, result # end def test_get_block_by_name - result = @doc.get_block_by_oname('block1') + result = @doc.get_block_by_anyname('block1') assert_equal @table[0], result - result_missing = @doc.get_block_by_oname('missing_block') + result_missing = @doc.get_block_by_anyname('missing_block') assert_equal({}, result_missing) end ### broken test def test_collect_block_dependencies @@ -461,14 +460,14 @@ assert_raises(RuntimeError) do @doc.collect_block_dependencies('missing_block') end end - def test_hide_menu_block_per_options + def test_hide_menu_block_on_name opts = { hide_blocks_by_name: true, block_name_hidden_match: 'block1' } block = FCB.new(oname: 'block1') - result = @doc.hide_menu_block_per_options(opts, block) + result = @doc.hide_menu_block_on_name(opts, block) assert result # this should be true based on the given logic end ### broken test # def test_fcbs_per_options