Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Request: Encoding capabilities #225

Open
lud opened this issue Jan 30, 2025 · 0 comments
Open

Feature Request: Encoding capabilities #225

lud opened this issue Jan 30, 2025 · 0 comments

Comments

@lud
Copy link

lud commented Jan 30, 2025

Hello,

I am trying to generate some github config files with Elixir. To do so I use a YAML template (too keep newlines and comments), but I have to inject bits of data inside.

For now I use JSON:

jobs:
  verify:
    runs-on: ubuntu-latest

    strategy:
      matrix:
        elixir: <%= json @matrix_elixir %>
        otp: <%= json @matrix_otp %>
        exclude: <%= json @matrix_exclude %>

To have better output capabilities, would you like to consider:

  • Allowing a fun/1 to be given as sort maps, in addition to boolean values. That function would return a term that would be used with Enum.sort_by/2. For instance:

    # version first, then jobs, then sort by key
    sorter = fn
      {:version, _} -> {0, 1}
      {:jobs, _} ->    {0, 2}
      {k, _} ->        {1, k}
    end
    Ymlr.document!(data, sort_maps: sorter)
  • Provide a function to encode a document without the --- and starting at some arbitrary indentation level:

    # version first, then jobs, then sort by key
    def yaml(data, indent) do
      Ymlr.value!(data, start_indent: indent)
    end
    jobs:
      verify:
        runs-on: ubuntu-latest
    
        strategy:
          matrix:
            elixir: 
              <%= yaml @matrix_elixir, 5 %>
            otp: 
              <%= yaml @matrix_otp, 5 %>
            exclude: 
              <%= yaml @matrix_exclude, 5 %>

What do you think about that?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant