Closed brandonpittman closed 4 years ago
Hi @brandonpittman
That sound like a smart idea.
I appreciate your PR, but I will have to ask you to add some tests, because as much as I see, there should be a change in R.template
specs.
Few more things:
VSCode complains about the naming of escape
so maybe it should be something like escapeSpecialChars
You are missing export
Current test suite is failing with the following log:
FAIL src/template.spec.js
✓ within bracets (3ms)
✓ ok
✓ no interpolation + curry (1ms)
✕ with missing template input (4ms)
● with missing template input
ReferenceError: bar is not defined
at eval (eval at template (:22), <anonymous>:1:23)
I’ll work on that today. Thanks.
@selfrefactor I changed the escape
name and exported the function.
I also changed the test because it shouldn't spit out the template string anymore. It's going to evaluate everything in the brackets, which should actually throw a reference error.
I will check it later today. Thank you again.
I copied your version of R.template and I ran it against the current Rambdax spec. This test:
test('with missing template input', () => {
const input = 'foo is {{bar}} even {{a}} more'
const templateInput = {
baz : 'BAR',
a : 1,
}
const result = template(input, templateInput)
const expectedResult = 'foo is {{bar}} even 1 more'
expect(result).toEqual(expectedResult)
})
you know that fails. because in your tests you expect to throw. We would introduce a breaking change, this even forcing to major bump. Tests are contracts, and I think this contract of R.template
not to throw on wrong input seems important.
Maybe you should change the method so it passes the failing test.
@selfrefactor Okay, we now just pass back the unprocessed input in the event of a ReferenceError. Existing specs pass and I added a new one for arbitrary JS expressions.
@brandonpittman - that sounds good to me. As you may have understand, my main interest is not the code itself rather than what happens with the tests. I will wait for you to notify me once you are ready with the tests.
Not sure what you mean.
The latest commit makes all your tests pass and passes a new test I wrote to cover bare expressions.
I will release a version this Sunday. Thank you for your collaboration.
Thank you!
Just released 3.6.0
including this MR.
@selfrefactor Still showing up at 3.5 on NPM.
I realized that just now, and finally the release is made.
I found myself wanting to push the limits of what
template
can do, but I didn't want to pull in a larger templating library, so I figured we could just allow the template function to handle any expression inside it.