Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 02:46
    HertzDevil synchronize #12282
  • 02:44
    HertzDevil synchronize #12494
  • 00:21
    HertzDevil synchronize #10839
  • Sep 26 21:51
    beta-ziliani synchronize #12511
  • Sep 26 18:52
    asterite unlabeled #12525
  • Sep 26 18:52
    asterite unlabeled #12525
  • Sep 26 18:47
    asterite closed #12525
  • Sep 26 17:35
    straight-shoota labeled #12386
  • Sep 26 17:18
    straight-shoota labeled #12195
  • Sep 26 17:17
    straight-shoota labeled #12527
  • Sep 26 17:17
    straight-shoota opened #12527
  • Sep 26 17:17
    straight-shoota labeled #12527
  • Sep 26 17:13
    straight-shoota labeled #12412
  • Sep 26 17:13
    straight-shoota unlabeled #12412
  • Sep 26 14:16
    straight-shoota demilestoned #12520
  • Sep 26 14:16
    straight-shoota demilestoned #12520
  • Sep 26 14:16
    straight-shoota milestoned #12520
  • Sep 26 14:16
    straight-shoota milestoned #12520
  • Sep 26 14:16
    straight-shoota milestoned #12520
  • Sep 26 14:16
    straight-shoota milestoned #12520
George Dietrich
@Blacksmoke16
sure you want === and not ==?
Matthew Berry
@mattrberry
I don't actually have a use-case for it
I'm just wondering
George Dietrich
@Blacksmoke16
=== should only be needed if you need custom case equality logic
it might just work tbh, like see the the when value is a type as the compiler expands it to is_a?
Matthew Berry
@mattrberry
Oh does the compiler special-case that?
George Dietrich
@Blacksmoke16
i think so yea
be easy enough to try
Matthew Berry
@mattrberry
Yeah seems like it does
Only other thing then would be that this should technically be able to compile I believe, since foo.is_a? cannot be an A, right? https://carc.in/#/r/bc45
Quinton Miller
@HertzDevil
that's what that rfc discusses
Matthew Berry
@mattrberry
Ah gotcha, thank you
George Dietrich
@Blacksmoke16
well technically foo.is_a? A would be true in either case
since its a parent to both
Ali Naqvi
@naqvis
true, case will end on the very first match, so for such scenario its better to move the parent or more general type to the end
bovepm
@bovepm
hi there! former rubyist and crystal newbee here. I am currently writing some crystal code and wanted to use the mixin Enumerable on class level rather than on instance level (see code below). any hints?
https://carc.in/#/r/bc7v
erdnaxeli
@erdnaxeli:cervoi.se
[m]
just extend it: https://carc.in/#/r/bc7z
bovepm
@bovepm
super, thanks for the quick reply
Thore Bödecker
@foxxx0
Hi, any suggestions on how I would best implement a predefined set of format strings / placeholders that can be user-specified (e.g. via config file)? I don't want allow users to directly influence the #sprintf formatstring for security reasons, I was thinking more in the direction of having something like "some prefix: ###foo.attr1### with ###foo.attr2###" where I want to replace "###foo.attr1###" with the value of foo.attr1 and so on. How could achieve that somewhat elegantly?
Ali Naqvi
@naqvis
@foxxx0 Crystal doesn't support RTTI, that means there is no way to achieve dynamic execution of props/methods. Crystal expects methods/fields calls to be known at compile time. What I understand from your context is you are looking for some template language which you can invoke at run-time
12 replies
Thore Bödecker
@foxxx0
correct
Ali Naqvi
@naqvis
AFAIK crinja does this trick of run-time execution, so that might be something you can refer to
Thore Bödecker
@foxxx0
mh, looks like crinja strictly expects values and not custom classes
maybe i'll need to parse the user-supplied argument then and provide crinja with the correct value? but then there is no point to pulling in crinja
Ali Naqvi
@naqvis
hmm, how come such conclusion?
Template engine doesn't force you to any specific set of usage
you can access any object as long as template engine has access to that object
For example
{%- for article in articles if article.published %}
  <div class="article">
    <h2><a href="{{ article.href|e }}">{{ article.title|e }}</a></h2>
    <p class="meta">written by <a href="{{ article.user.href|e
      }}">{{ article.user.username|e }}</a> on {{ article.pub_date|dateformat }}</p>
    <div class="text">{{ article.body }}</div>
  </div>
{%- endfor %}
Steve Hiemstra
@speg
speaking of templates, how do i make this work:
ECR.def_to_s "#{ECR_ROOT}/greeter.ecr"
Can't do that when calling a macro?
George Dietrich
@Blacksmoke16
does that not already work?
Steve Hiemstra
@speg

Kinda. I think it's constant above that is broken:

require "ecr"

ECR_ROOT = "./src/template/components/ecr"

class Greeter
  def initialize(@name : String)
  end

  ECR.def_to_s "#{ECR_ROOT}/greeter.ecr"
end

pp! ECR_ROOT
pp! Greeter.new("John").to_s # => "Greetings, John!\n"

Gives:

There was a problem expanding macro 'embed'

Code in macro 'def_to_s'

 2 | ECR.embed "#{ECR_ROOT}/greeter.ecr", "__io__"
     ^
Called macro defined in /usr/local/Cellar/crystal/1.0.0/src/ecr/macros.cr:69:3

 69 | macro embed(filename, io_name)

Which expanded to:

 > 1 | {{ run("ecr/process", "#{ECR_ROOT}/greeter.ecr", "__io__") }}
          ^--
Error: Error executing run (exit code: 1): ecr/process '"./src/template/components/ecr"/greeter.ecr' __io__


stderr:

    Error opening file with mode 'r': '\"./src/template/components/ecr\"/greeter.ecr': No such file or directory
George Dietrich
@Blacksmoke16
try and use __DIR__ instead of .
pretty sure . is the dir you're executing the file from while __DIR__ is the location of the file or something like that
oh but try doing ECR.def_to_s "#{ECR_ROOT.id}/greeter.ecr"
Steve Hiemstra
@speg
same thing, I had also tried using Dir.current with no luck
ooh, .id?
George Dietrich
@Blacksmoke16
yea
Steve Hiemstra
@speg
Success! 🙌🏼 Thank you sir. I haven't used macros yet, what's going on here?
George Dietrich
@Blacksmoke16
seems like its interpolating the string literal into the other string. Notice the path in the error has like \", instead of just like ecr/greeter.ecr
.id returns the raw value of the constant, e.g. ./src/template/components/ecr
maybe thats a bug as it's deff not what you'd expect :shrug:
Steve Hiemstra
@speg
hehe, neat. I was reading up on macros just last night but obvs need to learn some more. Thanks again!
didactic-drunk
@didactic-drunk
Why does crystal doc skip all my classes except for a monkey patched Slice in my project
George Dietrich
@Blacksmoke16
I'd guessCrypto already exists and is nodoc
didactic-drunk
@didactic-drunk
I don't see defined Cryptoanywhere. It's implicitly defined as Crypto::{Subtle,Bcrypt,Blowfish}
oprypin
@oprypin:matrix.org
[m]
@didactic-drunk: because Crypto is marked as originating from stdlib by its first occurrence in the whole code blob, and the whole stdlib is excluded from doc building
didactic-drunk
@didactic-drunk
@oprypin:matrix.org Now I have a workaround. Thank you
oprypin
@oprypin:matrix.org
[m]
@didactic-drunk: im scared. what is it?