Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do we need a SwiftStaticWebUI? #36

Open
helje5 opened this issue Jul 5, 2019 · 2 comments
Open

Do we need a SwiftStaticWebUI? #36

helje5 opened this issue Jul 5, 2019 · 2 comments
Labels
question Further information is requested

Comments

@helje5
Copy link
Member

helje5 commented Jul 5, 2019

Inspired by John Sundell working on a nice HTML static site renderer, but using his own DSL.

In the spirit of what StaticCMS does for generating static sites using WebObjects/GETobjects templates, we could do a SwiftStaticWebUI which does the same using SwiftUI "Views".

Idea dump:

This is quite different to what SwiftWebUI itself does (and would best be done as a separate project).
Essentially all the diffing and state handling goes away. This would essentially not need Bindings (or Combine) anymore, it would be a one-way flow "swift views" => HTML page.
Targets of "actions" would work very different, they would need to resolve to statically representable links.

Just like in StaticCMS I imagine that we would need an "OFS" (Object File System), essentially a way to load a file system hierarchy into Swift values, which then get rendered by SwiftUI Views.
Imagine a filesystem folder containing .md files, they would load into say "Markdown" objects. Then you'd have SwiftUI Views like:

struct ArticleView: View {
  let article: Markdown
  var body: some View { ... }
}

which could turn them into HTML. The OFS in GETobjects also decouples the objects from the actual store, e.g. it could also be a database vending the markdown objects, but still being rendered using the exact same Views.

Then there would need to be entry points which trigger the html website rendering traversal, something like:

SwiftStaticWebUI.expose([
  "/": MainPage(),
  "/about": AboutPage()
])

Or maybe using some enum instead of strings.

NavigationLinks could also still work:

NavigationLink(destination: AboutPage()) {
  some anchor
}

This might need some back-mapping of the Views to the URLs. Since the Views can also be parameterised (e.g. as the body of a ForEach):

struct CounterPage: View {
  let counter : Int
...
}

... we need a away to serialise those into the URL (like /counters/1.html). One way to do this could be Codable. Which would automagically work for many basic types.

Not sure whether it's worth it, but it would at least allow me to replace my own sites driven by StaticCMS with something non-Java, more up to date :-)

@helje5 helje5 added the question Further information is requested label Jul 5, 2019
@shial4
Copy link
Contributor

shial4 commented Jan 8, 2020

Could still work. Are you planning to work on it?
Have you seen John Sundell outcome?
What is your plan for 2020 and SwiftWebUI?

Cheers :)

@helje5
Copy link
Member Author

helje5 commented Jan 8, 2020

Yes, I had a look at Plot and Publish. Very nice, beautiful code, well done! It is a little different to what I have in mind though. (and doesn't have a ViewBuilder DSL, I actually toyed with adding one to Plot, but the whole setup is quite different)

I have some ideas on doing a SwiftUI-like View DSL for MicroExpress (or actually any hosting framework should work) which I may explore soon. That might become the Plot part in John-speak, and Publish would be the OFS+exporter stuff, which I may or may not do later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants