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.
83
84
85
86
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 83
def initialize(file)
@file = file
@manifest = JSON.parse(File.read(file))
end
|
Class Method Details
.try(manifest_path, pattern) ⇒ Object
78
79
80
81
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 78
def self.try(manifest_path, pattern)
paths = Dir[File.join(manifest_path, pattern)]
new(paths.first) if paths.any?
end
|
Instance Method Details
#append(logical_path, file) ⇒ Object
88
89
90
91
92
93
94
95
96
97
98
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 88
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
115
116
117
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 115
def assets
@manifest["assets"]
end
|
#dump ⇒ Object
123
124
125
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 123
def dump
JSON.generate(@manifest)
end
|
#files ⇒ Object
119
120
121
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 119
def files
@manifest["files"]
end
|
#remove(logical_path) ⇒ Object
100
101
102
103
104
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 100
def remove(logical_path)
if digested = assets.delete(logical_path)
files.delete(digested)
end
end
|
#remove_digest(logical_path) ⇒ Object
106
107
108
109
110
111
112
113
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 106
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
127
128
129
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 127
def write
File.open(@file, "wb") { |f| f.write(dump) }
end
|