Sha256: ff002435ce2a4b93f7405f6fb874a8a3e2823b5dadc09d246895ebc3e2a9556a

Contents?: true

Size: 1.44 KB

Versions: 6

Compression:

Stored size: 1.44 KB

Contents

module TinyMCE
  module Rails
    class JsonManifest < AssetManifest
      def self.try(manifest_path, pattern=nil)
        if pattern
          paths = Dir[File.join(manifest_path, pattern)]
          new(paths.first) if paths.any?
        elsif File.file?(manifest_path)
          new(manifest_path)
        end
      end

      def initialize(file)
        @file = file
        @manifest = JSON.parse(File.read(file))
      end

      def append(logical_path, file)
        stat = File.stat(file)

        assets[logical_path] = logical_path
        files[logical_path] = {
          "logical_path" => logical_path,
          "mtime"        => stat.mtime.iso8601,
          "size"         => stat.size,
          "digest"       => nil
        }
      end

      def remove(logical_path)
        if digested = assets.delete(logical_path)
          files.delete(digested)
        end
      end

      def remove_digest(logical_path)
        asset_path(logical_path) do |digested, logical_path|
          assets[logical_path] = logical_path
          files[logical_path] = files.delete(digested).tap { |f| f["digest"] = nil }

          yield digested, logical_path if block_given?
        end
      end

      def assets
        @manifest["assets"]
      end

      def files
        @manifest["files"]
      end

      def dump
        JSON.generate(@manifest)
      end

      def write
        File.open(@file, "wb") { |f| f.write(dump) }
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
tinymce-rails-7.5.1 lib/tinymce/rails/asset_manifest/json_manifest.rb
tinymce-rails-7.5.0 lib/tinymce/rails/asset_manifest/json_manifest.rb
tinymce-rails-6.8.5 lib/tinymce/rails/asset_manifest/json_manifest.rb
tinymce-rails-7.4.1 lib/tinymce/rails/asset_manifest/json_manifest.rb
tinymce-rails-7.4.0 lib/tinymce/rails/asset_manifest/json_manifest.rb
tinymce-rails-7.3.0 lib/tinymce/rails/asset_manifest/json_manifest.rb