Module: Prez::Files

Defined in:
lib/prez/files.rb

Defined Under Namespace

Classes: MissingError, Paths

Constant Summary collapse

SEARCH_PATHS =
{
  "js" => Prez::Files::Paths.new("js", ["js.coffee", "coffee", "js"], "javascripts"),
  "css" => Prez::Files::Paths.new("css", ["css.scss", "scss", "css"], "stylesheets"),
  "font" => Prez::Files::Paths.new("font", ["eot", "svg", "ttf", "woff", "woff2"], "fonts", binary: true),
  "image" => Prez::Files::Paths.new("image", ["gif", "jpeg", "jpg", "png", "svg", "tif", "tiff"], "images", binary: true)
}

Class Method Summary collapse

Class Method Details

.contents(name, extension) ⇒ Object



57
58
59
60
61
62
63
64
65
# File 'lib/prez/files.rb', line 57

def contents(name, extension)
  file = find name, extension

  if SEARCH_PATHS[extension].binary?
    File.read file, mode: "rb"
  else
    File.read file
  end
end

.find(name, extension) ⇒ Object



67
68
69
70
71
72
73
# File 'lib/prez/files.rb', line 67

def find(name, extension)
  unless SEARCH_PATHS[extension]
    raise Prez::Files::MissingError.new(name, extension)
  end

  SEARCH_PATHS[extension].find name
end