Sha256: b0ce557e9f07c2e468906e5e9312372421dcb54e9c96374a730c939f4ab0a097

Contents?: true

Size: 1.71 KB

Versions: 1

Compression:

Stored size: 1.71 KB

Contents

# Rack::ScriptStacker

Painless static file handling for Rack apps.

- Automatically configures `Rack::Static` by default.
- Glob and inject JavaScript/CSS files into served HTML.

# Usage

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

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

and

```ruby
# 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...

```html
<!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

```ruby
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

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

## Serve files at a different path

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

## Change the template for a stacker

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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
rack-scriptstacker-0.0.1 README.md