From ade244e5d0e423f2aea7eea2e9eec23627508aea Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Mon, 5 Aug 2013 00:14:09 +0200 Subject: [PATCH] Fix rendering of snapshot in the player --- .../javascripts/player/views/renderers/base.js.coffee | 10 +++++++--- app/helpers/asciicasts_helper.rb | 2 +- app/views/asciicasts/_player.html.erb | 2 +- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/assets/javascripts/player/views/renderers/base.js.coffee b/app/assets/javascripts/player/views/renderers/base.js.coffee index 59c8b58..4e7e6e4 100644 --- a/app/assets/javascripts/player/views/renderers/base.js.coffee +++ b/app/assets/javascripts/player/views/renderers/base.js.coffee @@ -64,10 +64,14 @@ class AsciiIo.Renderer.Base extends Backbone.View @fixTerminalElementSize() @fixPlayerContainerSize() - renderSnapshot: (text) -> + renderSnapshot: (snapshot) -> + return unless snapshot + i = 0 - for line in text.split("\n") - fragments = [[line, AsciiIo.Brush.default()]] + for line in snapshot + fragments = _(line).map (fragment) -> + fragment[1].bright = fragment[1].bold + [fragment[0], new AsciiIo.Brush(fragment[1])] @renderLine i, fragments, undefined i++ diff --git a/app/helpers/asciicasts_helper.rb b/app/helpers/asciicasts_helper.rb index 66dbfeb..7e53936 100644 --- a/app/helpers/asciicasts_helper.rb +++ b/app/helpers/asciicasts_helper.rb @@ -24,7 +24,7 @@ module AsciicastsHelper renderer_class: renderer_class, auto_play: options.key?(:auto_play) ? !!options[:auto_play] : false, hud: options.key?(:hud) ? !!options[:hud] : true, - snapshot: asciicast.snapshot + snapshot: asciicast.snapshot.to_json } end diff --git a/app/views/asciicasts/_player.html.erb b/app/views/asciicasts/_player.html.erb index 9ee9d43..c56a11c 100644 --- a/app/views/asciicasts/_player.html.erb +++ b/app/views/asciicasts/_player.html.erb @@ -13,7 +13,7 @@ rendererClass: <%= renderer_class.html_safe %>, autoPlay: <%= auto_play %>, hud: <%= hud %>, - snapshot: "<%= (j(snapshot)).html_safe %>" + snapshot: <%= snapshot.html_safe %> }); });