ventilation 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,22 @@
1
+ ## MAC OS
2
+ .DS_Store
3
+
4
+ ## TEXTMATE
5
+ *.tmproj
6
+ tmtags
7
+
8
+ ## EMACS
9
+ *~
10
+ \#*
11
+ .\#*
12
+
13
+ ## VIM
14
+ *.swp
15
+
16
+ ## PROJECT::GENERAL
17
+ coverage
18
+ rdoc
19
+ pkg
20
+ .yardoc
21
+
22
+ ## PROJECT::SPECIFIC
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,40 @@
1
+ Ventilation
2
+ ===========
3
+
4
+ Ventilation makes developing with ESI a snap.
5
+
6
+ ESI helps scale your website by allowing you to break it down into fragments
7
+ which can be cached independently and reconstructed on the fly. This allows
8
+ your server to spend the majority of its time creating the truly dynamic
9
+ sections of your site and the rest to be reused and mixed in at the edge.
10
+
11
+ Using ESI means you need to develop behind varnish or something capable of
12
+ composing the response. Ventilation however, removes this dependecny which
13
+ means you can develop with esi using nothing more the script/server. There is
14
+ no need to run a local varnish server (you still can if you want to).
15
+ Ventilation will automatically compose the page as if it was run through
16
+ varnish while you are in development. When you move out of development or put
17
+ your ventilation powered application behind varnish the composed content will
18
+ be replaced with esi tags allowing varnish to work it's magic.
19
+
20
+ WARNING: Using Varnish without Ventilation may result in death!
21
+
22
+ Example
23
+ =======
24
+
25
+ Include from a content delivery network.
26
+
27
+ <%= esi "http://cdn.megadomain.com/network_nav" %>
28
+
29
+ Include from somewhere else within your application.
30
+
31
+ <%= esi :header %>
32
+ <%= esi :header, :controller => :site %>
33
+
34
+ Copyright (c) 2010 [name of plugin creator], released under the MIT license
35
+
36
+ Resources
37
+ =========
38
+ * [Ventilation Home](http://github.com/agoragames/ventilation)
39
+ * [ESI Language Specification 1.0](http://www.w3.org/TR/esi-lang)
40
+ * [Edge Side Includes - Wikipedia](http://en.wikipedia.org/wiki/Edge_Side_Includes)
data/Rakefile ADDED
@@ -0,0 +1,43 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ begin
6
+ require 'jeweler'
7
+ Jeweler::Tasks.new do |gem|
8
+ gem.name = "ventilation"
9
+ gem.summary = %Q{Fancy ESI integration for your high prefomance web apps.}
10
+ gem.description = %Q{Helper methods for building esi tags, simplifies development bypassing the need for varnish.}
11
+ gem.email = "btaylor@agoragames.com"
12
+ gem.homepage = "http://github.com/agoragames/ventilation"
13
+ gem.authors = ["Blake Taylor"]
14
+ gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
15
+ gem.add_development_dependency "fakeweb", ">= 1.2.8"
16
+ gem.add_development_dependency "mocha", ">= 0.9.8"
17
+ end
18
+ Jeweler::GemcutterTasks.new
19
+ rescue LoadError
20
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
21
+ end
22
+
23
+ desc 'Test ventilation.'
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = true
29
+ end
30
+
31
+ desc 'Default: run unit tests.'
32
+ task :default => :test
33
+
34
+ task :test => :check_dependencies
35
+
36
+ Rake::RDocTask.new do |rdoc|
37
+ version = File.exist?('VERSION') ? File.read('VERSION') : ""
38
+
39
+ rdoc.rdoc_dir = 'rdoc'
40
+ rdoc.title = "ventilation #{version}"
41
+ rdoc.rdoc_files.include('README*')
42
+ rdoc.rdoc_files.include('lib/**/*.rb')
43
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.0
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'ventilation'
data/install.rb ADDED
@@ -0,0 +1 @@
1
+ # Install hook code here
@@ -0,0 +1,49 @@
1
+ require 'net/http'
2
+ require 'uri'
3
+ require 'action_controller'
4
+ require 'ventilation/deep_stack'
5
+
6
+ module Ventilation
7
+ module EsiHelper
8
+
9
+ # Render resource on the edge
10
+ def esi(resource, options = {})
11
+ env = ENV['RAILS_ENV']
12
+
13
+ # If we were passed a url...
14
+ if resource =~ /^(http:\/\/)?[a-zA-Z0-9\-\.]+\.(com|org|net|mil|edu)[a-zA-Z0-9\-\.\/]+$/i
15
+ # ...fetch and render an external resource...
16
+ case env
17
+ when 'production'
18
+ %%<esi:include src="#{resource}" />%
19
+ else
20
+ url = URI.parse(resource)
21
+ res = Net::HTTP.start(url.host, url.port) {|http|
22
+ http.get(url.path)
23
+ }
24
+ res.body
25
+ end
26
+ else
27
+ # ...otherwise render as an action.
28
+ case env
29
+ when 'production'
30
+ %%<esi:include src="#{url_for url_options.merge(:action => resource)}" />%
31
+ else
32
+ if controller = options[:controller]
33
+ controller = "#{controller.to_s.camelcase}Controller".constantize
34
+ else
35
+ controller = @controller.class
36
+ end
37
+ deep_stack = DeepStack.new(controller)
38
+ action = resource
39
+ deep_stack.get(action).body
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
45
+
46
+ # Include EsiHelper in the Application
47
+ module ApplicationHelper
48
+ include Ventilation::EsiHelper
49
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :ventilation do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,19 @@
1
+ module Ventilation
2
+ # Simulate concurrency by serving request recursively.
3
+ class DeepStack
4
+ include ActionController::TestProcess
5
+
6
+ def initialize(controller_class)
7
+ @request = ActionController::TestRequest.new
8
+ @response = ActionController::TestResponse.new
9
+
10
+ @controller = controller_class.new
11
+
12
+ if @controller
13
+ @controller.request = @request
14
+ @controller.params = {}
15
+ @controller.send(:initialize_current_url)
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1 @@
1
+ require 'app/helpers/esi_helper'
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+ require 'fakeweb'
5
+ require 'mocha'
6
+
7
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
8
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
9
+ require 'ventilation'
10
+
11
+ class Test::Unit::TestCase
12
+ end
@@ -0,0 +1,43 @@
1
+ require 'test_helper'
2
+ require 'ventilation/deep_stack'
3
+
4
+ class TestVentilation < Test::Unit::TestCase
5
+
6
+ context "a test consumer"do
7
+ setup do
8
+ FakeWeb.allow_net_connect = false
9
+ @consumer = TestConsumer.new
10
+ end
11
+
12
+ should "render external resource" do
13
+ expected = "response_from_example.com"
14
+ FakeWeb.register_uri(:get, "http://example.com/", :body => expected)
15
+
16
+ actual = @consumer.esi 'http://example.com/'
17
+
18
+ assert_equal expected, actual, "Expected response was not rendered by esi method"
19
+ end
20
+
21
+ should "use DeepStack to render internal resource" do
22
+ expected = 'rendered string'
23
+ response = mock()
24
+ response.expects(:body).returns(expected)
25
+ deep_stack = mock()
26
+ deep_stack.expects(:get).with(:index).returns(response)
27
+ Ventilation::DeepStack.expects(:new).with(WelcomeController).returns(deep_stack)
28
+
29
+ actual = @consumer.esi :index, :controller => :welcome
30
+
31
+ assert_equal expected, actual
32
+ end
33
+
34
+ end
35
+
36
+ end
37
+ # A consumer of the ApplicationHelper for testing purposes.
38
+ class TestConsumer
39
+ include ApplicationHelper
40
+ end
41
+
42
+ class WelcomeController
43
+ end
data/uninstall.rb ADDED
@@ -0,0 +1 @@
1
+ # Uninstall hook code here
@@ -0,0 +1,64 @@
1
+ # Generated by jeweler
2
+ # DO NOT EDIT THIS FILE DIRECTLY
3
+ # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
+ # -*- encoding: utf-8 -*-
5
+
6
+ Gem::Specification.new do |s|
7
+ s.name = %q{ventilation}
8
+ s.version = "0.1.0"
9
+
10
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
+ s.authors = ["Blake Taylor"]
12
+ s.date = %q{2010-09-24}
13
+ s.description = %q{Helper methods for building esi tags, simplifies development bypassing the need for varnish.}
14
+ s.email = %q{btaylor@agoragames.com}
15
+ s.extra_rdoc_files = [
16
+ "README.markdown"
17
+ ]
18
+ s.files = [
19
+ ".gitignore",
20
+ "MIT-LICENSE",
21
+ "README.markdown",
22
+ "Rakefile",
23
+ "VERSION",
24
+ "init.rb",
25
+ "install.rb",
26
+ "lib/app/helpers/esi_helper.rb",
27
+ "lib/tasks/ventilation.rake",
28
+ "lib/ventilation.rb",
29
+ "lib/ventilation/deep_stack.rb",
30
+ "test/test_helper.rb",
31
+ "test/ventilation_test.rb",
32
+ "uninstall.rb",
33
+ "ventilation.gemspec"
34
+ ]
35
+ s.homepage = %q{http://github.com/agoragames/ventilation}
36
+ s.rdoc_options = ["--charset=UTF-8"]
37
+ s.require_paths = ["lib"]
38
+ s.rubygems_version = %q{1.3.7}
39
+ s.summary = %q{Fancy ESI integration for your high prefomance web apps.}
40
+ s.test_files = [
41
+ "test/test_helper.rb",
42
+ "test/ventilation_test.rb"
43
+ ]
44
+
45
+ if s.respond_to? :specification_version then
46
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
47
+ s.specification_version = 3
48
+
49
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
+ s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
51
+ s.add_development_dependency(%q<fakeweb>, [">= 1.2.8"])
52
+ s.add_development_dependency(%q<mocha>, [">= 0.9.8"])
53
+ else
54
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
55
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
56
+ s.add_dependency(%q<mocha>, [">= 0.9.8"])
57
+ end
58
+ else
59
+ s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
60
+ s.add_dependency(%q<fakeweb>, [">= 1.2.8"])
61
+ s.add_dependency(%q<mocha>, [">= 0.9.8"])
62
+ end
63
+ end
64
+
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ventilation
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Blake Taylor
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-24 00:00:00 -04:00
19
+ default_executable:
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ - !ruby/object:Gem::Dependency
36
+ name: fakeweb
37
+ prerelease: false
38
+ requirement: &id002 !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ hash: 15
44
+ segments:
45
+ - 1
46
+ - 2
47
+ - 8
48
+ version: 1.2.8
49
+ type: :development
50
+ version_requirements: *id002
51
+ - !ruby/object:Gem::Dependency
52
+ name: mocha
53
+ prerelease: false
54
+ requirement: &id003 !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ hash: 43
60
+ segments:
61
+ - 0
62
+ - 9
63
+ - 8
64
+ version: 0.9.8
65
+ type: :development
66
+ version_requirements: *id003
67
+ description: Helper methods for building esi tags, simplifies development bypassing the need for varnish.
68
+ email: btaylor@agoragames.com
69
+ executables: []
70
+
71
+ extensions: []
72
+
73
+ extra_rdoc_files:
74
+ - README.markdown
75
+ files:
76
+ - .gitignore
77
+ - MIT-LICENSE
78
+ - README.markdown
79
+ - Rakefile
80
+ - VERSION
81
+ - init.rb
82
+ - install.rb
83
+ - lib/app/helpers/esi_helper.rb
84
+ - lib/tasks/ventilation.rake
85
+ - lib/ventilation.rb
86
+ - lib/ventilation/deep_stack.rb
87
+ - test/test_helper.rb
88
+ - test/ventilation_test.rb
89
+ - uninstall.rb
90
+ - ventilation.gemspec
91
+ has_rdoc: true
92
+ homepage: http://github.com/agoragames/ventilation
93
+ licenses: []
94
+
95
+ post_install_message:
96
+ rdoc_options:
97
+ - --charset=UTF-8
98
+ require_paths:
99
+ - lib
100
+ required_ruby_version: !ruby/object:Gem::Requirement
101
+ none: false
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ hash: 3
106
+ segments:
107
+ - 0
108
+ version: "0"
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ none: false
111
+ requirements:
112
+ - - ">="
113
+ - !ruby/object:Gem::Version
114
+ hash: 3
115
+ segments:
116
+ - 0
117
+ version: "0"
118
+ requirements: []
119
+
120
+ rubyforge_project:
121
+ rubygems_version: 1.3.7
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: Fancy ESI integration for your high prefomance web apps.
125
+ test_files:
126
+ - test/test_helper.rb
127
+ - test/ventilation_test.rb