Code Monkey home page Code Monkey logo

Comments (6)

a-h avatar a-h commented on September 26, 2024 1

The mission of templ is to:

Enable Go developers to build strongly typed, component-based HTML user interfaces with first-class developer tooling, and a short learning curve.

So, rendering text isn't part of the plan, but I've suggested how you can use templ to do something similar at #385 (comment)

from templ.

joerdav avatar joerdav commented on September 26, 2024

Thanks for the proposal, I wonder what value add this has over something like:

func SimpleEmail(to string) {
    return fmt.Sprintf(`
Hello %s,

Welcome to our system.

Thanks,
Some Team
`, to)
}

Would you suggest for control flow statements such as for, switch, if to be valid? As this may be hard to parse in this context.

from templ.

adpande avatar adpande commented on September 26, 2024

Yes, conditions , loops and expressions would be powerful. We can extent this latter even to support markdown.

from templ.

joerdav avatar joerdav commented on September 26, 2024

It may be powerful, but we need to think about how it would be even possible.

The way templ parses Go code is as follows...

It looks for a keyword at the start of a node such as for.
Then it parses the go expression up to the opening curly brace (this can be multiple lines of go code) {.
And then we continue parsing nodes until the closing curly brace }.

If it finds a keyword but then a subsequent step of parsing the statement fails, we don't assume anything, and throw an error.
By "we don't assume anything", what I mean is that if the stuff after the word for isn't valid go code, we don't fallback to it being regular text, (to avoid leaking code accidentally).

This is why in cases such as <div>for example</div>, you will see an error.
We basically say "hey, we're a bit confused here, you might have been trying to write a for loop, can you help?".
Then the dev can either fix the for loop syntax or show that they were trying to write normal text by doing <div>{for example}</div>

In the context of pure text, I'm struggling to see how we would parse it without encountering lots of errors like this.

from templ.

adpande avatar adpande commented on September 26, 2024

Yes, I understand. I will also think. Maybe also discuss it with other collaborators.

Thanks for considering it.

from templ.

silverwind avatar silverwind commented on September 26, 2024

This seems far to error-prone for the parser and JSX also does not allow it, for comparison. What you can do in JSX is either quoted the string "foo" or unquoted inside fragements, e.g. <Fragment>foo</Fragment> or shorthand <>foo</>, both which should be much easier to parse.

from templ.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.