Code Monkey home page Code Monkey logo

Comments (8)

flyx avatar flyx commented on June 21, 2024

Probably duplicate of #105, try nimble install yaml#head and see if it goes away.

I should do a release with this fix…

from nimyaml.

wreedb avatar wreedb commented on June 21, 2024

I ran the command you suggested and neither installing or searching for this yielded any packages with nimble

from nimyaml.

flyx avatar flyx commented on June 21, 2024

Well I don‘t know your setup. On a proper nimble installation it should fetch the current master version of NimYAML, which incorporates the fix mentioned.

If your setup doesn‘t allow you to do this for some reason, you have to wait for the next release. I estimate this to happen in 2-3 weeks.

from nimyaml.

flyx avatar flyx commented on June 21, 2024

I just remembered they changed the syntax, it's nimble install yaml@#head.

from nimyaml.

wreedb avatar wreedb commented on June 21, 2024

Ah, I see, I was a bit stumped by that as I thought I did have a proper installation of the library. I will try this when I get home from work and let you know if it fixes the issue. However, I had a question about the library-- I hacked up the presenter file on my machine to give me more so the behavior that I wanted, which is that it does not create new lines for values whatsoever. I then noticed that this was writing the values (sometimes) with double quotes, and (sometimes) not with double quotes, so I incorporated a function in my code to execute a perl command to remove every double quotation mark from the file that was written. Perhaps I've only made this unnecessarily messy and difficult for myself... Does this library have ways to control those formatting choices without hacking on the presenter file?

from nimyaml.

flyx avatar flyx commented on June 21, 2024

Does this library have ways to control those formatting choices without hacking on the presenter file?

There's PresentationOptions but it doesn't offer much. Generally, NimYAML's presenter has been written with the assumption that you serialize data for communication between software. Hence it cares only about the output being valid YAML, but not much about how the output formatted; as long as it's valid YAML, the software on the other end will be able to load it. The reason for that assumption is that if you cared about details of the presentation, you would probably choose another format like XML that gives far less leeway to formatting than YAML does, and hence will give you better control about how it looks when you serialize it.

NimYAML does allow for some more control over the output format via its YamlStream interface:

import yaml

proc dumpModified[T](value: T, target: Stream) =
  var
    origEvents = represent(value) # add other args as needed
    buffer = newBufferYamlStream()
  for e in origEvents:
    case e.kind
    of yamlScalar: e.scalarStyle = ssPlain
    else: discard
    buffer.put(e)
  present(buffer, target) # possibly give options here

(I'm not using Nim anymore apart from maintaining this lib so beware of errors)

This code would set the style of all scalars to plain (i.e. without quotes). If you need to choose different styles for different data, write custom representObject functions for your types and generate Events with the style set appropriately, as explained in the docs.

from nimyaml.

wreedb avatar wreedb commented on June 21, 2024

Ah, perhaps I should stop being so finicky about the format of something only I will see. However I will give this example a shot and see how it goes. You can probably close this issue if it is going to be fixed in the next release, and I'd like to say thank you for communicating with me about it, and for being very helpful when you were able.

from nimyaml.

flyx avatar flyx commented on June 21, 2024

I'd say it's a bit of a design problem of YAML to say "I'm a serialization language but you can use me in a lot of different styles". There will always be a discrepancy between how a user can style a YAML file and how a YAML implementation can, and that does cause friction because users want the implementation to write YAML like they do, and usually it doesn't. For example, very few YAML implementations, and certainly not NimYAML, can write comments.

Closing this as duplicate.

from nimyaml.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.