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.
88
89
90
91
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 88
def initialize(file)
@file = file
@manifest = JSON.parse(File.read(file))
end
|
Class Method Details
.try(manifest_path, pattern = nil) ⇒ Object
79
80
81
82
83
84
85
86
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 79
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
93
94
95
96
97
98
99
100
101
102
103
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 93
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
120
121
122
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 120
def assets
@manifest["assets"]
end
|
#dump ⇒ Object
128
129
130
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 128
def dump
JSON.generate(@manifest)
end
|
#files ⇒ Object
124
125
126
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 124
def files
@manifest["files"]
end
|
#remove(logical_path) ⇒ Object
105
106
107
108
109
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 105
def remove(logical_path)
if digested = assets.delete(logical_path)
files.delete(digested)
end
end
|
#remove_digest(logical_path) ⇒ Object
111
112
113
114
115
116
117
118
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 111
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
132
133
134
|
# File 'lib/tinymce/rails/asset_manifest.rb', line 132
def write
File.open(@file, "wb") { |f| f.write(dump) }
end
|