Update 3.x cheat sheet with details from 2.x cheat sheet

Created on 26 May 2023, over 1 year ago
Updated 17 June 2023, over 1 year ago

Problem/Motivation

The Twig Tweak 2.x cheat sheet has more details than the 3.x cheat sheet -- both in the plain(-ish) language explanations of each feature, and in parameter documentation. One example, check_markup filter:

Proposed resolution

Add filter/function explanations and parameter details to the 3.x cheat sheet. Use your judgement to keep things brief.

  • Refer to the 2.x cheat sheet β†’ .
  • In the 3.x cheat sheet, review each feature -- if it doesn't have a "what does this do" kind of explanation, copy/paste the "intro sentence" explanation from the 2.x cheat sheet to the 3.x cheat sheet. (See check_markup example at the top of this issue.)
    • Some features in the 3.x cheat sheet have explanations in the code snippets -- in those cases, use your judgement about whether the explanation from the 2.x cheat sheet adds any value.
    • For example: drupal_region has good explanations in code snippet comments, there's no need to add the "Drupal Region" intro sentence from the 2.x cheat sheet β†’ .
  • Add "Accepted parameters" details for each feature that takes parameters.
  • Review current twig_tweak module code as you go along, to check for added/removed/changed parameters, etc. (i.e. make sure not to copy/paste parameter details from 2.x that are no longer valid in 3.x).
  • Reminder: Some features in twig_tweak 3.x were not present in twig_tweak 2.x!

[original note -- no longer applicable]
I propose either:

  1. Update the 3.x cheat sheet with comparable details; or,
  2. If the details of each feature are documented in code (docblocks or something), add links/references to those code explanations.

Remaining tasks

  1. Do it!
    • Posted on Slack > #contribute with an offer to mentor a newer contributor; if there are no takers, I'll gladly do it myself.
πŸ“Œ Task
Status

Needs work

Version

3.0

Component

Documentation

Created by

πŸ‡ΊπŸ‡ΈUnited States alison

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @alison
  • Status changed to Needs work over 1 year ago
  • πŸ‡·πŸ‡ΊRussia Chi

    Makes sense.

  • πŸ‡ΊπŸ‡ΈUnited States alison

    @Chi I'm thinking about your comment on πŸ’¬ Cheat sheet: format_size fliter needs explanation Fixed :

    I wonder if we put more details into the documentation would it be still correct to call it cheat sheet? AFK cheat sheet is a document for those who don't want to spend time on reading detailed documentation.

    I'm not sure where the line is between cheat sheet and detailed documentation. I am sure that I always liked using the 2.x cheat sheet :) But I'm only one person.

    I think the brief "what this thing does" sentences are appropriate for a cheat sheet, and approximately one code snippet example per thing (not a hard rule).

    Possible alternatives to adding parameter details to the 3.x cheat sheet:

    1. A second .md file with the same content as the cheat sheet, plus all the "accepted parameters" details.
    2. Add docblocks in the code -- I'm picturing the docblocks in Migrate Plus plugin source code (example: dom_str_replace), and link to those from the cheat sheet.
    3. ??

    Or, just flesh out the cheat sheet like the 2.x version :)

  • πŸ‡·πŸ‡ΊRussia Chi

    Let's try the "flesh out" approach.

  • πŸ‡ΊπŸ‡ΈUnited States alison

    Cool, thanks!

    I'm posting on Slack > #contribute with an offer to mentor anyone who wants help, and if there are no takers, I'll get into it myself.

  • πŸ‡ΊπŸ‡ΈUnited States alison

    (If you land on this issue organically and are a new contributor who'd like help working on this issue, you can find me on Drupal Slack > #contribute channel or DM me on Slack @alison.)

  • πŸ‡·πŸ‡ΊRussia Chi

    One more option is creating a detailed documentation on drupal.org site. Though, I am not sure if it would be better.
    Here are some explanations on why the cheat sheet was moved to git. #3174273: Migrate documentation from drupal.org to Git β†’

  • Assigned to alison
  • πŸ‡ΊπŸ‡ΈUnited States alison

    Mmmmmmmmm good point. I think I like it in the code, especially given how nice it is to look at + make use of code snippets on a platform like GitLab versus Drupal.org?? -- I can see the merit of it being on Drupal docs, but I'm leaning toward keeping it in the code repo, unless someone else speaks up.

    Assigning to myself for this week.

  • Open in Jenkins β†’ Open on Drupal.org β†’
    Core: 10.1.x + Environment: PHP 8.1 & MariaDB 10.3.22
    last update over 1 year ago
    11 pass
  • @alison opened merge request.
  • πŸ‡ΊπŸ‡ΈUnited States alison

    Progress made, not done yet. Few questions:

    Question 1:
    I ran into something I didn't expect -- inside the parameter description lists, I couldn't use ` marks to format text as "code" (regular code HTML tags worked, but not the backticks). In other words, the following does not work, in the cheat-sheet.md file:

      <dt>`$name`</dt>
    

    The following does work: (imagine no "spaces" in the code tag) (I got tired of fighting with this editor to output the literal code tag inside the code snippet)

      <dt>< code >$name< /code ></dt>
    

    Not the end of the world, but it made me wonder:
    Is there a different way I should add parameter details in markdown, rather than the description lists as they're done in Drupal docs?

    Question 2:
    File URI - this bit:

    Media fields are fully supported including OEmbed resources, in which case it will return the URL to the resource, ...

    It should be "it will return the URI of the resource", correct? -- just wanted to gut-check it before changing.

    Question 3:
    File URL - the last section of this one, under this text: "It is also possible to extract file URL directly from an entity."

    The code examples are:

    {{ image|file_url }}
    {{ media|file_url }}
    

    Is the first example, {{ image|file_url }}, meant to demonstrate getting a file URL from an image file entity, or from a media entity that's a "media type called image"?

    (Depending on your answer) I suggest adding a comment before each one, i.e.

    {# On an image file entity: #}
    {{ image|file_url }}
    {# On a media entity: #}
    {{ media|file_url }}
    

    Question 4:
    File URI and File URL: The 2.x cheat sheet section on File URI starts with "Returns a file URI string." -- thoughts/feelings on adding this to the 3.x version? (If yes, I'll also add to the File URL section, "Returns a file URL string.")

  • πŸ‡·πŸ‡ΊRussia Chi

    regular code HTML tags worked, but not the backticks

    That's by design. Backticks are part of markdown which is not processed withing HTML tags, at least by GitHub/GitLab markdown parsers. You may try <q/> or <var/> tags instead.

    It should be "it will return the URI of the resource"

    Yes

    {{ image|file_url }}

    It extracts the URL from image entity type.

    thoughts/feelings on adding this to the 3.x version?

    Makes sense.

Production build 0.71.5 2024