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

Implement Reddit liquid tag #4221

Closed
wants to merge 12 commits into from
Closed

Implement Reddit liquid tag #4221

wants to merge 12 commits into from

Conversation

cesc1989
Copy link
Contributor

@cesc1989 cesc1989 commented Oct 3, 2019

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

  • Feature

Description

Implement Liquid tag for reddit content.

It takes the post URL and renders a block of content based on the JSON response of requesting that URL and appending .json:

url =  https://www.reddit.com/r/IAmA/comments/afvl2w/im_scott_from_scotts_cheap_flights_my_profession

json_url =  https://www.reddit.com/r/IAmA/comments/afvl2w/im_scott_from_scotts_cheap_flights_my_profession.json

I tried to emulate the same way the Medium liquid tag was coded and that's why the request is made and handled in a different class(RedditJsonFromUrlService)

I'm still pending to add tests and improve the styling of the reddit content.

Related Tickets & Documents

This PR resolves #1536

Added to documentation?

  • docs.dev.to

What gif best describes this PR or how it makes you feel?

grrrreat

@CLAassistant
Copy link

CLAassistant commented Oct 3, 2019

CLA assistant check
All committers have signed the CLA.

@benhalpern
Copy link
Contributor

Looking good so far, thanks for this

@cesc1989
Copy link
Contributor Author

Hi @benhalpern 👋

I'm close to finish this but got a couple of questions. Hope this is the place to ask.

  1. When rendering reddit content that has image, this happens:

01-reddit-image

Don't know where in the codebase happens but seems the image URL is wrapped to make it lazy load. I'm not very sure how to proceed fix/proceed/handle this situation and would appreciate your input.

  1. Reddit content again but with text only:

02-reddit-text

I tried to parse the markdown content but couldn't successfully do it. Again, what would be a way to solve this _in_ Dev?
  1. Final question is this in the PR checks:

codeclimate/diff-coverage — 17% (50% threshold)

Don't understand what's going on there. I installed the codeclimate firefox plugin but can't see the diff.

I appreciate your time 😄

@benhalpern
Copy link
Contributor

@cesc1989 I believe it is likely the images are only failing locally because you don't have Cloudinary fully set up. We can confirm this, but that is my suspicion right now.

With regards to the text/markdown/html, we should be able to parse as markdown in our normal parser.

CodeClimate is down because it needs tests. Check out spec/liquid_tags and add tests similar to what's in there for similar tags.

@maestromac @Zhao-Andy if either of you want to add some guidance or suggestions here when you could, that would be great.

@maestromac
Copy link
Contributor

Hello @cesc1989

  1. We lazy load all images and defer the image to Cloudinary. I've tested your branch locally and it seems to be loading the image. Is it not loading at all on your end?

  2. We use Redcarpet and you can try to play around with it to see how it renders your Reddit's content (ie markdown = Redcarpet::Markdown.new(renderer, extensions = {}) or take a look to see how we use it here). If that doesn't work and complicate things, would it be possible to just render the plain text without the markdown?

  3. Seems like diff-coverage is no longer the issue here

@benhalpern
Copy link
Contributor

We lazy load all images and defer the image to Cloudinary. I've tested your branch locally and it seems to be loading the image. Is it not loading at all on your end?

@maestromac I believe this is because the cloudinary key is set to Optional in their env. So it probably works for you and not them if they don't have it set properly. I'd say this part of the PR should be good to go.

We mostly just need to proper markdown parsing now.

@cesc1989 cesc1989 changed the title WIP Implement Reddit liquid tag Implement Reddit liquid tag Nov 6, 2019
@pr-triage pr-triage bot added the PR: unreviewed bot applied label for PR's with no review label Nov 6, 2019
@cesc1989
Copy link
Contributor Author

cesc1989 commented Nov 6, 2019

Thanks a bunch! @benhalpern @maestromac

I finally could render the text content properly 😄 I think the PR is ready to be reviewed/merged. Let me know if there's anything to change/improve.

@Zhao-Andy
Copy link
Contributor

Hey @cesc1989 sorry for the late review! I'm reviewing it now and noticed the icon could be more true to Reddit's icon. Do you mind if I push up a new SVG file?

Have some additional comments to make, but overall looks great!

Copy link
Contributor

@Zhao-Andy Zhao-Andy left a comment

Choose a reason for hiding this comment

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

Left some comments. Great PR so far!

app/views/liquids/_reddit.html.erb Outdated Show resolved Hide resolved
app/views/liquids/_reddit.html.erb Outdated Show resolved Hide resolved
docs/frontend/liquid-tags.md Show resolved Hide resolved
spec/liquid_tags/reddit_tag_spec.rb Outdated Show resolved Hide resolved
app/services/reddit_json_from_url_service.rb Outdated Show resolved Hide resolved
app/liquid_tags/reddit_tag.rb Outdated Show resolved Hide resolved
app/assets/images/reddit-icon.svg Outdated Show resolved Hide resolved
@pr-triage pr-triage bot added PR: reviewed-changes-requested bot applied label for PR's where reviewer requests changes PR: unreviewed bot applied label for PR's with no review and removed PR: unreviewed bot applied label for PR's with no review PR: reviewed-changes-requested bot applied label for PR's where reviewer requests changes labels Nov 14, 2019
@cesc1989
Copy link
Contributor Author

@Zhao-Andy just submitted the suggested changes 😄

The reddit icon does look nicer. Thanks!

@cesc1989
Copy link
Contributor Author

BTW, @Zhao-Andy I think the code in app/views/pages/_editor_guide_text.html.erb would benefit from using more partials(maybe per tag). I freaked out when saw all that HTML with no order whatsoever 😅

How do you handle this kind of refactors?

I decided a UI similar to the Stack Exchange tag would be better.

Now the Reddit tag looks a bit similar.
Also emphasize notice about compilation of article when using any
liquid tag
Sometimes the attribute `post_hint` might be null and neither condition
would apply.
@cesc1989 cesc1989 requested review from jacobherrington and a team as code owners March 18, 2020 19:51
@maestromac maestromac requested review from Zhao-Andy and removed request for jacobherrington and a team March 18, 2020 19:51
Copy link
Contributor

@maestromac maestromac left a comment

Choose a reason for hiding this comment

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

Sorry for the delay. Tested locally. Works great!

@pr-triage pr-triage bot added PR: reviewed-approved bot applied label for PR's where reviewer approves changes and removed PR: unreviewed bot applied label for PR's with no review labels Mar 18, 2020
Copy link
Contributor

@maestromac maestromac left a comment

Choose a reason for hiding this comment

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

Actually the size of the VCR is concerning. I need to think about a better way to test this without relying on VCR.

@pr-triage pr-triage bot added PR: reviewed-changes-requested bot applied label for PR's where reviewer requests changes and removed PR: reviewed-approved bot applied label for PR's where reviewer approves changes labels Mar 18, 2020
@cesc1989
Copy link
Contributor Author

cesc1989 commented Mar 18, 2020

Actually the size of the VCR is concerning. I need to think about a better way to test this without relying on VCR.

@maestromac thanks for reviewing!

I'll take a look at it and see how could it be improved.

Copy link
Contributor

@Zhao-Andy Zhao-Andy left a comment

Choose a reason for hiding this comment

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

Overall looks good! One improvement I'd like to see i having more useful error handling. For example, if I use an invalid link here:

{% reddit https://www.reddit.com/r/aww/comments/ag3s4 %}

# errors out:
"base:  no implicit conversion of String into Integer"

Instead of a run time error, I think we'd want to raise an error like this:
https://github.com/thepracticaldev/dev.to/blob/1481faf34d5a98b259c677aa8e058e14902882ca/app/liquid_tags/gist_tag.rb#L36-L39

Sorry for the delay on all this! I'll keep a better eye on this so we can get this released sooner rather than later. :)

@mstruve
Copy link
Contributor

mstruve commented May 7, 2020

Hey @cesc1989!

Thank you so much for the PR to add this incredible feature! 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. Since this PR has not been active for a while and has some conflicts I am going to close it for now. If you would still like to get this merged please feel free to resolve the conflicts, make the requested changes, and then open the PR back up. We would be more than happy to help push this through if you would like!

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

@mstruve mstruve closed this May 7, 2020
@cesc1989
Copy link
Contributor Author

Thank you @mstruve for the heads up.

I have this inline to work but had it completely forgotten. Soon I'll be tackling the conflicts and the last reviews 🤠 👍

@cesc1989
Copy link
Contributor Author

cesc1989 commented May 27, 2020

Hi @mstruve @Zhao-Andy

I just pushed (to my fork branch) solved conflicts and the two feedback items provided. Do I have to open another PR?

@rhymes
Copy link
Contributor

rhymes commented May 28, 2020

Hi @cesc1989, I think so, as GitHub won't let me reopen this. Make sure you're up to date with master when you create it

@cesc1989 cesc1989 mentioned this pull request May 28, 2020
3 tasks
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.

Reddit Liquid Tag
7 participants