Skip to content

Commit

Permalink
Merge branch 'master' of git://github.com/resolve/refinerycms
Browse files Browse the repository at this point in the history
  • Loading branch information
ugisozols committed Sep 3, 2010
2 parents 56f0615 + 7df7d4e commit f7820fb
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 84 deletions.
2 changes: 1 addition & 1 deletion Gemfile
Expand Up @@ -42,7 +42,7 @@ gem 'refinerycms-inquiries', '~> 0.9.8.4', :require => 'inquiries'
# gem 'refinerycms-theming', '~> 0.9.8', :require => 'theming'

# Add i18n support (optional, you can remove this if you really want to).
gem 'refinerycms-i18n', '~> 0.9.8.3', :require => 'refinery/i18n'
gem 'refinerycms-i18n', '~> 0.9.8.4', :require => 'refinery/i18n'

# Specify a version of RMagick that works in your environment:
gem 'rmagick', '~> 2.12.0', :require => false
Expand Down
15 changes: 8 additions & 7 deletions Gemfile.lock
@@ -1,6 +1,6 @@
GIT
remote: git://github.com/alan/rack-test.git
revision: 167c2b2ca4c32b1645ec29d9a82d4e022d73bb7a
revision: 8ae89a2cbcfac129a66da86091994727b094f73c
specs:
rack-test (0.5.4)
rack (>= 1.0)
Expand All @@ -24,7 +24,7 @@ PATH
GEM
remote: http://rubygems.org/
specs:
ZenTest (4.3.3)
ZenTest (4.4.0)
abstract (1.0.0)
actionmailer (3.0.0)
actionpack (= 3.0.0)
Expand Down Expand Up @@ -84,16 +84,16 @@ GEM
culerity (0.2.12)
database_cleaner (0.5.2)
diff-lcs (1.1.2)
dragonfly (0.7.4)
dragonfly (0.7.5)
rack
erubis (2.6.6)
abstract (>= 1.0.0)
factory_girl (1.3.2)
ffi (0.6.3)
rake (>= 0.8.7)
filters_spam (0.2)
friendly_id (3.1.3)
babosa (>= 0.1.0)
friendly_id (3.1.6)
babosa (~> 0.2.0)
gherkin (2.1.5)
trollop (~> 1.16.2)
i18n (0.4.1)
Expand Down Expand Up @@ -129,7 +129,8 @@ GEM
rake (>= 0.8.4)
thor (~> 0.14.0)
rake (0.8.7)
refinerycms-i18n (0.9.8.3)
refinerycms-i18n (0.9.8.4)
refinerycms (~> 0.9.8)
routing-filter (~> 0.1.6)
refinerycms-inquiries (0.9.8.4)
filters_spam (~> 0.1)
Expand Down Expand Up @@ -182,7 +183,7 @@ DEPENDENCIES
rack-test!
rails (= 3.0.0)
refinerycms!
refinerycms-i18n (~> 0.9.8.3)
refinerycms-i18n (~> 0.9.8.4)
refinerycms-inquiries (~> 0.9.8.4)
rmagick (~> 2.12.0)
rspec (~> 2.0.0.beta)
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/application_controller.rb
Expand Up @@ -3,6 +3,7 @@

# You can extend refinery with your own functions here and they will likely not get overriden in an update.

class ApplicationController < Refinery::ApplicationController
class ApplicationController < ActionController::Base
include Refinery::ApplicationController

end
160 changes: 85 additions & 75 deletions vendor/refinerycms/core/lib/refinery/application_controller.rb
@@ -1,101 +1,111 @@
require 'action_controller'

class Refinery::ApplicationController < ActionController::Base
module Refinery::ApplicationController

helper_method :home_page?,
:local_request?,
:just_installed?,
:from_dialog?,
:admin?,
:login?
def self.included(controller)
controller.send :include, InstanceMethods
controller.send :include, ClassMethods
end

protect_from_forgery # See ActionController::RequestForgeryProtection
module ClassMethods
def self.included(c) # Extend controller
c.helper_method :home_page?,
:local_request?,
:just_installed?,
:from_dialog?,
:admin?,
:login?

include Crud # basic create, read, update and delete methods
include AuthenticatedSystem
c.protect_from_forgery # See ActionController::RequestForgeryProtection

before_filter :find_pages_for_menu,
:show_welcome_page?
c.send :include, Crud # basic create, read, update and delete methods
c.send :include, AuthenticatedSystem

after_filter :store_current_location!,
:if => Proc.new {|c| c.send(:refinery_user?) rescue false }
c.send :before_filter, :find_pages_for_menu,
:show_welcome_page?

rescue_from ActiveRecord::RecordNotFound,
ActionController::UnknownAction,
ActionView::MissingTemplate,
:with => :error_404
c.send :after_filter, :store_current_location!,
:if => Proc.new {|c| c.send(:refinery_user?) rescue false }

def admin?
controller_name =~ %r{^admin/}
c.send :rescue_from, ActiveRecord::RecordNotFound,
ActionController::UnknownAction,
ActionView::MissingTemplate,
:with => :error_404
end
end

def error_404(exception=nil)
if (@page = Page.where(:menu_match => "^/404$").includes(:parts, :slugs).first).present?
# render the application's custom 404 page with layout and meta.
render :template => "/pages/show",
:format => 'html',
:status => 404
else
# fallback to the default 404.html page.
file = Rails.root.join('public', '404.html')
file = Refinery.root.join('vendor', 'refinerycms', 'core', 'public', '404.html') unless file.exist?
render :file => file.cleanpath.to_s,
:layout => false,
:status => 404
module InstanceMethods
def admin?
controller_name =~ %r{^admin/}
end
end

def from_dialog?
params[:dialog] == "true" or params[:modal] == "true"
end
def error_404(exception=nil)
if (@page = Page.where(:menu_match => "^/404$").includes(:parts, :slugs).first).present?
# render the application's custom 404 page with layout and meta.
render :template => "/pages/show",
:format => 'html',
:status => 404
else
# fallback to the default 404.html page.
file = Rails.root.join('public', '404.html')
file = Refinery.root.join('vendor', 'refinerycms', 'core', 'public', '404.html') unless file.exist?
render :file => file.cleanpath.to_s,
:layout => false,
:status => 404
end
end

def home_page?
root_url(:only_path => true) == request.path
end
def from_dialog?
params[:dialog] == "true" or params[:modal] == "true"
end

def just_installed?
Role[:refinery].users.empty?
end
def home_page?
root_url(:only_path => true) == request.path
end

def local_request?
Rails.env.development? or request.remote_ip =~ /(::1)|(127.0.0.1)|((192.168).*)/
end
def just_installed?
Role[:refinery].users.empty?
end

def login?
(controller_name =~ /^(user|session)(|s)/ and not admin?) or just_installed?
end
def local_request?
Rails.env.development? or request.remote_ip =~ /(::1)|(127.0.0.1)|((192.168).*)/
end

protected
def login?
(controller_name =~ /^(user|session)(|s)/ and not admin?) or just_installed?
end

# get all the pages to be displayed in the site menu.
def find_pages_for_menu
@menu_pages = Page.top_level
end
protected

# use a different model for the meta information.
def present(model)
presenter = (Object.const_get("#{model.class}Presenter") rescue ::Refinery::BasePresenter)
@meta = presenter.new(model)
end
# get all the pages to be displayed in the site menu.
def find_pages_for_menu
@menu_pages = Page.top_level
end

# this hooks into the Rails render method.
def render(action = nil, options = {}, &blk)
present(@page) unless admin? or @meta.present?
super
end
# use a different model for the meta information.
def present(model)
presenter = (Object.const_get("#{model.class}Presenter") rescue ::Refinery::BasePresenter)
@meta = presenter.new(model)
end

def show_welcome_page?
render :template => "/welcome", :layout => "login" if just_installed? and controller_name != "users"
end
# this hooks into the Rails render method.
def render(action = nil, options = {}, &blk)
present(@page) unless admin? or @meta.present?
super
end

private
def store_current_location!
if admin?
# ensure that we don't redirect to AJAX or POST/PUT/DELETE urls
session[:refinery_return_to] = request.path if request.get? and !request.xhr? and !from_dialog?
elsif defined?(@page) and @page.present?
session[:website_return_to] = @page.url
def show_welcome_page?
render :template => "/welcome", :layout => "login" if just_installed? and controller_name != "users"
end
end

private
def store_current_location!
if admin?
# ensure that we don't redirect to AJAX or POST/PUT/DELETE urls
session[:refinery_return_to] = request.path if request.get? and !request.xhr? and !from_dialog?
elsif defined?(@page) and @page.present?
session[:website_return_to] = @page.url
end
end
end
end
6 changes: 6 additions & 0 deletions vendor/refinerycms/images/lib/images.rb
Expand Up @@ -22,6 +22,12 @@ class Engine < Rails::Engine
app_images.analyser.register(Dragonfly::Analysis::RMagickAnalyser)
app_images.analyser.register(Dragonfly::Analysis::FileCommandAnalyser)

# This little eval makes it so that dragonfly urls work in traditional
# situations where the filename and extension are required, e.g. lightbox.
# What this does is takes the url that is about to be produced e.g.
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw
# and adds the filename onto the end (say the image was 'refinery_is_awesome.jpg')
# /system/images/BAhbB1sHOgZmIiMyMDEwLzA5LzAxL1NTQ19DbGllbnRfQ29uZi5qcGdbCDoGcDoKdGh1bWIiDjk0MngzNjAjYw/refinery_is_awesome.jpg
app_images.instance_eval %{
def url_for(job, *args)
image_url = nil
Expand Down

0 comments on commit f7820fb

Please sign in to comment.