Permalink
Browse files

make this work with rails2

do a lot of namespace forcing on the side
  • Loading branch information...
1 parent 1652927 commit 06fd712c2dbe73280de138f41bb12cf1b7c63669 @seamusabshere seamusabshere committed Jul 29, 2010
View
15 README.rdoc
@@ -1,16 +1,11 @@
= brighter_planet_layout
-Description goes here.
+== Requirements
-== Note on Patches/Pull Requests
-
-* Fork the project.
-* Make your feature addition or bug fix.
-* Add tests for it. This is important so I don't break it in a
- future version unintentionally.
-* Commit, do not mess with rakefile, version, or history.
- (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
-* Send me a pull request. Bonus points for topic branches.
+* You need to create <tt>app/views/layouts/_title.html.erb</tt> with something like:
+
+ <h1>APPLICATION_NAME</h1>
+ <h2>THE SOCIAL WEB APP</h2>
== Copyright
View
2 app/helpers/brighter_planet_helper.rb
@@ -3,7 +3,7 @@ module BrighterPlanetHelper
def render_or_nothing(*args)
begin
render(*args)
- rescue ActionView::MissingTemplate
+ rescue ::ActionView::MissingTemplate
nil
end
end
View
2 app/views/layouts/_google_analytics.html.erb
@@ -1,6 +1,6 @@
<% javascript_tag do %>
var _gaq = _gaq || [];
- _gaq.push(['_setAccount', '<%= Rails.application.google_analytics_ua_number %>']);
+ _gaq.push(['_setAccount', '<%= ::BrighterPlanetLayout.google_analytics_ua_number %>']);
_gaq.push(['_trackPageview']);
(function() {
View
4 app/views/layouts/brighter_planet.html.erb
@@ -1,12 +1,12 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en" dir="ltr" id="brighterplanet-com">
<head>
- <title><%= title = @title ? "#{@title} [#{Rails.application.name}]" : Rails.application.name %></title>
+ <title><%= title = @title ? "#{@title} [#{::BrighterPlanetLayout.application_name}]" : ::BrighterPlanetLayout.application_name %></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="Content-Language" content="en" />
<%= stylesheet_link_tag 'brighter_planet', 'application', 'idle' %>
<%= javascript_include_tag :defaults %>
- <%= csrf_meta_tag %>
+ <%= csrf_meta_tag if ::Rails::VERSION::MAJOR == 3 %>
<link rel="shortcut icon" type="image/ico" href="/favicon.ico" />
<%= render_or_nothing :partial => 'layouts/head' %>
<%= yield :head %>
View
48 lib/brighter_planet_layout.rb
@@ -2,56 +2,72 @@
require 'yaml'
module BrighterPlanetLayout
- GEM_ROOT = File.expand_path File.join(File.dirname(__FILE__), '..')
- VERSION = YAML.load File.read(File.join(GEM_ROOT, 'VERSION'))
+ GEM_ROOT = ::File.expand_path ::File.join(::File.dirname(__FILE__), '..')
+ VERSION = ::YAML.load ::File.read(::File.join(GEM_ROOT, 'VERSION'))
def self.view_path
- File.join GEM_ROOT, 'app', 'views'
+ ::File.join GEM_ROOT, 'app', 'views'
end
def self.helper_file
- File.join GEM_ROOT, 'app', 'helpers', 'brighter_planet_helper.rb'
+ ::File.join GEM_ROOT, 'app', 'helpers', 'brighter_planet_helper.rb'
end
def self.layout_warning_file
- File.join Rails.root, 'public', "BRIGHTER_PLANET_LAYOUT_VERSION_#{VERSION}"
+ ::File.join rails_root, 'public', "BRIGHTER_PLANET_LAYOUT_VERSION_#{VERSION}"
end
def self.public_path
- File.join GEM_ROOT, 'public'
+ ::File.join GEM_ROOT, 'public'
end
def self.copy_static_files_to_web_server_document_root
- Dir[File.join(public_path, '*')].each do |source_path|
- dest_path = File.join(Rails.root, 'public', source_path.gsub(public_path, ''))
- if File.directory? source_path
- FileUtils.cp_r source_path.concat('/.'), dest_path
+ ::Dir[::File.join(public_path, '*')].each do |source_path|
+ dest_path = ::File.join(rails_root, 'public', source_path.gsub(public_path, ''))
+ if ::File.directory? source_path
+ ::FileUtils.cp_r source_path.concat('/.'), dest_path
else
- FileUtils.cp source_path, dest_path
+ ::FileUtils.cp source_path, dest_path
end
end
install_layout_warning
end
def self.install_layout_warning
- FileUtils.touch layout_warning_file
+ ::FileUtils.touch layout_warning_file
end
def self.layout_warning_installed?
- File.readable? layout_warning_file
+ ::File.readable? layout_warning_file
end
def self.copy_static_files?
not heroku? and not serve_static_files_using_rack? and not layout_warning_installed?
end
def self.heroku?
- File.readable? '/home/heroku_rack/heroku.ru'
+ ::File.readable? '/home/heroku_rack/heroku.ru'
end
def self.serve_static_files_using_rack?
- not heroku? and not Rails.env.production?
+ not heroku? and not ::Rails.env.production?
+ end
+
+ def self.application_name
+ ::Rails::VERSION::MAJOR == 3 ? ::Rails.application.name : ::APPLICATION_NAME
+ end
+
+ def self.google_analytics_ua_number
+ ::Rails::VERSION::MAJOR == 3 ? ::Rails.application.google_analytics_ua_number : ::GOOGLE_ANALYTICS_UA_NUMBER
+ end
+
+ def self.rails_root
+ ::Rails.respond_to? :root ? ::Rails.root : ::RAILS_ROOT
end
end
-require 'brighter_planet_layout/railtie'
+if defined? ::Rails::Railtie and ::Rails::VERSION::MAJOR == 3
+ require 'brighter_planet_layout/railtie'
+elsif defined? ::Rails and ::Rails::VERSION::MAJOR == 2
+ require 'brighter_planet_layout/rails'
+end
View
10 lib/brighter_planet_layout/rails.rb
@@ -0,0 +1,10 @@
+if defined? ::Rails and ::Rails::VERSION::MAJOR == 2
+ require 'brighter_planet_layout'
+ require ::BrighterPlanetLayout.helper_file
+ ::Rails.configuration.to_prepare do
+ ::ApplicationController.helper ::BrighterPlanetHelper
+ ::ApplicationController.layout 'brighter_planet'
+ # sabshere 7/29/10 the view path appears to be magically appended
+ # ::ApplicationController.append_view_path ::BrighterPlanetLayout.view_path
+ end
+end
View
18 lib/brighter_planet_layout/railtie.rb
@@ -1,21 +1,21 @@
module BrighterPlanetLayout
- class Railtie < Rails::Railtie
+ class Railtie < ::Rails::Railtie
rake_tasks do
load 'brighter_planet_layout/rake_tasks.rb'
end
initializer 'brighter_planet_layout' do |app|
- app.paths.app.views.push BrighterPlanetLayout.view_path
- if BrighterPlanetLayout.serve_static_files_using_rack?
- app.middleware.use '::ActionDispatch::Static', BrighterPlanetLayout.public_path
+ app.paths.app.views.push ::BrighterPlanetLayout.view_path
+ if ::BrighterPlanetLayout.serve_static_files_using_rack?
+ app.middleware.use '::ActionDispatch::Static', ::BrighterPlanetLayout.public_path
end
- if BrighterPlanetLayout.copy_static_files?
- BrighterPlanetLayout.copy_static_files_to_web_server_document_root
+ if ::BrighterPlanetLayout.copy_static_files?
+ ::BrighterPlanetLayout.copy_static_files_to_web_server_document_root
end
end
config.to_prepare do
- require BrighterPlanetLayout.helper_file
- ApplicationController.helper BrighterPlanetHelper
- ApplicationController.layout 'brighter_planet'
+ require ::BrighterPlanetLayout.helper_file
+ ::ApplicationController.helper ::BrighterPlanetHelper
+ ::ApplicationController.layout 'brighter_planet'
end
end
end
View
2 lib/brighter_planet_layout/rake_tasks.rb
@@ -1,5 +1,5 @@
namespace :brighter_planet_layout do
task :copy_static_files => :environment do
- BrighterPlanetLayout.copy_static_files_to_web_server_document_root
+ ::BrighterPlanetLayout.copy_static_files_to_web_server_document_root
end
end
View
3 rails/init.rb
@@ -0,0 +1,3 @@
+if defined? ::Rails and ::Rails::VERSION::MAJOR == 2
+ require 'brighter_planet_layout/rails'
+end

0 comments on commit 06fd712

Please sign in to comment.