lib/directory_searcher.rb in markdown_exec-1.8.4 vs lib/directory_searcher.rb in markdown_exec-1.8.5

- old
+ new

@@ -3,10 +3,34 @@ # encoding=utf-8 require 'find' +def format_and_highlight_hash( + data, + highlight_color_sym: :exception_color_detail, + plain_color_sym: :menu_chrome_color, + label: 'Data:', + highlight: [], + line_prefix: ' ', + line_postfix: '', + key_has_value: ': ' +) + formatted_deps = data&.map do |key, value| + color_sym = highlight.include?(key) ? highlight_color_sym : plain_color_sym + dkey = string_send_color(key, color_sym) + + "#{line_prefix}#{dkey}#{key_has_value}" \ + "#{string_send_color(value, + highlight.include?(value) ? highlight_color_sym : plain_color_sym)}: " \ + "#{formatted_sub_items}#{line_postfix}" + end + + "#{line_prefix}#{string_send_color(label, + highlight_color_sym)}#{line_postfix}\n" + formatted_deps.join("\n") +end + # Formats and highlights a list of dependencies. Dependencies are presented with indentation, # and specific items can be highlighted in a specified color, while others are shown in a plain color. # # @param dependencies [Hash] A hash of dependencies, where each key is a dependency name, # and its value is an array of sub-items. @@ -45,10 +69,28 @@ "#{line_prefix}#{string_send_color(label, highlight_color_sym)}#{line_postfix}\n" + formatted_deps.join("\n") end # warn menu_blocks.to_yaml.sub(/^(?:---\n)?/, "MenuBlocks:\n") +def format_and_highlight_lines( + lines, + highlight_color_sym: :exception_color_detail, + plain_color_sym: :menu_chrome_color, + label: 'Dependencies:', + highlight: [], + line_prefix: ' ', + line_postfix: '' +) + formatted_deps = lines&.map do |item| + "#{line_prefix}- #{string_send_color(dep_name, + highlight.include?(dep_name) ? highlight_color_sym : plain_color_sym)}: #{item}#{line_postfix}" + end || [] + + "#{line_prefix}#{string_send_color(label, + highlight_color_sym)}#{line_postfix}\n" + formatted_deps.join("\n") +end + IndexedLine = Struct.new(:index, :line) do def to_s line end end @@ -75,10 +117,9 @@ # @return [Array<String>] List of matching directory names. def search_in_directory_names match_dirs = [] @paths.each do |path| Find.find(path) do |p| - # p 'search_in_directory_names', p # Find.prune unless @include_subdirectories || path == p match_dirs << p if File.directory?(p) && p.match?(@pattern) end end match_dirs