Sha256: 9c0527aaefae7dc0d0b46da4f18f11208af870fef3d7cf9107f2b34781d35a02
Contents?: true
Size: 1.39 KB
Versions: 1
Compression:
Stored size: 1.39 KB
Contents
# frozen_string_literal: true require 'json' require_relative 'image' require_relative 'imageset' module XCAssets class XCAssets attr_reader :name def initialize(name) @name = name @imagesets = [] end def add_imageset(imageset) @imagesets << imageset end def save(directory) root = directory.join("#{name}.xcassets") root.rmtree if root.exist? root.mkpath write_imagesets(root) write_contents_json(root) end private def write_imagesets(root) @imagesets.each do |imageset| path = root.join("#{imageset.name}.imageset") path.rmtree if path.exist? path.mkpath imageset.images.each do |image| if image.resource FileUtils.cp image.resource, path.join(image.filename) end end contents_path = path.join("Contents.json") File.open(contents_path, 'w+') do |file| file.write JSON.pretty_generate(imageset.contents) end end end def assets_filename "#{name}.xcassets" end def write_contents_json(root) path = root.join('Contents.json') contents = { :info => { :author => 'xcode', :version => 1 } } contents_string = JSON.pretty_generate(contents) File.open(path, 'w+') do |file| file.write contents_string end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
KCommercialPipeline-0.2.5.1 | lib/KCommercialPipeline/core/resource/xcassets/xcassets.rb |