Skip to content
This repository was archived by the owner on Feb 23, 2019. It is now read-only.

Commit 2ffecc3

Browse files
committed
Added object url related functions.
1 parent 26c717c commit 2ffecc3

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

source/Url.mint

+36
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,40 @@ module Url {
3535
})()
3636
`
3737
}
38+
39+
/*
40+
Creates an url from the given content and type, which is available until the
41+
current window is closed.
42+
43+
Url.createObjectUrlFromString("Content", "text/html")
44+
*/
45+
fun createObjectUrlFromString (string : String, type : String) : String {
46+
`
47+
(() => {
48+
let blob = new Blob([string], {type : type})
49+
return URL.createObjectURL(blob)
50+
})()
51+
`
52+
}
53+
54+
/*
55+
Creates an url from the given file, which is available until the current
56+
window is closed.
57+
58+
File.fromString("Content", "test.html", "text/html")
59+
|> Url.createObjectUrlFromFile()
60+
*/
61+
fun createObjectUrlFromFile (file : File) : String {
62+
`URL.createObjectURL(file)`
63+
}
64+
65+
/*
66+
Releases an existing object URL which was previously created.
67+
68+
Url.createObjectUrlFromString("Content", "text/html")
69+
|> Url.revokeObjectUrl()
70+
*/
71+
fun revokeObjectUrl (url : String) : Void {
72+
`URL.revokeObjectURL(url)`
73+
}
3874
}

tests/Url.mint

+24
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,27 @@ suite "Url.parse" {
1717
}
1818
}
1919
}
20+
21+
suite "Url.createObjectUrlFromFile" {
22+
test "it creates an url from a file" {
23+
(File.fromString("Content", "test.html", "text/html")
24+
|> Url.createObjectUrlFromFile()) != ""
25+
}
26+
}
27+
28+
suite "Url.createObjectUrlFromString" {
29+
test "it creates an url from a file" {
30+
Url.createObjectUrlFromString("Content", "text/html") != ""
31+
}
32+
}
33+
34+
suite "Url.revokeObjectUrl" {
35+
test "it revokes the given url" {
36+
try {
37+
Url.createObjectUrlFromString("Content", "text/html")
38+
|> Url.revokeObjectUrl()
39+
40+
true
41+
}
42+
}
43+
}

0 commit comments

Comments
 (0)