Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

initial commit

  • Loading branch information...
commit da2266fe1461d780ee1ed13c8b356546237c5900 0 parents
Keith Norman and Allison Liechty authored
29 public/javascripts/application.js
@@ -0,0 +1,29 @@
+$(function() {
+ $("#regex_input, #test_string").bind('keyup', function(e){
+ $.post('/', $(e.target).parents("form").serialize(), function(response){
+ var results = eval("(" + response + ")");
+ var result;
+ $("#match_capture").empty();
+ $("#match").empty();
+ if(results.matches){
+ result = escapeHTMLEncode(results.matches[0])
+ if(result == "undefined")
+ result = "no matches"
+ $("#match").html(result);
+ results.matches.shift();
+ for(var i = 0; i < results.matches.length; i++){
+ $("#match_capture").append($("<li>" + results.matches[i] + "</li>"))
+ }
+ }
+ else
+ $("#match").html(results.error);
+ });
+ })
+})
+
+function escapeHTMLEncode(str) {
+ var div = document.createElement('div');
+ var text = document.createTextNode(str);
+ div.appendChild(text);
+ return div.innerHTML;
+}
32 rubex.rb
@@ -0,0 +1,32 @@
+require 'rubygems'
+require 'sinatra'
+require 'haml'
+require 'sass'
+require 'json'
+
+get '/screen.css' do
+ header 'Content-Type' => 'text/css; charset=utf-8'
+ sass :screen
+end
+
+get '/' do
+ haml :index
+end
+
+# create
+post '/' do
+ response = {}
+ begin
+ regex = %r{#{params[:regex]}}
+ rescue Exception => e
+ response[:error] = e.message
+ return response.to_json
+ end
+ str = params[:test_string]
+ matches = str.match(regex)
+ response[:matches] = []
+ matches.to_a.each do |match|
+ response[:matches].push(match)
+ end
+ response.to_json
+end
20 views/index.haml
@@ -0,0 +1,20 @@
+#output
+ %h2 Matches
+ #match
+
+ %h2 Captures
+ %ol#match_capture
+#regex
+ %form{:method=>"POST", :action=>"/"}
+ %label Regex:
+ #regex_input_wrapper
+ %span< /
+ %input#regex_input{:name=>"regex"}><
+ %span /
+
+
+ #test_string_container
+ %label Test String
+ %textarea#test_string{:name=>"test_string"}
+
+
12 views/layout.haml
@@ -0,0 +1,12 @@
+!!! Strict
+%html
+ %head
+ %title ruby regex tester
+ %link{:rel=>"stylesheet", :type=>"text/css", :media=>"screen", :charset=>"utf-8", :href=>"/screen.css"}
+ %script{:src=>"http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js", :type=>"text/javascript"}
+ %script{:src=>"/javascripts/application.js", :type=>"text/javascript"}
+
+ %body
+ #container
+ %h1 Rubex
+ = yield
44 views/screen.sass
@@ -0,0 +1,44 @@
+body
+ :background #000
+ :text-align center
+ :font-family Monaco, Verdana
+ :color #fff
+h1
+ :color #97bf0d
+h2
+ :font-size 14px
+ :font-weight normal
+#container
+ :width 600px
+ :text-align left
+ :margin 0 auto
+
+ form
+ label
+ :display block
+ :color #fff
+ input
+ :width 450px
+ :padding 3px
+ :font-size 14px
+ textarea
+ :width 460px
+ :height 150px
+ :font-size 14px
+ :font-family Monaco, Verdana
+ :padding 3px
+ span
+ :color #fff
+ #regex_input_wrapper
+ :overflow hidden
+ :margin-bottom 15px
+ span:first-child
+ :margin-right 3px
+ span:last-child
+ :margin-left 3px
+ span, input
+ :float left
+ :display block
+ #match
+ :background #a5a5a5
+ :padding 0 4px
Please sign in to comment.
Something went wrong with that request. Please try again.