I'm playing around with Sinatra, and I would like to make one of my routes case insensitive. I tried adding the route like this:
get "(?i)/tileflood/?" do
end
But it doesn't match any permutation of /tileflood as expected. I tested the following regex on rubular.com, and it matches just fine. Am I missing something?
\/(?i)tileflood\/?
You want a real regexp for your route:
require 'sinatra'
get %r{^/tileflood/?$}i do
request.url + "\n"
end
Proof:
smagic:~ phrogz$ curl http://localhost:4567/tileflood
http://localhost:4567/tileflood
smagic:~ phrogz$ curl http://localhost:4567/tIlEflOOd
http://localhost:4567/tIlEflOOd
smagic:~ phrogz$ curl http://localhost:4567/TILEFLOOD/
http://localhost:4567/TILEFLOOD/
smagic:~ phrogz$ curl http://localhost:4567/TILEFLOOD/z
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { text-align:center;font-family:helvetica,arial;font-size:22px;
color:#888;margin:20px}
#c {margin:0 auto;width:500px;text-align:left}
</style>
</head>
<body>
<h2>Sinatra doesn't know this ditty.</h2>
<img src='/__sinatra__/404.png'>
<div id="c">
Try this:
<pre>get '/TILEFLOOD/z' do
"Hello World"
end</pre>
</div>
</body>
</html>
smagic:~ phrogz$ curl http://localhost:4567/tileflaad
<!DOCTYPE html>
<html>
<head>
<style type="text/css">
body { text-align:center;font-family:helvetica,arial;font-size:22px;
color:#888;margin:20px}
#c {margin:0 auto;width:500px;text-align:left}
</style>
</head>
<body>
<h2>Sinatra doesn't know this ditty.</h2>
<img src='/__sinatra__/404.png'>
<div id="c">
Try this:
<pre>get '/tileflaad' do
"Hello World"
end</pre>
</div>
</body>
</html>
Related
I got a reference json file called reference.json with key/values that I want to replace in .html files.
{
"a.js": "first.1a.js",
"b.js": "second.2b.js",
"c.js": "third.3b.js"
}
Then I got 3 different html files
test1.html
<!DOCTYPE html>
<html lang="en">
<head>
..
<body>
<div class="container">
<h1>file 1</h1>
</div>
<script src="a.js"></script>
<script src="b.js"></script>
<script src="c.js"></script>
</body>
</html>
test2.html
<!DOCTYPE html>
<html lang="en">
<head>
...
</head>
<body>
<div class="container">
<h1>file 2</h1>
</div>
<script src="a.js"></script>
<script src="b.js"></script>
<script src="c.js"></script>
</body>
</html>
And a file in a folder folder1/test3.html
<!DOCTYPE html>
<html lang="en">
<head>
...
<body>
<div class="container">
<h1>file 3</h1>
</div>
<script src="../js/a.js"></script>
<script src="../js/b.js"></script>
<script src="../js/c.js"></script>
</body>
</html>
How can I search through all of my .html files and replace with values from my json with grep and sed?
Assuming your reference.json is well formatted, this one-liner will do it for you :
$ CMD=" sed -i $( cat reference.json | grep ":" | sed 's/ //g;s/,//g;s/"//g' | sed 's/:/\//g' | awk '{printf("s/%s/g;",$0)}' )" && find . -name "*.html" -exec ${CMD} {} \;
Explanation :
Use the reference.json to form an sed substitution expression to use it in an sed command. Use find command to find all the "*.html" files and perform the substitution.
If the reference.json is not formatted, you can use the following command to format it :
$ python -m json.tool reference.json
When I create a sgvizler.visualization.Table with Sgvizler 0.6 and the SPARQL query has no results, Sgvizler doesn't draw anything, not even the table header. This may confuse users who may think that the result is still being calculated or that the script has crashed. How can I configure Sgvizler to draw the table header even when the result is empty?
Minimum Working Example
<!doctype html>
<html>
<head>
<meta charset="utf-8"/>
<script type="text/javascript" src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.0/jquery.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript" src="http://mgskjaeveland.github.io/sgvizler/v/0.6/sgvizler.js"></script>
<script>
sgvizler
.defaultEndpointURL("https://dbpedia.org/sparql")
.defaultChartFunction("sgvizler.visualization.Table")
.defaultChartWidth(1000);
$(document).ready(function (){ sgvizler.containerDrawAll(); });
</script>
</head>
<body>
<h2>First Table</h2>
<div id="results"
data-sgvizler-query="
select distinct ?class
{
?class rdfs:subClassOf dbo:Animal.
}
">
</div>
<h2>Second Table</h2>
<div id="noresults"
data-sgvizler-query="
select distinct ?class
{
?class rdfs:subClassOf dbo:Unicorn.
}
">
</div>
</body>
</html>
This is a bug in the parser, which looks only at the first row of results to build the JSON accepted by the google.visualization.DataTable object.
The solution would be to rewrite the parser to check the "column headers" of the SPARQL result set.
The parser is here: https://github.com/mgskjaeveland/sgvizler/blob/master/src/parser.js
I have (roughly) this LIFT-ified HTML in my default template:
<html>
<head>
<title>FooBar Application | <lift:bind name="page-title"/></title>
</head>
<body>
<h1><lift:bind name="page-title" /></h1>
<div id="page-content">
<lift:bind name="page-content" />
</div>
</body>
</html>
...and then this in my main template:
<lift:surround at="page-content">
<lift:bind-at name="page-title">Home</lift:bind-at>
</lift>
...which give me this in the generated HTML:
<html>
<head>
<title>FooBar Application | <lift:bind name="page-title"/></title>
</head>
<body>
<h1>Home</h1>
<div id="page-content">
</div>
</body>
</html>
Why is the <lift:bind> tag in the <title> getting escaped, and the one in the <body><h2> not? And how do I prevent that from happening?
Are the pages defined through SiteMap? As was mentioned before, <title> can be a special case, and it is interpreted in several places - some of which might be doing the escaping. If you can, I'd try setting the page title in one of two ways:
Through the Sitemap you can use the Title Loc Param as referenced here: Dynamic title with Lift
You can also have something like: <title data-lift="PageTitle"></title> to have it invoke a snippet called page-title. Where, the snippet would be something like:
class PageTitle {
def render = "*" #> "FooBar Application | Home"
}
I would like to append some code to a page using jQuery/jQuery mobile,
but I am tripping up on some of the page() and pageshow and refresh methods.
Here is my code. you can cut, paste and run as is.
<!DOCTYPE html>
<html>
<head>
<title>Page Title</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.css" />
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.2.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/mobile/1.0b2/jquery.mobile-1.0b2.min.js"></script>
<script>
//$(document).ready(function() // get error when I use this
$('div').live('pageshow', function () {
function fnCreateGroups(){
var section = "<p>and add a whole bunch of html code...</p>";
myClone = $(section);
alert((myClone).html()); // this works
myClone.appendTo("#placeholder").page(); // but not appending
}
fnCreateGroups();
});
</script>
</head>
<body>
<div data-role="page">
<div id="placeholder">
<div data-role="content">
<div id="placeholder">this is a small amount of html code.</div>
</div>
</div>
</div>
</body>
</html>
Beta2 release notes:
http://jquerymobile.com/blog/2011/08/03/jquery-mobile-beta-2-released/
instead of:
myClone.appendTo("#placeholder").page();
try
myClone.appendTo("#placeholder").trigger('create');
From your comment:
You are running the live() on all div's
$('div').live('pageshow', function ()
try using the page id instead
$('#change_this_page_only').live('pageshow', function ()
and this:
<div data-role="page">
to something like this:
<div data-role="page" id="change_this_page_only">
The below code:
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:fb="http://www.facebook.com/2008/fbml"
xml:lang="en" lang="en">
<head>
<title>FB Test</title>
</head>
<body>
Test
<fb:serverfbml style="width: 350px;">
<script type="text/fbml">
<fb:connect-form action="http://127.0.0.1/post_invite">
</fb:connect-form>
</script>
</fb:serverfbml>
</body>
</html>
Results in the following error:
- Warning: Compilation failed
- Warning: <class 'zope.tal.htmltalparser.NestingError'>: Open tags <html>, <body>, <fb:serverfbml>, <script> do not match close tag </fb:connect-form>, at line 16, column 4
PTRuntimeError: ['Compilation failed', u"<class 'zope.tal.htmltalparser.NestingError'>: Open tags <html>, <body>, <fb:serverfbml>, <script> do not match close tag </fb:connect-form>, at line 16, column 4"]
Yet the structure seems valid to me...
You can't put tags inside of a <script> tag, and the strict ZPT parser is complaining about that. You'll have to somehow escape the contents, like with a tal:content="structure string:" construct:
<script type="text/fbml" tal:content="structure string:
<fb:connect-form action="http://127.0.0.1/post_invite"<
>/fb:connect-form<
"></script>
The script tag must not contain xml to my knowledge.
You could enclose the contents in xml comments and see if that works.