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

Refactor template model #263

Merged
merged 15 commits into from Feb 11, 2015
Merged

Refactor template model #263

merged 15 commits into from Feb 11, 2015

Conversation

thomas-p-wilson
Copy link

Some highlights:

  • RenderConfiguration, CompileConfiguration, and ParseConfiguration have been combined into the Environment
  • The various Resource implementations (StringJtwigResource, et al) have been refactored into a set of Loaders and Resources. The Environment is now solely responsible for managing the resolution and loading of resource. Multiple loaders may be specified through the use of the ChainLoader. As a result, the resolution process should always return a path relative to an arbitrary resource root, in much the same way as we specify a resource as 'client/list.twig' and whatnot.
  • Concurrent rendering demonstrated a hang when the output stream wasn't specified. This is resolved with an exception noting the problem. Helpful in unit tests
  • Unit tests have been widely refactored for uniformity, in addition to the refactoring required due to all my other changes.
  • Template caching is now supported. At minimum a per-execution cache is required due to the new resolution and loading process, but the cache can be cleared after execution. In my local tests, render time drops considerably on the second run. I've seen a drop in one of my projects from ~1200ms to ~25ms after a second run. TODO: Auto-clear the ExecutionCache after rendering has completed.
  • With the existence of the Template and its implementations, we now have a place to store per-template information, present examples being Macro and Block information, for later usage. This also allows us to use the SetVariable tag during template extension.

@coveralls
Copy link

Coverage Status

Coverage decreased (-3.13%) when pulling 5836ae7 on thomas-p-wilson:refactor-template-model into 9ccf625 on jtwig:master.

protected JtwigBasicParser basicParser;
protected JtwigTagPropertyParser tagPropertyParser;
protected JtwigConstantParser constantParser;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why use protected for all variables? Any plans for them?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no reason that subclasses shouldn't be able to access and/or manipulate object state. If there was a reason that object state should be immutable, then I would declare them private, but as it is conceivable that one might want to subclass the Environment for some reason, I'd rather retain the ability to easily handle the state of the subclass.

@joao-de-melo joao-de-melo added this to the 4.0.0 milestone Jan 1, 2015
@joao-de-melo
Copy link
Member

We need more tests on this! @thomas-p-wilson I can help you on this, just let me know what you need.

@thomashunziker
Copy link

Is there a chance to get some of the improvements also into the 3.x branch? Especially the caching improvements?

@thomas-p-wilson
Copy link
Author

@thomashunziker The caching changes are a pretty big departure from the way the 3.x branch works, but I'm more than happy to look into something that would remain backward compatible.

@thomas-p-wilson
Copy link
Author

@lyncodev Thanks for the offer! I'll take you up on that! I've got some minor changes coming tomorrow for caching and resource resolution, after which I'll be catching up on tests. I'll update here as I begin writing tests so that we don't write tests for the same things, sound good?

@joao-de-melo
Copy link
Member

@thomas-p-wilson sounds like a plan to me.


@Override
public TemplateCache addParsed(final String name, final Template template) {
parsed.put(name, template);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An Hashmap allows Null keys, meaning that you can have Null names on the Hashmap. Howerver, your getters don't allow Null names. You should add also a null check at put methods.

@joao-de-melo
Copy link
Member

@thomas-p-wilson I try to be around slack if you wanna have a quick chat around the testing.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.82%) to 92.19% when pulling de3309c on thomas-p-wilson:refactor-template-model into 9ccf625 on jtwig:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-1.01%) to 93.0% when pulling cd351f2 on thomas-p-wilson:refactor-template-model into 9ccf625 on jtwig:master.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.49%) to 93.51% when pulling 6593262 on thomas-p-wilson:refactor-template-model into 9ccf625 on jtwig:master.

@coveralls
Copy link

Coverage Status

Coverage increased (+0.12%) to 94.13% when pulling 77b67e4 on thomas-p-wilson:refactor-template-model into 9ccf625 on jtwig:master.

@joao-de-melo
Copy link
Member

Nice one @thomas-p-wilson. Shall I merge it? So that we can start working on new shiny features?

@thomas-p-wilson
Copy link
Author

I'd say go for it. I/we can fix up any issues that arise as they come up.
On Feb 11, 2015 5:02 PM, "João Melo" notifications@github.com wrote:

Nice one @thomas-p-wilson https://github.com/thomas-p-wilson. Shall I
merge it? So that we can start working on new shiny features?


Reply to this email directly or view it on GitHub
#263 (comment).

joao-de-melo pushed a commit that referenced this pull request Feb 11, 2015
@joao-de-melo joao-de-melo merged commit 0bea70d into jtwig:master Feb 11, 2015
@thomas-p-wilson thomas-p-wilson deleted the refactor-template-model branch February 11, 2015 22:50
@thomas-p-wilson thomas-p-wilson restored the refactor-template-model branch February 11, 2015 22:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants