Method: HookApp#linked_bookmarks

Defined in:
lib/hook/hookapp.rb

#linked_bookmarks(args, opts) ⇒ Object

Get a list of all hooks on a file/url.



474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
# File 'lib/hook/hookapp.rb', line 474

def linked_bookmarks(args, opts)
  result = []

  separator = args.length == 1 && opts[:format] == 'paths' && opts[:null_separator] ? "\0" : "\n"

  if args.nil? || args.empty?
    result = output_array(all_bookmarks, opts)
  else
    args.each do |url|
      source_mark = bookmark_for(url)
      filename = source_mark[:name]

      case opts[:format]
      when /^m/
        filename = "[#{source_mark[:name]}](#{source_mark[:url]})"
        filename += " <file://#{CGI.escape(source_mark[:path])}>" if source_mark[:path]
      when /^p/
        filename = "File: #{source_mark[:name]}"
        filename += " (#{source_mark[:path]})" if source_mark[:path]
      when /^h/
        filename = "File: #{source_mark[:name]}"
        filename += " (#{source_mark[:url]})" if source_mark[:url]
      else
        filename = "Bookmarks attached to #{source_mark[:path] || source_mark[:url]}"
      end

      hooks_arr = get_hooks(url)

      output = output_array(hooks_arr, opts)
      result.push({ file: filename, links: output.join(separator) }) if output
    end


    if result.length > 1 || opts[:format] == 'verbose'
      result.map! do |res|
        "#{res[:file]}\n\n#{res[:links]}\n"
      end
    else
      result.map! do |res|
        res[:links]
      end
    end
  end
  result.join(separator)
end