slinso / egon Goto Github PK
View Code? Open in Web Editor NEWThis project forked from benbjohnson/ego
An ERB-style templating language for Go.
License: MIT License
This project forked from benbjohnson/ego
An ERB-style templating language for Go.
License: MIT License
I would suggest adding a few tags from EJS:
<%= Outputs the value into the template (HTML escaped)
<%- Outputs the unescaped value into the template
<%# Comment tag, no execution, no output
%> Plain ending tag
-%> Trim-mode ('newline slurp') tag, trims following newline
The raw print block already exists as <%==
, but I'd consider changing this to EJS syntax.
I'd also do something with <%%
and %%>
, changing the closing tag just to %>
? With the addition of -%>
(see above), we can get rid of some extra whitespaces because of <%%
and <%!
definitions.
I'm splitting up a project into many files, like this:
./partials/head.ejs
./partials/header.ejs
./partials/foot.ejs
./partials/footer.ejs
./index.ejs
./content/setup.ejs
./content/login.ejs
./content/error.ejs
Using them with available functions is a bit of a hassle as I have to take care of a few horrible things to make this usable. For example, my index.ejs looks something like this:
<%%
import (
"app/common"
"app/web/templates/partials"
"app/web/templates/content"
"github.com/codegangsta/inject"
)
%%><%! injector inject.Injector, view common.View %><%
injector.Invoke(partials.HeadTemplate)
injector.Invoke(partials.HeaderTemplate)
%><div class="container-fluid"><%
switch {
case view.Content == "error":
injector.Invoke(content.ErrorTemplate)
break
case view.Content == "setup":
injector.Invoke(content.SetupTemplate)
break
case view.Content == "login":
injector.Invoke(content.LoginTemplate)
break
}
%></div><%
injector.Invoke(partials.FooterTemplate)
injector.Invoke(partials.FootTemplate)
%>
The problems with this approach:
One possible fix would be to add an option to compile everything into one golang file, so I could skip additional imports (solves 1/2 of the problem). The name generation for functions is good enough to prevent clashes.
I suggest to add an include statement, that would "copy-paste" the file contents on compile time into the main source file. From EJS:
Includes are relative to the template with the include call. For example if you have "./views/users.ejs" and "./views/user/show.ejs" you would use <%- include('user/show'); %>.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.