Class: MarkdownExec::MarkParse
- Includes:
- ArrayUtil, StringUtil
- Defined in:
- lib/markdown_exec.rb
Overview
:reek:DuplicateMethodCall { allow_calls: [‘block’, ‘item’, ‘lm’, ‘opts’, ‘option’, ‘@options’, ‘required_blocks’] } :reek:MissingSafeMethod { exclude: [ read_configuration_file! ] } :reek:TooManyInstanceVariables ### temp :reek:TooManyMethods ### temp
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#prompt ⇒ Object
readonly
Returns the value of attribute prompt.
-
#run_state ⇒ Object
readonly
Returns the value of attribute run_state.
Instance Method Summary collapse
- #choices_from_block_names(value, found_in_block_names) ⇒ Object
- #choices_from_file_names(directory_names, colorize: true, histogram: true, pattern: '*') ⇒ Object
-
#determine_filename(specified_filename: nil, specified_folder: nil, default_filename: nil, default_folder: nil, filetree: nil) ⇒ Object
Determines the correct filename to use for searching files.
-
#initialize(options = {}) ⇒ MarkParse
constructor
A new instance of MarkParse.
-
#list_files_specified(fn, filetree = nil) ⇒ Object
Searches for files based on the specified or default filenames and folders.
- #list_markdown_files_in_path ⇒ Object
-
#list_recent_output(saved_stdout_folder, saved_stdout_glob, list_count) ⇒ Object
:reek:UtilityFunction.
-
#list_recent_scripts(saved_script_folder, saved_script_glob, list_count) ⇒ Object
:reek:UtilityFunction.
-
#mde_vux_main_loop(files) ⇒ Object
Reports and executes block logic.
- #run ⇒ Object
- #select_document_if_multiple(files = list_markdown_files_in_path, cycle: true, prompt: options[:prompt_select_md].to_s) ⇒ Object
- #tab_completions(data = menu_for_optparse) ⇒ Object
-
#update_options(opts = {}, over: true) ⇒ Object
:reek:BooleanParameter :reek:ControlParameter.
Methods included from StringUtil
Methods included from ArrayUtil
Constructor Details
#initialize(options = {}) ⇒ MarkParse
Returns a new instance of MarkParse.
293 294 295 296 297 298 |
# File 'lib/markdown_exec.rb', line 293 def initialize( = {}) @option_parser = nil @options = HashDelegator.new() @fout = FOut.new(@delegate_object) end |
Instance Attribute Details
#options ⇒ Object (readonly)
Returns the value of attribute options.
288 289 290 |
# File 'lib/markdown_exec.rb', line 288 def @options end |
#prompt ⇒ Object (readonly)
Returns the value of attribute prompt.
288 289 290 |
# File 'lib/markdown_exec.rb', line 288 def prompt @prompt end |
#run_state ⇒ Object (readonly)
Returns the value of attribute run_state.
288 289 290 |
# File 'lib/markdown_exec.rb', line 288 def run_state @run_state end |
Instance Method Details
#choices_from_block_names(value, found_in_block_names) ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 369 370 |
# File 'lib/markdown_exec.rb', line 358 def choices_from_block_names(value, found_in_block_names) found_in_block_names[:matched_contents].map do |matched_contents| filename, details, = matched_contents nexo = AnsiFormatter.new(@options).format_and_highlight_array( details, highlight: [value] ) [FileInMenu.(filename)] + nexo.map do |str| { disabled: '', name: (' ' * 20) + str } end end.flatten end |
#choices_from_file_names(directory_names, colorize: true, histogram: true, pattern: '*') ⇒ Object
372 373 374 375 376 377 378 379 380 |
# File 'lib/markdown_exec.rb', line 372 def choices_from_file_names(directory_names, colorize: true, histogram: true, pattern: '*') directory_names[:data].map do |dn| find_files(pattern, [dn], exclude_dirs: true) end.flatten(1).map do |str| FileInMenu.(str, colorize: colorize, histogram: histogram) end end |
#determine_filename(specified_filename: nil, specified_folder: nil, default_filename: nil, default_folder: nil, filetree: nil) ⇒ Object
Determines the correct filename to use for searching files
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 |
# File 'lib/markdown_exec.rb', line 384 def determine_filename( specified_filename: nil, specified_folder: nil, default_filename: nil, default_folder: nil, filetree: nil ) File.join( *(if specified_filename&.present? if specified_filename.start_with?('/') [specified_filename] else [specified_folder || default_folder, specified_filename] end elsif specified_folder&.present? [specified_folder, if filetree @options[:md_filename_match] else @options[:md_filename_glob] end] else [default_folder, default_filename] end) ) end |
#list_files_specified(fn, filetree = nil) ⇒ Object
Searches for files based on the specified or default filenames and folders
792 793 794 795 796 797 798 |
# File 'lib/markdown_exec.rb', line 792 def list_files_specified(fn, filetree = nil) return Dir.glob(fn) unless filetree filetree.select do |filename| filename == fn || filename.match(/^#{fn}$/) || filename.match(%r{^#{fn}/.+$}) end end |
#list_markdown_files_in_path ⇒ Object
800 801 802 803 |
# File 'lib/markdown_exec.rb', line 800 def list_markdown_files_in_path Dir.glob(File.join(@options[:path], @options[:md_filename_glob])) end |
#list_recent_output(saved_stdout_folder, saved_stdout_glob, list_count) ⇒ Object
:reek:UtilityFunction
806 807 808 809 810 |
# File 'lib/markdown_exec.rb', line 806 def list_recent_output(saved_stdout_folder, saved_stdout_glob, list_count) SavedFilesMatcher.most_recent_list(saved_stdout_folder, saved_stdout_glob, list_count) end |
#list_recent_scripts(saved_script_folder, saved_script_glob, list_count) ⇒ Object
:reek:UtilityFunction
813 814 815 816 817 |
# File 'lib/markdown_exec.rb', line 813 def list_recent_scripts(saved_script_folder, saved_script_glob, list_count) SavedFilesMatcher.most_recent_list(saved_script_folder, saved_script_glob, list_count) end |
#mde_vux_main_loop(files) ⇒ Object
Reports and executes block logic
820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 |
# File 'lib/markdown_exec.rb', line 820 def mde_vux_main_loop(files) @options[:filename] = select_document_if_multiple(files) @options.vux_main_loop(menu_from_yaml: @menu_from_yaml) do |type, data| case type when :command_names simple_commands(data).keys when :call_proc simple_commands(data[0])[data[1]][1].call when :end_of_cli execute_simple_commands(, stage: 2) else raise end end end |
#run ⇒ Object
963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 |
# File 'lib/markdown_exec.rb', line 963 def run initialize_parse_execute_cli execute_block_with_error_handling rescue BlockMissing warn 'Block missing' exit 1 rescue AppInterrupt, TTY::Reader::InputInterrupt, BlockMissing warn 'Exiting...' if $DEBUG exit 1 rescue StandardError error_handler('run') # rubocop:disable Style/RescueStandardError rescue warn 'Exiting...' if $DEBUG exit 1 # rubocop:enable Style/RescueStandardError end |
#select_document_if_multiple(files = list_markdown_files_in_path, cycle: true, prompt: options[:prompt_select_md].to_s) ⇒ Object
1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 |
# File 'lib/markdown_exec.rb', line 1006 def select_document_if_multiple(files = list_markdown_files_in_path, cycle: true, prompt: [:prompt_select_md].to_s) return files[0] if (count = files.count) == 1 return unless count >= 2 opts = .dup select_option_or_exit( HashDelegator.new(@options) .string_send_color( prompt, :prompt_color_after_script_execution ), files, HashDelegator.(opts).merge( cycle: cycle ) ) end |
#tab_completions(data = menu_for_optparse) ⇒ Object
1077 1078 1079 1080 1081 |
# File 'lib/markdown_exec.rb', line 1077 def tab_completions(data = ) data.map do |item| "--#{item[:long_name]}" if item[:long_name] end.compact end |
#update_options(opts = {}, over: true) ⇒ Object
:reek:BooleanParameter :reek:ControlParameter
1085 1086 1087 1088 1089 1090 1091 1092 |
# File 'lib/markdown_exec.rb', line 1085 def (opts = {}, over: true) if over @options = @options.merge opts else @options.merge! opts end @options end |