Skip to content

Commit

Permalink
Convert rails plugin to gem.
Browse files Browse the repository at this point in the history
  • Loading branch information
Blake Taylor committed Sep 24, 2010
0 parents commit bbeb7df
Show file tree
Hide file tree
Showing 15 changed files with 221 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## MAC OS
.DS_Store

## TEXTMATE
*.tmproj
tmtags

## EMACS
*~
\#*
.\#*

## VIM
*.swp

## PROJECT::GENERAL
coverage
rdoc
pkg

## PROJECT::SPECIFIC
20 changes: 20 additions & 0 deletions MIT-LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2010 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
13 changes: 13 additions & 0 deletions README
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FancyEsi
========

Introduction goes here.


Example
=======

Example goes here.


Copyright (c) 2010 [name of plugin creator], released under the MIT license
42 changes: 42 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
require 'rake'
require 'rake/testtask'
require 'rake/rdoctask'

begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "fancy_esi"
gem.summary = %Q{Fancy ESI integration for your high prefomance web apps.}
gem.description = %Q{Helper methods for building esi tags, simplifies development bypassing the need for varnish.}
gem.email = "btaylor@agoragames.com"
gem.homepage = "http://github.com/blakefrost/fancy_esi"
gem.authors = ["Blake Taylor"]
gem.add_development_dependency "thoughtbot-shoulda", ">= 0"
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
end

desc 'Test fancy_esi.'
Rake::TestTask.new(:test) do |t|
t.libs << 'lib'
t.libs << 'test'
t.pattern = 'test/**/*_test.rb'
t.verbose = true
end

desc 'Default: run unit tests.'
task :default => :test

task :test => :check_dependencies

Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""

rdoc.rdoc_dir = 'rdoc'
rdoc.title = "fancy_esi #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.0
41 changes: 41 additions & 0 deletions fancy_esi.gemspec
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-

Gem::Specification.new do |s|
s.name = %q{fancy_esi}
s.version = "0.0.0"

s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Blake Taylor"]
s.date = %q{2010-09-24}
s.description = %q{Helper methods for building esi tags, simplifies development bypassing the need for varnish.}
s.email = %q{btaylor@agoragames.com}
s.extra_rdoc_files = [
"README"
]
s.homepage = %q{http://github.com/blakefrost/fancy_esi}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.summary = %q{Fancy ESI integration for your high prefomance web apps.}
s.test_files = [
"test/fancy_esi_test.rb",
"test/test_helper.rb"
]

if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3

if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<thoughtbot-shoulda>, [">= 0"])
else
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
end
else
s.add_dependency(%q<thoughtbot-shoulda>, [">= 0"])
end
end

1 change: 1 addition & 0 deletions init.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
require 'fancy_esi'
1 change: 1 addition & 0 deletions install.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Install hook code here
44 changes: 44 additions & 0 deletions lib/app/helpers/esi_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'net/http'
require 'uri'
require 'action_controller/test_process'

module EsiHelper
def esi(url_options)
env = ENV['RAILS_ENV']
# env = 'production'

if url_options[:action]
# Internal
case env
when 'production'
%%<esi:include src="#{url_for url_options}" max-age="0"/>%
else
if controller = url_options[:controller]
controller = "#{controller.to_s.camelcase}Controller".constantize
else
controller = @controller.class
end
deep_stack = DeepStack.new(controller)
action = url_options[:action]
deep_stack.get(action).body
end
else
# External
case env
when 'production'
%%<esi:include src="#{url_options[:host]}#{url_options[:path]}" max-age="0"/>%
else
host = url_options[:host]
path = url_options[:path]
url = URI.parse(host)
res = Net::HTTP.start(url.host, url.port) {|http|
http.get(path)
}
res.body
end

end

end

end
1 change: 1 addition & 0 deletions lib/fancy_esi.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# FancyEsi
20 changes: 20 additions & 0 deletions lib/fancy_esi/deep_stack.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class DeepStack
include ActionController::TestProcess

def initialize(controller_class)
@request = ActionController::TestRequest.new
@response = ActionController::TestResponse.new

# if klass = self.class.controller_class
# @controller ||= klass.new rescue nil
# end

@controller = controller_class.new

if @controller
@controller.request = @request
@controller.params = {}
@controller.send(:initialize_current_url)
end
end
end
4 changes: 4 additions & 0 deletions lib/tasks/fancy_esi.rake
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# desc "Explaining what the task does"
# task :fancy_esi do
# # Task goes here
# end
8 changes: 8 additions & 0 deletions test/fancy_esi_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
require 'test_helper'

class FancyEsiTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
3 changes: 3 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
require 'rubygems'
require 'active_support'
require 'active_support/test_case'
1 change: 1 addition & 0 deletions uninstall.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# Uninstall hook code here

0 comments on commit bbeb7df

Please sign in to comment.