inukshuk / jekyll-scholar

jekyll extensions for the blogging scholar
MIT License
1.12k stars 102 forks source link

Custom bibliography list class and attributes #295

Closed amoodie closed 4 years ago

amoodie commented 4 years ago

Summary

This PR adds support for custom bibliography list classes, and attributes. I.e, the changes, expose the bibliography_list_attributes config option as an option in the {% bibliography %} Liquid tag.

NOTE: I am not a ruby developer. In fact I have never edited ruby code before this PR. Please review carefully and critically.

Changes

  1. Add an option to the utilities.rb optparse function named bibliography_list_attributes.
  2. Add a function to utilities.rb named bibliography_list_attributes, which returns the passed bibliography_list_attributes argument if it was given, otherwise, returns an empty Hash {}.
  3. The bibliography_list_attributes function is now called during the merge with config['bibliography_class'] during the call to render_item.
  4. This merge enables custom HTML attributes to be passed, such as reversing the list with --bibliography_list_attributes {:reversed=>'reversed'}. Additionally, the class of the bibliography list can overridden by passing, e.g., --bibliography_list_attributes {:class=>'bibliography__custom'}.

Potential problems?

Thoughts

amoodie commented 4 years ago

realized this probably addresses #234.

inukshuk commented 4 years ago

This is good work thanks!

I'm a little hesitant to merge this, because I'm a concerned that this is too much effort, or too complicated for something that should not be difficult. I don't mean this PR specifically, but rather that I was not anticipating the need for users to control the list generation in this way. I guess originally I was mostly thinking about styling issues and had the vague though that you could always just wrap your bibliography in a div with a custom class and then apply any custom styles you need in a flexible way.

Obviously, your use case here points to a flaw in that logic namely that the reverse attribute really is something that you can't add via a wrapper. Can you think of other examples where you absolutely need to control the list element itself? If there's just the one (and maybe class) we could turn those into separate options. This would at least remove the need for using eval; this is definitely something I'd like to avoid (thinking about scenarios where you have some setup similar to github-pages and multiple users can push their pages to it, this sounds like a dangerous thing to do).

amoodie commented 4 years ago

Hiya, yeah, I think you're correct that this is probably over complicated. It also feels wrong to expose the ruby Hash guts to the user.

I think that adding a --reverse option should be straightforward enough. This would be able to satisfy my use case, too. I'm currently building off my own fork, which is working for the moment, so when I find some time, I'll implement a --reverse option, and PR.

One question: what should the behavior of --reverse be when the default option for bibliography_list_attributes is set to be reversed already (e.g., the config below)? Should supplying --reverse in that case produce an 1) un-reversed list (i.e, an ascending list) or 2) should it do nothing?

scholar:
  bibliography_list_attributes:
    reversed: "reversed"

I guess we can close this PR and I'll send another when I get the chance?

inukshuk commented 4 years ago

Good question! I guess we could make it a boolean option bibliography_list_reverse that can be overridden in the bibliography tag using --reverse. That would probably require us to improve on the extremely simple attribute generation code here (i.e. skipping attributes if their value is false should be sufficient?).

amoodie commented 4 years ago

Okay, thanks for the response. I'll add this to the list to work on when I get a chance. I'll base changes from whatever the state of the repo is at the time, and ditch what I've done here, so I'm going to close this PR and open a new one in the future. Cheers.