Method: Doing::Plugins.template_for_trigger

Defined in:
lib/doing/plugin_manager.rb

.template_for_trigger(trigger, type: :export, save_to: nil) ⇒ String

Find and return the appropriate template for a trigger string. Outputs a string that can be written out to the terminal for redirection

Parameters:

  • trigger (String)

    The trigger to test

  • type (Symbol) (defaults to: :export)

    the plugin type (:import, :export)

Returns:

  • (String)

    string content of template for trigger

Raises:



242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
# File 'lib/doing/plugin_manager.rb', line 242

def template_for_trigger(trigger, type: :export, save_to: nil)
  plugins[valid_type(type)].clone.delete_if { |_t, o| o[:templates].nil? }.each do |_, options|
    options[:templates].each do |t|
      next unless trigger =~ /^(?:#{t[:trigger].normalize_trigger})$/

      tpl = options[:class].template(trigger)
      return tpl unless save_to

      raise PluginException.new('No default filename defined', :export, t[:name]) unless t.key?(:filename)

      return save_template(tpl, save_to, t[:filename])
    end
  end
  raise Errors::InvalidArgument, "No template type matched \"#{trigger}\""
end