No commit activity in last 3 years
No release in over 3 years
Quickly inject static file lists into served HTML.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
>= 0

Runtime

~> 1.6
 Project Readme

Rack::ScriptStacker

Painless static file handling for Rack apps.

  • Automatically configures Rack::Static by default.
  • Glob and inject JavaScript/CSS files into served HTML.
    • Inserts CSS before </head> and JS before </body> by default.
    • Change the inject mode to use placeholder slots instead.

Usage

<!-- index.html //-->

<!doctype html>
<html lang="en">
    <head>
    </head>
    <body>
    </body>
</html>

and

# config.ru

require 'rack/scriptstacker'

class App
  def call env
    [
      200,
      {'Content-Type' => 'text/html'},
      [File.read('index.html')]
    ]
  end
end

use Rack::ScriptStacker do
  css 'static/css'
  javascript 'static/javascript'
end

run app

Results in...

<!doctype html>
<html lang="en">
    <head>
      <link rel="stylesheet" type="text/css" href="/static/css/main.css" />
    </head>
    <body>
      <script type="text/javascript" src="/static/javascript/main.js"></script>
      <script type="text/javascript" src="/static/javascript/util.js"></script>
    </body>
</html>

Configure static serving yourself

use Rack::ScriptStacker, configure_static: false do
  css 'static/css'
  javascript 'static/javascript'
end

use Rack::Static, url: ['static']

Serve multiple sets of files in order

use Rack::ScriptStacker do
  css 'static/css'
  javascript 'vendor/javascript'
  javascript 'static/javascript'
end

Serve files at a different path

use Rack::ScriptStacker, configure_static: false do
  css 'css' => 'stylesheets'
  javascript 'js' => 'scripts'
end

Change the template for a stacker

use Rack::ScriptStacker,
    stackers: {
      javascript: { template: '<script src="%s"></script>' }
    } do
  javascript 'static/javascript'
end

Use placeholder slots

<!-- index.html //-->

<!doctype html>
<html lang="en">
    <head>
      <!-- ScriptStacker: CSS //-->
    </head>
    <body>
      <!-- ScriptStacker: JAVASCRIPT //-->
    </body>
</html>

use Rack::ScriptStacker, inject_mode: :slot do
  css 'static/css'
  javascript 'static/javascript'
end