Introduce proper player helper with proper template

openid
Marcin Kulik 12 years ago
parent 4fba36778e
commit 560ab8362a

@ -1,15 +1,10 @@
module AsciicastsHelper module AsciicastsHelper
def player_script_tag(asciicast, options = {}) def player(asciicast, options = {})
speed = (options[:speed] || 1).to_f
benchmark = !!params[:bm]
auto_play = options.key?(:auto_play) ? !!options[:auto_play] : false
hud = options.key?(:hud) ? !!options[:hud] : true
if params[:fallback] if params[:fallback]
klass = "AsciiIo.FallbackPlayer" player_class = "AsciiIo.FallbackPlayer"
else else
klass = "window.Worker && $.browser.webkit ? " \ player_class = "window.Worker && $.browser.webkit ? " \
"AsciiIo.Player : AsciiIo.FallbackPlayer" "AsciiIo.Player : AsciiIo.FallbackPlayer"
end end
@ -19,24 +14,17 @@ module AsciicastsHelper
renderer_class = "AsciiIo.Renderer.Pre" renderer_class = "AsciiIo.Renderer.Pre"
end end
return <<EOS.html_safe render :partial => 'asciicasts/player', :locals => {
<script> player_class: player_class,
$(function() { cols: asciicast.terminal_columns,
var playerClass = #{klass}; lines: asciicast.terminal_lines,
window.player = new playerClass({ speed: (options[:speed] || params[:speed] || 1).to_f,
el: $('.player'), benchmark: !!params[:bm],
cols: #{asciicast.terminal_columns}, asciicast_id: asciicast.id,
lines: #{asciicast.terminal_lines}, renderer_class: renderer_class,
speed: #{speed}, auto_play: options.key?(:auto_play) ? !!options[:auto_play] : false,
benchmark: #{benchmark}, hud: options.key?(:hud) ? !!options[:hud] : true,
model: new AsciiIo.Asciicast({ id: #{asciicast.id} }), snapshot: asciicast.snapshot
rendererClass: #{renderer_class}, }
autoPlay: #{auto_play},
hud: #{hud},
snapshot: "#{j asciicast.snapshot.to_s}"
});
});
</script>
EOS
end end
end end

@ -1,5 +1,18 @@
<div class="player"></div> <div class="player"></div>
<%= player_script_tag(asciicast, <script>
:speed => local_assigns[:speed], $(function() {
:hud => local_assigns[:hud] var playerClass = <%= player_class.html_safe %>;
) %> window.player = new playerClass({
el: $('.player'),
cols: <%= cols %>,
lines: <%= lines %>,
speed: <%= speed %>,
benchmark: <%= benchmark %>,
model: new AsciiIo.Asciicast({ id: <%= asciicast_id %> }),
rendererClass: <%= renderer_class.html_safe %>,
autoPlay: <%= auto_play %>,
hud: <%= hud %>,
snapshot: "<%= j snapshot %>"
});
});
</script>

@ -1,11 +1,6 @@
<section id="presentation" class="feature"> <section id="presentation" class="feature">
<div class="asciicast-wrapper"> <div class="asciicast-wrapper">
<%= render :partial => 'asciicasts/player', :locals => { <%= player @asciicast %>
:asciicast => @asciicast,
:speed => params[:speed],
:hud => true
} %>
</div> </div>
</section> </section>

@ -18,11 +18,7 @@
<div class="secondary_info"> <div class="secondary_info">
<% if @asciicast -%> <% if @asciicast -%>
<%= render :partial => 'asciicasts/player', :locals => { <%= player @asciicast, :speed => 2.0, :hud => false %>
:asciicast => @asciicast,
:speed => 2.0,
:hud => false
} %>
<% end -%> <% end -%>
</div> </div>
</div> </div>

Loading…
Cancel
Save