Skip to main content

YAML file inheritance with nested string replacement fields and conditional formatting.

Project description

See https://github.com/CodeOptimist/rimworld-mod-description-tool for example inheritance.

---
fruit1: &fruit1
  - name: 'Strawberry'
  - name: 'Apple'
  - name: 'Banana'

fruit1_names: &fruit1_names !each [ *fruit1, 'name' ]
fruit1_names_joined: !join [ ", ", *fruit1_names ]
fruit1_names_sliced: !each [ *fruit1, 'name', '{l|_,3}' ]

fruit2: &fruit2
  - property: &strawberry { common: 'Strawberry', scientific: 'Fragaria × ananassa' }
  - property: { common: 'Apple', scientific: 'Malus domestica' }
  - property: { common: 'Banana', scientific: 'Musa acuminata' }

fruit2_property: !each [ *fruit2, 'property' ]
fruit2_scientific_joined: !join [ ", ", !each [ *fruit2, 'property.scientific' ] ]

fruit3: &fruit3 !insert
  - [ *fruit1 ]
  - name: 'Pineapple'
fruit3_names: !each [ *fruit3, 'name' ]

has_dog: ~
dog: 'a dog named "[BRACKY]"'
has_cat: Yup
cat: 'a cat named "{{CURLY}}"'

matrix: &matrix !concat
  - [ 1, 2, 3 ]
  - [ 4, 5, 6 ]
  - [ 7, 8, 9 ]
float_matrix: !each [ *matrix, ~, '{l:.3f}' ]

fruit4: !merge
  <: *strawberry
  color: 'red'

# [text to format, expected literal result]
tests:
  - [ '{fruit1_names}', "['Strawberry', 'Apple', 'Banana']" ]
  - [ '{fruit1_names_joined}', 'Strawberry, Apple, Banana' ]
  - [ '{fruit1_names_sliced}', "['Str', 'App', 'Ban']" ]
  - [ '{fruit2_scientific_joined}', 'Fragaria × ananassa, Malus domestica, Musa acuminata' ]
  - [ '{fruit3_names}', "['Strawberry', 'Apple', 'Banana', 'Pineapple']" ]
  - [ '{dog}', 'a dog named "[BRACKY]"' ]
  - [ '{has_dog?={{dog}} is {dog}}', '' ]
  - [ '{cat}', 'a cat named "{CURLY}"' ]
  - [ '{has_cat?={{cat}} is {cat}}', '{cat} is a cat named "{CURLY}"' ]
  - [ '{has_cat?+ sure do.}', 'Yup sure do.' ]
  - [ '{optional?}', '' ]
  - [ '{matrix}', '[1, 2, 3, 4, 5, 6, 7, 8, 9]' ]
  - [ '{fruit4!e}', "{'common': 'Strawberry', 'scientific': 'Fragaria × ananassa', 'color': 'red'}" ]
  - [ '{float_matrix}', "['1.000', '2.000', '3.000', '4.000', '5.000', '6.000', '7.000', '8.000', '9.000']" ]
  - [ '{fruit1.name^Apple!e}', "{'name': 'Apple'}" ]
  - [ '{fruit2_property.common^Banana!e}', "{'common': 'Banana', 'scientific': 'Musa acuminata'}" ]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

codeoptimist.yaml-0.2.0.tar.gz (18.1 kB view hashes)

Uploaded Source

Built Distribution

codeoptimist.yaml-0.2.0-py3-none-any.whl (18.7 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page