Class: Roadie::FilesystemProvider

Inherits:
AssetProvider show all
Defined in:
lib/roadie/filesystem_provider.rb

Overview

A provider that looks for files on the filesystem

Usage:

config.roadie.provider = FilesystemProvider.new("prefix", "path/to/stylesheets")

Path specification follows certain rules thatare detailed in #initialize.

See Also:

Instance Attribute Summary (collapse)

Attributes inherited from AssetProvider

#prefix

Instance Method Summary (collapse)

Methods inherited from AssetProvider

#all

Constructor Details

- (FilesystemProvider) initialize(prefix = "/stylesheets", path = nil)

Initializes a new instance of FilesystemProvider.

The passed path can come in some variants:

  • Pathname - will be used as-is

  • String - If pointing to an absolute path, uses that path. If a relative path, relative from the Rails.root

  • nil - Use the default path (equal to “public/stylesheets”)

Examples:

Pointing to a directory in the project

FilesystemProvider.new(Rails.root.join("public", "assets"))
FilesystemProvider.new("public/assets")

Pointing to external resource

FilesystemProvider.new("/home/app/stuff")

Parameters:

  • prefix (String) (defaults to: "/stylesheets")

    The prefix (see AssetProvider#prefix)

  • path (String, Pathname, nil) (defaults to: nil)

    The path to use



32
33
34
35
36
37
38
39
# File 'lib/roadie/filesystem_provider.rb', line 32

def initialize(prefix = "/stylesheets", path = nil)
  super(prefix)
  if path
    @path = resolve_path(path)
  else
    @path = default_path
  end
end

Instance Attribute Details

- (Pathname) path (readonly)

Pathname representing the directory of the assets

Returns:

  • (Pathname)

    Pathname representing the directory of the assets



14
15
16
# File 'lib/roadie/filesystem_provider.rb', line 14

def path
  @path
end

Instance Method Details

- (String) find(name)

Looks for the file in the tree. If the file cannot be found, and it does not end with “.css”, the lookup will be retried with “.css” appended to the filename.

Returns:

  • (String)

    contents of the file



45
46
47
48
49
50
51
52
53
54
# File 'lib/roadie/filesystem_provider.rb', line 45

def find(name)
  base = remove_prefix(name)
  file = path.join(base)
  if file.exist?
    file.read.strip
  else
    return find("#{base}.css") if base.to_s !~ /\.css$/
    raise CSSFileNotFound.new(name, base.to_s)
  end
end