diff --git a/Gemfile b/Gemfile
index f0bf84f..74d8dc1 100644
--- a/Gemfile
+++ b/Gemfile
@@ -15,3 +15,7 @@ end
gem "faraday", "~> 2.12"
gem "concurrent-ruby", "~> 1.3"
+
+gem "activesupport", "~> 8.0"
+
+gem "redcarpet", "~> 3.6"
diff --git a/Gemfile.lock b/Gemfile.lock
index b9930ea..d7eb086 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -1,9 +1,25 @@
GEM
remote: https://rubygems.org/
specs:
+ activesupport (8.0.1)
+ base64
+ benchmark (>= 0.3)
+ bigdecimal
+ concurrent-ruby (~> 1.0, >= 1.3.1)
+ connection_pool (>= 2.2.5)
+ drb
+ i18n (>= 1.6, < 2)
+ logger (>= 1.4.2)
+ minitest (>= 5.1)
+ securerandom (>= 0.3)
+ tzinfo (~> 2.0, >= 2.0.5)
+ uri (>= 0.13.1)
base64 (0.2.0)
+ benchmark (0.4.0)
+ bigdecimal (3.1.9)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
+ drb (2.2.1)
faraday (2.12.1)
faraday-net_http (>= 2.0, < 3.5)
json
@@ -13,8 +29,11 @@ GEM
faraday-net_http_persistent (2.3.0)
faraday (~> 2.5)
net-http-persistent (>= 4.0.4, < 5)
+ i18n (1.14.6)
+ concurrent-ruby (~> 1.0)
json (2.9.0)
logger (1.6.2)
+ minitest (5.25.4)
multi_json (1.15.0)
mustermann (3.0.3)
ruby2_keywords (~> 0.0.1)
@@ -38,7 +57,9 @@ GEM
rack (>= 3.0.0)
rackup (2.2.1)
rack (>= 3)
+ redcarpet (3.6.0)
ruby2_keywords (0.0.5)
+ securerandom (0.4.1)
sinatra (4.1.1)
logger (>= 1.6.0)
mustermann (~> 3.0)
@@ -53,6 +74,8 @@ GEM
sinatra (= 4.1.1)
tilt (~> 2.0)
tilt (2.4.0)
+ tzinfo (2.0.6)
+ concurrent-ruby (~> 1.0)
uri (1.0.2)
PLATFORMS
@@ -61,11 +84,13 @@ PLATFORMS
x64-mingw-ucrt
DEPENDENCIES
+ activesupport (~> 8.0)
concurrent-ruby (~> 1.3)
faraday (~> 2.12)
norairrecord (~> 0.1.4)
puma (~> 6.5)
rackup (~> 2.2)
+ redcarpet (~> 3.6)
sinatra (~> 4.1)
sinatra-contrib (~> 4.1)
diff --git a/app/helpers.rb b/app/helpers.rb
new file mode 100644
index 0000000..a06d365
--- /dev/null
+++ b/app/helpers.rb
@@ -0,0 +1,21 @@
+require 'active_support/number_helper'
+require 'redcarpet'
+
+module Sinatra
+ module RenderMarkdownHelper
+ def md(markdown)
+ (@renderer ||= Redcarpet::Markdown.new(Redcarpet::Render::HTML, autolink: true, tables: true)).render(markdown)
+ end
+ end
+ module SchmoneyHelper
+ def cashify(amount)
+ ActiveSupport::NumberHelper.number_to_currency amount
+ end
+ end
+ module IIHelper
+ def render_ii(shipment, field, emoji, description, representation=nil)
+ return unless shipment[field]
+ "
#{emoji}: #{representation&.call(shipment) || shipment[field]}"
+ end
+ end
+end
\ No newline at end of file
diff --git a/app/main.rb b/app/main.rb
index 2448ec2..b640398 100644
--- a/app/main.rb
+++ b/app/main.rb
@@ -2,7 +2,10 @@ require 'sinatra/base'
require "sinatra/content_for"
require "sinatra/cookies"
require 'securerandom'
+require 'active_support'
+require 'active_support/core_ext/object/blank'
+require_relative './helpers'
require_relative './awawawa'
require_relative './signage'
@@ -13,6 +16,9 @@ end
class ShipmentViewer < Sinatra::Base
helpers Sinatra::ContentFor
helpers Sinatra::Cookies
+ helpers Sinatra::RenderMarkdownHelper
+ helpers Sinatra::SchmoneyHelper
+ helpers Sinatra::IIHelper
set :host_authorization, permitted_hosts: []
diff --git a/app/shipment_types.rb b/app/shipment_types.rb
index 0864ddb..eadaea6 100644
--- a/app/shipment_types.rb
+++ b/app/shipment_types.rb
@@ -93,6 +93,10 @@ class Shipment < Norairrecord::Table
source_record: source_url
}.compact.to_json
end
+
+ def internal_info_partial
+ nil
+ end
end
class WarehouseShipment < Shipment
@@ -170,6 +174,10 @@ class WarehouseShipment < Shipment
"error parsing JSON for #{source_id}!"
end
end
+
+ def internal_info_partial
+ :_warehouse_internal_info
+ end
end
class HighSeasShipment < Shipment
@@ -240,6 +248,10 @@ class HighSeasShipment < Shipment
def shipped?
fields['status'] == 'fulfilled'
end
+
+ def internal_info_partial
+ :_highseas_internal_info
+ end
end
class HSMinutemanShipment < HighSeasShipment
diff --git a/app/views/_highseas_internal_info.erb b/app/views/_highseas_internal_info.erb
new file mode 100644
index 0000000..4635c8b
--- /dev/null
+++ b/app/views/_highseas_internal_info.erb
@@ -0,0 +1 @@
+<%= render_ii(shipment, 'dollar_cost', 'đź’¸', 'cost to fulfill', -> (s) { cashify s['dollar_cost'] }) %>
\ No newline at end of file
diff --git a/app/views/_shipment.erb b/app/views/_shipment.erb
index 72cccc9..bad9009 100644
--- a/app/views/_shipment.erb
+++ b/app/views/_shipment.erb
@@ -29,9 +29,16 @@
<% end %>
<% end %>
-
đź“… Created on <%= shipment.date[..9] %>
<% if @show_ids %>
đź‘€ Airtable: <%= external_link(shipment.source_id, shipment.source_url) %>
<% end %>
+
đź“… Created on <%= shipment.date[..9] %>
+ <% if @internal and shipment.internal_info_partial %>
+
+