Use actual embed scripts on "embed example" page

element
Marcin Kulik 9 years ago
parent 646beacc03
commit d68c0f3282

@ -15,6 +15,25 @@ module AsciicastsHelper
content_tag(:style, css.html_safe) content_tag(:style, css.html_safe)
end end
def embed_script(asciicast)
src = asciicast_url(asciicast, format: :js)
id = "asciicast-#{asciicast.id}"
%(<script type="text/javascript" src="#{src}" id="#{id}" async></script>).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
%(<a href="#{url}" target="_blank"><img src="#{img_src}" #{width}/></a>)
end
def embed_markdown_link(asciicast)
img_src = asciicast_url(asciicast, format: :png)
url = asciicast_url(asciicast)
"[![asciicast](#{img_src})](#{url})"
end
private private
def translate_asset_paths(css) def translate_asset_paths(css)

@ -52,25 +52,6 @@ class AsciicastPagePresenter
asciicast.views_count asciicast.views_count
end end
def embed_script
src = routes.asciicast_url(asciicast, format: :js)
id = "asciicast-#{asciicast.id}"
%(<script type="text/javascript" src="#{src}" id="#{id}" async></script>)
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
%(<a href="#{url}" target="_blank"><img src="#{img_src}" #{width}/></a>)
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? def show_admin_dropdown?
[show_edit_link?, [show_edit_link?,
show_delete_link?, show_delete_link?,

@ -11,17 +11,17 @@
p p
span HTML: span HTML:
br 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 p
span Markdown: span Markdown:
br 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 h2 Player
p If you're embedding on your own page or on a site which permits script tags, p If you're embedding on your own page or on a site which permits script tags,
you can use the full player widget: you can use the full player widget:
p 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 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. p See the #{link_to 'embedding docs', docs_path(:embedding)} for additional options.

@ -5,12 +5,12 @@ p
Some pilots get picked and become television programs. Some don't, become Some pilots get picked and become television programs. Some don't, become
nothing. She starred in one of the ones that became nothing. 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 p
' And now again. There should be an embedded player below this paragraph. ' 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 p
' This is at the bottom of the page, below all players. ' This is at the bottom of the page, below all players.

@ -110,21 +110,6 @@ describe AsciicastPagePresenter do
it { should eq(5) } it { should eq(5) }
end 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) {
/^<script[^>]+#{src_regexp}[^>]+#{id_regexp}[^>]*><\/script>/
}
it 'is an async script tag including asciicast id' do
expect(subject).to match(script_regexp)
end
end
describe '#show_description?' do describe '#show_description?' do
subject { presenter.show_description? } subject { presenter.show_description? }

Loading…
Cancel
Save