Sha256: 2255398cb5d36cdebc07c98820a6ef2d3275cf4a5d61d846c314c640966c19c8

Contents?: true

Size: 1.69 KB

Versions: 70

Compression:

Stored size: 1.69 KB

Contents

# frozen_string_literal: true

module Doing
  # Hooks.register :post_config do |wwid|
  #   wwid.config['twizzle'] = 'Fo shizzle'
  #   wwid.write_config(File.expand_path('~/Desktop/wwidconfig.yml'))
  # end

  # Hooks.register :post_read, priority: 10 do |wwid|
  #   Doing.logger.warn('Hook 1:', 'triggered priority 10')
  #   Doing.logger.warn('Hook 2:', wwid.config['twizzle'])
  # end

  # Hooks.register :post_read, priority: 100 do |wwid|
  #   Doing.logger.warn('Hook 2:', 'triggered priority 100')
  # end

  Hooks.register :post_write do |filename|
    res = `/bin/bash /Users/ttscoff/scripts/after_doing.sh`.strip
    Doing.logger.debug('Hooks:', res) unless res =~ /^\.\.\.$/

    wwid = WWID.new
    wwid.configure
    if filename == wwid.config['doing_file']
      diff = wwid.get_diff(filename)
      puts diff
    end
  end

  Hooks.register :post_entry_added do |wwid, entry|
    if wwid.config.key?('day_one_trigger') && entry.tags?(wwid.config['day_one_trigger'], :and)

      logger.info('New entry:', 'Adding to Day One')
      add_to_day_one(entry, wwid.config)
    end
  end

  ##
  ## Add the entry to Day One using the CLI
  ##
  ## @param      entry  The entry to add
  ##
  def self.add_to_day_one(entry, config)
    dayone = TTY::Which.which('dayone2')
    flagged = entry.tags?('flagged') ? ' -s' : ''
    tags = entry.tags.map { |t| Shellwords.escape(t) }.join(' ')
    tags = tags.length.positive? ? " -t #{tags}" : ''
    date = " -d '#{entry.date.strftime('%Y-%m-%d %H:%M:%S')}'"
    title = entry.title.tag(config['day_one_trigger'], remove: true)
    title += "\n#{entry.note}" unless entry.note.empty?
    `echo #{Shellwords.escape(title)} | #{dayone} new#{flagged}#{date}#{tags}`
  end
end

Version data entries

70 entries across 70 versions & 1 rubygems

Version Path
doing-2.1.88 lib/examples/plugins/hooks.rb
doing-2.1.87 lib/examples/plugins/hooks.rb
doing-2.1.86 lib/examples/plugins/hooks.rb
doing-2.1.85 lib/examples/plugins/hooks.rb
doing-2.1.84 lib/examples/plugins/hooks.rb
doing-2.1.83 lib/examples/plugins/hooks.rb
doing-2.1.82 lib/examples/plugins/hooks.rb
doing-2.1.81 lib/examples/plugins/hooks.rb
doing-2.1.80 lib/examples/plugins/hooks.rb
doing-2.1.79 lib/examples/plugins/hooks.rb
doing-2.1.78 lib/examples/plugins/hooks.rb
doing-2.1.77 lib/examples/plugins/hooks.rb
doing-2.1.76 lib/examples/plugins/hooks.rb
doing-2.1.75 lib/examples/plugins/hooks.rb
doing-2.1.74 lib/examples/plugins/hooks.rb
doing-2.1.73 lib/examples/plugins/hooks.rb
doing-2.1.72 lib/examples/plugins/hooks.rb
doing-2.1.69 lib/examples/plugins/hooks.rb
doing-2.1.68 lib/examples/plugins/hooks.rb
doing-2.1.66 lib/examples/plugins/hooks.rb