-
Notifications
You must be signed in to change notification settings - Fork 94
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
Asset references #1002
Conversation
There was a problem hiding this 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 ] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Was that strictly necessary?
There was a problem hiding this comment.
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.
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 ? |
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... |
If I understand correctly these parent-child relationships are mainly there to handle the package versioning on If we follow the odig conventions (which as far as I know
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 Does that make sense ? |
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. 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. |
(which reminds me: this PR is lacking documentation update on assets) |
f479436
to
cbbbc84
Compare
70f83f2
to
c10fb42
Compare
The state of this PR is: Also, I think a decision regarding the referencing and resolving of pages should be made before making a hard decision on this one! |
c10fb42
to
7c00147
Compare
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]>
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]>
Signed-off-by: Paul-Elliot <[email protected]>
14f51a4
to
367601a
Compare
Signed-off-by: Paul-Elliot <[email protected]>
doc/parent_child_spec.mld
Outdated
@@ -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 |
There was a problem hiding this comment.
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_
... ?
There was a problem hiding this comment.
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.
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. |
There was a problem hiding this 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/parent_child_spec.mld
Outdated
@@ -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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice :)
src/model/reference.ml
Outdated
| _ -> expected [ "page" ] location |> Error.raise_exception) | ||
| next_token :: tokens -> ( | ||
match kind with | ||
| `TUnknown -> `Dot (label_parent next_token tokens, identifier) |
There was a problem hiding this comment.
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
?
src/model/reference.ml
Outdated
not_allowed ~what:"Page label" | ||
~in_what:"the last component of a reference path" ~suggestion | ||
location | ||
|> Error.raise_exception) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
@@ -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 |
There was a problem hiding this comment.
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.
@@ -0,0 +1,71 @@ | |||
In this file, we test the resolving of asset references. |
There was a problem hiding this comment.
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"
).
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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]>
Signed-off-by: Paul-Elliot <[email protected]>
Co-authored-by: Guillaume Petiot <[email protected]>
Signed-off-by: Paul-Elliot <[email protected]>
Closing now since asset referencing will change subsequently soon. But some of the code will be used! |
Assets were introduced in #975.
This PR adds references to assets.
Resolving of reference to asset work like this:
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:
odoc
#972