Class: Cabriolet::LIT::ContentTypeDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/cabriolet/lit/content_type_detector.rb

Overview

Detects content type and file group for LIT files

Class Method Summary collapse

Class Method Details

.content_type(filename) ⇒ String

Guess content type from filename



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/cabriolet/lit/content_type_detector.rb', line 11

def self.content_type(filename)
  ext = ::File.extname(filename).downcase
  case ext
  when ".html", ".htm"
    "text/html"
  when ".css"
    "text/css"
  when ".jpg", ".jpeg"
    "image/jpeg"
  when ".png"
    "image/png"
  when ".gif"
    "image/gif"
  when ".txt"
    "text/plain"
  else
    "application/octet-stream"
  end
end

.file_group(filename) ⇒ Integer

Guess file group (0=HTML spine, 1=HTML other, 2=CSS, 3=Images)



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/cabriolet/lit/content_type_detector.rb', line 35

def self.file_group(filename)
  ext = ::File.extname(filename).downcase
  case ext
  when ".html", ".htm"
    0 # HTML spine (simplification - could be group 1 for non-spine)
  when ".css"
    2 # CSS
  when ".jpg", ".jpeg", ".png", ".gif"
    3 # Images
  else
    1 # Other
  end
end