Skip to content

Commit

Permalink
Added support for custom stylesheets. Like scripts they can be specif…
Browse files Browse the repository at this point in the history
…ied in manifest.json. Use the key 'styles'.
  • Loading branch information
michael committed Sep 8, 2010
1 parent 1da62bc commit a927afa
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
2 changes: 1 addition & 1 deletion dist/commands/serve.js
Expand Up @@ -36,7 +36,7 @@
});
app.get(/^\/files\/(.+)$/, function(req, res) {
res.writeHead(200, {
'Content-Type': 'text/javascript'
'Content-Type': req.params[0].indexOf('css') >= 0 ? 'text/css' : 'text/javascript'
});
res.write(fs.readFileSync(("" + (CWD) + "/" + (req.params[0])), 'utf-8'));
return res.end();
Expand Down
3 changes: 2 additions & 1 deletion server.coffee
Expand Up @@ -78,14 +78,15 @@ app.get '/collections/:collection', (req, res) ->
# Serves static files from the visualization directory
app.get /^\/files\/(.+)$/, (req, res) ->
res.writeHead(200, {
'Content-Type': 'text/javascript'
'Content-Type': if req.params[0].indexOf('css') >= 0 then 'text/css' else 'text/javascript'
})
res.write fs.readFileSync("visualizations/#{req.params[0]}", 'utf-8')
res.end()

app.get '/:vis', (req, res) ->
manifest = JSON.parse(fs.readFileSync("visualizations/#{req.params.vis}/manifest.json", 'utf-8'))
manifest['dir'] = "/files/#{req.params.vis}/"
manifest['hosted'] = true
res.send render('templates/show.mustache', manifest)

app.listen 5001
4 changes: 2 additions & 2 deletions src/commands/serve.coffee
Expand Up @@ -44,7 +44,7 @@ app.get '/', (req, res) ->
# Serves static files from the current directory
app.get /^\/files\/(.+)$/, (req, res) ->
res.writeHead(200, {
'Content-Type': 'text/javascript'
'Content-Type': req.params[0].indexOf('css') >= 0 ? 'text/css' : 'text/javascript'
})
res.write fs.readFileSync("#{CWD}/#{req.params[0]}", 'utf-8')
res.end()
Expand All @@ -59,4 +59,4 @@ jsl.stdin.end()

app.listen SERVER_PORT

puts 'listening on port 5000...'
puts 'listening on port 5000...'
13 changes: 13 additions & 0 deletions templates/index.mustache
Expand Up @@ -26,5 +26,18 @@
{{/visualizations}}
</div>
</div>
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18430895-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
</body>
</html>
20 changes: 20 additions & 0 deletions templates/show.mustache
Expand Up @@ -9,6 +9,11 @@
{{/scripts}}

<link href="/stylesheets/application.css" media="screen" rel="stylesheet" type="text/css" />

<!-- loads additional styles specified in manifest.json -->
{{#styles}}
<link href="{{dir}}{{.}}" media="screen" rel="stylesheet" type="text/css" />
{{/styles}}
</head>
<body>
<div id="header">
Expand Down Expand Up @@ -52,5 +57,20 @@
<div id="sidebar">

</div>
{{#hosted}}
<script type="text/javascript">
var _gaq = _gaq || [];
_gaq.push(['_setAccount', 'UA-18430895-1']);
_gaq.push(['_trackPageview']);
(function() {
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
})();
</script>
{{/hosted}}
</body>
</html>

0 comments on commit a927afa

Please sign in to comment.