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)
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
def translate_asset_paths(css)

@ -52,25 +52,6 @@ class AsciicastPagePresenter
asciicast.views_count
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?
[show_edit_link?,
show_delete_link?,

@ -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.

@ -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.

@ -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) {
/^<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
subject { presenter.show_description? }

Loading…
Cancel
Save