daredoes / linked-lovelace-ui

Create cards that can be re-used, updated, and handle templated data.
MIT License
29 stars 3 forks source link

Don't try and match invalid var characters #14

Closed clehmann closed 1 year ago

clehmann commented 1 year ago

Only allow alphanumeric and underscores in variable names to be replaces. This was matching any $ in the file before, even if it was just a normal character. Example template - this would break on the '$' in the template

type: custom:button-card
entity: sensor.docker_$containerName$_status
name: $fullContainerName$
icon: $icon$
styles:
  button-card:
    - font-size: 20px
    - width: 100%
  grid:
    - width: 100%
    - grid-template-areas: '"i n memory" "i n status"'
    - grid-template-columns: 1fr 2fr 3fr
    - grid-template-rows: min-content min-content
  name:
    - font-weight: bold
    - padding-right: 40px
  icon:
    - width: 60px
  custom_fields:
    status:
      - align-self: start
      - text-align: start
      - padding-right: 20px
      - padding-bottom: 4px
    memory:
      - align-self: start
      - text-align: start
      - padding-right: 20px
      - padding-bottom: 4px
custom_fields:
  memory: |
    [[[
      return `<ha-icon
        icon="mdi:memory"
        style="width: 20px; height: 20px; color: deepskyblue; padding-right: 8px">
        </ha-icon><span>RAM: <span style="color: var(--text-color-sensor);">${states['sensor.docker_$containerName$_memory'].state}mb</span></span>`
    ]]]
  status: |
    [[[
      return `<ha-icon
        icon="mdi:server"
        style="width: 20px; height: 20px; color: deepskyblue; padding-right:8px">
        </ha-icon><span>Status: <span style="color: var(--text-color-sensor);">${states['sensor.docker_$containerName$_status'].state}</span></span>`
    ]]]
daredoes commented 1 year ago

This is greatly appreciated! my implementation is not the best. @clehmann could you rebase your branch onto the latest master? Should be easier than resolving the conflicts. After that, I'll approve and release this

clehmann commented 1 year ago

Sure, I'll get to it tonight