jhass changed the topic of #crystal-lang to: The Crystal programming language | https://crystal-lang.org | Crystal 0.35.1 | 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
avane has quit [Ping timeout: 264 seconds]
<hightower2> ok so, I'm trying to compile shards (the tool) now. I run `make`, but it tells me: "require "./config": can't find file "prelude"". Any hints?
<oprypin> hightower2, CRYSTAL_PATH not set up
<oprypin> try `echo $CRYSTAL_PATH` or `(source bin/crystal; echo $CRYSTAL_PATH)` (not sure if the latter makses sense)
<hightower2> sure. thanks
avane has joined #crystal-lang
deavmi has quit [Ping timeout: 256 seconds]
deavmi has joined #crystal-lang
ua has quit [Ping timeout: 264 seconds]
ua has joined #crystal-lang
f1refly has joined #crystal-lang
f1reflyylmao has quit [Ping timeout: 264 seconds]
avane has quit [Quit: ZNC - https://znc.in]
avane has joined #crystal-lang
<FromGitter> <Dan-Do> How to print the String::Builder content for debugging?
<FromGitter> <Blacksmoke16> ```str = String.build do |str| ⏎ # ... ⏎ end ⏎ ⏎ pp str``` [https://gitter.im/crystal-lang/crystal?at=5fc07bad02560e32e9221d16]
<FromGitter> <Dan-Do> ```String.build(input.bytesize) do |buffer| ⏎ #print here to debug ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5fc07bc43afabc22f157c5a7]
<FromGitter> <Dan-Do> cannot use `to_s`: ⏎ `Can only invoke 'to_s' once on String::Builder (Exception)`
<FromGitter> <Blacksmoke16> can you not just debug the final string?
<FromGitter> <Blacksmoke16> or maybe use a multi writer to also write to a memory IO that you can debug with
<FromGitter> <Dan-Do> the result string is not expected, so I have to debug inside
<FromGitter> <Blacksmoke16> mmk
<FromGitter> <Blacksmoke16> multi writer is prob your only way then
<FromGitter> <Blacksmoke16> it must be one heck of a string if its not simple to see like "oh this part of the string is wrong, lets go look there"
<FromGitter> <Dan-Do> ```temp = String.build(buffer.capacity) do |dest| ⏎ IO.copy(buffer,dest) ⏎ end ⏎ pp! temp``` ⏎ ⏎ it seems I cannot copy the str builder buffer io [https://gitter.im/crystal-lang/crystal?at=5fc07d662a4f2a3d1f59a3ef]
<FromGitter> <Blacksmoke16> https://crystal-lang.org/api/master/IO/MultiWriter.html sorry, i meant this thing
<FromGitter> <naqvis> @Dan-Do what's your use-case?
<FromGitter> <naqvis> String::Builder is used to build the string
<FromGitter> <Dan-Do> I have an input string, whose some patterns need to be replaced. So I use StringBuilder
<FromGitter> <Blacksmoke16> that doesnt seem like the right use case for that
<FromGitter> <Blacksmoke16> given the string already exists. would like gsub or something not be more useful?
<FromGitter> <Dan-Do> modify some codes to suite my need
<FromGitter> <Blacksmoke16> :thinking:
<FromGitter> <Blacksmoke16> okey dokey
<FromGitter> <Dan-Do> It uses `String.build(bytesize) do |buffer|` so I just re-use :)
ua has quit [Ping timeout: 246 seconds]
<FromGitter> <Blacksmoke16> i dont suppose you got an example of what you're trying to do?
<FromGitter> <Dan-Do> Just an example, let's say I have a string `<div id='...' class='...'>abc-xyz</div>.....repeated text...`
<FromGitter> <Dan-Do> I want to loop through the input and remove everything inside`<div>...</div>`
<FromGitter> <Blacksmoke16> sec
<FromGitter> <Dan-Do> oh no, we go too far, basically how to print the buffer of StringBuilder to debug :)
<FromGitter> <Dan-Do> so I cannot use IO.copy(src,dest)
<FromGitter> <Blacksmoke16> i guess what im proposing is you can just use a regex or something for this
<FromGitter> <Dan-Do> actually I want to remove the tagged template literal, for example: ⏎ `<span class="form-clear d-none" onclick=${e=>{e.currentTarget.previousSibling.value="";getData();}}><i class="fas fa-times"></i></span>`
<FromGitter> <Blacksmoke16> and what should the desired output be?
<FromGitter> <Dan-Do> `<span class="form-clear d-none" onclick=''><i class="fas fa-times"></i></span>`
<FromGitter> <Dan-Do> there may be nested :)
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/a0cl
<FromGitter> <Blacksmoke16> i also noticed `gsub Regex`, does actually respect capture groups
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/a0cm i would have expected that to not also replace the whitespace
<FromGitter> <Blacksmoke16> but maybe thats just me...
<FromGitter> <Blacksmoke16> ah rip, ruby is the same
<FromGitter> <naqvis> @Dan-Do Though I won't recommend this, but if you insist to debug builder internal buffer :P ⏎ ⏎ ```String.build do |sb| ⏎ sb << "Hello" ⏎ pp String.new(sb.buffer) ⏎ end``` [https://gitter.im/crystal-lang/crystal?at=5fc08d0602560e32e92241ed]
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/a0co can use lookbehind/aheads
<FromGitter> <Dan-Do> > @Dan-Do Though I won't recommend this, but if you insist to debug builder internal buffer :P ⏎ > ``` ⏎ > String.build do |sb| ⏎ > sb << "Hello" ⏎ > pp String.new(sb.buffer) ... [https://gitter.im/crystal-lang/crystal?at=5fc08d62b12c2622f9088137]
<FromGitter> <Blacksmoke16> im still like 90% sure what you're doing isnt the best option
<FromGitter> <naqvis> totally agree ^
<FromGitter> <Blacksmoke16> like any reason *not* to use a regex for this?
<FromGitter> <Dan-Do> > https://play.crystal-lang.org/#/r/a0co can use lookbehind/aheads ⏎ ⏎ Thanks, I will look at the regex option
<FromGitter> <Dan-Do> I am not familiar with regex :(
<FromGitter> <Blacksmoke16> is what you want to remove always going to be in the format of `onclick=${e=>{e.currentTarget.previousSibling.value="";getData();}}`?
<FromGitter> <Blacksmoke16> I.e. ending in `}}`?
<FromGitter> <Blacksmoke16> if so you could do something like https://play.crystal-lang.org/#/r/a0cu
<FromGitter> <Dan-Do> it starts with `${`, nested by multiple `{...}`, ends with `}` (like javascript)
<FromGitter> <Blacksmoke16> is it always the last tag, im assuming you could also have like `onclick=${...} class="foo">`?
<FromGitter> <Dan-Do> yes
<FromGitter> <Dan-Do> sorry, I mean there may be more after the `}`
<FromGitter> <Dan-Do> can be `onclick=${...${nested}...} class="foo">`
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/a0d0
<FromGitter> <Blacksmoke16> seems to work fine 👍
<FromGitter> <Blacksmoke16> https://play.crystal-lang.org/#/r/a0d2 updated to allow for `onclick` attributes that dont start with `$`
<FromGitter> <Dan-Do> can we remove onclick= from `regex = /(?<=onclick=)\$.*}+/`?
<FromGitter> <Blacksmoke16> in order to use it for other stuff?
<FromGitter> <Dan-Do> yeap :)
<FromGitter> <Dan-Do> ex `<foo bar_can_be_anything...${...${nested}...} class="test">`
postmodern has quit [Quit: Leaving]
<FromGitter> <Blacksmoke16> `/(?<=(?: onclick|othertag)=)\$.*}+/`
<FromGitter> <Blacksmoke16> er actually
<FromGitter> <Blacksmoke16> `/(?<=[\w\d_-]=)\$.*}+/`
<FromGitter> <Blacksmoke16> would match anything that includes a word, digit, `-`, or `_` that ends with `=$`
<FromGitter> <Blacksmoke16> but i guess backing up, why do you need to do this in the first place? I'm assuming you're sanitizing html for something?
<FromGitter> <Dan-Do> correct
<FromGitter> <Blacksmoke16> https://shardbox.org/shards/sanitize maybe checkout that?
<FromGitter> <Dan-Do> It sanitize to much, basically I just want to sanitize only tagged template literal
<FromGitter> <Blacksmoke16> okey dokey
<FromGitter> <Dan-Do> the regex does not work
<FromGitter> <Blacksmoke16> this is getting complex if it can happen anywhere
<FromGitter> <Blacksmoke16> i assume you just cant not add this stuff to the html in the first place?
<FromGitter> <Blacksmoke16> `/\${.*}+/m`
<FromGitter> <Blacksmoke16> might be able to get away with that
<FromGitter> <Blacksmoke16> capture anything between a `${` and `}`
<FromGitter> <Blacksmoke16> anyway, gl im off to bed o/
<FromGitter> <Dan-Do> Thank you very much. Have a nice sleep!
ua has joined #crystal-lang
ua has quit [Excess Flood]
ua has joined #crystal-lang
<FromGitter> <Dan-Do> I am nearly there, the regex does not remove the biggest one
ua has quit [Ping timeout: 240 seconds]
ua has joined #crystal-lang
<FromGitter> <3n-k1> you might just have an easier time writing a basic parser
<kevinsjoberg> If I want to get involved in the Crystal project more than just backing it through Open Collective, where do I start? I'd love to become a regular contributor, helping out in any way I can. 🙂
<FromGitter> <3n-k1> pseudocode: ⏎ ⏎ ```code paste, see link``` [https://gitter.im/crystal-lang/crystal?at=5fc0b34fed05c659158c2c16]
<FromGitter> <3n-k1> that's very bad pseudocode, but i am tired
<jhass> oprypin: first time I saw source bin/crystal :D
<jhass> hightower2: to use your locally compiled compiler, just put bin/crystal into your path first, the wrapper script will take care to set all the env vars correctly :)
<kevinsjoberg> straight-shoota: thanks, will give them a look in a bit!
<FromGitter> <Dan-Do> > pseudocode: ⏎ > ``` ⏎ > seek to start of string to replace ('${') ⏎ > start = whatever the current index is ⏎ > counter = 1 ... [https://gitter.im/crystal-lang/crystal?at=5fc0f0e4b12c2622f9097269]
Flipez has quit [Quit: The Lounge - https://thelounge.github.io]
Flipez has joined #crystal-lang
hightower2 has quit [Ping timeout: 240 seconds]
f1refly67 has joined #crystal-lang
f1refly67 is now known as f1reflyylmao
<f1reflyylmao> When I'm defining a module, lets name it CelestiteSpec, in two files, /spec/celestite_spec.cr and /spec/celestite_spec/cases/func.cr, crystal complains that it can't find the function myfun() that I defined in the func.cr which is directly required in the celestite_spec.cr even though it's in the same namepsace in both files
<f1reflyylmao> I'm not sure how to fix this, I thought I can just put my module definition across multiple files, require them and I can use all of the definitions of the module in every file?
<f1reflyylmao> What am I doing wrong?
<erdnaxeli> for which file does it complains ?
<erdnaxeli> ok forget this question :p
<erdnaxeli> in celestite_spec.cr you have require "./cases/func" ?
<straight-shoota> f1reflyylmao, that should really work
<straight-shoota> maybe try a small reproducible example?
<oprypin> lemme guess: wildcards are involved 😑
<oprypin> this is probably a circular dependency
<f1reflyylmao> erdnaxeli: I've required the whole of ./cases/*
<f1reflyylmao> oprypin: yes ^^'
<oprypin> well theres your problem
<f1reflyylmao> not sure if its circular though, I don't think so
<straight-shoota> hm, but wildecard requires usually only cause issues with namespaces, not methods
<f1reflyylmao> I didn't require anything in my func.cr
<straight-shoota> s/wildcard/circular/
<f1reflyylmao> well, no files at least
<oprypin> f1reflyylmao, you required all alphabetically preceding files :D
<f1reflyylmao> theres currently only one file in that directory, so I'm afraid I didnt
<oprypin> oh
<straight-shoota> if you could reduce the code to share a reproducible example
<f1reflyylmao> I' working on this during breaks and after work, so my progress since my last question isn't too much
<f1reflyylmao> Yeah ill try
<f1reflyylmao> I'll first try to get it to run like it's now
<f1reflyylmao> I might just put everything in different namespaces, would probably look cleaner anyways..
<oprypin> f1reflyylmao, it's not about namespaced, purely about files and circular dependencies
<f1reflyylmao> I could also try re-adding all my requires
<f1reflyylmao> to make sure
<f1reflyylmao> Step by step
<oprypin> if a requires b and b requires a, then b will not be able to rely on what's in a
<oprypin> but hm maybe i shouldn't be so sure about it
<oprypin> anyway if u have all the code and the ability to post it, should be no problem for someone to find whats wrong
<straight-shoota> > if a requires b and b requires a, then b will not be able to rely on what's in a
<straight-shoota> that's not true
<straight-shoota> not in general
<f1reflyylmao> Well
<straight-shoota> there can be issues, but AFAIK only with namespaces
<f1reflyylmao> thing is
<f1reflyylmao> It's bad and I dont really want to make it public
<f1reflyylmao> I'll post a broken example should this continue to be a problem after restructuring
<straight-shoota> then reduce it to the minimal code that reproduces the issue
<f1reflyylmao> Yeah
<straight-shoota> chances are, you'll notice what's wrong on the way
<f1reflyylmao> Hopefully
<FromGitter> <vladfaust> Could you please tell me where shards cache is stored? (to be used with `--local` flag)
<straight-shoota> default is $HOME/.cache/shards
<straight-shoota> you can configure it with SHARDS_CACHE_PATH env var
kreyren has quit [Quit: Leaving]
ua has quit [Ping timeout: 256 seconds]
ua has joined #crystal-lang
<repo> heyo /
<repo> is there a way to configure the name, email and github account for crystal init templates?
<oprypin> repo, copy the file from a previous project. easier & better.
<repo> it's not better
<repo> literally every file containing that information is project specific
<oprypin> everything you enter into crystal init is also project specific
<repo> exactly
<oprypin> exactly, so no advantage to crystal init
<repo> huh?
<repo> right.. maybe i'll just write something myself then
<FromGitter> <Blacksmoke16> repo: https://github.com/athena-framework/component-template this is what i did :shrug:
<FromGitter> <Blacksmoke16> then can just find/replace some stuff and are good to go with CI/docs etc ready to go
<repo> yeah i just wish there was a way around the searching and replacing
<repo> oprypin: hm that obviously doesn't work
<repo> at least not here and user.name is set
<oprypin> oh hm yea that didnt work for me either
<oprypin> prob jsut broken in crystal release 0.35.1. works for me on master
<repo> ah ok
<oprypin> i dont see any obvious reason for it to be broken though
<erdnaxeli> Hi, is there any tricks to have a README.md working in github but also in crystal doc?
<erdnaxeli> Event the default one does not work, a the crystal doc builder does not understand ```yaml
<FromGitter> <asterite> Yes, going back to the past and convincing other to merge a certain PR sent by me
<FromGitter> <asterite> Then your question would fade like Marty's hands
f1reflyylmao has quit [Ping timeout: 245 seconds]
<oprypin> erdnaxeli: just remove the readme from api docs
<erdnaxeli> ok, thanks 😅
<erdnaxeli> I think I found your PR asterite
<erdnaxeli> so there is no solution ? :(
<erdnaxeli> or should I submit PR to fix the current markdown implementation ?
<erdnaxeli> (which I am not sure I want to do or I even am capable of doing ^^)
<straight-shoota> I don't think there's any point in fixing the markdown parser
<straight-shoota> it would need a complete rewrite
<straight-shoota> and there's a complete implementation in markd shard
<erdnaxeli> yep but this solution already has been refused :p
<erdnaxeli> so it's a dead end ?
<straight-shoota> temporarily
<straight-shoota> until we can agree on how to proceed
<erdnaxeli> ok
<straight-shoota> the best short term (and maybe also longterm) solution is to use the compiler to extract docs (via --format json) and use a separte tool for generating the html
<erdnaxeli> ok
<erdnaxeli> (why is that tool in python? :D)
<straight-shoota> it's a plugin for mkdocs
<straight-shoota> this is the result => https://oprypin.github.io/crsfml-mkdocstrings/
<straight-shoota> (klick on API in header nav)
<straight-shoota> IMO that's a brilliant solution
<straight-shoota> the compiler doesn't need to care about generating a static website
<straight-shoota> there are other tools way better for that
<straight-shoota> it's super flexible: you can easily include other documents besides API docs into a single website
<FromGitter> <j8r> yes totally agree
<FromGitter> <j8r> ideally, in my opinion, the API generation tool should be a separate project
<FromGitter> <j8r> anyway, will see what other core member prefer in the future...
<straight-shoota> honestly, it doesn't matter
<straight-shoota> everyone can use the tool they deem best for the job
Flipez has quit [Quit: Ping timeout (120 seconds)]
Flipez has joined #crystal-lang
<FromGitter> <j8r> it matters here, because it prevents the use of markd
<erdnaxeli> hmm I am not sure. I like the idea of installing only crystal and having the full toolbox to write a project: test, formater, doc, …
<FromGitter> <j8r> would be one solution to split it, like done for shards
<straight-shoota> but why use markd when there's a better solution? =)
<erdnaxeli> (and dependencies manager)
<straight-shoota> erdnaxeli, agreed. doc solution should be provided with crystal
<straight-shoota> but that's no contradiction. It doesn't need to be implemented in the compiler
<FromGitter> <j8r> so, `crystal deps` -> improved to `shards` ⏎ `crystal docs` -> improved to `...?`
<straight-shoota> dunno
<erdnaxeli> oh that's right, shards is not in the compiler
<FromGitter> <j8r> agree to, the doc tool would be bundled
<oprypin> j8r, improved to `mkdocs build`
<erdnaxeli> it used to be crystal deps? I didn't know
<FromGitter> <j8r> Not sure whats does https://github.com/oprypin/mkdocstrings-crystal
<oprypin> j8r, sorry it's not ready for publishing, no readme, just uh spoilers
<FromGitter> <j8r> is it a "drop-in" replacement to `crystal docs`? If so, yeah, why not!
<FromGitter> <j8r> but can't be bundled with crystal
<straight-shoota> y not?
<FromGitter> <j8r> maybe it can, sure... This will add a maintenance burden
<FromGitter> <j8r> users having issues with Python3, etc
<FromGitter> <j8r> or we bundled a statically linked Python3 interpreter :°
<straight-shoota> it's less maintenance than rolling our own thing
<oprypin> this one *is* much slower tho. we'll see
<straight-shoota> ofc
<straight-shoota> but performance is a secondary problem
<FromGitter> <j8r> Maybe that's just me, it's quite a pride to being capable to have such tool in Crystal
<straight-shoota> you could write a similar one in Crystal, why not
<FromGitter> <j8r> For the maintenance heavy side, another pros of having a separate project :)
<straight-shoota> the great thing is, we can just build on existing tools now, and later improve on performance (and maybe pride)
<FromGitter> <j8r> I tired straight-shoota. one issue is that the compiler is not very pluggable
<FromGitter> <j8r> *tried
<FromGitter> <j8r> that markdown situation is quite unfortunate :( ⏎ One way or another, a real solution will have to be decided
<straight-shoota> agreed
<FromGitter> <j8r> nvm I tried for the playground, I remember, not the doc generator.
<straight-shoota> lately I've been focusing on polishing UX issues with the docs generator to make it somewhat presentable for 1.0
<straight-shoota> next I'd like to improve and formalize the extraction phase, to make it a solid base for hooking in an external frontend
<straight-shoota> then the options are open: use mkdocstrings, any other SSG or build a generator in Crystal
<FromGitter> <j8r> will be great!
<erdnaxeli> 👍️
<FromGitter> <asterite> In one universe of the multiverse, the conversation above never happened
<FromGitter> <j8r> ...because Crystal didn't exist?
<FromGitter> <j8r> or everyone was not alive anymore...
<FromGitter> <j8r> anyway, got a mail about Crystal 1.0 - I'm now quite hyped for the release!
<FromGitter> <j8r> too bad https://github.com/crystal-lang/crystal/wiki/Used-in-production for most of them we don't know how/where they use Crystal
<FromGitter> <asterite> No, because in that universe my PR got merged and markdown would work fine for all. But no, that was a terrible idea
<FromGitter> <j8r> haaa, the universe where you are the BDFL 😆
<FromGitter> <asterite> Haha, good point. I guess then I prefer this universe :-)
<straight-shoota> xD
<erdnaxeli> trying to run the crystal repo's spec on my machine was not the best idea…
<straight-shoota> haha, yeah that's intensive
<straight-shoota> are you really running literally *all* spec? Or just stdlib?
<straight-shoota> the latter alone is already huge
<erdnaxeli> I typed `make spec`, then I had to reboot my computer :D
<straight-shoota> yeah
<straight-shoota> try "make std_spec" next time
<straight-shoota> even that eats some gigs of memory
<straight-shoota> best just run isolated specs and leave the full suite for CI
<straight-shoota> "bin/crystal spec spec/std/time*" for example
<erdnaxeli> that's way better, thanks!