Sha256: 6daca2e610f9e3b0929689bb1cae818b6790232428116c2b65a3eea19dcffed1

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 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)
          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

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
saber-1.1.1 lib/saber/task/generate.rb
saber-1.1.0 lib/saber/task/generate.rb
saber-1.0.2 lib/saber/task/generate.rb