use OrderedTable instead of OrderedTableRef for mimedb (#19522)
* use OrderedTable instead of OrderedTableRef for mimedb Signed-off-by: David Krause <enthus1ast@users.noreply.github.com> * added changelog entry for mimedb change Signed-off-by: David Krause <enthus1ast@users.noreply.github.com>
This commit is contained in:
parent
551225d888
commit
cda77c1520
3 changed files with 6 additions and 2 deletions
|
|
@ -40,6 +40,8 @@ becomes an alias for `addr`.
|
||||||
|
|
||||||
- Added `std/oserrors` for OS error reporting. Added `std/envvars` for environment variables handling.
|
- Added `std/oserrors` for OS error reporting. Added `std/envvars` for environment variables handling.
|
||||||
|
|
||||||
|
- Changed mimedb to use an `OrderedTable` instead of `OrderedTableRef`, to use it in a const.
|
||||||
|
|
||||||
## Language changes
|
## Language changes
|
||||||
|
|
||||||
- Pragma macros on type definitions can now return `nnkTypeSection` nodes as well as `nnkTypeDef`,
|
- Pragma macros on type definitions can now return `nnkTypeSection` nodes as well as `nnkTypeDef`,
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@ from strutils import startsWith, toLowerAscii, strip
|
||||||
|
|
||||||
type
|
type
|
||||||
MimeDB* = object
|
MimeDB* = object
|
||||||
mimes: OrderedTableRef[string, string]
|
mimes: OrderedTable[string, string]
|
||||||
|
|
||||||
const mimes* = {
|
const mimes* = {
|
||||||
"123": "application/vnd.lotus-1-2-3",
|
"123": "application/vnd.lotus-1-2-3",
|
||||||
|
|
@ -1904,7 +1904,7 @@ func newMimetypes*(): MimeDB =
|
||||||
## Creates a new Mimetypes database. The database will contain the most
|
## Creates a new Mimetypes database. The database will contain the most
|
||||||
## common mimetypes.
|
## common mimetypes.
|
||||||
{.cast(noSideEffect).}:
|
{.cast(noSideEffect).}:
|
||||||
result.mimes = mimes.newOrderedTable()
|
result.mimes = mimes.toOrderedTable()
|
||||||
|
|
||||||
func getMimetype*(mimedb: MimeDB, ext: string, default = "text/plain"): string =
|
func getMimetype*(mimedb: MimeDB, ext: string, default = "text/plain"): string =
|
||||||
## Gets mimetype which corresponds to `ext`. Returns `default` if `ext`
|
## Gets mimetype which corresponds to `ext`. Returns `default` if `ext`
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,8 @@ template main() =
|
||||||
var m = newMimetypes()
|
var m = newMimetypes()
|
||||||
doAssert m.getMimetype("mp4") == "video/mp4"
|
doAssert m.getMimetype("mp4") == "video/mp4"
|
||||||
doAssert m.getExt("application/json") == "json"
|
doAssert m.getExt("application/json") == "json"
|
||||||
|
m.register("foo", "baa")
|
||||||
|
doAssert m.getMimetype("foo") == "baa"
|
||||||
# see also `runnableExamples`.
|
# see also `runnableExamples`.
|
||||||
# xxx we should have a way to avoid duplicating code between runnableExamples and tests
|
# xxx we should have a way to avoid duplicating code between runnableExamples and tests
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue