Skip to content

Commit

Permalink
no rack patching
Browse files Browse the repository at this point in the history
  • Loading branch information
minad committed Oct 22, 2012
1 parent c50e25b commit 347b843
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 21 deletions.
1 change: 0 additions & 1 deletion config.ru
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ $: << ::File.join(app_path, 'lib')
Encoding.default_external = Encoding::UTF_8

require 'fileutils'
require 'rack/olelo_patches'
require 'rack/relative_redirect'
require 'rack/static_cache'
require 'olelo'
Expand Down
1 change: 1 addition & 0 deletions lib/olelo.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
require 'set'
require 'yaml'
require 'mimemagic'
require 'socket'

begin
require 'yajl/json_gem'
Expand Down
4 changes: 2 additions & 2 deletions lib/olelo/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -85,8 +85,8 @@ def validate_password(password, confirm)

def anonymous(request)
ip = request.ip || 'unknown-ip'
name = request.remote_host ? "#{request.remote_host} (#{ip})" : ip
new(name, "anonymous@#{ip}")
host = request.ip && Socket.gethostbyaddr(request.ip.split('.').map(&:to_i).pack('C*')).first rescue nil
new(host ? "#{host} (#{ip})" : ip, "anonymous@#{ip}")
end

def find!(name)
Expand Down
4 changes: 4 additions & 0 deletions lib/olelo/util.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ def self.included(base)

extend self

def no_cache?(env = @env)
env['HTTP_PRAGMA'] == 'no-cache' || env['HTTP_CACHE_CONTROL'].to_s.include?('no-cache')
end

def check
errors = []
yield(errors)
Expand Down
14 changes: 0 additions & 14 deletions lib/rack/olelo_patches.rb

This file was deleted.

6 changes: 3 additions & 3 deletions plugins/aspects/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def call(context, page)
# Plug-in the aspect subsystem
module ::Olelo::PageHelper
def render_page(page)
Cache.cache("include-#{page.path}-#{page.version.cache_id}", :update => request.no_cache?, :defer => true) do |context|
Cache.cache("include-#{page.path}-#{page.version.cache_id}", :update => no_cache?, :defer => true) do |context|
begin
context = Context.new(:page => page, :params => {:included => true})
Aspect.find!(page, :layout => true).call(context, page)
Expand All @@ -163,7 +163,7 @@ def show_page
params[:aspect] ||= 'subpages' if params[:path].to_s.ends_with? '/'
@selected_aspect, layout, header, content =
Cache.cache("aspect-#{page.path}-#{page.version.cache_id}-#{build_query(params)}",
:update => request.no_cache?, :defer => true) do |cache|
:update => no_cache?, :defer => true) do |cache|
aspect = Aspect.find!(page, :name => params[:aspect])
cache.disable! if !aspect.cacheable?
context = Context.new(:page => page, :params => params, :request => request)
Expand All @@ -187,7 +187,7 @@ def show_page
hook :menu do |menu|
if menu.name == :actions && view_menu = menu[:view]
Cache.cache("aspect-menu-#{page.path}-#{page.version.cache_id}-#{@selected_aspect}",
:update => request.no_cache?, :defer => true) do
:update => no_cache?, :defer => true) do
aspects = Aspect.find_all(page).select {|a| !a.hidden? || a.name == @selected_aspect || a.name == page.attributes['aspect'] }.map do |a|
[Locale.translate("aspect_#{a.name}", :fallback => titlecase(a.name)), a]
end.sort_by(&:first)
Expand Down
2 changes: 1 addition & 1 deletion plugins/blog/main.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
Tags::Tag.define 'menu', :optional => 'path', :description => 'Show blog menu', :dynamic => true do |context, attrs, content|
page = Page.find(attrs[:path]) rescue nil
if page
Cache.cache("blog-#{page.path}-#{page.version.cache_id}", :update => context.request.no_cache?, :defer => true) do
Cache.cache("blog-#{page.path}-#{page.version.cache_id}", :update => no_cache?(context.request.env), :defer => true) do
years = {}
page.children.each do |child|
(years[child.version.date.year] ||= [])[child.version.date.month] = true
Expand Down

0 comments on commit 347b843

Please sign in to comment.