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

Feature/enhanced columns #34

Merged

Conversation

binarystargames
Copy link
Contributor

@binarystargames binarystargames commented Feb 11, 2022

Added a "ratio" feature to columns shortcode. Code sample/execution:

{{< flexcolumns ratio="3:7" >}}
**Sunrod**<br/>
*Bomb, At-Will, Standard*<br/>
*Spend 1 Reagent*
<--->
<br/>
Make an attack vs PD on 1d3+1 nearby targets.

*Hit:* The target takes radiant damage equal to your level and is Dazed (11+ save ends).

*Miss:* The target is Dazed until the start of your next turn.

*Special:* You may partially activate this as a free action (including outside of combat) to create light twice as bright as a torch for about an hour. While still lit, you may throw it to use the Bomb ability as above (it flares up and then stops working on contact).

{{< /flexcolumns >}}

This code becomes: https://binarystar.games/docs/36th-way/classes/list-of-classes/alchemist/#1st-level


I've also got a CSS rule locally to flatten columns to vertical when hugo-book gets rid of the side TOC/menu because the default hugo-book ones look not great at low width. I left it out for now but it's an option.

@michaeltlombardi
Copy link
Contributor

Looking over this, I wonder if this isn't worth contributing back upstream to hugo-book directly as it's explicitly an enhancement of their shortcode. If we file an issue with them to enhance the columns shortcode with the ratio parameter, I think that will be strictly better for everyone.

If they reject the feature request / implementation, I think we can instead incorporate this as {{ flex-columns }} or something; I think the changeset for this is (without refactoring) too large to feasibly keep patched if the upstream implementation changes. That being said, this file does not seem to update often; 3 patches since implementation, only one since 2020.

@binarystargames
Copy link
Contributor Author

Makes sense. I'll see if I have the energy to look into their requested process sometime this week.

@michaeltlombardi
Copy link
Contributor

If you want, I'm happy to go ahead and file the issue and link to your prototype here - I really do think this is a great improvement over the upstream shortcode and hugely useful for folks!

@binarystargames
Copy link
Contributor Author

That would be very appreciated!

@michaeltlombardi
Copy link
Contributor

@binarystargames I think the upstream maintainer is unlikely to merge your contribution to the upstream. Instead of having to maintain our own implementation on top of theirs, can this be reworked to be a new shortcode called flexcolumns? And then we can document it and just have it be an extension here instead.

@binarystargames
Copy link
Contributor Author

Yep, I can do that.

@binarystargames
Copy link
Contributor Author

Added a commit that does just that, updated the overview example. I implemented it locally on my site, so that example link is current - that's using the new {{< flexcolumns ratio="3:7" >}} situation.

@binarystargames
Copy link
Contributor Author

Secondary question: while I'm working on columns, how do you feel about adding a parameter to flatten them whenever the sidebar disappears? We can certainly leave it to CSS to handle too, which is what I'm currently doing for my site. Not sure how you feel about one implementation vs. the other.

@michaeltlombardi
Copy link
Contributor

Secondary question: while I'm working on columns, how do you feel about adding a parameter to flatten them whenever the sidebar disappears? We can certainly leave it to CSS to handle too, which is what I'm currently doing for my site. Not sure how you feel about one implementation vs. the other.

I think having a shortcode parameter like "flattenInMobileView" would be very useful - if people want more control over the presentation, they can ignore that parameter flag and implement their own CSS, but I don't think that's the majority of our target audience.

@binarystargames
Copy link
Contributor Author

Done.

To accomplish this, I also added platen.scss injected via inject/head.html (because I suspect to do at least a few of the things on that issues tracker we'll want somewhere to put this kind of stuff). Let me know if you'd rather I separate that out to another PR or something.

By default it uses default columns behavior, but including flattenInMobileView="true" adds the flattening. (I added it to Sunrod and Tanglefoot Bag from the initial demo link and nothing else so you can see the difference: https://binarystar.games/docs/36th-way/classes/list-of-classes/alchemist/#1st-level )

Copy link
Contributor

@michaeltlombardi michaeltlombardi left a comment

Choose a reason for hiding this comment

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

Overall, this looks great! One minor note unrelated to the code, for this project if we can use rebase to update the working branch instead of merging upstream/main into it, that would be preferable - it helps keep the git history a little neater to follow.

It might also be possible to rebase and combine the first four commits into one - I think this work is really comprised of two chunks: Adding the new shortcode and extending the head injection.

Otherwise the implementation looks great and I'm stoked about this!

layouts/shortcodes/flexcolumns.html Outdated Show resolved Hide resolved
layouts/partials/platen/docs/inject/head.html Outdated Show resolved Hide resolved
assets/platen.scss Outdated Show resolved Hide resolved
layouts/partials/platen/docs/inject/head.html Outdated Show resolved Hide resolved
@binarystargames
Copy link
Contributor Author

binarystargames commented May 16, 2022

Made a few changes as prescribed:

  • Moved the inject out of head to baseof because we're already altering that from hugo-book.
  • Refactored flexcolumns,html for improved readability/to use better tools as demonstrated

Definitely happy to rebase rather than merge in directly whenever this looks good.

Comment on lines +1 to +2
{{- $platenStyles := resources.Get "platen.scss" | resources.ExecuteAsTemplate "platen.scss" . | resources.ToCSS | resources.Minify | resources.Fingerprint }}
<link rel="stylesheet" href="{{ $platenStyles.RelPermalink }}" {{ template "integrity" $platenStyles }}>
Copy link
Contributor

Choose a reason for hiding this comment

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

Commenting here to remind myself:

I have come across this pattern a couple of times now, and I think it's probably worth defining a partial for ourselves so we can reference an SCSS style link injection via something like

{{ partial "platen/GetScssLink" "platen.scss" }}

I've been using some utils partials over in toroidal - it turns out partials can be used to return values instead of writing text into a file, so that might be useful.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, we used a similar value return with a partial with platen/getCssClass for class injection in baseof.

Copy link
Contributor

@michaeltlombardi michaeltlombardi left a comment

Choose a reason for hiding this comment

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

Some thoughts, suggestions, and questions. Also worth considering: if there are error conditions, can we handle those explicitly with the errorf function to give our users (who may not be technical at all) more helpful information than hugo's default when a template breaks?

layouts/shortcodes/flexcolumns.html Outdated Show resolved Hide resolved
layouts/shortcodes/flexcolumns.html Outdated Show resolved Hide resolved
Copy link
Contributor

@michaeltlombardi michaeltlombardi left a comment

Choose a reason for hiding this comment

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

Okay, this looks great! I think the only dangling (non-blocking) questions are:

  • is if there's any sensible error handling we can use here - maybe to check the ratio string specified, make sure that it's numbers separated by colons?
  • can the flattenInMobileView parameter be a direct boolean instead of a string?

@binarystargames
Copy link
Contributor Author

binarystargames commented May 18, 2022

sensible error handling

It's hard to believe, but this is actually pretty robust in that regard. The reason for this is how poorly formed CSS works: flex-grow:(not a number/empty) just doesn't get processed and falls back to flex-grow:1.

At that same Alchemist link, you can see examples of:

  • Needleburst: ratio="3::7"
  • Immunity Shot: ratio="3:"
  • Vitalizing Draught: ratio=":7
  • Leadbody: ratio="3:a"
  • Sliptongue: ratio="a:3"
  • Incendiary Paste: ratio="3"
  • Snake Venom: ratio="a"

The last two broke without a check for ":" so I've included a colon check. In all of the other cases, it just fell back to 1.

can the flattenInMobileView parameter be a direct boolean instead of a string?

Sure can! The following now work:

  • {{< flexcolumns ratio="3:7" flattenInMobileView=true >}}
  • {{< flexcolumns "3:7" true >}}

Copy link
Contributor

@michaeltlombardi michaeltlombardi left a comment

Choose a reason for hiding this comment

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

Okay! That all makes sense and this looks great! Two minor fixes to the docs and my last (🤞🏻) question: With the way flex-grow works, I'm wondering if we should warn when people submit an invalid ratio - probably just a single warning message like "Hey this ratio is invalid, we're going to fall back on an even ratio" and maybe include an option to treat the warning as an error.

I couldn't quickly find the docs on turning warnings into errors, but I did find how folks can suppress an error. Not blocking for this PR, I'll merge tonight or tomorrow either way.

layouts/shortcodes/flexcolumns.html Outdated Show resolved Hide resolved
layouts/shortcodes/flexcolumns.html Outdated Show resolved Hide resolved
Prior to this commit, theme users were able to specify the `columns`
shortcode to arrange their content into multiple evenly distributed
columns.

This commit builds on that work by introducing a new `flexcolumns`
shortcode which allows users to optionally specify a ratio to have more
control over column widths.
@michaeltlombardi michaeltlombardi merged commit ce0e3d8 into platenio:main Jun 5, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants