Skip to content

Instantly share code, notes, and snippets.

@bollwyvl
Last active January 11, 2016 19:03
Show Gist options
  • Save bollwyvl/7c1501003b1080aa6a14 to your computer and use it in GitHub Desktop.
Save bollwyvl/7c1501003b1080aa6a14 to your computer and use it in GitHub Desktop.
LMY: is Metä(l) YAML :-{}

LMY: is Metä(l) YAML :-{}

Literate YAML with mustaches

RIP 2015

Goals

  • write YAML...
    • or Markdown
    • or JSON
  • add mustache-style template tags...
  • load multiple files as data sources...
    • ...of many types...
      • .json
        • .jsonld
        • .ipynb
      • .ini/.cfg
      • .yml
      • .csv
    • ...into optional aliases
    • ...from a path in the files
  • ...get out JSON
    • ...or YAML
    • ...or Markdown
    • ...or HTML
    • ...or a JS app

Show me the LMY: Command Line

Any valid YML (and by extension JSON) is valid LMY:

# data.lmy
{% for lang in ["py", "js"]%}
{{ lang }}:
  name: {{ data[lang].name }}
  version: {{ data[lang].version }}
{% endfor %}

...and any number of data files can be loaded into the available data context.

lmy data.lmy py:setup.cfg#/metadata js:package.json

By default, lmy will make JSON...

{"py": {"name": "py-lmy", "version": "0.1.0"}, "js": {"name": "js-lmy", "version": "0.1.0"}}

Make it pretty:

lmy data.lmy --pretty py:setup.cfg#/metadata js:package.json
{
  "py": {
    "name": "py-lmy",
    "version": "0.1.0"
  },
  "js": {
    "name": "js-lmy",
    "version": "0.1.0"
  }
}

...or, get the intermediate YAML, which is already pretty...

lmy data.lmy --yaml py:setup.cfg#/metadata js:package.json
py:
  name: py-lmy
  version: 0.1.0
js:
  name: js-lmy
  version: 0.1.0

Add -o or --output to any of the above to write files.

Think More About CLI

  • multiple input files...
    • join?
    • merge?
    • split?
    • stream?
  • multiple output files...
    • split into documents on YAML document streams?
  • meta LMY
    • .lmy.lmy?
      • document vs data expansion?
    • How to escape without being awful?

Literate LMY

If the intent of a document is more important than the data, # comments are unnecessarily verbose. In the style of literate CoffeeScript, an .lmy.md file will be processed as a templated markdown file, and

# The LMYsphere

    {% for lang in ["py", "js"]%}
    {{ lang }}:
      name: {{ get[lang].name }}
      version: {{ data[lang].version }}
    {% endfor %}

LMY is about data, so the default will generate JSON...

lmy README.lmy.md py:setup.cfg#/metadata js:package.json

same as above :{)

...or can be expanded to template-free Markdown with embedded YAML...

lmy README.lmy.md --markdown py:setup.cfg#/metadata js:package.json
# The LMYsphere

    py:
      name: py-lmy
      version: 0.1.0
    js:
      name: js-lmy
      version: 0.1.0

...or go all the way to HTML, leaving the data as expanded, indented YAML...

lmy README.lmy.md --html py:setup.cfg#/metadata js:package.json

too long

...with the added option of generating nested tables, a la console.table...

lmy README.lmy.md --html --pretty=tables py:setup.cfg#/metadata js:package.json

too long to show

Think more about HTML

  • different table representations

LMY apps

Some LMY can make a standalone JavaScript application

Prior Art

The LMYsphere

  • JavaScript
    • js-lmy: a LMY processor for node and the browser
    • codemirror-lmy: a CodeMirror mode
    • prosemiror-lmy: a ProseMirror mode
    • ace-lmy: an Ace mode
  • Python
    • py-lmy: a LMY processor for python
    • a pygments mode
  • Editors
    • atom-lmy: LMY syntax highlighting for atom
    • atom-linter-lmy: LMY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment