Permalink
Browse files

Server, plist, Chrome extension, and small readme update

  • Loading branch information...
1 parent 832c5fe commit df8f20e7bdf89280b41bbc13f30f0f45e16dbe11 @stewart committed Apr 23, 2012
Showing with 105 additions and 0 deletions.
  1. +50 −0 bin/dcssd
  2. +18 −0 com.averagestudios.dotcss.plist
  3. +11 −0 ext/dotcss.js
  4. +4 −0 ext/jquery.js
  5. +12 −0 ext/manifest.json
  6. +10 −0 readme.md
View
@@ -0,0 +1,50 @@
+#!/usr/bin/env ruby
+
+if (%w( -h --help -help help ) & ARGV).length > 0
+ puts "usage: dcssd [-hv]"
+ puts "starts dotcss server in the foreground. kill with <Control>C"
+ exit
+end
+
+if ARGV.include?('-v')
+ puts 'dcssd 1.0'
+ exit
+end
+
+require "webrick"
+
+dotcss = Class.new(WEBrick::HTTPServlet::AbstractServlet) do
+ def do_GET(request, response)
+ file = File.expand_path("#{request.path.gsub('/','')}")
+ body = "/* dotcss is working */\n"
+ body << File.read(file) if File.file?(file)
+
+ response.status = body.empty? ? 204 : 200
+
+ if origin = detect_origin(request)
+ response['Access-Control-Allow-Origin'] = origin
+ end
+
+ response['Content-Type'] = 'text/javascript'
+ response.body = body
+ end
+
+ def detect_origin(req)
+ path = req.path
+ origin = req.header['origin']
+ search = path.gsub('/','').gsub(/\.js$/,'') + '$'
+
+ if origin.length == 1 && path.length != 1 && origin[0].match(search)
+ origin[0]
+ end
+ end
+end
+
+server = WEBrick::HTTPServer.new(:Port => 1243)
+server.mount('/', dotcss)
+
+%w( INT TERM ).each do |sig|
+ trap(sig) { server.shutdown }
+end
+
+server.start
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>Label</key>
+ <string>com.averagestudios.dotcss</string>
+ <key>KeepAlive</key>
+ <true/>
+ <key>ProgramArguments</key>
+ <array>
+ <string><%= DAEMON_INSTALL_DIR %>/dcssd</string>
+ </array>
+ <key>RunAtLoad</key>
+ <true/>
+ <key>WorkingDirectory</key>
+ <string><%= File.join(ENV['HOME'], ".css") %></string>
+</dict>
+</plist>
View
@@ -0,0 +1,11 @@
+$.ajax({
+ url: 'http://localhost:1243/' + window.location.host.replace('www.', '') + '.css',
+ dataType: 'text',
+ success: function (data) {
+ var body = $("body");
+ $('<style></style>').appendTo(body).text(data);
+ },
+ error: function() {
+ console.log("No dotcss server found at localhost:1243");
+ }
+});
View

Large diffs are not rendered by default.

Oops, something went wrong.
View
@@ -0,0 +1,12 @@
+{
+ "name" : "dotcss",
+ "version" : "1.0",
+ "description" : "~/.css",
+ "content_scripts": [{
+ "all_frames": true,
+ "run_at" : "document_start",
+ "matches" : ["http://*/*", "https://*/*"],
+ "js" : ["jquery.js", "dotcss.js"]
+ }],
+ "permissions": ["tabs"]
+}
View
@@ -28,6 +28,16 @@ Chrome extensions can't access the local filesystem, so dotcss runs a tiny web s
Multiple versions of Chrome installed? Drag `builds/dotcss.crx` to whichever is your favourite.
+## quick notes on css
+
+If your CSS isn't working, it means one of three things:
+
+1. Your selectors are off - by this, I mean either you're trying to style the wrong element, or your selector isn't specific enough to override the existing CSS
+2. Inline styles are preventing you from styling the element
+3. dotcss fucked up
+
+The first two are more likely than the third, but if you run into something weird, please file an issue and I'll try to help you.
+
## uninstall
rake uninstall

0 comments on commit df8f20e

Please sign in to comment.