Class: Roadie::FilesystemProvider
- Inherits:
-
AssetProvider
- Object
- AssetProvider
- Roadie::FilesystemProvider
- 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.
Instance Attribute Summary (collapse)
-
- (Pathname) path
readonly
Pathname representing the directory of the assets.
Attributes inherited from AssetProvider
Instance Method Summary (collapse)
-
- (String) find(name)
Looks for the file in the tree.
-
- (FilesystemProvider) initialize(prefix = "/stylesheets", path = nil)
constructor
Initializes a new instance of FilesystemProvider.
Methods inherited from AssetProvider
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”)
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
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.
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 |