summaryrefslogtreecommitdiff
path: root/new/splash/lib
diff options
context:
space:
mode:
Diffstat (limited to 'new/splash/lib')
-rw-r--r--new/splash/lib/splash.rb2
-rw-r--r--new/splash/lib/splash/batch_builder.rb25
-rw-r--r--new/splash/lib/splash/builder.rb10
-rw-r--r--new/splash/lib/splash/pages_db_manager.rb9
-rw-r--r--new/splash/lib/splash/processors/splash_processor.rb53
5 files changed, 99 insertions, 0 deletions
diff --git a/new/splash/lib/splash.rb b/new/splash/lib/splash.rb
index 68674f9..5a29956 100644
--- a/new/splash/lib/splash.rb
+++ b/new/splash/lib/splash.rb
@@ -4,6 +4,8 @@ require_relative '../../lib/crys'
require_relative 'splash/server'
require_relative 'splash/builder'
+require_relative 'splash/batch_builder'
+require_relative 'splash/pages_db_manager'
module Crys
module Splash
diff --git a/new/splash/lib/splash/batch_builder.rb b/new/splash/lib/splash/batch_builder.rb
new file mode 100644
index 0000000..1502a80
--- /dev/null
+++ b/new/splash/lib/splash/batch_builder.rb
@@ -0,0 +1,25 @@
+module Crys
+ module Splash
+ class BatchBuilder < Crys::BatchBuilder
+ def db_path
+ "#{File.dirname(File.dirname(File.dirname(__FILE__)))}/db/pages.yaml"
+ end
+
+ def output_dir
+ "#{File.dirname(File.dirname(File.dirname(__FILE__)))}/output"
+ end
+
+ def image_dir
+ "#{File.dirname(File.dirname(File.dirname(File.expand_path(__FILE__))))}/assets/images"
+ end
+
+ def db
+ Crys::Splash::PagesDbManager.new
+ end
+
+ def builder_class
+ Crys::Splash::Builder
+ end
+ end
+ end
+end
diff --git a/new/splash/lib/splash/builder.rb b/new/splash/lib/splash/builder.rb
index 5a737e9..dc52d64 100644
--- a/new/splash/lib/splash/builder.rb
+++ b/new/splash/lib/splash/builder.rb
@@ -1,8 +1,18 @@
# frozen_string_literal: true
+require_relative "processors/splash_processor"
+
module Crys
module Splash
class Builder < Crys::Builder
+
+ def html_processor
+ Crys::Splash::SplashProcessor
+ end
+
+ def pages_db_manager
+ Crys::Splash::PagesDbManager.new
+ end
end
end
end
diff --git a/new/splash/lib/splash/pages_db_manager.rb b/new/splash/lib/splash/pages_db_manager.rb
new file mode 100644
index 0000000..11a8d6f
--- /dev/null
+++ b/new/splash/lib/splash/pages_db_manager.rb
@@ -0,0 +1,9 @@
+module Crys
+ module Splash
+ class PagesDbManager < Crys::PagesDbManager
+ def db_path
+ "#{File.dirname(File.dirname(File.dirname(__FILE__)))}/db/pages.yaml"
+ end
+ end
+ end
+end
diff --git a/new/splash/lib/splash/processors/splash_processor.rb b/new/splash/lib/splash/processors/splash_processor.rb
new file mode 100644
index 0000000..463dd65
--- /dev/null
+++ b/new/splash/lib/splash/processors/splash_processor.rb
@@ -0,0 +1,53 @@
+require "yaml"
+
+module Crys
+ module Splash
+ class SplashProcessor < Crys::HtmlProcessor
+ def not_real
+ [
+ "doctor",
+ "starfleet officer",
+ "magician",
+ "hacker",
+ "emperor of an evil galaxy",
+ "replicant",
+ "computer",
+ "evil genius"
+ ].sample
+ end
+
+ def update_badge(url_part)
+ @main_rss = fetch_rss(name: :main)
+ if @main_rss.items.last(20).any? { |it| it.link.include? url_part }
+ new_badge
+ end
+ end
+
+ def more_update_badge(name:)
+ path = case name
+ when :bookmarks
+ "/assets/more/bookmarks.yml"
+ when :links
+ "/assets/more/links.yml"
+ end
+
+ yaml = YAML.load_file(project_root + path)
+ _, vals = yaml.first
+ last_added = Time.parse(vals.last.fetch("date"))
+
+ if (Time.now - last_added) / (24 * 60* 60) < 30
+ new_badge
+ end
+ end
+
+
+ def new_badge
+ image = process_image(file: "new.gif")
+ code = ERB.new <<-EOF
+<img src="<%=image.relative_path%>" width="32" height="22" class="new-badge" alt="NEW">
+EOF
+ code.result(binding)
+ end
+ end
+ end
+end