Class: Collage

Inherits:
Object
  • Object
show all
Defined in:
lib/collage.rb

Defined Under Namespace

Classes: Packager

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options) ⇒ Collage

Returns a new instance of Collage.



2
3
4
5
6
# File 'lib/collage.rb', line 2

def initialize(app, options)
  @app = app
  @path = File.expand_path(options[:path])
  @files = options[:files]
end

Class Method Details

.filenameObject



25
26
27
# File 'lib/collage.rb', line 25

def filename
  "js.js"
end

.html_tag(path) ⇒ Object



33
34
35
# File 'lib/collage.rb', line 33

def html_tag(path)
  %Q{<script type="text/javascript" src="/#{filename}?#{timestamp(path)}"></script>}
end

.timestamp(path) ⇒ Object



29
30
31
# File 'lib/collage.rb', line 29

def timestamp(path)
  Packager.new(path).timestamp
end

Instance Method Details

#call(env) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/collage.rb', line 8

def call(env)
  return @app.call(env) unless env['PATH_INFO'] == "/#{Collage.filename}"

  result = Packager.new(@path, @files)

  result.ignore(filename)

  File.open(filename, 'w') {|f| f.write(result) }

  [200, {'Content-Type' => 'text/javascript', 'Content-Length' => result.size.to_s, 'Last-Modified' => File.mtime(filename).httpdate}, result]
end

#filenameObject



20
21
22
# File 'lib/collage.rb', line 20

def filename
  File.join(@path, Collage.filename)
end