From 7cda16cef11e2519faa3fa33b5ec3d32e2de4faa Mon Sep 17 00:00:00 2001 From: Edward Loveall Date: Mon, 5 Jul 2021 15:36:38 -0400 Subject: [PATCH] Show the host for the iframe link Instead of showing only: Click to visit embedded content An embedded link now displays with the domain it's linking to: Embedded content at example.com This hopefully breaks up the links a bit so it'e easier to distinguish between a bunch of them in a row (as long as they are on different domains). --- spec/components/page_content_spec.cr | 8 +++++++- spec/models/nodes_spec.cr | 8 ++++++++ src/components/page_content.cr | 2 +- src/models/nodes.cr | 4 ++++ 4 files changed, 20 insertions(+), 2 deletions(-) diff --git a/spec/components/page_content_spec.cr b/spec/components/page_content_spec.cr index 983b263..f9c537f 100644 --- a/spec/components/page_content_spec.cr +++ b/spec/components/page_content_spec.cr @@ -156,7 +156,13 @@ describe PageContent do html = PageContent.new(page: page).render_to_string - html.should eq %(

Click to visit embedded content

) + html.should eq stripped_html <<-HTML +

+

+ Embedded content at example.com +
+

+ HTML end it "renders an ordered list" do diff --git a/spec/models/nodes_spec.cr b/spec/models/nodes_spec.cr index dc46144..f9a43ac 100644 --- a/spec/models/nodes_spec.cr +++ b/spec/models/nodes_spec.cr @@ -1,6 +1,14 @@ require "../spec_helper" module Nodes + describe IFrame do + it "returns embedded url with subdomains" do + iframe = IFrame.new(href: "https://dev.example.com/page") + + iframe.domain.should eq("dev.example.com") + end + end + describe Image do it "adjusts the width and height proportionally" do image = Image.new(src: "image.png", originalWidth: 1000, originalHeight: 603) diff --git a/src/components/page_content.cr b/src/components/page_content.cr index a4213a1..3019b6e 100644 --- a/src/components/page_content.cr +++ b/src/components/page_content.cr @@ -57,7 +57,7 @@ class PageContent < BaseComponent def render_child(child : IFrame) div class: "embedded" do a href: child.href do - text "Click to visit embedded content" + text "Embedded content at #{child.domain}" end end end diff --git a/src/models/nodes.cr b/src/models/nodes.cr index da55d66..9241e00 100644 --- a/src/models/nodes.cr +++ b/src/models/nodes.cr @@ -123,6 +123,10 @@ module Nodes def initialize(@href : String) end + def domain + URI.parse(href).host + end + def ==(other : IFrame) other.href == href end