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

Refactor common HTML methods into HtmlHelper #4174

Closed

Conversation

Br1ght0ne
Copy link
Contributor

@Br1ght0ne Br1ght0ne commented Oct 1, 2019

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Documentation Update

Description

  • prefix_all_images(html, width)
  • giphy_img?(source)
  • allowed_image_host?(src)

Offenders:

Added to documentation?

  • docs.dev.to
  • readme
  • no documentation needed

This change is Reviewable

@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Oct 1, 2019
- prefix_all_images(html, width)
- giphy_img?(source)
- allowed_image_host?(src)

Offenders:
- app/labor/markdown_parser.rb
- app/models/html_variant.rb
@Br1ght0ne Br1ght0ne force-pushed the prefix-all-images-html-helper branch from 18fcc96 to c244dbf Compare October 1, 2019 15:05
@Br1ght0ne Br1ght0ne changed the title Refactor prefix_all_images into HtmlHelper Refactor common HTML methods into HtmlHelper Oct 1, 2019
@rhymes
Copy link
Contributor

rhymes commented Oct 2, 2019

Hi @filalex77, thanks a lot for your contribution!

Although you managed to lower duplication stats I'm not completely comfortable with this refactoring because at the end of the day the result is a generic (the classic "utility" module hintend by its nameHtmlHelper). The fact that you have to call the main entry point do_prefix_all_images (and the fact that the other two functions that used to be private are not private anymore) is also a hint to this issue.

For experience, generic sounding modules will end up becoming a repository of methods that we don't know where to put instinctively.

I think you're on a good path with the idea but the naming and placing need to be improved. The prefix_all_images method hints to its purpose in the first line which is a comment that says wrap with cloudinary or.... You also left img_of_size duplicated.

The helpers situation right now in the code base is not great, theoretically helpers should help view rendering, but we also have decorators and actual view objects so I can see why that's not very clear.

In this case prefix_all_images is a method used in a model so it's a little bit weird if it gets refactor in a view helper.

I'm not 100% sure yet where and how this code should get refactored into and i'm open for a discussion, I'm not convinced this is the best way though.

@lightalloy what do you think?

@Br1ght0ne
Copy link
Contributor Author

@rhymes Thanks! My thoughts exactly.

I put it as a helper for now to make discussion easier, but I was also mixed about where it should belong. And thanks for img_of_size, didn't notice it.

I'll wait on more input.

@lightalloy
Copy link
Contributor

@rhymes, I agree, I'm not comfortable with the refactoring using helpers in this case too. I try to avoid adding more code to helpers unless it's a small change or a small method to use in the templates.
As one of the options to deduplicate I suggest:

  • change Markdown#prefix_all_images to be a class method (that would require changing allowed_image_host, giphy_img and img_of_size to be class methods as well)
  • change the code that uses this method accordingly
  • call Markdown.prefix_all_images in HtmlVariant

This is not an ideal solution, of course, just a step to deduplicate.
Another option is to move the prefix image logic into its own class. Ideally, I would put the markdown parsing logic in its own namespace but it requires more work, so I wouldn't do it in this pr.

Copy link
Contributor

@rhymes rhymes left a comment

Choose a reason for hiding this comment

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

I'm going to put this placeholder for other reviewers, check the discussion for details

@pr-triage pr-triage bot added PR: reviewed-changes-requested bot applied label for PR's where reviewer requests changes and removed PR: unreviewed bot applied label for PR's with no review labels Oct 7, 2019
@mstruve
Copy link
Contributor

mstruve commented May 7, 2020

Hey @filalex77!

Thanks so much for the PR. With that said, we are in the process of going through and cleaning up some of our PR history to help us better prioritize what we need to be focusing on. We have decided unfortunately not to move forward with this PR so I am going to close it.

Thanks so much for being an awesome contributor! Ping us anytime if you have questions!

@mstruve mstruve closed this May 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
PR: reviewed-changes-requested bot applied label for PR's where reviewer requests changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants