Skip to content

Conversation

unnawut
Copy link
Contributor

@unnawut unnawut commented Jan 11, 2018

Sorry for the consecutive PR. Just found another spot where the example in the @moduledoc is not working. The CONTRIBUTING.md part below is not a valid keyword.

["README.md", "CONTRIBUTING.md": [filename: "contributing", title: "Contributing"]]

This PR changes it to:

["README.md", {"CONTRIBUTING.md", [filename: "contributing", title: "Contributing"]}]

I made sure to finish my work with ex_doc before submitting this PR. So this should be the last one for now.

@wojtekmach
Copy link
Member

wojtekmach commented Jan 11, 2018

["a.md": []] is valid syntax, it evaluates to [{:"a.md", []}]. I tested above configuration on local project using ex_doc and it worked as expected - did you run into any issues?

@unnawut
Copy link
Contributor Author

unnawut commented Jan 11, 2018

According to the existing doc, my config would look like this:

extras: [
  "README.md": [filename: "introduction", title: "Introduction"],
  "docs/document.md"
],

And yes it is returning a syntax error:

** (SyntaxError) mix.exs:15: syntax error before: "docs/document.md"
   (elixir) lib/code.ex:334: Code.load_file/2
   (mix) lib/mix/cli.ex:26: Mix.CLI.proceed/1
   (elixir) lib/code.ex:376: Code.require_file/2

Writing this way works fine:

extras: [
  {"README.md", [filename: "introduction", title: "Introduction"]},
  "docs/document.md"
],

Actually... I tried swapping the two extras I have, now this works:

extras: [
  "docs/document.md",
  "README.md": [filename: "introduction", title: "Introduction"]
],

Maybe I'm not familiar with the keyword syntax enough, but the Keyword docs state that "A keyword is a list of two-element tuples where the first element of the tuple is an atom and the second element can be any value". This config allows mainly a list of strings and/or tuples with {"string", []}, so I'm not sure if the keyword syntax can strictly apply here?

But regardless of that, not sure if the sequence of the config values should cause a syntax error here.

@josevalim
Copy link
Member

Similar to function calls, you can use the keyword syntax only at the end of the data structure. :) So the example is correct. Thanks for the PR in any case!

@josevalim josevalim closed this Jan 11, 2018
@unnawut
Copy link
Contributor Author

unnawut commented Jan 11, 2018

This syntax caveat isn't documented in Keyword. Are you keen to have a PR to the documentation there?

@josevalim
Copy link
Member

Good catch. I will change it accordingly! thanks!

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

Successfully merging this pull request may close these issues.

3 participants