Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

hot damn! got minitest working, app sorta working. no cache yet though

  • Loading branch information...
commit 6ed5354a0eb84d03c8eb5e1ab4ddeda5f2a05f3a 1 parent ee9d661
@hojberg hojberg authored
View
11 Gemfile
@@ -2,5 +2,12 @@ source :rubygems
gem "rack"
-gem "rack-test"
-gem 'minitest'
+group :test do
+ gem "rack-test", :require => "rack/test"
+ gem 'minitest', :require => 'minitest/spec'
+ gem 'guard'
+ gem 'guard-minitest'
+ gem 'rb-fsevent'
+ gem 'growl_notify'
+end
+
View
16 Gemfile.lock
@@ -1,12 +1,28 @@
GEM
remote: http://rubygems.org/
specs:
+ growl_notify (0.0.1)
+ rb-appscript
+ guard (0.7.0)
+ thor (~> 0.14.6)
+ guard-minitest (0.4.0)
+ guard (~> 0.4)
minitest (2.6.0)
rack (1.3.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rb-appscript (0.6.0)
+ rb-fsevent (0.4.3.1)
+ thor (0.14.6)
PLATFORMS
ruby
DEPENDENCIES
+ growl_notify
+ guard
+ guard-minitest
minitest
rack
+ rack-test
+ rb-fsevent
View
6 Guardfile
@@ -0,0 +1,6 @@
+guard 'minitest' do
+ watch(%r|^spec/(.*)_spec\.rb|)
+ watch(%r|^lib/(.*)\.rb|) { |m| "spec/#{m[1]}_spec.rb" }
+ watch(%r|^lib/rack/(.*)\.rb|) { |m| "spec/rack_#{m[1]}_spec.rb" }
+ watch(%r|^spec/spec_helper\.rb|) { "spec" }
+end
View
4 README.md
@@ -1,6 +1,6 @@
# rack-combot - ATTENTION, this stuff aint working yet :)
-Combines assets into single files to improve performance.
+Asset combinator for rack
## Installation
@@ -11,5 +11,5 @@ gem install rack-combot
In your routes.rb file add the following route
```ruby
- match 'combot', :to => RackCombot.new
+ match 'combot', :to => Rack::Combot.configure(:root => "/public")
```
View
2  config.ru
@@ -1,2 +0,0 @@
-require 'yui_combot'
-run YUICombot.new
View
47 lib/rack/combot.rb
@@ -0,0 +1,47 @@
+require "rack/combot/config"
+require "pathname"
+require 'uri'
+
+module Rack
+ class Combot
+ def self.configure(*args)
+ new(*args)
+ end
+
+ MIME_TYPES = {
+ "js" => "css/javascript",
+ "css" => "text/css"
+ }
+
+ def initialize(options = {})
+ root = Pathname.new(options[:root] || Dir.pwd)
+ @config = Rack::Combot::Config.new(root)
+ end
+
+ # rack request handler
+ def call(env)
+ params = env["QUERY_STRING"]
+ file_names = params.split("&")
+ extention = file_names[0].split(".").last
+
+ combo = Combination.new(@config.root, file_names).combine
+
+ [200, {"Content-Type" => MIME_TYPES[extention]}, combo]
+ end
+
+ class Combination
+ def initialize(root, file_names)
+ @file_contents = []
+
+ file_names.each do |file_name|
+ @file_contents << ::File.open("#{root}/#{file_name}", 'r') { |f| f.read }
+ end
+ end
+
+ def combine
+ @combo ||= @file_contents.join
+ end
+ end
+
+ end
+end
View
19 lib/rack/combot/config.rb
@@ -0,0 +1,19 @@
+module Rack
+ class Combot
+ class Config
+ def initialize(root)
+ @cache = []
+ @root = root
+ end
+
+ def cache(*names)
+ @cache.concat(names)
+ end
+
+ def root
+ @root
+ end
+ end
+ end
+end
+
View
1  lib/rack_combot.rb
@@ -0,0 +1 @@
+require 'rack/combot'
View
41 rack_combot.rb
@@ -1,41 +0,0 @@
-class RackCombot
- @@combinations = {}
-
- def call(env)
- qa = env["QUERY_STRING"]
-
- if @@combinations.has_key? qs
- combination = @@combinations[qs]
- else
- combination = Combination.new(qs.split("&"))
- @@combinations[qs] = combination
- end
-
- [
- 200,
- {"Content-Type" => "application/javascript"},
- combination.combine
- ]
- end
-
-private
-
- class Combination
-
- def initialize(file_names)
- @file_contents = []
-
- file_names.each do |file_name|
- @file_contents << File.open(file_name, 'r') { |f| f.read }
- end
-
- @files = files
- end
-
- def combine
- @combo ||= @files.join
- end
-
- end
-
-end
View
1  spec/public/css1.css
@@ -0,0 +1 @@
+.lorem { background: blue; }
View
1  spec/public/css2.css
@@ -0,0 +1 @@
+#lipsum { border: 1px solid red }
View
1  spec/public/js1.js
@@ -0,0 +1 @@
+function lorem() { return "a"; }
View
1  spec/public/js2.js
@@ -0,0 +1 @@
+function ipsum() { return "b"; }
View
30 spec/rack_combot_spec.rb
@@ -0,0 +1,30 @@
+require 'spec_helper'
+
+describe "combing assets from query string" do
+ include Rack::Test::Methods
+
+ before(:each) do
+ @app = Rack::Combot.configure(:root => File.dirname(__FILE__) + '/public')
+ end
+
+ it "combines javascript" do
+ @app.call({
+ "QUERY_STRING" => "js1.js&js2.js"
+ }).must_equal([
+ 200,
+ {"Content-Type" => "css/javascript"},
+ "function lorem() { return \"a\"; }\nfunction ipsum() { return \"b\"; }\n"
+ ])
+ end
+
+ it "combines css" do
+ @app.call({
+ "QUERY_STRING" => "css1.css&css2.css"
+ }).must_equal([
+ 200,
+ {"Content-Type" => "text/css"},
+ ".lorem { background: blue; }\n#lipsum { border: 1px solid red }\n"
+ ])
+ end
+
+end
View
8 spec/spec_helper.rb
@@ -0,0 +1,8 @@
+require "rubygems"
+require "bundler"
+Bundler.setup
+
+$:.unshift File.expand_path("../../lib", __FILE__)
+
+require "rack/combot"
+Bundler.require(:test)
View
21 test/rack_combot_spec.rb
@@ -1,21 +0,0 @@
-require 'rubygems'
-require 'rack/test'
-require 'minitest/spec'
-require 'minitest/autorun'
-require File.expand_path(File.dirname(__FILE__) + '/../rack_combot')
-
-describe "something" do
- include Rack::Test::Methods
-
- before do
- @app = RackCombo.new
- end
-
- it "combines files" do
-
- 3.must_equal(4)
- end
-
- after(:each) do
- end
-end
Please sign in to comment.
Something went wrong with that request. Please try again.