mde / mde/ejs

Function to return JS object containing EJS template bindings structure.

Open
#782 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
8.1k
Forks
846
PR merge metrics
No merged PRs in 30d

Description

I believe this issue has already been raised previously here, but it seems the original question may have been misunderstood.

I've also encountered this problem. In my use case, I want to generate a request schema based on the bindings within an EJS template. Ideally, I need a function that returns an object representing the variables used in the template.

For example, given this template:

<p><%- SomeRandomVar %></p>
<p><%- User.FirstName %></p>
<% for (let badge of User.Badges) { %>
  <p><%- badge.Name %></p>
<% } %>

I would expect something like:

{
  "SomeRandomVar": "string",
  "User": {
    "Badges": [
      {
        "Name": "string"
      }
    ]
  }
}

I don't need a fully fleshed out JSON schema but just getting some of the variable names from within the template would be a good start. Is there anything built into EJS already that provides this sort of functionality or would this be a new feature request?

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

No implementation file or test is named. Start by reading the related issue #683 and inspecting EJS's existing public API for template parsing or compilation; the work would be complete when a documented function can extract template variable names or structure, with behavior for nested properties and loop variables covered by tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
web-dev
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.