segmentio / myth

A CSS preprocessor that acts like a polyfill for future versions of the spec.
4.33k stars 131 forks source link

Add support for input from stdin #107

Closed rtheunissen closed 9 years ago

rtheunissen commented 9 years ago

Other preprocessors like Sass, Less, and Stylus, provide a flag to indicate that input will be coming from stdin, rather than a file. Could we also have such a flag for Myth? I know you can pipe the contents of a file to Myth, but what if you want to compile a string?

ianstormtaylor commented 9 years ago

Can you give me a quick example of the use case? Do you mean passing in a string directly as a command-line arg?

rtheunissen commented 9 years ago

Less states that "if source is set to '-' (dash or hyphen-minus), input is read from stdin." Source

Sass has an --stdin, -s flag to specify using stdin rather than a file. Source

Stylus reads from stdin as well if no file arg was provided. Docs

Coffeescript has an -s, --stdio flag to specify using stdin rather than a file. Docs

The use case here is when you have a string you would like to compile, but would like to avoid writing to a temporary file first. The problem with using piped input such as echo "content" | ... is that echo and printf are not consistent across platforms and interpolating the string could result in a command which is too long or poorly escaped.

ianstormtaylor commented 9 years ago

Ah, Myth already supports stdin without a flag by omitting the file argument, just like Stylus.

rtheunissen commented 9 years ago

Oh nice! Sorry for not taking a closer look before creating this issue.