Sha256: d5e5e0cf1d302da93951396e73a95b3c93e31f879f54f4fb2ef480deb5243534

Contents?: true

Size: 1 KB

Versions: 2

Compression:

Stored size: 1 KB

Contents

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)
          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

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
saber-1.0.1 lib/saber/task/generate.rb
saber-1.0.0 lib/saber/task/generate.rb