-
Notifications
You must be signed in to change notification settings - Fork 840
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
Layout support #62
Comments
This uses template inheritance? |
Yes. The goal is to have a system in which you can nest templates and have that partial be extended. |
This looks really interesting, but it seems like it's pretty far outside the purview of the EJS library. It does provide a simple I would be happy to help with making an extension like this work well with EJS -- even possibly exposing something you can plug into that makes things easier. But I don't think this belongs in the core lib. |
Yea I looked into A plugable interface works fine so far as I am concerned. Laravel has a similar setup to allow for extensions. Is this something that is on the roadmap? |
It is now. Or it will be, if you can help us stub out what it is and how it should work. :) |
Yea man no problem. I'll put together some architecture to allow for plugging. |
To be honest, I think this is getting too much like Jade. From an implementation PoV it is hard to implement the "commands" like extends, etc. What you can work towards is something like this which is admittedly more spartan but easier to implement: <% extends('templ', function (section) { %>
<% section('title', function () { %>
<h1>Hola</h1>
<% }) %>
<% section('body', function () { %>
<p>¿Cómo estás?</p>
<p>Bien, ¿y tú?</p>
<% }) %>
<% }) %> <% layout('templ', function (section) { %>
<%- yield('title') %>
<%- yield('body') %>
<% }) %> |
@TimothyGu that's a pretty good take on it. I'll give it a shot tonight |
@whitneyit Good luck :) |
As part of implementing the layout functions, I decided to clean up the compile source of the generated compile function. When running tests with var __line = 1, __lines = "<style><% var value = 'bar' %><% include style.css %></style>", __filename = "test/fixtures/include_preprocessor.css.ejs"; try {var __output = ""; with (locals || {}) { ;__output += "<style>";; var value = 'bar' ;(function(){;__output += "body {\n foo: '";;__line = 2;;__output += escape(value);__output += "';\n}";;__line = 3;})();;__output += "</style>";};return __output.trim();} catch (e) { rethrow(e, __lines, __filename, __line); } It now looks like this var __line = 1
, __lines = "<style><% var value = 'bar' %><% include style.css %></style>"
, __filename = "test/fixtures/include_preprocessor.css.ejs";
try {
var __output = "";
with (locals || {}) {
__output += "<style>";
var value = 'bar';
(function(){
__output += "body {\n foo: '";
__line = 2;
__output += escape(value)
__output += "';\n}";
__line = 3;
})();
__output += "</style>";
}
return __output.trim();
} catch (e) {
rethrow(e, __lines, __filename, __line);
} I just formatted the lines and removed the extra semicolons. Is this something that you guys would want as a separate PR? Apart from asthetics the only functional difference was that I added a |
First of all, always rebase your commits on the master branch. Technically putting semicolons in front (only) is more robust, in order to keep semicolon-less code working now and in the future. The I don't really care about whitespace, but EJS v1 did beautify the sources. Why break something that worked? Also always remember to run |
I ran all of the tests and everything passed fine. I don't understand what
I'll implement your suggestions and continue to use the extra whitespace
|
When I said
I meant EJS v2 removed something that worked in EJS v1. |
Ok mate I wasn't sure if that's what you meant or if I you meant that I Cheers
|
@TimothyGu I reformated the output of the compile function with your suggestions. I removed the The output now looks like: var __line = 1
, __lines = "<style><% var value = 'bar' %><% include style.css %></style>"
, __filename = "test/fixtures/include_preprocessor.css.ejs";
try {
var __output = [];
with (locals || {}) {
; __output.push("<style>")
; var value = 'bar'
; (function(){
; __output.push("body {\n foo: '")
; __line = 2
; __output.push(escape(value))
; __output.push("';\n}")
; __line = 3
; })()
; __output.push("</style>")
}
return __output.join("").trim();
} catch (e) {
rethrow(e, __lines, __filename, __line);
} |
@whitneyit said:
I'm not 100% sure what you are referring to here. Please do make a PR. This looks much nicer than the original output. |
I edited my comment because I noticed that you addressed issue #60 and it looked like the output was different but I was mistaken. |
@whitneyit #63 does change the code in this area, but it is not merged yet and I'll fix any merge conflicts. |
I just found out about https://github.com/JacksonTian/ejs-mate. It surely looks fairly promising, although some work might be necessary to adapt it to EJS v2. |
Oh wow that's really cool. I had basic support for layouts working already. Cheers for the link :) On 5 February 2015 at 12:03, Timothy Gu notifications@github.com wrote:
Regards, |
Any ideas when layout support will be ready? We are needing this asap. Thanks! |
I don't have the time to work on this just yet. Its still on my list of By all means feel free to contribute :) Regards,
|
I would love this! Thanks for taking time for this and if you want someone to discuss implementation details with just post here :) |
Any ETA updates on this sweet enhancement? |
Hi, Any advices to make it works ? |
@whitneyit Are you still working on this? |
@whitneyit ping? If I don't hear from you within ~7 days, I will close this. |
I made some progress on this but I no longer have access to the client's machine where the work was being done and again I do not have the spare time to work on this. |
I've started to implement layout support for ejs and before I go too far down the rabbit hole I thought it would be worthwhile to get some feedback.
In my fork of the repo I have started to add some test file for the possible layout syntax. The idea behind the syntax is based off of Laravel's templating engine.
I have put together a few example use cases that will need to be tested against.
Layout files
Use cases
What do you think?
The text was updated successfully, but these errors were encountered: