From 51ee9f00fb4fff9d93763b195f8d392eb8e3097a Mon Sep 17 00:00:00 2001 From: Gregory Ballantine Date: Sat, 4 Mar 2023 11:14:54 -0500 Subject: [PATCH] Added script attribute for videos --- Gemfile | 2 ++ Gemfile.lock | 4 ++++ db/migrations/0004_add_script_attribute.rb | 11 +++++++++++ lib/models/video.rb | 6 ++++++ lib/routes/video.rb | 3 ++- views/video/view.erb | 10 ++++++++++ 6 files changed, 35 insertions(+), 1 deletion(-) create mode 100644 db/migrations/0004_add_script_attribute.rb diff --git a/Gemfile b/Gemfile index de37cd7..5f59b34 100644 --- a/Gemfile +++ b/Gemfile @@ -7,6 +7,8 @@ gem 'puma', '~> 6.1' gem 'sequel', '~> 5.66' gem 'sqlite3', '~> 1.6' +gem 'kramdown', '~> 2.4' + # Use rerun gem to auto-reload app gem 'rerun' diff --git a/Gemfile.lock b/Gemfile.lock index 4a4c7d9..83ed571 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -2,6 +2,8 @@ GEM remote: https://rubygems.org/ specs: ffi (1.15.5) + kramdown (2.4.0) + rexml listen (3.8.0) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) @@ -19,6 +21,7 @@ GEM ffi (~> 1.0) rerun (0.14.0) listen (~> 3.0) + rexml (3.2.5) ruby2_keywords (0.0.5) sequel (5.66.0) sinatra (3.0.5) @@ -39,6 +42,7 @@ PLATFORMS x86_64-linux DEPENDENCIES + kramdown (~> 2.4) puma (~> 6.1) rerun sequel (~> 5.66) diff --git a/db/migrations/0004_add_script_attribute.rb b/db/migrations/0004_add_script_attribute.rb new file mode 100644 index 0000000..56f9b07 --- /dev/null +++ b/db/migrations/0004_add_script_attribute.rb @@ -0,0 +1,11 @@ +Sequel.migration do + + up do + add_column(:videos, :script, String) + end + + down do + drop_column(:videos, :script) + end + +end diff --git a/lib/models/video.rb b/lib/models/video.rb index ee51556..32db117 100644 --- a/lib/models/video.rb +++ b/lib/models/video.rb @@ -1,5 +1,11 @@ +require 'kramdown' + class Video < Sequel::Model many_to_one :channel + def parseScript() + return Kramdown::Document.new(@values[:script]).to_html + end + end diff --git a/lib/routes/video.rb b/lib/routes/video.rb index ec639ca..41c2e00 100644 --- a/lib/routes/video.rb +++ b/lib/routes/video.rb @@ -31,7 +31,8 @@ namespace '/video' do name: params[:video_name], channel_id: params[:video_channel], directory_path: video_path, - description: params[:video_description] + description: params[:video_description], + script: "# Introduction\n\n# Body\n\n# Conclusions" ) Dir.mkdir(video_path) diff --git a/views/video/view.erb b/views/video/view.erb index 660fe1c..0b8ea5d 100644 --- a/views/video/view.erb +++ b/views/video/view.erb @@ -25,3 +25,13 @@ + +
+
+

Video script

+ +
+ + <%= video.parseScript() %> +
+