Class: Roadie::AssetProvider Abstract

Inherits:
Object
  • Object
show all
Defined in:
lib/roadie/asset_provider.rb

Overview

This class is abstract.

Subclass to create your own providers

Direct Known Subclasses

AssetPipelineProvider, FilesystemProvider

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (AssetProvider) initialize(prefix = "/assets")

A new instance of AssetProvider

Parameters:

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

    Prefix of assets as seen from the browser

See Also:



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

def initialize(prefix = "/assets")
  @prefix = prefix
  @quoted_prefix = prepare_prefix(prefix)
end

Instance Attribute Details

- (Object) prefix (readonly)

The prefix is whatever is prepended to your stylesheets when referenced inside markup.

The prefix is stripped away from any URLs before they are looked up in #find:

find("/assets/posts/comment.css")
# Same as: (if prefix == "/assets"
find("posts/comment.css")


10
11
12
# File 'lib/roadie/asset_provider.rb', line 10

def prefix
  @prefix
end

Instance Method Details

- (Object) all(files)

Iterates all the passed elements and calls #find on them, joining the results with a newline.

Examples:

MyProvider.all("first", "second.css", :third)

Parameters:

  • files (Array)

    The target files to be loaded together

Raises:

See Also:



27
28
29
# File 'lib/roadie/asset_provider.rb', line 27

def all(files)
  files.map { |file| find(file) }.join("\n")
end

- (Object) find(name)

This method is abstract.

Implement in your own subclass

Return the CSS contents of the file specified. A provider should not care about the .css extension; it can, however, behave differently if it's passed or not.

If the asset cannot be found, the method should raise CSSFileNotFound.

Examples:

MyProvider.find("mystyle")
MyProvider.find("mystyle.css")
MyProvider.find(:mystyle)

Parameters:

  • name (String, Symbol)

    Name of the file requested

Raises:



45
46
47
# File 'lib/roadie/asset_provider.rb', line 45

def find(name)
  raise "Not implemented"
end