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

Use soft linebreaks for constant doc styles #5657

Merged
merged 1 commit into from
May 23, 2018

Conversation

Sija
Copy link
Contributor

@Sija Sija commented Jan 30, 2018

Fixes cases like KeyBindingHandler constant entry in Readline docs.

@bew
Copy link
Contributor

bew commented Jan 30, 2018

Could you show a screenshot before/after to explain visually what this does? Ty

@Sija
Copy link
Contributor Author

Sija commented Jan 30, 2018

@bew sure!

before:

screen shot 2018-01-30 at 01 50 58

after:

screen shot 2018-01-30 at 01 51 16

@oprypin
Copy link
Member

oprypin commented Jan 30, 2018

I think this is invalid. If code is changed to be the exact same thing as pre, then how do you do code?

@ysbaddaden
Copy link
Contributor

Maybe we should fix the doc templates to use PRE instead for constant summaries, or some kind of inline block? Having a nicely formatted value is definitely nicer, but having CODE == PRE seems too much.

@donovanglover
Copy link
Contributor

From my understanding of it this commit just makes <code></code> sections behave like <pre><code></code></pre> (aka preserve extra spaces and new line characters), but without the extra styling already provided for pre tags (useful in this case).

One important difference, however, is that using white-space: pre will remove text wrapping for all code blocks not wrapped in pre tags, consequentially making the entire page horizontally scrollable given a small enough viewport. This is in contrast to how pre tags have their own scrollbox, since the pre element is display: block and the code element is display: inline.

In any case, I'd suggest using white-space: pre-wrap as opposed to simply pre. If you do, you need to restrict its scope to only the sections you want to change (i.e. .entry-const), so other code blocks that don't need this change aren't changed.

.entry-const code {
    white-space: pre-wrap;
}

Ref:

@donovanglover
Copy link
Contributor

In the long term it may be ideal to use pre, but in the short term this pull request fixes the issue at hand. It's a trivial fix for a trivial issue, whereas migrating to pre may require a lot more changes.

I say that we merge this CSS fix for now, until there's a valid reason to change what isn't broken. crystal docs can always be refactored later as Crystal gets closer to 1.0.

@jhass
Copy link
Member

jhass commented Jan 30, 2018

Am I missing something or isn't this just that we somewhere generate (from Markdown) a <code> where we should generate a <pre><code>?

@oprypin
Copy link
Member

oprypin commented Jan 30, 2018

The styling works fully as intended, just that this constant's definition is too scary for docs.

I expect numerous doc regressions if this is merged, because presumably this affects method parameters as well

@Sija
Copy link
Contributor Author

Sija commented Feb 1, 2018

I've force-pushed changes with @gloverdonovan's suggestion.

@Sija
Copy link
Contributor Author

Sija commented Feb 1, 2018

Since .entry-const is used in just one place throughout the codebase (src/compiler/crystal/tools/doc/html/type.html) there shouldn't be any regressions. Is it GTG now?

@donovanglover
Copy link
Contributor

Maybe the title should be updated to reflect what this pull request actually does?

@Sija Sija changed the title Make <code> behave more like <pre> in terms of linebreaks Use soft linebreaks for constant doc styles Feb 6, 2018
@Sija
Copy link
Contributor Author

Sija commented Feb 6, 2018

@gloverdonovan I updated the PR title accordingly(?)

@Sija
Copy link
Contributor Author

Sija commented Feb 6, 2018

@ysbaddaden @jhass @oprypin ready for another review

@asterite
Copy link
Member

asterite commented Feb 6, 2018

Maybe constant values shouldn't be shown in the docs.

@oprypin
Copy link
Member

oprypin commented Feb 6, 2018

Values would be fine, it's the chunks of source code that's the problem.

@asterite
Copy link
Member

asterite commented Feb 6, 2018

What are values? You mean just show literals like numbers and strings? Maybe that's a good compromise.

@Sija
Copy link
Contributor Author

Sija commented Feb 6, 2018

@asterite @oprypin do you see any problem with proposed solution? It fixes problem at hand with no downsides. Better options could be discussed in another issue/PR.

@oprypin
Copy link
Member

oprypin commented Feb 6, 2018

I see it as exacerbating the problem. Before, we have an unwanted chunk of code taking up 3 lines, and after, we have it taking up 8 lines.

Copy link
Member

@oprypin oprypin left a comment

Choose a reason for hiding this comment

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

Oh, actually, before this change, the chunk of code is also non-runnable (newlines are missing and not replaced by semicolons). So yeah, it's an improvement, although it kinda hides the root problem.

@asterite
Copy link
Member

asterite commented Feb 6, 2018

I think what @oprypin says is exactly the thing. There's a problem: constant values look ugly. So a fix is to make it beautiful. Another fix is to hide them, because they are irrelevant.

I originally included values in constants because of enum members, to know their values (I don't know why, though). So instead of rushing and "fixing" this we are taking some time to discuss what's the real problem and what a good solution might be.

@straight-shoota
Copy link
Member

@asterite I strongly disagree on the value of constants being irrelevant for API docs. They are certainly not always meaningful, but on many occassions it's super useful to know. Especially when it's just a plain literal:

MAX_CODEPOINT = 0x10FFFF

It wouldn't hurt to have some lines about the details alongside, but you shouldn't need to wrap that plain value in prose.

If it's more complicated than that, for sure, there is no point in printing all this:

STDERR = (IO::FileDescriptor.new(2, blocking: (LibC.isatty(2)) == 0)).tap do |f| f.flush_on_newline = true end 

Or the Readline example mentioned in the OP.

In such cases, it is essential to have a doc string describing all the details about this constant, it's value and usage. Perhaps it would be nice to add the inferred type alongside the name, but nothing else.

@Sija
Copy link
Contributor Author

Sija commented Feb 27, 2018

@asterite Before now there was no discussion about constants being irrelevant in docs. This PR fixes only the presentation layer (you have new lines - then show 'em!). ATM we have a mess - we see the values, yet we see them garbled. How bad is fixing this?

@Sija
Copy link
Contributor Author

Sija commented May 23, 2018

From #6118 (comment) by @asterite:

This is an improvement over the old code. It might not fix all problems, but that's how we move in Crystal, fixing things slowly.

Shall we use that approach, merge this and discuss future improvements in another issue/pr?

@asterite
Copy link
Member

Actually, what we can do is to change the doc generator to only show simple constants, like numbers, booleans, chars and strings. Everything else could be hidden.

@Sija
Copy link
Contributor Author

Sija commented May 23, 2018

@asterite Personally I'd find it counter-intuitive and misleading. Anyhow, let's discuss this in a new issue/pr please.

@asterite
Copy link
Member

@Sija Do you find the value of STDOUT useful?

We can always show a "show source" that leads to where the constant is defined, and there you can see the value.

@oprypin
Copy link
Member

oprypin commented May 23, 2018

Personally I'd find it counter-intuitive and misleading. Anyhow, let's discuss this in a new issue/pr please.

@RX14
Copy link
Contributor

RX14 commented May 23, 2018

It's impossible (for me) to work out if this is the right change, it's just CSS so lets merge it and see if anything breaks with existing <code> blocks.

@RX14 RX14 added this to the Next milestone May 23, 2018
@RX14 RX14 added kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:docs topic:compiler topic:tools labels May 23, 2018
@RX14 RX14 merged commit 6cef3d2 into crystal-lang:master May 23, 2018
chris-huxtable pushed a commit to chris-huxtable/crystal that referenced this pull request Jun 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. kind:docs topic:compiler topic:tools
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants