Skip to content

Commit

Permalink
Restore sprockets approach for JS and CSS
Browse files Browse the repository at this point in the history
But drop minification to reduce dependencies
  • Loading branch information
onli committed Feb 14, 2020
1 parent 256c56a commit afd9178
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ gem 'thread'
gem 'rack-contrib'
gem 'xmlrpc'
gem 'htmlentities'
gem 'sprockets'
17 changes: 13 additions & 4 deletions server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class Ursprung < Sinatra::Application

set :static_cache_control, [:public, max_age: 31536000]

set :assets, Sprockets::Environment.new

class << self; attr_accessor :baseUrl end
class << self; attr_accessor :pool end
@pool = Thread.pool(2)
Expand Down Expand Up @@ -104,6 +106,13 @@ def self.loadConfiguration()
settings.views = File.join(settings.design_root, design)
use Rack::TryStatic, :root => File.join(settings.views, 'public'), :urls => %w[/] # first look in the designs public folder
settings.public_folder = 'public' # and otherwise in the global one, where also all the uploads are
settings.assets.clear_paths # js/css files else stay the same after a design switch

settings.assets.append_path File.join(settings.views, "js")
settings.assets.append_path File.join(settings.views, "css")

settings.assets.append_path File.join(settings.design_default, "js") if design != "default"
settings.assets.append_path File.join(settings.design_default, "css") if design != "default"
end

configure do
Expand Down Expand Up @@ -369,7 +378,7 @@ def serveIndex(page: -1, tag: nil)
end

# A Page (entry with comments)
get %r{/([0-9]+)/([\w]+)} do |id, title|
get %r{/([0-9]+)/(.+)} do |id, title|
db = Database.new
entry = Entry.new(id.to_i)
comments = db.getCommentsForEntry(id)
Expand Down Expand Up @@ -402,14 +411,14 @@ def serveIndex(page: -1, tag: nil)
end


get "/js/:file.js" do
get "/js/:file.js" do
content_type "application/javascript"
body File.read(settings.views + '/js/' + params[:file] + ".js").to_s
body settings.assets[params[:file]+".js"].to_s
end

get "/css/:file.css" do
content_type "text/css"
body File.read(settings.views + '/css/' + params[:file] + ".css").to_s
body settings.assets[params[:file]+".css"].to_s
end

post '/logout' do
Expand Down

0 comments on commit afd9178

Please sign in to comment.