Skip to content

Commit

Permalink
Fixed indentation in YAML
Browse files Browse the repository at this point in the history
  • Loading branch information
avinder-red-crackle committed Dec 27, 2024
1 parent af6c364 commit fad02d5
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
11 changes: 9 additions & 2 deletions website/_includes/lunar/governance-as-code.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ <h2>Governance-As-Code</h2>
</div>

<script>
/**
* Copying text from SVGs removes the indentation.
* This workaround gets the selected text and adds the necessary line breaks and indentation.
*/

const getIndicesFromOriginalText = (text, copiedText) => {
const textArr = text.split('')
const copiedArr = copiedText.split('')
Expand Down Expand Up @@ -57,17 +62,19 @@ <h2>Governance-As-Code</h2>
}

document.getElementById('code-collectors').addEventListener('copy', e => {
// This text should have the exact text and spacing as in the SVG file.
const text =
'collectors:\n- runBash: lunar collect hasTests true\n hook:\n type: before-command\n patterns:\n - ^go test.*\n - ^npm test.*\n - ^python -m .unittest.*'
'collectors:\n - runBash: lunar collect "hasTests" true\n hook:\n type: before-command\n patterns:\n - ^go test.*\n - ^npm test.*\n - ^python -m .unittest.*'

const { startIndex, endIndex } = getIndicesFromOriginalText(text, document.getSelection().toString())
event.clipboardData.setData('text/plain', text.substring(startIndex, endIndex))
event.preventDefault()
})

document.getElementById('code-policies').addEventListener('copy', e => {
// This text should have the exact text and spacing as in the SVG file.
const text =
'policies:\n- name: "Should have unit tests"\n runPython: |-\n import lunar\n hasTests = lunar.get(hasTests)\n lunar.assertTrue(hasTests)'
'policies:\n - name: "Should have unit tests"\n runPython: |-\n import lunar\n hasTests = lunar.get("hasTests")\n lunar.assertTrue(hasTests)'

const { startIndex, endIndex } = getIndicesFromOriginalText(text, document.getSelection().toString())
event.clipboardData.setData('text/plain', text.substring(startIndex, endIndex))
Expand Down
4 changes: 2 additions & 2 deletions website/assets/svg/governance-as-code.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit fad02d5

Please sign in to comment.