ChanServ changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Fund Crystal's development: https://crystal-lang.org/sponsors | GH: https://github.com/crystal-lang/crystal | Docs: https://crystal-lang.org/docs | Gitter: https://gitter.im/crystal-lang/crystal
<FromGitter> <moe:busyloop.net> oh yea i think mine will be similar, just trying to minimize the boilerplate, ⏎ this is what it looks like so far ⏎ ⏎ https://gist.github.com/m-o-e/ce32608cdbf3ef4e7ec2df50ecef70e7 [https://gitter.im/crystal-lang/crystal?at=6240fbd7c435002500103c56]
ur5us has quit [Remote host closed the connection]
ur5us has joined #crystal-lang
<FromGitter> <Blacksmoke16> +1 for the rendering feature, i may see why you need content negotiation now ;)
<FromGitter> <Blacksmoke16> are they global tho? like can you have two diff routes handle returned strings differently?
<FromGitter> <moe:busyloop.net> heh, yea, that's exactly where i bumped into it. want the default exception handler to render as text when there's no accept json in the request. (because reading escaped json in spec errors is annoying)
<FromGitter> <moe:busyloop.net> yea they are global atm. the whole thing is a singleton cause no way to make the macro magic work otherwise. but i'll probably add optional scopes at some point to group routes/renderers together. should be doable, just not high on the list atm
<FromGitter> <Blacksmoke16> 👍 sounds like a plan
<FromGitter> <Blacksmoke16> if its a singleton, id make sure it properly handles concurrent requests
<FromGitter> <moe:busyloop.net> yeh it does. i mean it's not fully a singleton. handlers etc. are instances. just `.render` & co are macros, so the top-level has to be pretty much singleton. ⏎ ⏎ but through the voodoo of namedtuples you can of course also have a renderer that does ⏎ https://gist.github.com/m-o-e/8bc1d8aac923002cae8971770e5ea0de - so it's quite flexible overall :) [https:
<FromGitter> ... //gitter.im/crystal-lang/crystal?at=62410300257a3578254d9abd]
<FromGitter> <Blacksmoke16> ahh gotcha
<FromGitter> <nimble:cyberia.club> is there a way to embed js/html into the http server?
<FromGitter> <Blacksmoke16> @moe:busyloop.net dunno if it helps but https://crystal-lang.org/api/master/NamedTuple.html#from%28hash%3AHash%29%3Aself-class-method is a thing. E.g. allows double splatting
<FromGitter> <Blacksmoke16> @nimble:cyberia.club you mean return HTML/JS in the response?
<FromGitter> <nimble:cyberia.club> Yes
<FromGitter> <Blacksmoke16> sure, its just a string
<FromGitter> <nimble:cyberia.club> How do I do it?
<FromGitter> <Blacksmoke16> just as you would any string
<FromGitter> <Blacksmoke16> `context.response << "string"`, being one of the ways
<FromGitter> <moe:busyloop.net> hmm, sounds like you may want a more fully featured framework like athena, amber or lucky. returning raw html like that works but will get cumbersome for anything but very simple cases
<FromGitter> <Blacksmoke16> or at least use a templating engine like Crinja or ECR
<FromGitter> <moe:busyloop.net> yup
<FromGitter> <nimble:cyberia.club> Its my first tome using crystal I am just getting the basics sorry
<FromGitter> <nimble:cyberia.club> and documentation is hard to find
<FromGitter> <nimble:cyberia.club> I suppose ⏎ context.response.content_type ⏎ ⏎ I have to set this up to use html ? [https://gitter.im/crystal-lang/crystal?at=624109208db2b95f0a8a3017]
<FromGitter> <Blacksmoke16> those are the two best sources
<FromGitter> <nimble:cyberia.club> Yeah I am using that but I don't know where to go from there, hence I am here
<FromGitter> <Blacksmoke16> yea so like in that first example want to use `text/html` instead, then `.print html`
<FromGitter> <Blacksmoke16> where `html` is the HTML string you want to return
<FromGitter> <Blacksmoke16> could use https://crystal-lang.org/api/master/ECR.html for that
ur5us_ has joined #crystal-lang
ur5us has quit [Ping timeout: 256 seconds]
<FromGitter> <nimble:cyberia.club> I can't get this to work
<FromGitter> <Blacksmoke16> are you getting a specific error or?
<FromGitter> <Blacksmoke16> and what's your code?
<FromGitter> <nimble:cyberia.club> context.response.content_type = "text/html" ⏎ context.response.print "index.html"
<FromGitter> <Blacksmoke16> right, you're printing the string `index.html`
<FromGitter> <Blacksmoke16> if its just a raw file, you could do something like `context.response.print File.read "index.html"`
<FromGitter> <Blacksmoke16> or if its going to be large ⏎ ⏎ ```File.open "index.html" do |file| ⏎ IO.copy file, context.response ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=6241149cc61ef0178e93c476]
<FromGitter> <nimble:cyberia.club> Alright that worked now thanks!
<FromGitter> <nimble:cyberia.club> I have another question however and I don't think I have seen this one being asked
<FromGitter> <nimble:cyberia.club> How can I make the server "reactive" I mean updating it without reloading. I have seen it is capable of such in the playground
<FromGitter> <Blacksmoke16> `crystal play` you mean?
<FromGitter> <Blacksmoke16> it uses websockets
<FromGitter> <nimble:cyberia.club> Thing is I want to do a countdown timer I already got most of the Time logic already
<FromGitter> <nimble:cyberia.club> Yes
<FromGitter> <nimble:cyberia.club> But it only updates for whoever is seeing the page if they refresh it
<FromGitter> <nimble:cyberia.club> I really want to avoid using javascript for this
<FromGitter> <nimble:cyberia.club> Since I want to learn crystal
<FromGitter> <nimble:cyberia.club> I will give it a look
<FromGitter> <Blacksmoke16> im pretty sure you have to use *some* JS
<FromGitter> <Blacksmoke16> as the server cant return interactive context afaik?
<FromGitter> <Blacksmoke16> since the HTML would be static
<FromGitter> <Blacksmoke16> tho ofc its Rails, dont think anything like that exists in Crystal land atm
She has joined #crystal-lang
jmdaemon has quit [Ping timeout: 268 seconds]
jmdaemon has joined #crystal-lang
ur5us_ has quit [Ping timeout: 272 seconds]
<FromGitter> <rishavs> If there is a need to refresh it, this sounds like a simple server side logic. If you want to do this without refreshing the page you will need either JS (the normal way) or websockets (the way Elixir liveView uses)
nq_ has quit [Ping timeout: 252 seconds]
jhass[m] has quit [Quit: Bridge terminating on SIGTERM]
Melancholia[m] has quit [Quit: Bridge terminating on SIGTERM]
jhass[m] has joined #crystal-lang
Melancholia[m] has joined #crystal-lang
jmdaemon has quit [Ping timeout: 252 seconds]
<FromGitter> <SebastianSzturo> Is there an official crystal shards website? Seems like most of the ones linked have expired ssl certificates and are unmaintained
<jhass[m]> shards is designed as a decentralized system, so not really. https://shardbox.org/ is as close as it gets being maintained by one of the core team
<jhass[m]> what all the broken sites mostly did was just returning the results for a github search with language:crystal anyhow
<FromGitter> <SebastianSzturo> Ah makes sense, thanks you!
<FromGitter> <moe:busyloop.net> i still hope crystalshards.org will be recovered. it's been the most useful of the bunch :(
jhass[m] has quit [Quit: User was banned]
Melancholia[m] has quit [Quit: User was banned]
ua_ has quit [Ping timeout: 256 seconds]
ua_ has joined #crystal-lang
jhass[m] has joined #crystal-lang
Melancholia[m] has joined #crystal-lang
<FromGitter> <Blacksmoke16> @SebastianSzturo https://github.com/veelenga/awesome-crystal is also pretty good
jmdaemon has joined #crystal-lang
lanodan has quit [Quit: WeeChat 3.3]
lanodan has joined #crystal-lang
lanodan has quit [Ping timeout: 240 seconds]
lanodan has joined #crystal-lang
lanodan has quit [Ping timeout: 260 seconds]
lanodan has joined #crystal-lang
renich has joined #crystal-lang
ur5us_ has joined #crystal-lang
renich has quit [Remote host closed the connection]
renich has joined #crystal-lang
jmdaemon has quit [Quit: ZNC 1.8.2 - https://znc.in]
jmdaemon has joined #crystal-lang
renich has quit [Remote host closed the connection]
renich has joined #crystal-lang
FromGitter has quit [Remote host closed the connection]
oprypin has quit [Quit: Bye]
oprypin has joined #crystal-lang
FromGitter has joined #crystal-lang
FromGitter has quit [Remote host closed the connection]
oprypin has quit [Client Quit]
oprypin has joined #crystal-lang
FromGitter has joined #crystal-lang
ur5us_ has quit [Ping timeout: 250 seconds]