class Roadie::FilesystemProvider

Asset provider that looks for files on your local filesystem.

It will be locked to a specific path and it will not access files above that directory.

Attributes

path[R]

Public Class Methods

new(path = Dir.pwd) click to toggle source
# File lib/roadie/filesystem_provider.rb, line 15
def initialize(path = Dir.pwd)
  @path = path
end

Public Instance Methods

find_stylesheet(name) click to toggle source

@return [Stylesheet, nil]

# File lib/roadie/filesystem_provider.rb, line 20
def find_stylesheet(name)
  file_path = build_file_path(name)
  if File.exist? file_path
    Stylesheet.new file_path, File.read(file_path)
  end
end
find_stylesheet!(name) click to toggle source

@raise InsecurePathError @return [Stylesheet]

# File lib/roadie/filesystem_provider.rb, line 29
def find_stylesheet!(name)
  file_path = build_file_path(name)
  if File.exist? file_path
    Stylesheet.new file_path, File.read(file_path)
  else
    basename = File.basename file_path
    raise CssNotFound.new(
      css_name: basename,
      message: %{#{file_path} does not exist. (Original name was "#{name}")},
      provider: self
    )
  end
end
inspect() click to toggle source
# File lib/roadie/filesystem_provider.rb, line 47
def inspect
  "#<#{self.class} #{@path}>"
end
to_s() click to toggle source
# File lib/roadie/filesystem_provider.rb, line 43
def to_s
  inspect
end

Private Instance Methods

build_file_path(name) click to toggle source
# File lib/roadie/filesystem_provider.rb, line 53
def build_file_path(name)
  raise InsecurePathError, name if name.include?("..")
  File.join(@path, name[/^([^?]+)/])
end