Skip to content

Instantly share code, notes, and snippets.

@alejandrobabio
Last active December 8, 2017 15:36
Show Gist options
  • Save alejandrobabio/b687e078328787f1c5ca6372151c1243 to your computer and use it in GitHub Desktop.
Save alejandrobabio/b687e078328787f1c5ca6372151c1243 to your computer and use it in GitHub Desktop.
dry-web-roda & sprockets
doctype html
html
head
link rel="stylesheet" href=asset("application.css")
script rel="javascript" type="text/javascript" src=asset("ng_application.js")
body
== yield
# frozen_string_literal: true
require 'focus/view/context'
module Focus
module Spa
module View
class Context < Focus::View::Context
def asset(name)
if ENV['RACK_ENV'] == 'production'
"/public/spa/assets/#{name}"
else
"/spa/assets/#{name}"
end
end
end
end
end
end
# frozen_string_literal: true
Focus::Spa::Container.boot :sprockets do |system|
start do
require 'sprockets'
require 'slim'
sprockets = Sprockets::Environment.new(system.root) do |env|
env.logger = system['core.logger']
end
sprockets.append_path(File.join(system.root, 'assets', 'javascripts'))
sprockets.append_path(File.join(system.root, 'assets', 'stylesheets'))
sprockets.append_path(File.join(system.root, 'assets', 'images'))
project_root = system.root.parent.parent
sprockets.append_path(
File.join(project_root, 'vendor', 'assets', 'bower_components')
)
sprockets.context_class.class_eval do
def asset_path(path, _options = {})
path
end
end
sprockets.register_engine '.slim', Slim::Template, mime_type: 'text/slim',
silence_deprecation: true
register 'sprockets', sprockets
end
end
# frozen_string_literal: true
require 'dry/web/roda/application'
require_relative 'container'
module Focus
module Spa
class Web < Dry::Web::Roda::Application
route do |r|
# Enable this after writing your first web/routes/ file
# r.multi_route
r.on 'assets' do
r.run self.class['sprockets']
end
r.root do
r.view 'welcome'
end
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment