Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

quick rack app to serve samples, to make testing over windows VMs muc…

…h much easier
  • Loading branch information...
commit 4ef751207a0a4698e8cf63fd8f624406f227fea6 1 parent 9a2714e
@justinfrench authored
Showing with 84 additions and 1 deletion.
  1. +1 −1  sample/basic_inputs.html
  2. +69 −0 sample/config.ru
  3. +14 −0 sample/index.html
View
2  sample/basic_inputs.html
@@ -4,7 +4,7 @@
<meta content="noindex,nofollow" name="robots">
<meta charset="utf-8">
<title>Formtastic</title>
- <link href="../app/assets/stylesheets/formtastic.css" rel="stylesheet" type="text/css" />
+ <link href="/formtastic.css" rel="stylesheet" type="text/css" />
<style>
body {
font-family: helvetica, arial;
View
69 sample/config.ru
@@ -0,0 +1,69 @@
+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
View
14 sample/index.html
@@ -0,0 +1,14 @@
+<!DOCTYPE html>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>untitled</title>
+</head>
+<body>
+
+ <ul>
+ <li><a href="/basic_inputs.html">Basic Inputs</li>
+ </ul>
+
+</body>
+</html>
Please sign in to comment.
Something went wrong with that request. Please try again.