Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Sarasa
{
"message": "Hello world!"
}
import * from dw::http::Server
import * from dw::http::Client
ns svg http://www.w3.org/2000/svg
fun renderSVG(x) = write(x, 'text/xml', {
encoding: "UTF-8",
onInvalidChar: "ignore",
inlineCloseOn: "none",
writeDeclaration: false
}) as Binary
type CircleOptions = {|
x: Number,
y: Number,
radius?: Number,
fill?: String
|}
fun circle(opts: CircleOptions) =
svg#circle @(fill: opts.fill default '#000000', cx: opts.x, cy: opts.y, r: opts.radius default 7): null
type RectOptions = {|
x: Number,
y: Number,
width: Number,
height: Number,
fill?: String
|}
fun rect(opts: RectOptions) =
svg#rect @(fill: opts.fill default '#FFFFFF', x: opts.x, y: opts.y, width: opts.width, height: opts.height): null
---
api({
host: "0.0.0.0",
port: 8080
}, {
"/": {
GET: (request) -> {
body: renderSVG({
svg#svg @(width: '100%', height: '65px', viewBox: '0 0 1132 65'): {
svg#g @(class: 'bars'): {
svg#rect @(class: 'bg', fill: '#ccc', width: '100%', height: '25'): '',
svg#rect @(class: 'data', fill: '#00FFFF', width: '$(random() * 100)%', height: '25'): ''
},
svg#g @(class: 'markers'): {
svg#rect @(fill: '#001f3f', x: '0%', y: '0', width: '2px', height: '35'): '',
svg#rect @(fill: '#001f3f', x: '25%', y: '0', width: '2px', height: '35'): '',
svg#rect @(fill: '#001f3f', x: '50%', y: '0', width: '2px', height: '35'): '',
svg#rect @(fill: '#001f3f', x: '75%', y: '0', width: '2px', height: '35'): '',
svg#rect @('text-anchor': '', fill: '#001f3f', x: '1130', y: '0', width: '2px', height: '35'): ''
},
svg#g @('text-anchor': 'middle'): {
svg#text @('text-anchor': 'start', fill: '#0074d9', x: '0', y: '60'): 'From DW',
svg#text @(fill: '#0074d9', x: '25%', y: '60'): '25%',
svg#text @(fill: '#0074d9', x: '50%', y: '60'): '50%',
svg#text @(fill: '#0074d9', x: '75%', y: '60'): '75%',
svg#text @('text-anchor': 'end', fill: '#0074d9', x: '100%', y: '60'): now() as String
}
}
}),
headers: {
'Content-Type': 'image/svg+xml',
'tu-vieja-en-tanga': 'application/xml'
}
},
POST: (request) -> {
body: {
//TODO: Remove as String
name: (request).body.name as String
},
status: 302
}
}
})
{
"project": {
"name": "Sarasa",
"mainScript": "scripts/main.dwl",
"apiled": {
"deploymentId": "bc05d242-2295-4b98-8dc6-5c2700990b47",
"domain": "sarasa"
}
},
"meta": {
"projectFileVersion": "0.1.0",
"creationDate": "12/04/2017"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.