Class: TinyMCE::Rails::JsonManifest
Instance Attribute Summary
#file
Class Method Summary
collapse
Instance Method Summary
collapse
#asset_path, #each, load, #to_s
Constructor Details
Returns a new instance of JsonManifest.
13
14
15
16
|
# File 'lib/tinymce/rails/asset_manifest/json_manifest.rb', line 13
def initialize(file)
@file = file
@manifest = JSON.parse(File.read(file))
end
|
Class Method Details
.try(manifest_path, pattern = nil) ⇒ Object
4
5
6
7
8
9
10
11
|
# File 'lib/tinymce/rails/asset_manifest/json_manifest.rb', line 4
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
|
Instance Method Details
#append(logical_path, file) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
|
# File 'lib/tinymce/rails/asset_manifest/json_manifest.rb', line 18
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
|
#assets ⇒ Object
45
46
47
|
# File 'lib/tinymce/rails/asset_manifest/json_manifest.rb', line 45
def assets
@manifest["assets"]
end
|
#dump ⇒ Object
53
54
55
|
# File 'lib/tinymce/rails/asset_manifest/json_manifest.rb', line 53
def dump
JSON.generate(@manifest)
end
|
#files ⇒ Object
49
50
51
|
# File 'lib/tinymce/rails/asset_manifest/json_manifest.rb', line 49
def files
@manifest["files"]
end
|
#remove(logical_path) ⇒ Object
30
31
32
33
34
|
# File 'lib/tinymce/rails/asset_manifest/json_manifest.rb', line 30
def remove(logical_path)
if digested = assets.delete(logical_path)
files.delete(digested)
end
end
|
#remove_digest(logical_path) ⇒ Object
36
37
38
39
40
41
42
43
|
# File 'lib/tinymce/rails/asset_manifest/json_manifest.rb', line 36
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
|
#write ⇒ Object
57
58
59
|
# File 'lib/tinymce/rails/asset_manifest/json_manifest.rb', line 57
def write
File.open(@file, "wb") { |f| f.write(dump) }
end
|