Skip to content

Expose helpers (inflection, change-case) in params and prompt hooks#326

Merged
jondot merged 2 commits intojondot:masterfrom
blikblum:allow-inflection-in-prompt
Feb 21, 2022
Merged

Expose helpers (inflection, change-case) in params and prompt hooks#326
jondot merged 2 commits intojondot:masterfrom
blikblum:allow-inflection-in-prompt

Conversation

@blikblum
Copy link
Contributor

This change allows to call helpers in prompt or params.

Fixes: #59

Makes #61 unnecessary

It's useful when you need to define a var, derived from passed/prompted params, used in many places in the template.

See the template below:

---
to: ./src/application/dashboard/<%- tagName %>.js
---
import { html } from 'component'
import { <%- statsClassName %> } from './stats/<%- h.changeCase.camelCase(statsClassName) %>.js'
import { PatientsStats } from './patients-stats.js'
import './<%- tagName %>.scss'

const itemColors = {
  0: 'green',
  1: 'orange',
  2: 'red',
  3: 'blue',
}

class <%- componentName %> extends PatientsStats {
  title = '<%- title %>'

  statsClass = <%- statsClassName %>

  chartOptions = { type: 'pie' }

  showPatientsList(e) {
    e.preventDefault()

    this.modals.dialog('stats-patient-list-dialog', {
      scrollable: true,
      size: 'xl',
      properties: { stats: this.stats, title: 'xxxx' },
    })
  }

  renderData() {
    const data = this.stats.get('data')
    return html` <div class="d-flex flex-row-reverse mt--3">
   
          `
        )}
      </ul>`
  }
}

customElements.define('<%- tagName %>', <%- componentName %>)

export { <%- componentName %> }

componentName is used in many places and derived from passed name param: h.changeCase.pascalCase(name)

Currently i have either to use h.changeCase.pascalCase(name) in every place is needed or implement custom code in prompt.js

With this PR i could do:

module.exports = {
  params: ({ args, h }) => {
    return { componentName: h.inflection.pascalCase(args.name) }
  },
}

@agriluke
Copy link

Have you tried the following?

const inflection = require('inflection')

This works for me, but I couldn't find it documented anywhere

@agriluke
Copy link

Have you tried the following?

const inflection = require('inflection')

This works for me, but I couldn't find it documented anywhere

Ignore that. False positive because I'm using a monorepo.

@blikblum
Copy link
Contributor Author

blikblum commented Jun 6, 2021

@jondot any opinions on this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Expose inflection on prompt callback

3 participants