Module: Rack::Svelte

Defined in:
lib/rack/svelte.rb,
lib/rack/svelte/version.rb,
lib/rack/svelte/cogs.rb

Overview

Svelte for Rack w/ Cogs(tm)

Examples:

Within a rackup file (or with Rack::Builder)

require 'rack/svelte'
use Rack::Svelte,
  #app_root_dir:              Rack::Directory.new('').root,
  app_root_dir:               ::File.expand_path(File.dirname(__FILE__)),
  components_dir_in:          '/app/components',
  components_dir_out:         '/public/app/js',
  default_dir_out_overwrite:  false,
  default_dir_out_clear:      false,
  format:                     'iife'
run app

Rails example

# above Rails::Initializer block
require 'rack/svelte'

# inside Rails::Initializer block
config.middleware.use Rack::Svelte,
  app_root_dir:               Rails.root.to_s,
  components_dir_in:          '/app/components',
  components_dir_out:         '/public/app/js',
  default_dir_out_overwrite:  false,
  default_dir_out_clear:      false,
  format:                     'iife'

Defined Under Namespace

Classes: Cogs

Constant Summary collapse

VERSION =
'0.1.3'

Class Method Summary collapse

Class Method Details

.new(backend, options = {}) ⇒ void

This method returns an undefined value.

Create a new Rack::Svelte middleware component that builds Svelte components

using the svelte-ruby gem. The +options+ Hash can include any Svelte compiler
options AND components_dir_in, components_dir_in

Default svelte-rack options are:

default_root:               '/'
default_components_in:      '/app/components'
default_components_out:     '/public/app/js'
default_dir_out_overwrite:  false
default_dir_out_clear:      false

Parameters:

  • backend (#rack_object)

    set implicitly by Rack, use the var: ‘backend`

  • options (Hash) (defaults to: {})

    for processing and svelte compiler

Options Hash (options):

  • :app_root_dir (String)

    app’s root dir (path expanded)

  • :components_dir_in (String)

    where svelte-rack look for components (path begins at app’s root dir)

  • :components_dir_out (String)

    where svelte-rack writes compiled js (path begins at app’s root dir)

  • :dir_out_overwrite (Boolean)

    overwrite any files with matching name in the components_dir_out dir

  • :dir_out_clear (Boolean)

    clear entire components_dir_out dir before writing new files

See Also:



57
58
59
# File 'lib/rack/svelte.rb', line 57

def self.new(backend, options = {})
  Cogs.new(backend, options)
end