Skip to content

Commit

Permalink
Sort by when writing datasets
Browse files Browse the repository at this point in the history
  • Loading branch information
Breck Yunits authored and Breck Yunits committed May 10, 2024
1 parent a19358f commit 1e0e499
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 18 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -27,6 +27,7 @@ blog/planets.json
feed.xml
*.txt
*.csv
planetMeasures.tsv

# Do not check in external assets copied by Scroll
blog/dataTables.dataTables.min.css
Expand Down
6 changes: 3 additions & 3 deletions blog/datasets.scroll
@@ -1,8 +1,8 @@
date 4/21/2024
groups All
writeConcepts planets.csv
writeConcepts planets.json
writeConcepts planets.tsv
writeConcepts planets.csv planets.json planets.tsv
writeMeasures planetMeasures.tsv
sortBy -Values

import header.scroll
keyboardNav
Expand Down
3 changes: 3 additions & 0 deletions grammar/concepts.grammar
Expand Up @@ -34,3 +34,6 @@ writeConceptsParser
catchAllCellType filePathCell
description Compiles concepts to a delimited file and write to disk.
extends abstractCommandParser
sortByParser
cruxFromId
cells keywordCell anyCell
3 changes: 3 additions & 0 deletions grammar/measures.grammar
Expand Up @@ -6,6 +6,9 @@ writeMeasuresParser
catchAllCellType filePathCell
description Writes measure statistics to a delimited file and write to disk.
extends abstractCommandParser
sortByParser
cruxFromId
cells keywordCell anyCell

printMeasuresParser
description Print measures statistics in a page into an HTML table.
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{
"name": "scroll-cli",
"version": "85.4.0",
"version": "85.5.0",
"description": "A language for bloggers. A curated collection of tools for thoughts.",
"main": "scroll.js",
"engines": {
Expand Down
3 changes: 3 additions & 0 deletions releaseNotes.scroll
Expand Up @@ -4,6 +4,9 @@ title Scroll Release Notes

thinColumns

# 85.5.0 5/10/2024
- 🎉 `writeConcepts` and `writeMeasures` can now take multiple filenames in one line and also include a `sortBy` condition.

# 85.4.0 5/10/2024
- 🎉 Scroll now auto-adds a "filename" measure as to which file the concept appears in.

Expand Down
37 changes: 23 additions & 14 deletions scroll.js
Expand Up @@ -300,12 +300,15 @@ class ScrollFile {
return tree.toString()
}

compileConcepts(format = "csv") {
return this._compileArray(format, this.concepts)
compileConcepts(format = "csv", sortBy = "") {
if (!sortBy) return this._compileArray(format, this.concepts)
return this._compileArray(format, lodash.sortBy(this.concepts, sortBy))
}

compileMeasures(format = "csv") {
return this._compileArray(format, addMeasureStats(this.concepts, this.measures))
compileMeasures(format = "csv", sortBy = "") {
const withStats = addMeasureStats(this.concepts, this.measures)
if (!sortBy) return this._compileArray(format, withStats)
return this._compileArray(format, lodash.sortBy(withStats, sortBy))
}

evalVariables(code, originalScrollCode) {
Expand Down Expand Up @@ -776,20 +779,26 @@ import footer.scroll
if (!file.has(scrollKeywords.writeConcepts)) return
const { permalink } = file
file.scrollProgram.findNodes(scrollKeywords.writeConcepts).forEach(node => {
const link = node.getWord(1) || permalink.replace(".html", ".tsv")

const extension = link.split(".").pop()
fileSystem.write(folder + link, file.compileConcepts(extension))
this.log(`💾 Wrote concepts in ${file.filename} to ${link}`)
const files = node.getWordsFrom(1)
if (!files.length) files.push(permalink.replace(".html", ".tsv"))
const sortBy = node.get("sortBy")
files.forEach(link => {
const extension = link.split(".").pop()
fileSystem.write(folder + link, file.compileConcepts(extension, sortBy))
this.log(`💾 Wrote concepts in ${file.filename} to ${link}`)
})
})

if (!file.has(scrollKeywords.writeMeasures)) return
file.scrollProgram.findNodes(scrollKeywords.writeMeasures).forEach(node => {
const link = node.getWord(1) || permalink.replace(".html", ".tsv")

const extension = link.split(".").pop()
fileSystem.write(folder + link, file.compileMeasures(extension))
this.log(`💾 Wrote measures in ${file.filename} to ${link}`)
const files = node.getWordsFrom(1)
if (!files.length) files.push(permalink.replace(".html", ".tsv"))
const sortBy = node.get("sortBy")
files.forEach(link => {
const extension = link.split(".").pop()
fileSystem.write(folder + link, file.compileMeasures(extension, sortBy))
this.log(`💾 Wrote measures in ${file.filename} to ${link}`)
})
})
}

Expand Down

0 comments on commit 1e0e499

Please sign in to comment.