Sha256: 8cb57bc1e762c1a60ba2f9a8c7b522657a6f1d8194ac12cc3013838142706150

Contents?: true

Size: 1.12 KB

Versions: 13

Compression:

Stored size: 1.12 KB

Contents

require 'pathname'

module SVGGVS
  class Context
    attr_reader :individual_files

    def initialize(cardfile = "Cardfile")
      @cardfile = cardfile

      @individual_files = []
    end

    def self.load(cardfile = "Cardfile")
      context = new(cardfile)
      context.load
      context
    end

    def session
      @session ||= SVGGVS::Session.new
    end

    def cardrc?
      ::File.file?('.cardrc')
    end

    def load
      session

      if cardrc?
        self.instance_eval(::File.read('.cardrc'))
      end

      self.instance_eval(cardfile_rb)
    end

    def cardfile_rb
      @cardfile_rb ||= ::File.read(@cardfile)
    end

    def write_merged_file
      session.on_card_finished = nil
      session.run

      session.file.save @session.svg_merged_target
    end

    def write_individual_files
      session.on_card_finished do |index|
        target = Pathname(session.individual_files_path % index)

        target.parent.mkpath

        session.file.dup_with_only_last_target.save target.to_s

        session.file.clear_targets!

        @individual_files << target
      end

      session.run
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
svggvs-0.0.13 lib/svggvs/context.rb
svggvs-0.0.12 lib/svggvs/context.rb
svggvs-0.0.10.1 lib/svggvs/context.rb
svggvs-0.0.10 lib/svggvs/context.rb
svggvs-0.0.9 lib/svggvs/context.rb
svggvs-0.0.8 lib/svggvs/context.rb
svggvs-0.0.7 lib/svggvs/context.rb
svggvs-0.0.6 lib/svggvs/context.rb
svggvs-0.0.5 lib/svggvs/context.rb
svggvs-0.0.4 lib/svggvs/context.rb
svggvs-0.0.3 lib/svggvs/context.rb
svggvs-0.0.2 lib/svggvs/context.rb
svggvs-0.0.1 lib/svggvs/context.rb