scalatags icon indicating copy to clipboard operation
scalatags copied to clipboard

StringFrag.toString doesn't behave as expected

Open adridadou opened this issue 6 years ago • 7 comments

if you use .toString to render the tags (instead of .render) StringFrag doesn't behave as expected.

I.e. StringFrag("hello world").toString shouldBe "hello world" but actually StringFrag("hello world").toString is "StringFrag(hello world)"

adridadou avatar Jun 12 '19 08:06 adridadou

Actually, I would prefer it if that were the expected behaviour, i.e. render produces HTML or DOM output, while toString tells you what DSL tree you built for debugging purposes.

But you are right, right now the documentation states that toString produces HTML.

Bathtor avatar Jun 12 '19 08:06 Bathtor

Yeah let's just make its .toString produce HTML. Swapping out HTML v.s. DSL output would be a big breaking change which wouldn't get caught by the compiler. The small amount of elegance gained doesn't seem worth the transitional pain

lihaoyi avatar Jun 12 '19 08:06 lihaoyi

If that's the case, I would then change the documentation to use .render instead of .toString

Otherwise it's confusing.

The thing is that .toString is implemented as some sort of .render for ALMOST all the tags, but not this one

adridadou avatar Jun 12 '19 08:06 adridadou

.toString doesn't produce HTML for StringFrag though.

adridadou avatar Jun 12 '19 08:06 adridadou

the only change I'm proposing here is to have StringFrag returning its content rather than a default toString implementation because I am pretty sure this is not what ppl are expecting there.

adridadou avatar Jun 12 '19 08:06 adridadou

Changing the documentation to tell people to use .render seems fine by me

lihaoyi avatar Jun 12 '19 08:06 lihaoyi

sounds good to me!

adridadou avatar Jun 12 '19 08:06 adridadou