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

Asset references #1002

Closed
wants to merge 14 commits into from
Closed

Asset references #1002

wants to merge 14 commits into from

Conversation

panglesd
Copy link
Collaborator

Assets were introduced in #975.

This PR adds references to assets.

Resolving of reference to asset work like this:

  • Search the asset in the current page's asset (or the explicitely given page)
  • if not found, recurse in the parent page.

In case of unqualified reference (e.g. "caml.gif", page-name."caml.gif") the asset possibility is tested last.

References to assets is a prerequesite to:

Copy link
Contributor

@trefis trefis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM modulo nitpicks

@@ -291,7 +294,8 @@ type what =
| `Module_type_u_expr of Component.ModuleType.U.expr
| `Child_module of string
| `Child_page of string
| `Reference of Reference.t ]
| `Reference of Reference.t
| `Asset_reference of Reference.Asset.t ]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was that strictly necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Of course, not strictly necessary.
In #972 it was used to make the message a little bit more precise, since we know the reference resolved passed in the command line is an asset reference.
I can remove, I don't have an opinion on this.

test/xref2/references_to_assets.t/run.t Outdated Show resolved Hide resolved
@dbuenzli
Copy link
Contributor

Do you actually have a design doc somewhere on how all this is supposed to work because I'm afraid to say it doesn't make much sense to me. In an opam install how do you know which assets is attached to which page ?

@panglesd
Copy link
Collaborator Author

No, I don't have a design doc, but I finally realized that all these parent-child relationship do not make sense in terms of opam installs, and that we will need to do something about that before going further...
Thanks for the insight!

@dbuenzli
Copy link
Contributor

If I understand correctly these parent-child relationships are mainly there to handle the package versioning on ocaml.org (or at least that's how it was sold to me when I said it wouldn't be such a good idea not to have self-describing documents).

If we follow the odig conventions (which as far as I know dune does). Then maybe to generate the docs of a package we can simply:

  1. Make index.mld the root of a parent-child relationship for the package (note odig generates an index.mld if there is none provided).
  2. Any module found in the package is made a child of index.mld
  3. Any page found in odoc-pages (cf convention) is made a child of it.
  4. Any asset found (using file extensions) in odoc-pages and/or odoc-assets is attached to index.mld.

Since IIUC this PR a child can access it's parent assets then any asset is available for use in all the doc strings and manuals of the package.

For users it's a simple model: your package simply has a folder with odoc pages and assets which are all accessible flately. This should be entirely sufficient for 98% of the packages out there.

Does that make sense ?

@panglesd panglesd mentioned this pull request Sep 26, 2023
@panglesd
Copy link
Collaborator Author

panglesd commented Sep 26, 2023

Yes, this makes sense to me.

I think simply adding some documentation about this on odoc's doc, maybe on the one about the driver, would suffice.
(And, making sure dune keeps following the convention when it adds supports for assets.)

Maybe, one day, one would want to use this parent-child relationship even inside a package, but I'm convinced that the package-flat hierarchy is enough for 99% of the usecases.

@panglesd
Copy link
Collaborator Author

(which reminds me: this PR is lacking documentation update on assets)

@panglesd
Copy link
Collaborator Author

panglesd commented Nov 3, 2023

The state of this PR is:
There are some refactoring suggested by @jonludlam: Populate the environment for once at the beginning, to have all assets available, instead of looking them up recursively on demand.

Also, I think a decision regarding the referencing and resolving of pages should be made before making a hard decision on this one!

Reference can now be toward assets.
When resolving them, look up the assets of the current page, and if
not found, recurse in the parent page.

Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
@@ -175,17 +175,17 @@ installed and might be used by a different driver.
In order for drivers to build consistent documentation for a package, the
following convention should be followed.

- [.mld] pages are installed in a package's [share] directory, under the
- [.mld] pages and assets are installed in a package's [share] directory, under the
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should assets be installed in a particular directory, or with a particular name?
With the proposed convention, assets with extension .mld are recognized as pages. But I think this is fine. If really needed, we could find some ways to work around the restriction with extension .mld_... ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine to me, as long as we mention this caveat.

@panglesd
Copy link
Collaborator Author

panglesd commented Jan 8, 2024

I implemented @jonludlam's suggestion to populate the environment with available assets, which I agree makes the code better.

I also added an explanation on the convention for assets in installed packages.

Currently, the resolving of assets is going "up" in the parent-child hierarchy, looking for the asset. This might not be the "final" strategy: we might want to change this to be closer to what is done with pages (see the discussion on that in #1011). However, I believe that it is safe to start with this strategy, as I don't expect a change in the strategy to break (future) existing documentation.

So in my opinion, this PR is ready to be merged.

Copy link
Collaborator

@gpetiot gpetiot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few typos, and a few suggestions, otherwise looks good to me!

doc/ocamldoc_differences.mld Show resolved Hide resolved
doc/odoc_for_authors.mld Outdated Show resolved Hide resolved
doc/parent_child_spec.mld Outdated Show resolved Hide resolved
@@ -175,17 +175,17 @@ installed and might be used by a different driver.
In order for drivers to build consistent documentation for a package, the
following convention should be followed.

- [.mld] pages are installed in a package's [share] directory, under the
- [.mld] pages and assets are installed in a package's [share] directory, under the
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems fine to me, as long as we mention this caveat.

src/model/reference.ml Outdated Show resolved Hide resolved
src/model_desc/paths_desc.ml Outdated Show resolved Hide resolved
src/xref2/env.ml Outdated Show resolved Hide resolved
Copy link
Collaborator

@Julow Julow left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

doc/parent_child_spec.mld Outdated Show resolved Hide resolved
| _ -> expected [ "page" ] location |> Error.raise_exception)
| next_token :: tokens -> (
match kind with
| `TUnknown -> `Dot (label_parent next_token tokens, identifier)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think label_parent makes sense here. Perhaps it should be page ?

not_allowed ~what:"Page label"
~in_what:"the last component of a reference path" ~suggestion
location
|> Error.raise_exception)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't understand this error message and suggestion. I think expected [ "page" ] would be a reasonable error.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, there was something wrong here!

Pages reference cannot have a parent, and I want to preserve this behavior in this PR. Should be better now.

src/model/reference.ml Outdated Show resolved Hide resolved
@@ -784,7 +824,12 @@ let resolve_reference_dot_sg env ~parent_path ~parent_ref ~parent_sg name =
Error (`Find_by_name (`Any, name))

let resolve_reference_dot_page env page name =
L.in_page env page name >>= resolved1
match (L.in_page env page name, page) with
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's not the usual shape of functions in this module. To make this more efficient and maintainable, it should match on the result of a single search like resolve_reference_dot_type below.
The correct find function is not in the Find module yet, it is currently inlined in L.in_page and should be extended for assets.

src/xref2/ref_tools.ml Outdated Show resolved Hide resolved
@@ -0,0 +1,71 @@
In this file, we test the resolving of asset references.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing in this test shows a working asset reference. Shouldn't caml.gif_hidden be renamed ?
Also, the only reference that seems to be intended to work do not test page parents (there's no other_page."caml.gif").

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, at the end there are working asset references. The assets are not passed in the html generation phase, which creates "dead links" just as there are dead links when you do not html-generate some of the pages), but the test checks that the links point to the right place.
Do you think it would be better to actually pass some image in the html generation, to compare the path more accurately?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went ahead and passed assets in the test.

panglesd and others added 4 commits February 6, 2024 09:38
Fixed convention's wrong installed folder for pages and assets
Fixed error message when a page reference has a parent
Fixed typo in desc
Add precision in test

Signed-off-by: Paul-Elliot <[email protected]>
Co-authored-by: Guillaume Petiot <[email protected]>
@panglesd
Copy link
Collaborator Author

Closing now since asset referencing will change subsequently soon. But some of the code will be used!

@panglesd panglesd closed this Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants