Skip to content

Replacing string parameter #39

@OdedYanovich

Description

@OdedYanovich

I use Sketch in order to replace code like this:

html.div(
    [
      attribute.style([
        #("display", "grid"),
        #("grid-template", "repeat(5, 1fr) / repeat(2, 1fr)"),
        #("place-items", "center;"),
        #("grid-auto-flow", "column"),
        #("height", "100vh"),
        #("background-color", "black"),
        #("color", "white"),
        #("font-size", "1.6rem"),
        #("padding", "1rem"),
        #("box-sizing", "border-box"),
        #(
          "background",
          "linear-gradient(to left, rgb(255, 0, 0) "
            <> model.hp |> float.round |> int.to_string
            <> "%, rgba(0,0,0,1))",
        ),
      ]), ...

with code like that:

html.div(
    css.class([
      css.display("grid"),
      css.grid_template("repeat(5, 1fr) / repeat(2, 1fr)"),
      css.place_items("center"),
      css.grid_auto_flow("column"),
      css.height(vh(100)),
      css.background_color("black"),
      css.color("white"),
      css.font_size(rem(1.6)),
      css.padding(rem(1.0)),
      css.box_sizing("border-box"),
      css.background(
        "linear-gradient(to left, rgb(255, 0, 0) "
        <> model.hp |> float.round |> int.to_string
        <> "%, rgba(0,0,0,1))",
      ),
    ]),
    [], ...

(If there is another use for the library then I missed it).
I love it for it, but when I compere these code blocks I see the need for more,
What about the other string in the pair?
Why "center" is a string and not an enum variant?
why is "repeat(5, 1fr) / repeat(2, 1fr)" not a pair of functions?
If removing strings is valuable then there is work to be done

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions