jamesplease / jamesplease/puppets

Templating API

Open
#16 10 comments 0 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
4
Forks
0
PR merge metrics
No merged PRs in 30d

Description

Marionette's template API is potentially more complex than it needs to be. TemplateCache and Renderer are the two abstractions in Marionette for doing things with templates, yet I'm not sure if they're a good idea.

The actions that these two things do are:
1. Resolving templates (templateCache instance)
2. Caching resolved templates (TemplateCache class prop)
3. Compiling templates (templateCache instance)
4. Rendering templates (Renderer)

This works, but it strikes me as an odd systems. In Puppets, the system could possibly be conceptually simpler. Rather than grouping these actions into two arbitrary objects, I will approach each of them as independent things.
#
### Resolving templates

A common default resolution mechanism is to make AJAX requests to fetch templates from the server. LayoutManager and Angular take this approach. In Puppets, I will discourage this to the extent that it won't be as easily configured. Rather, the default will look for the templates at:

`Puppets.templates`

which is more similar to Ember's approach. This will encourage users to precompile their templates into functions.

Proposed API:
##### `Puppets.resolveTemplate( templateName )`

Fetch a compiled or precompiled template by name.
### Compiling templates

Compiling templates on the fly will be discouraged, but it will be possible out-of-the-box. The API
will look like:
##### `Puppets.compileTemplate( templateString )`

This would be Handlebars by default.
### Caching templates

A lightweight `Puppets.Cache` object should be created. Each instance of Puppets should create a new one for the templates, and store it as `Puppets.templateCache`.
##### `Puppets.templateCache.get( templateName )`
##### `Puppets.templateCache.set( templateName )`
### Rendering templates

Last but not least is the render method.
##### `Puppets.renderTemplate( templateFunction, data )`

Contributor guide

No contributing guide indexed for this repository

Research direction

Begin with the existing TemplateCache and Renderer abstractions described in the issue. Review how template resolution, caching, compilation, and rendering are currently divided, then compare that behavior with the proposed Puppets.resolveTemplate, compileTemplate, templateCache, and renderTemplate APIs. Done requires a decided, scoped API direction; the issue does not name files or tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
handlebars, javascript
Domain
frontend
Issue type
Refactor
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.