From 442181efe9768980280103d6f8469f926f452963 Mon Sep 17 00:00:00 2001 From: Marcin Kulik Date: Mon, 11 Jan 2016 16:14:46 +0100 Subject: [PATCH] Use actual asciicast width and height in example player usage --- app/assets/stylesheets/asciicasts.sass | 4 ++++ app/models/asciicast.rb | 8 ++++++++ app/presenters/asciicast_page_presenter.rb | 2 +- app/serializers/asciicast_serializer.rb | 4 +--- app/views/asciicasts/_download.html.erb | 2 +- 5 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/assets/stylesheets/asciicasts.sass b/app/assets/stylesheets/asciicasts.sass index 0ca7097..c0bb45e 100644 --- a/app/assets/stylesheets/asciicasts.sass +++ b/app/assets/stylesheets/asciicasts.sass @@ -106,6 +106,10 @@ margin-bottom: 5px padding: 6px + pre + word-wrap: normal + overflow: auto + .special-label font-size: 12px background-color: rgb(255, 239, 198) diff --git a/app/models/asciicast.rb b/app/models/asciicast.rb index cf3d7d4..b0841a3 100644 --- a/app/models/asciicast.rb +++ b/app/models/asciicast.rb @@ -65,6 +65,14 @@ class Asciicast < ActiveRecord::Base collection end + def width + terminal_columns + end + + def height + terminal_lines + end + def title=(value) value ? super(value.strip[0...255]) : super end diff --git a/app/presenters/asciicast_page_presenter.rb b/app/presenters/asciicast_page_presenter.rb index 8811734..541bac8 100644 --- a/app/presenters/asciicast_page_presenter.rb +++ b/app/presenters/asciicast_page_presenter.rb @@ -4,7 +4,7 @@ class AsciicastPagePresenter attr_reader :routes, :asciicast, :current_user, :policy, :playback_options - delegate :download_filename, to: :asciicast, prefix: true + delegate :download_filename, :width, :height, to: :asciicast, prefix: true def self.build(routes, asciicast, current_user, playback_options) decorated_asciicast = asciicast.decorate diff --git a/app/serializers/asciicast_serializer.rb b/app/serializers/asciicast_serializer.rb index b263ef2..67d9e8f 100644 --- a/app/serializers/asciicast_serializer.rb +++ b/app/serializers/asciicast_serializer.rb @@ -1,9 +1,7 @@ class AsciicastSerializer < ActiveModel::Serializer self.root = false - attributes :id, :url, :snapshot - attribute :terminal_columns, key: :width - attribute :terminal_lines, key: :height + attributes :id, :url, :snapshot, :width, :height def id object.to_param diff --git a/app/views/asciicasts/_download.html.erb b/app/views/asciicasts/_download.html.erb index d67da11..d510b46 100644 --- a/app/views/asciicasts/_download.html.erb +++ b/app/views/asciicasts/_download.html.erb @@ -45,7 +45,7 @@ <body> <div id="player-container"></div> <script> - asciinema_player.core.CreatePlayer('player-container', '/<%= page.asciicast_download_filename %>'); + asciinema_player.core.CreatePlayer('player-container', '/<%= page.asciicast_download_filename %>', { width: <%= page.asciicast_width %>, height: <%= page.asciicast_height %> }); </script> </body> </html>