From 23fd16850ab918936e234754a9511805e7c6a24d Mon Sep 17 00:00:00 2001 From: Arpit Jalan Date: Fri, 1 May 2015 18:34:45 +0530 Subject: [PATCH] FIX: include youtube link in embedded comments --- app/controllers/embed_controller.rb | 2 +- app/helpers/embed_helper.rb | 11 ++++++++++- app/views/embed/comments.html.erb | 3 +-- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/app/controllers/embed_controller.rb b/app/controllers/embed_controller.rb index af3ef591c..4eaaa4c37 100644 --- a/app/controllers/embed_controller.rb +++ b/app/controllers/embed_controller.rb @@ -41,7 +41,7 @@ class EmbedController < ApplicationController topic_embeds = TopicEmbed.where(embed_url: urls).includes(:topic).references(:topic) topic_embeds.each do |te| - url = te.embed_url + url = te.embed_url url = "#{url}#discourse-comments" unless params[:embed_url].include?(url) by_url[url] = I18n.t('embed.replies', count: te.topic.posts_count - 1) end diff --git a/app/helpers/embed_helper.rb b/app/helpers/embed_helper.rb index 908a465f6..c7cbe524f 100644 --- a/app/helpers/embed_helper.rb +++ b/app/helpers/embed_helper.rb @@ -14,5 +14,14 @@ module EmbedHelper end end + def get_html(cooked) + fragment = Nokogiri::HTML.fragment(cooked) + # convert lazyYT div to link + fragment.css('div.lazyYT').each do |yt_div| + youtube_id = yt_div["data-youtube-id"] + youtube_link = "https://www.youtube.com/watch?v=#{youtube_id}" + yt_div.replace "

#{youtube_link}

" + end + raw fragment + end end - diff --git a/app/views/embed/comments.html.erb b/app/views/embed/comments.html.erb index 5428fd99c..f381e965a 100644 --- a/app/views/embed/comments.html.erb +++ b/app/views/embed/comments.html.erb @@ -25,7 +25,7 @@ <%= post.user.title %> <%- end %> - <%= raw post.cooked %> + <%= get_html(post.cooked) %> <%- if post.reply_count > 0 %> <%- if post.reply_count == 1 %> @@ -51,4 +51,3 @@ <% end %> <% end %> -