diff --git a/app/helpers/asciicasts_helper.rb b/app/helpers/asciicasts_helper.rb
index a0ed867..1f2eca2 100644
--- a/app/helpers/asciicasts_helper.rb
+++ b/app/helpers/asciicasts_helper.rb
@@ -15,6 +15,25 @@ module AsciicastsHelper
content_tag(:style, css.html_safe)
end
+ def embed_script(asciicast)
+ src = asciicast_url(asciicast, format: :js)
+ id = "asciicast-#{asciicast.id}"
+ %().html_safe
+ end
+
+ def embed_html_link(asciicast)
+ img_src = asciicast_url(asciicast, format: :png)
+ url = asciicast_url(asciicast)
+ width = %{width="#{asciicast.image_width}"} if asciicast.image_width
+ %()
+ end
+
+ def embed_markdown_link(asciicast)
+ img_src = asciicast_url(asciicast, format: :png)
+ url = asciicast_url(asciicast)
+ "[![asciicast](#{img_src})](#{url})"
+ end
+
private
def translate_asset_paths(css)
diff --git a/app/presenters/asciicast_page_presenter.rb b/app/presenters/asciicast_page_presenter.rb
index 5831b37..24cf952 100644
--- a/app/presenters/asciicast_page_presenter.rb
+++ b/app/presenters/asciicast_page_presenter.rb
@@ -52,25 +52,6 @@ class AsciicastPagePresenter
asciicast.views_count
end
- def embed_script
- src = routes.asciicast_url(asciicast, format: :js)
- id = "asciicast-#{asciicast.id}"
- %()
- end
-
- def embed_html_link
- img_src = routes.asciicast_url(asciicast, format: :png)
- url = routes.asciicast_url(asciicast)
- width = %{width="#{asciicast.image_width}"} if asciicast.image_width
- %()
- end
-
- def embed_markdown_link
- img_src = routes.asciicast_url(asciicast, format: :png)
- url = routes.asciicast_url(asciicast)
- "[![asciicast](#{img_src})](#{url})"
- end
-
def show_admin_dropdown?
[show_edit_link?,
show_delete_link?,
diff --git a/app/views/asciicasts/_embed.html.slim b/app/views/asciicasts/_embed.html.slim
index 13d3c41..6d060aa 100644
--- a/app/views/asciicasts/_embed.html.slim
+++ b/app/views/asciicasts/_embed.html.slim
@@ -11,17 +11,17 @@
p
span HTML:
br
- input[type="text" value=page.embed_html_link data-behavior="auto-select" readonly]
+ input[type="text" value=embed_html_link(page.asciicast) data-behavior="auto-select" readonly]
p
span Markdown:
br
- input[type="text" value=page.embed_markdown_link data-behavior="auto-select" readonly]
+ input[type="text" value=embed_markdown_link(page.asciicast) data-behavior="auto-select" readonly]
h2 Player
p If you're embedding on your own page or on a site which permits script tags,
you can use the full player widget:
p
- input[type="text" value=page.embed_script data-behavior="auto-select" readonly]
+ input[type="text" value=embed_script(page.asciicast) data-behavior="auto-select" readonly]
p Paste the above script tag where you want the player to be displayed on your page.
p See the #{link_to 'embedding docs', docs_path(:embedding)} for additional options.
diff --git a/app/views/asciicasts/example.html.slim b/app/views/asciicasts/example.html.slim
index 3e6984e..281bb4c 100644
--- a/app/views/asciicasts/example.html.slim
+++ b/app/views/asciicasts/example.html.slim
@@ -5,12 +5,12 @@ p
Some pilots get picked and become television programs. Some don't, become
nothing. She starred in one of the ones that became nothing.
-script[type="text/javascript" src=asciicast_url(@asciicast, format: 'js') id="asciicast-#{@asciicast.to_param}" async data-speed="2"]
+= embed_script @asciicast
p
' And now again. There should be an embedded player below this paragraph.
-script[type="text/javascript" src=asciicast_url(@asciicast, format: 'js') id="asciicast-#{@asciicast.to_param}" async data-speed="2"]
+= embed_script @asciicast
p
' This is at the bottom of the page, below all players.
diff --git a/spec/presenters/asciicast_page_presenter_spec.rb b/spec/presenters/asciicast_page_presenter_spec.rb
index 1bded65..9015d34 100644
--- a/spec/presenters/asciicast_page_presenter_spec.rb
+++ b/spec/presenters/asciicast_page_presenter_spec.rb
@@ -110,21 +110,6 @@ describe AsciicastPagePresenter do
it { should eq(5) }
end
- describe '#embed_script' do
- subject { presenter.embed_script }
-
- let(:asciicast) { stub_model(Asciicast, id: 123).decorate }
- let(:src_regexp) { /src="[^"]+\b123\b[^"]*\.js"/ }
- let(:id_regexp) { /id="asciicast-123"/ }
- let(:script_regexp) {
- /^