lapis icon indicating copy to clipboard operation
lapis copied to clipboard

Documentation bug. `HTML Generation` page does not have lua version for examples

Open akaRem opened this issue 9 years ago • 14 comments

seen at http://leafo.net/lapis/reference/html_generation.html

akaRem avatar Apr 11 '15 15:04 akaRem

Not sure if you're the person to answer this but I created the html generator syntax with moonscript in mind. Would people want to write that syntax in lua? It becomes pretty verbose. I made etlua specifically for lua users but never really polled any lua users to see what they prefer.

Anyway, that's why there aren't any docs for it currently, but I can either add some or put a note about it.

leafo avatar Apr 25 '15 06:04 leafo

I feel like the clarification you just presented is helpful- I feel like the docs generally give the impression that the moonscript and lua approaches generally have equivalent functionality. Making it clear that the html options are moonscript and etlua is helpful to me.

nelson2005 avatar Apr 27 '15 15:04 nelson2005

Came here with the same problem, would be good to maybe just have your comment above or words to the same effect at the top of the documentation page for html generation.

kraftman avatar Aug 22 '15 14:08 kraftman

Is it worth also providing lua translations of the html builders? Would anyone use it?

leafo avatar Aug 22 '15 16:08 leafo

It's hard to say without seeing one.  At the very least a note that etlua plays thank role.  It's just that the documentation naturally indicates that there is a lua version, so it just struck me as odd when I found it for some things but not others. Erik On Aug 22, 2015 12:38 PM, leaf [email protected] wrote:Is it worth also providing lua translations of the html builders? Would anyone use it?

—Reply to this email directly or view it on GitHub.

nelson2005 avatar Aug 23 '15 01:08 nelson2005

I'd definitely use a Lua version of it if it's made.

soccermitchy avatar Aug 30 '15 16:08 soccermitchy

I`d too.

borikinternet avatar Sep 13 '15 21:09 borikinternet

I'd too. I don't like moonscript.. :(

akaRem avatar Sep 21 '15 21:09 akaRem

If it's still wanted, I wouldn't mind going through and converting the MoonScript version of the examples to Lua, and submitting a pull for it.

I think a note should definitely be added to the top to say that this isn't recommended however. @leafo How would I add a note to the top that only shows up on the Lua version? I figured out how with the code examples, but not with anything else.

TangentFoxy avatar Aug 03 '16 08:08 TangentFoxy

Yes, it's still wanted.

borikinternet avatar Aug 03 '16 09:08 borikinternet

Just submitted a pull for it..but it's not very complete, as a lot of the HTML generation stuff is based on MoonScript classes. I honestly do not think this is a good idea in its current state. If anyone else wants to work on it, please do.

TangentFoxy avatar Aug 04 '16 14:08 TangentFoxy

Yes, some general info on how to invoke the builder would be nice. Not just for Lua. For example, the same call structure can be created in Fennel:

(html #(
  div { :class "main container" } #(
    (h1 #(
      (text "SuperApp ")
      (sup (. Config app_version))))
    (p #(
      (text "This is the debug interface. Use the ")
      (a { :href "#" } "API")
      (text " to build stuff. Don't rely on this interface. If you're not a developer, you shouldn't be here."))))))

produces this Lua code:

_1_(...)
local function _2_()
  local function _3_()
    local function _4_()
      return text("SuperApp ")(sup(Config[app_version]))
    end
    local function _5_()
      return text("This is the debug interface. Use the ")(a({href = "#"}, "API"), text(" to build stuff. Don't rely on this interface. If you're not a developer, you shouldn't be here."))
    end
    return h1(_4_)(p(_5_))
  end
  return div({class = "main container"}, _3_)
end
return html(_2_)

(I know there's a Fennel HTML generator, but it's not as sophisticated as Lapis')

Even if it's literally just the HTML builder. Then it can be applied to other frameworks which rely less on MoonScript (e.g. Turbo.lua (no affiliation with me)).

turbo avatar Oct 18 '19 18:10 turbo

Nevermind, with @TangentFoxy's example, this works:

(let [render_html (. (assert (require "lapis.html")) :render_html)]
 (print (render_html
   #(html
     #(div { :class "main container" } #(do
       (h1 #(do
         (text "SuperApp")
         (sup "2019.3")))
       (p #(do
         (text "This is the debug interface. Use the ")
         (a { :href "#" } "API")
         (text " to build stuff. Don't rely on this interface. If you're not a developer, you shouldn't be here.")))))))))

We then have to teach HTML tag names to the Fennel compiler so it doesn't complain about undeclared globals:

fennel --globals html,div,h1,text,sup,p,a test.fnl

turbo avatar Oct 18 '19 18:10 turbo

@turbo Oh I'm glad to know that worked out for you! :D

TangentFoxy avatar Jan 04 '20 04:01 TangentFoxy