From cef3ca28922727a078ab657b72a08dd2e199adfd Mon Sep 17 00:00:00 2001 From: Astoria Date: Fri, 28 Oct 2022 13:25:16 -0500 Subject: [PATCH] Add BBCode support --- v5.rb | 1 + views/blogpage.erb | 13 +++++++++++++ views/blogwindow.erb | 4 +++- views/index.erb | 6 ++---- 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/v5.rb b/v5.rb index 38a77d0..6bea88c 100755 --- a/v5.rb +++ b/v5.rb @@ -2,6 +2,7 @@ require 'sinatra' require 'erb' require 'date' +require 'ruby-bbcode' class Page @path diff --git a/views/blogpage.erb b/views/blogpage.erb index f8bc4f4..2140d54 100644 --- a/views/blogpage.erb +++ b/views/blogpage.erb @@ -14,6 +14,7 @@ <%= erb :asidemenu %>
<%= erb :blogbar, locals: {title: title} %> + <% addtags = { :rbe => { html_open: "\<%=", html_close: "%\>" }, :rb => { html_open: "\<%", html_close: "%\>" } } %>
<% if File.exist?("." + request.path_info) && request.path_info.end_with?(".erb") %> <%= ERB.new(File.read("." + request.path_info)).result(binding) %> @@ -23,6 +24,10 @@ <%= markdown(File.read("." + request.path_info)) %> <% elsif File.exist?("." + request.path_info + ".md") %> <%= markdown(File.read("." + request.path_info + ".md")) %> + <% elsif File.exist?("." + request.path_info) && request.path_info.end_with?(".bb") %> + <%= ERB.new(File.read("." + request.path_info).gsub("\n[rb]", '[rb]').bbcode_to_html(false, addtags) + "
").result(binding) %> + <% elsif File.exist?("." + request.path_info + ".bb") %> + <%= ERB.new(File.read("." + request.path_info + ".bb").gsub("\n[rb]", '[rb]').bbcode_to_html(false, addtags)+ "
").result(binding) %> <% end %> <% if File.exist?("." + request.path_info + ".meta") %>
diff --git a/views/blogwindow.erb b/views/blogwindow.erb index 2d1c65a..29d66e3 100644 --- a/views/blogwindow.erb +++ b/views/blogwindow.erb @@ -3,8 +3,10 @@ <%= markdown(File.read(file)) %> <% elsif file.end_with?(".erb") %> <%= ERB.new(File.read(file)).result(binding) %> + <% elsif file.end_with?(".bb") %> + <% addtags = { :rbe => { html_open: "\<%=", html_close: "%\>" }, :rb => { html_open: "\<%", html_close: "%\>" } } %> + <%= ERB.new(File.read(file).gsub("\n[rb]", '[rb]').bbcode_to_html(false, addtags) + "
").result(binding) %> <% end %> - <%= date %> diff --git a/views/index.erb b/views/index.erb index 87b4b45..7241fca 100644 --- a/views/index.erb +++ b/views/index.erb @@ -4,7 +4,7 @@ <% contents = Dir.children("./" + folder).grep(/#{searchquery}/) %> <% if !contents.empty? %> <% contents.each do |content| %> - <% if content.end_with?(".erb") || content.end_with?(".md") %> + <% if content.end_with?(".erb") || content.end_with?(".md") || content.end_with?(".bb") %> <% if File.exists?("./" + folder + "/" + content + ".meta") %> <% newPage = Page.new(folder + "/" + content, DateTime.parse(File.read("./" + folder + "/" + content + ".meta"), "%Y.%m.%d")) %> <% else %> @@ -24,9 +24,7 @@ <% contentsArray.sort_by! { |page| page.getdate } %> <% contentsArray.reverse.each do |content| %> - <% if content.getpath.end_with?(".erb") %> + <% if content.getpath.end_with?(".erb") || content.getpath.end_with?(".md") || content.getpath.end_with?(".bb") %> <%= erb :blogwindow, locals: {file: "./" + content.getpath, date: content.getdate.strftime("%Y.%m.%d")} %> - <% elsif content.getpath.end_with?(".md") %> - <%= erb :blogwindow, locals: {file: "./" + content.getpath, date: content.getdate.strftime("%Y.%m.%d")} %> <% end %> <% end %> \ No newline at end of file