rack-combobot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ .DS_Store
2
+ *.gem
data/.rbenv-version ADDED
@@ -0,0 +1 @@
1
+ 1.9.3-p0
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in rack-combot.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,30 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rack-combobot (0.0.1)
5
+ rack
6
+ rake
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ guard (0.7.0)
12
+ thor (~> 0.14.6)
13
+ guard-minitest (0.4.0)
14
+ guard (~> 0.4)
15
+ minitest (2.6.0)
16
+ rack (1.3.0)
17
+ rack-test (0.5.7)
18
+ rack (>= 1.0)
19
+ rake (0.9.2.2)
20
+ thor (0.14.6)
21
+
22
+ PLATFORMS
23
+ ruby
24
+
25
+ DEPENDENCIES
26
+ guard
27
+ guard-minitest
28
+ minitest
29
+ rack-combobot!
30
+ rack-test
data/Guardfile ADDED
@@ -0,0 +1,6 @@
1
+ guard 'minitest' do
2
+ watch(%r|^spec/(.*)_spec\.rb|)
3
+ watch(%r|^lib/(.*)\.rb|) { |m| "spec/#{m[1]}_spec.rb" }
4
+ watch(%r|^lib/rack/(.*)\.rb|) { |m| "spec/rack_#{m[1]}_spec.rb" }
5
+ watch(%r|^spec/spec_helper\.rb|) { "spec" }
6
+ end
data/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # rack-combobot - ATTENTION, this stuff aint working yet :)
2
+
3
+ Asset combinator for rack
4
+
5
+ ## Installation
6
+
7
+ gem install rack-combobot
8
+
9
+ ### Rails apps
10
+
11
+ In your routes.rb file add the following route
12
+
13
+ ```ruby
14
+ match 'combot', :to => Rack::Combobot.configure(:root => "/public")
15
+ ```
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ # encoding: UTF-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler/setup'
5
+ require 'bundler/gem_tasks'
6
+ require 'rake'
7
+ require 'rake/testtask'
8
+
9
+ Rake::TestTask.new do |t|
10
+ t.pattern = "spec/*_spec.rb"
11
+ end
12
+
13
+ task :default => [:test]
@@ -0,0 +1,19 @@
1
+ module Rack
2
+ class Combobot
3
+ class Config
4
+ def initialize(root)
5
+ @cache = []
6
+ @root = root
7
+ end
8
+
9
+ def cache(*names)
10
+ @cache.concat(names)
11
+ end
12
+
13
+ def root
14
+ @root
15
+ end
16
+ end
17
+ end
18
+ end
19
+
@@ -0,0 +1,48 @@
1
+ require "rack/combobot/config"
2
+ require "pathname"
3
+ require 'uri'
4
+
5
+ module Rack
6
+ class Combobot
7
+ def self.configure(*args)
8
+ new(*args)
9
+ end
10
+
11
+ MIME_TYPES = {
12
+ "js" => "css/javascript",
13
+ "css" => "text/css"
14
+ }
15
+
16
+ def initialize(options = {})
17
+ root = Pathname.new(options[:root] || Dir.pwd)
18
+ @config = Rack::Combobot::Config.new(root)
19
+ end
20
+
21
+ # rack request handler
22
+ def call(env)
23
+ params = env["QUERY_STRING"]
24
+ file_names = params.split("&")
25
+ extention = file_names[0].split(".").last
26
+
27
+ # TODO: create a simple key value hash with the query string as key
28
+ combo = Combination.new(@config.root, file_names).combine
29
+
30
+ [200, {"Content-Type" => MIME_TYPES[extention]}, combo]
31
+ end
32
+
33
+ class Combination
34
+ def initialize(root, file_names)
35
+ @file_contents = []
36
+
37
+ file_names.each do |file_name|
38
+ @file_contents << ::File.open("#{root}/#{file_name}", 'r') { |f| f.read }
39
+ end
40
+ end
41
+
42
+ def combine
43
+ @combo ||= @file_contents.join
44
+ end
45
+ end
46
+
47
+ end
48
+ end
@@ -0,0 +1 @@
1
+ require 'rack/combobot'
@@ -0,0 +1,28 @@
1
+ # encoding: UTF-8
2
+
3
+ $:.push File.expand_path("../lib", __FILE__)
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "rack-combobot"
7
+ s.version = "0.0.1"
8
+ s.authors = ["Simon Højberg", "Christopher Meiklejohn"]
9
+ s.email = ["r.hackr@gmail.com", "christopher.meiklejohn@gmail.com"]
10
+ s.homepage = "https://github.com/hojberg/rack-combobot"
11
+ s.summary = "asset combinator"
12
+ s.description = "combines assets to server 1 file"
13
+
14
+ s.rubyforge_project = "rack-combobot"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ s.add_dependency "rake"
22
+ s.add_dependency "rack"
23
+
24
+ s.add_development_dependency "minitest"
25
+ s.add_development_dependency "rack-test"
26
+ s.add_development_dependency "guard"
27
+ s.add_development_dependency "guard-minitest"
28
+ end
@@ -0,0 +1 @@
1
+ .lorem { background: blue; }
@@ -0,0 +1 @@
1
+ #lipsum { border: 1px solid red }
@@ -0,0 +1 @@
1
+ function lorem() { return "a"; }
@@ -0,0 +1 @@
1
+ function ipsum() { return "b"; }
@@ -0,0 +1,30 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe "combing assets from query string" do
4
+ include Rack::Test::Methods
5
+
6
+ before(:each) do
7
+ @app = Rack::Combobot.configure(:root => File.dirname(__FILE__) + '/public')
8
+ end
9
+
10
+ it "combines javascript" do
11
+ @app.call({
12
+ "QUERY_STRING" => "js1.js&js2.js"
13
+ }).must_equal([
14
+ 200,
15
+ {"Content-Type" => "css/javascript"},
16
+ "function lorem() { return \"a\"; }\nfunction ipsum() { return \"b\"; }\n"
17
+ ])
18
+ end
19
+
20
+ it "combines css" do
21
+ @app.call({
22
+ "QUERY_STRING" => "css1.css&css2.css"
23
+ }).must_equal([
24
+ 200,
25
+ {"Content-Type" => "text/css"},
26
+ ".lorem { background: blue; }\n#lipsum { border: 1px solid red }\n"
27
+ ])
28
+ end
29
+
30
+ end
@@ -0,0 +1,11 @@
1
+ require "rubygems"
2
+ require "bundler"
3
+ Bundler.setup
4
+
5
+ $:.unshift File.expand_path("../../lib", __FILE__)
6
+
7
+ require "rack/combobot"
8
+
9
+ require 'minitest/spec'
10
+ require 'minitest/autorun'
11
+ require 'rack/test'
metadata ADDED
@@ -0,0 +1,136 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-combobot
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Simon Højberg
9
+ - Christopher Meiklejohn
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2012-01-04 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rake
17
+ requirement: &2153038700 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: '0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *2153038700
26
+ - !ruby/object:Gem::Dependency
27
+ name: rack
28
+ requirement: &2153038000 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *2153038000
37
+ - !ruby/object:Gem::Dependency
38
+ name: minitest
39
+ requirement: &2153037580 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :development
46
+ prerelease: false
47
+ version_requirements: *2153037580
48
+ - !ruby/object:Gem::Dependency
49
+ name: rack-test
50
+ requirement: &2153037120 !ruby/object:Gem::Requirement
51
+ none: false
52
+ requirements:
53
+ - - ! '>='
54
+ - !ruby/object:Gem::Version
55
+ version: '0'
56
+ type: :development
57
+ prerelease: false
58
+ version_requirements: *2153037120
59
+ - !ruby/object:Gem::Dependency
60
+ name: guard
61
+ requirement: &2153036680 !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ! '>='
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ type: :development
68
+ prerelease: false
69
+ version_requirements: *2153036680
70
+ - !ruby/object:Gem::Dependency
71
+ name: guard-minitest
72
+ requirement: &2153036220 !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :development
79
+ prerelease: false
80
+ version_requirements: *2153036220
81
+ description: combines assets to server 1 file
82
+ email:
83
+ - r.hackr@gmail.com
84
+ - christopher.meiklejohn@gmail.com
85
+ executables: []
86
+ extensions: []
87
+ extra_rdoc_files: []
88
+ files:
89
+ - .gitignore
90
+ - .rbenv-version
91
+ - Gemfile
92
+ - Gemfile.lock
93
+ - Guardfile
94
+ - README.md
95
+ - Rakefile
96
+ - lib/rack-combobot.rb
97
+ - lib/rack/combobot.rb
98
+ - lib/rack/combobot/config.rb
99
+ - rack-combobot.gemspec
100
+ - spec/public/css1.css
101
+ - spec/public/css2.css
102
+ - spec/public/js1.js
103
+ - spec/public/js2.js
104
+ - spec/rack_combobot_spec.rb
105
+ - spec/spec_helper.rb
106
+ homepage: https://github.com/hojberg/rack-combobot
107
+ licenses: []
108
+ post_install_message:
109
+ rdoc_options: []
110
+ require_paths:
111
+ - lib
112
+ required_ruby_version: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ required_rubygems_version: !ruby/object:Gem::Requirement
119
+ none: false
120
+ requirements:
121
+ - - ! '>='
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project: rack-combobot
126
+ rubygems_version: 1.8.13
127
+ signing_key:
128
+ specification_version: 3
129
+ summary: asset combinator
130
+ test_files:
131
+ - spec/public/css1.css
132
+ - spec/public/css2.css
133
+ - spec/public/js1.js
134
+ - spec/public/js2.js
135
+ - spec/rack_combobot_spec.rb
136
+ - spec/spec_helper.rb