Class: Serve::FileTypeHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/serve/handlers/file_type_handler.rb

Overview

:nodoc:

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root_path, template_path, extension) ⇒ FileTypeHandler

Returns a new instance of FileTypeHandler



35
36
37
38
39
# File 'lib/serve/handlers/file_type_handler.rb', line 35

def initialize(root_path, template_path, extension)
  @root_path = root_path
  @template_path = template_path
  @extension = extension
end

Instance Attribute Details

#extensionObject (readonly)

Returns the value of attribute extension



34
35
36
# File 'lib/serve/handlers/file_type_handler.rb', line 34

def extension
  @extension
end

Class Method Details

.configure(extension, options) ⇒ Object



22
23
24
# File 'lib/serve/handlers/file_type_handler.rb', line 22

def self.configure(extension, options)
  extension_options[extension.to_sym].merge!(options)
end

.extension(*extensions) ⇒ Object



7
8
9
10
11
# File 'lib/serve/handlers/file_type_handler.rb', line 7

def self.extension(*extensions)
  extensions.each do |ext|
    FileTypeHandler.handlers[ext] = self
  end
end

.extension_optionsObject



26
27
28
# File 'lib/serve/handlers/file_type_handler.rb', line 26

def self.extension_options
  @extension_options ||= Hash.new{|h,k| h[k] = {}}
end

.extensionsObject



13
14
15
# File 'lib/serve/handlers/file_type_handler.rb', line 13

def self.extensions
  handlers.keys
end

.handlersObject



3
4
5
# File 'lib/serve/handlers/file_type_handler.rb', line 3

def self.handlers
  @handlers ||= {}
end

.handlers_for(path) ⇒ Object



17
18
19
20
# File 'lib/serve/handlers/file_type_handler.rb', line 17

def self.handlers_for(path)
  extensions = File.basename(path).split(".")[1..-1]
  extensions.collect{|e| [handlers[e], e] if handlers[e]}.compact
end

.options_for(extension) ⇒ Object



30
31
32
# File 'lib/serve/handlers/file_type_handler.rb', line 30

def self.options_for(extension)
  extension_options[extension.to_sym]
end

Instance Method Details

#content_typeObject



45
46
47
# File 'lib/serve/handlers/file_type_handler.rb', line 45

def content_type
  'text/html'
end

#layout?Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/serve/handlers/file_type_handler.rb', line 49

def layout?
  true
end

#parse(input, context) ⇒ Object



53
54
55
# File 'lib/serve/handlers/file_type_handler.rb', line 53

def parse(input, context)
  input.dup
end

#process(input, context) ⇒ Object



41
42
43
# File 'lib/serve/handlers/file_type_handler.rb', line 41

def process(input, context)
  parse(input, context)
end