Skip to content

Conversation

@klnsv
Copy link
Contributor

@klnsv klnsv commented Nov 26, 2025

This PR is another attempt to refactor the function render_html_list

Current capabilities:

  1. Removes the usage of skip_wrapper
  2. Performs the same function as the previous version of this function

Please ignore the tags. I just used that for debugging. If it is okay, I will commit to this PR again with all those removed, if not, it will be helpful to debug.

@klnsv
Copy link
Contributor Author

klnsv commented Nov 28, 2025

Hopefully this commit resolves the previous errors encountered. I couldn't run that blog-rack project as it required some config.ru but I think this will render the page with no issues

@klnsv
Copy link
Contributor Author

klnsv commented Nov 28, 2025

image

Notice how defaults.title and defaults.body render nothing?

I tried logging it to the terminal and got empty strings
image

Not sure if it what you intended to do. maybe something is set like string | nil This occurs in the else block

Is it a bug or a feature?

@klnsv
Copy link
Contributor Author

klnsv commented Nov 28, 2025

Other than that, everything seems fine. Hopefully, this refactor doesn't confuse anybody. Please look at the latest commit. I have removed the comments and debug lines and is ready to merge.

@azimux
Copy link
Contributor

azimux commented Nov 29, 2025

Seems like that nil default or whatever you found is a bug but an existing bug. I think it's that we render <li>#{data}</li> instead of <li>#{data.inspect}</li>. It actually kind of reminds me of a bug you fixed in the sh-cli-connector.

else
html << "<ul>"
html << "<li>#{data}</li>"
html << "</ul>"
Copy link
Contributor

Choose a reason for hiding this comment

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

ah it kind of surprises me that we render the ul/li stuff here. But seems like it gives the right result in the browser.

Copy link
Contributor

Choose a reason for hiding this comment

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

So thinking about this... I think we should not render ul/li here. It's just a datapoint. If we want it in a ul/li it would be the responsibility of its parent. Basically wherever we are rendering a collection we would use ul/li but wherever it's an atom we'd just render the atom (with whatever additional formatting we might want but not a single-item unordered list.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Idk maybe I'm wrong. So, the parent datatype sometimes has a collection, which are filled with elements of the same datatype as the parent. So, it fails in that case without skip wrapper

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since you said the tree can be arbitrary, I thought this would be safe but also, I tried testing out what you said before making this decision and it actually required skip_wrapper. For example, there are some cases where the ::Hash has ::Hash elements as its child and it fails then. That is why I refactored this way.


def render_html_list(data, skip_wrapper: false)
def render_html_list(data)
html = ""
Copy link
Contributor

Choose a reason for hiding this comment

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

not related to this PR but we could change this to html = +"" to make this compatible with upcoming frozen string changes in Ruby

html << "</ul>" unless skip_wrapper
html << "</ul>"
when ::Array
html << "<ul>" unless skip_wrapper
Copy link
Contributor

Choose a reason for hiding this comment

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

I think that because we are rendering a collection here, we need the <ul> and a <li> for each child.

html << "<li>"
html << foobara_reference_link(data)
html << "</li>"
html << "</ul>"
Copy link
Contributor

Choose a reason for hiding this comment

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

Since these are not collections, I think we should not render <ul> here. Maybe this is only give the right result since ::Array is missing its <ul>s and <li>s.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, yeah this might work only for ::Array I think. I added it like this for the sake of uniformity. I will commit it after testing. It will fail if we add <ul> in ::Array and the elements are something like ::Hash or Manifest::TypeDeclaration

@klnsv
Copy link
Contributor Author

klnsv commented Nov 29, 2025

Actually, the outputs you see in the terminal pic is the inspect thing.

@azimux
Copy link
Contributor

azimux commented Nov 29, 2025

Going to merge this because it's an improvement over what's in main and it works. Better to attempt further improvements from main I think in other PRs. Thanks again!

@azimux azimux merged commit f8a8677 into foobara:main Nov 29, 2025
1 check passed
@azimux azimux mentioned this pull request Nov 29, 2025
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.

2 participants