Here's what my data looks like (YAML):
-
name: objectA
components:
-
name: "component_1"
-
name: "component_2"
styles:
-
name: "new style"
components:
-
name: "component_1"
-
name: "other style"
components:
-
name: "component_4"
I would like to retrieve in my mustache the full list of components for objectA, meaning i need to access all the components children values and concatenate them or uniq them.
The goal would be to have a template like this:
{{#allComponents}}
{{name}}
{{/allComponents}}
which should output:
component_1
component_2
component_4
PS: i am using GRMustache
There's very little chance any Mustache implementation could handle such a specific need with any native built-in syntax of any kind. And GRMustache does actually not.
The simplest path is to prepare your allComponents key before rendering your data.
Related
Given a path template with two parts such as:
paths:
/blah/{fooPart}-stuff-{barPart}:
parameters:
- in: path
name: fooPart
description: foo part of this matrix ID
required: true
schema:
type: string
- in: path
name: barPart
description: bar part of this matrix ID
required: true
schema:
type: string
I'd like to provide an list of examples. Since the fooPart and the barPart are correlated, i'd like to have each example have the corrrelated data elements. I'd imagine putting it in the components
examples:
Happy:
summary: Happy path
value:
fooPart: red
barPart: up
Sad:
summary: Sad path
value:
fooPart: up
barPart: red
When i add the refs as an examples list to each parameter, like so
- in: path
name: fooPart
description: foo part of this matrix ID
required: true
schema:
type: string
examples:
happy:
$ref: "#/components/example/Happy"
sad:
$ref: "#/components/example/Sad"
the rendered display is ... adequate? Wrong? Not helpful? The examples aren't correlated and the array specified as value is presented in the box for each parameter, as seen here. I recognize, this is what i told it to do. Is there any way to bundle all the examples together? Or is my only option the one i will offer as an answer? Ugh.
I'm assuming the only option is
examples:
HappyFoo:
summary: Happy path
value: red
HappyBar:
summary: Happy path
value: up
SadFoo:
summary: Sad path
value: red
SadBar:
summary: Sad path
value: red
With each parameter only including its own values like so:
parameters:
- in: path
name: fooPart
description: foo part of this matrix ID
required: true
schema:
type: string
examples:
Happy:
$ref: "#/components/examples/HappyFoo"
Sad:
$ref: "#/components/examples/SadFoo"
The examples aren't correlated, but at least the value in the box is correct as seen here.
I have a template that looks like this:
---
date: "2016-01-01T06:00-06:00"
value: "/{{ page.date | date: '%Y/%m/%d' }}/index.html"
---
Value prints: {{ value }} <br/>
But we expect: {{ page.date | date: '%Y/%m/%d' }}/index.html <br/>
When I render the site then the site looks like this:
Value prints: /{{ page.date | date: '%Y/%m/%d' }}/index.html
But we expect: 2016/01/01/index.html
I really want the value parameter to have the expected value.
As far as I can tell, this sort of thing should work. I want to use this technique to calculate permalinks. My thinking is based on https://www.11ty.dev/docs/permalinks/
I'm running eleventy 0.12.1
Things I've tried:
yaml, json and js frontmatter
markdown template
njk template
literally copy pasting sample code from the docs
At this point I think Eleventy might have a bug
At the moment of writing, eleventy doesn't support template syntax in any frontmatter fields except the permalink field:
permalink: Change the output target of the current template. Normally, you cannot use template syntax to reference other variables in your data, but permalink is an exception.
Source
Instead, you can use computed data, which allows you to set frontmatter data based on other frontmatter fields. Something like this should work:
date: "2016-01-01T06:00-06:00"
eleventyComputed:
value: "/{{ page.date | date: '%Y/%m/%d' }}/index.html"
I've some YAML files which I wanted to apply to create Custom Resources. But before applying it I want to change the spec and ENVs of the YAML snippet. So what could be the best way to do this?
What I'm doing now is:
Let suppose this is the YAML
apiVersion: litmuschaos.io/v1alpha1
kind: ChaosEngine
metadata:
name: nginx-chaos
namespace: default
spec:
appinfo:
appns: 'default'
applabel: 'app=nginx'
appkind: 'deployment'
# It can be true/false
annotationCheck: 'false'
# It can be active/stop
engineState: 'active'
chaosServiceAccount: pod-delete-sa
monitoring: false
# It can be delete/retain
jobCleanUpPolicy: 'delete'
experiments:
- name: pod-delete
spec:
components:
env:
# set chaos duration (in sec) as desired
- name: TOTAL_CHAOS_DURATION
value: '30'
# set chaos interval (in sec) as desired
- name: CHAOS_INTERVAL
value: '10'
# pod failures without '--force' & default terminationGracePeriodSeconds
- name: FORCE
value: 'false'
I Download this file from the raw link. (1 function for this)
Replace a field like jobCleanUpPolicy: 'delete' to jobCleanUpPolicy: 'retain' (1 fn)
Replace the next line when a match is found like value: 'false' to value: 'true' for FORCE ENV. (1 fn)
Applying the final manifest created! (1 function)
Can this be optimized?
If you create a struct representing the resource (or, even better, can import the package which defines the CRD) you could take the yaml string, marshal it into the struct and then edit the fields directly as fields of a struct instead
Hi You may use LitmusPortal to use this.Refer
I refer to an other component, and some of its fields become required.
Example with AbstractQuestion, a component that I will refer to later on:
AbstractQuestion:
type: object
properties:
title:
description: Question statement
type: string
label:
description: Question label
type: string
required:
description: whether an answer is required for this question or if it could be left blank
type: boolean
question_type:
description: campaign type
enum:
- profile
- feeling
type: string
answer_type:
enum:
- string
- list
- date
type: string
max_length:
description: >-
for open ended questions this is the max characters possible. for list type questions
this would be the max number of options to select when multiple answers are accepted
type: integer
modelizable:
description: 'whether the questions'' answers are suitable for feeding ML models (e.g. 1,2,3,4)'
type: boolean
choices:
$ref: '#/components/schemas/QuestionChoices'
Now, I will use it to define a Post request body, specifying which field are required. NB: I didn't specify this in the previous object because it is also used in an other context (GET or PUT requests for example) where those fields are not required.
QuestionPost:
allOf:
- $ref: '#/components/schemas/AbstractQuestion'
required:
- title
- label
- required
- question_type
- answer_type
- modelizable
When I try this solution, my tests do not pass, as they match the yaml file to my api and find this error:
openapi_spec_validator.exceptions.ExtraParametersError: Required list has not defined properties: ['label', 'title', 'answer_type', 'question_type', 'modelizable', 'required']
It seems unable to find the required properties in the referenced component.
When I try this solution:
QuestionPost:
$ref: '#/components/schemas/AbstractQuestion'
required:
- title
- label
- required
- question_type
- answer_type
- modelizable
I get a warning in my editor. My understanding of the doc is that the required field will be ignored.
Maybe what I'm trying to achieve is just not possible? How would you do it?
I want to mock/stub:
#the_bill = GovKit::OpenCongress::Bill.find_by_idents("112-s368").first
for use in my tests.
which returns the following object that i would like to fix for the purpose of my tests:
--- !ruby/object:GovKit::OpenCongress::Bill
bill_type: s
co_sponsors:
- !ruby/object:GovKit::OpenCongress::Person {}
id: 68340
introduced: 1297836000
most_recent_actions:
- result:
created_at: "2011-02-17T07:45:50Z"
govtrack_order:
amendment_id:
text: Read twice and referred to the Committee on Agriculture, Nutrition, and Forestry.
date: 1297836000
how:
id: 287979
vote_type:
type: BillAction
roll_call_id:
action_type: action
datetime: "2011-02-16T00:00:00Z"
where:
bill_id: 68340
roll_call_number:
- result:
created_at: "2011-02-17T07:45:49Z"
govtrack_order:
amendment_id:
text:
date: 1297836000
how:
id: 287978
vote_type:
type: BillAction
roll_call_id:
action_type: introduced
datetime: "2011-02-16T00:00:00Z"
where:
bill_id: 68340
roll_call_number:
number: 368
plain_language_summary:
recent_blogs: []
I've tried Factory_girl (can't do it, not model based object), Fabrication (still same issues) and OpenStruct, probably possible, but had trouble converting yaml to OpenStruct and getting the mock in the right place.
Right now, i'm doing the api call in my tests, not what i want. I am thinking webmock is my solution, but I couldn't find out in the docs how to just load a simple object.
Try VCR for mocking out an API. I had the exact same question about 6 months ago and only recently discovered this library. It does exactly what you need, will cache the objects for testing later, but can also automatically refresh them on regular intervals. So far it's hands down the best solution I've found for this.