module Saber module Task # Generate meta data file. # # Usage # ----- # # Task["generate"].invoke(:generate, ["bib", "ebook", "Hello.epub", isbn]) # > generate Hello.epub.yml data file. # class Generate < Base include Thor::Actions source_root "#{Rc.p.root}/templates" desc "generate", "generate" def generate(tracker_name, type, filename, *args) require "saber/tracker/#{tracker_name}" if !args.empty? template_file = find_in_source_paths("#{tracker_name}/#{type}.yml") dest = "#{filename}.yml" if !args.empty? and Tracker[tracker_name].can_populate?(type) require "yaml" populate = {} data = YAML.load_file(template_file) tracker = Tracker[tracker_name].new tracker.login populate = tracker.populate(type, *args) data.merge!(populate) create_file dest, YAML.dump(data) else copy_file template_file, dest end end end end end