Sha256: 841064b663f4c23c2fafb301dadfdcab3150d093c73e7f138add9836df265259
Contents?: true
Size: 1.42 KB
Versions: 38
Compression:
Stored size: 1.42 KB
Contents
module Rack module Formtastic class Samples def initialize(app) @app = app end def call(env) @status, @headers, @body = @app.call(env) @env = env @body = '' if favicon? @body = static_file if !favicon? && static_file? @body = stylesheet if stylesheet? @headers ||= {} @headers['Content-Type'] = mime(extension) [@status, @headers, @body] end def static_file? !stylesheet? end def stylesheet? @env["PATH_INFO"] =~ /\.(css)/ end def favicon? @env["PATH_INFO"] =~ /favicon.ico$/ end def extension @env["PATH_INFO"].split(".").last end def mime(extension) mimes[extension] || mimes['html'] end def mimes { 'ico' => 'image/x-icon', 'html' => 'text/html', 'css' => 'text/css', 'js' => 'text/javascript' } end def static_file ::File.open(file_path) end def stylesheet ::File.open(::File.join("../app/assets/stylesheets", file_path)) end def file_path @env["PATH_INFO"].gsub(/^\//, '').gsub(/^$/, 'index.html') end end end end use Rack::ContentLength use Rack::Formtastic::Samples app = lambda { |env| [200, @headers, @body] } run app
Version data entries
38 entries across 38 versions & 3 rubygems