refactor: Keep file extensions when getting files
- Use `name_fix_keepext` instead of `name_fix` - Update calls to `image_get`, `file_get`, and `file_or_image_get` - Update checks in `image_exists`, `file_exists`, and `file_or_image_exists`
This commit is contained in:
@@ -188,7 +188,7 @@ fn test_save_and_load_with_images() {
|
||||
|
||||
col := a.get_collection('docs')!
|
||||
// assert col.images.len == 1
|
||||
assert col.image_exists('test')!
|
||||
assert col.image_exists('test.png')!
|
||||
|
||||
// // Save
|
||||
// a.save(destination_meta: '/tmp/atlas_meta')!
|
||||
@@ -199,9 +199,9 @@ fn test_save_and_load_with_images() {
|
||||
|
||||
// loaded_col := a2.get_collection('docs')!
|
||||
// assert loaded_col.images.len == 1
|
||||
// assert loaded_col.image_exists('test')!
|
||||
// assert loaded_col.image_exists('test.png')!
|
||||
|
||||
img_file := col.image_get('test')!
|
||||
img_file := col.image_get('test.png')!
|
||||
assert img_file.name == 'test.png'
|
||||
assert img_file.is_image()
|
||||
}
|
||||
|
||||
@@ -104,7 +104,7 @@ pub fn (c Collection) page_get(name_ string) !&Page {
|
||||
|
||||
// Get an image by name
|
||||
pub fn (c Collection) image_get(name_ string) !&File {
|
||||
name := texttools.name_fix(name_)
|
||||
name := texttools.name_fix_keepext(name_)
|
||||
mut img := c.files[name] or { return FileNotFound{
|
||||
collection: c.name
|
||||
file: name
|
||||
@@ -117,7 +117,7 @@ pub fn (c Collection) image_get(name_ string) !&File {
|
||||
|
||||
// Get a file by name
|
||||
pub fn (c Collection) file_get(name_ string) !&File {
|
||||
name := texttools.name_fix(name_)
|
||||
name := texttools.name_fix_keepext(name_)
|
||||
mut f := c.files[name] or { return FileNotFound{
|
||||
collection: c.name
|
||||
file: name
|
||||
@@ -129,7 +129,7 @@ pub fn (c Collection) file_get(name_ string) !&File {
|
||||
}
|
||||
|
||||
pub fn (c Collection) file_or_image_get(name_ string) !&File {
|
||||
name := texttools.name_fix(name_)
|
||||
name := texttools.name_fix_keepext(name_)
|
||||
mut f := c.files[name] or { return FileNotFound{
|
||||
collection: c.name
|
||||
file: name
|
||||
@@ -145,20 +145,20 @@ pub fn (c Collection) page_exists(name_ string) !bool {
|
||||
|
||||
// Check if image exists
|
||||
pub fn (c Collection) image_exists(name_ string) !bool {
|
||||
name := texttools.name_fix(name_)
|
||||
name := texttools.name_fix_keepext(name_)
|
||||
f := c.files[name] or { return false }
|
||||
return f.ftype == .image
|
||||
}
|
||||
|
||||
// Check if file exists
|
||||
pub fn (c Collection) file_exists(name_ string) !bool {
|
||||
name := texttools.name_fix(name_)
|
||||
name := texttools.name_fix_keepext(name_)
|
||||
f := c.files[name] or { return false }
|
||||
return f.ftype == .file
|
||||
}
|
||||
|
||||
pub fn (c Collection) file_or_image_exists(name_ string) !bool {
|
||||
name := texttools.name_fix(name_)
|
||||
name := texttools.name_fix_keepext(name_)
|
||||
_ := c.files[name] or { return false }
|
||||
return true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user