Class: BrighterPlanet::Layout

Inherits:
Object
  • Object
show all
Includes:
Singleton
Defined in:
lib/brighter_planet_layout.rb,
lib/brighter_planet_layout/railtie.rb,
lib/brighter_planet_layout/version.rb

Defined Under Namespace

Classes: Railtie

Constant Summary collapse

GEM_ROOT =
::File.expand_path ::File.join(::File.dirname(__FILE__), '..')
S3_BUCKET =
'brighterplanetlayout'
VERSION =
'0.5.6'

Instance Method Summary collapse

Instance Method Details

#application_nameObject



102
103
104
# File 'lib/brighter_planet_layout.rb', line 102

def application_name
  (::Rails::VERSION::MAJOR >= 3) ? ::Rails.application.name : ::APPLICATION_NAME
end

#asset_pipeline_probably_working?Boolean

3.2+

Returns:

  • (Boolean)


82
83
84
# File 'lib/brighter_planet_layout.rb', line 82

def asset_pipeline_probably_working?
  ::Rails::VERSION::MAJOR >= 3 and ::Rails::VERSION::MINOR > 1
end

#cdn_host(protocol) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/brighter_planet_layout.rb', line 18

def cdn_host(protocol)
  case protocol.to_s
  when 'https://'
    'do1ircpq72156.cloudfront.net'
  else
    'layout.brighterplanet.com'
  end
end

#cdn_url(path, protocol = 'http://') ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/brighter_planet_layout.rb', line 27

def cdn_url(path, protocol = 'http://')
  path = path.sub(%r{^/}, '')
  if ::Rails.env.production? and not ::ENV['DISABLE_BRIGHTER_PLANET_LAYOUT_CDN'] == 'true'
    "#{protocol}#{cdn_host(protocol)}/#{VERSION}/#{path}"
  else
    "/#{path}"
  end
end

#copy_static_files?Boolean

Returns:

  • (Boolean)


73
74
75
# File 'lib/brighter_planet_layout.rb', line 73

def copy_static_files?
  not heroku? and not serve_static_files_using_rack? and not layout_warning_installed?
end

#copy_static_files_to_web_server_document_rootObject

sabshere 11/17/10 now this is only really useful for syncing error pages



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/brighter_planet_layout.rb', line 53

def 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.sub(public_path, ''))
    if ::File.directory? source_path
      ::FileUtils.cp_r ::File.join(source_path, '.'), dest_path
    else
      ::FileUtils.cp source_path, dest_path
    end
  end
  install_layout_warning
end

#google_analytics_ua_numberObject



106
107
108
# File 'lib/brighter_planet_layout.rb', line 106

def google_analytics_ua_number
  (::Rails::VERSION::MAJOR >= 3) ? ::Rails.application.google_analytics_ua_number : ::GOOGLE_ANALYTICS_UA_NUMBER
end

#helper_fileObject



40
41
42
# File 'lib/brighter_planet_layout.rb', line 40

def helper_file
  ::File.join GEM_ROOT, 'app', 'helpers', 'brighter_planet_helper.rb'
end

#heroku?Boolean

Returns:

  • (Boolean)


77
78
79
# File 'lib/brighter_planet_layout.rb', line 77

def heroku?
  ::File.readable? '/home/heroku_rack/heroku.ru'
end

#include_application_javascript?Boolean

Returns:

  • (Boolean)


90
91
92
# File 'lib/brighter_planet_layout.rb', line 90

def include_application_javascript?
  supports_asset_pipeline? || File.exist?(File.join(rails_root, 'public', 'javascripts', 'application.js'))
end

#include_application_stylesheet?Boolean

Returns:

  • (Boolean)


86
87
88
# File 'lib/brighter_planet_layout.rb', line 86

def include_application_stylesheet?
  supports_asset_pipeline? || File.exist?(File.join(rails_root, 'public', 'stylesheets', 'application.css'))
end

#install_layout_warningObject



65
66
67
# File 'lib/brighter_planet_layout.rb', line 65

def install_layout_warning
  ::FileUtils.touch layout_warning_file
end

#layout_warning_fileObject



44
45
46
# File 'lib/brighter_planet_layout.rb', line 44

def layout_warning_file
  ::File.join rails_root, 'public', "BRIGHTER_PLANET_LAYOUT_VERSION_#{VERSION}"
end

#layout_warning_installed?Boolean

Returns:

  • (Boolean)


69
70
71
# File 'lib/brighter_planet_layout.rb', line 69

def layout_warning_installed?
  ::File.readable? layout_warning_file
end

#public_pathObject



48
49
50
# File 'lib/brighter_planet_layout.rb', line 48

def public_path
  ::File.join GEM_ROOT, 'public'
end

#rails_rootObject



110
111
112
# File 'lib/brighter_planet_layout.rb', line 110

def rails_root
  ::Rails.respond_to?(:root) ? ::Rails.root : ::RAILS_ROOT
end

#serve_static_files_using_rack?Boolean

Returns:

  • (Boolean)


98
99
100
# File 'lib/brighter_planet_layout.rb', line 98

def serve_static_files_using_rack?
  not ::Rails.env.production? and not heroku?
end

#supports_asset_pipeline?Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/brighter_planet_layout.rb', line 94

def supports_asset_pipeline?
  Rails::VERSION::MAJOR >= 3 && Rails::VERSION::MINOR >= 1
end

#view_pathObject



36
37
38
# File 'lib/brighter_planet_layout.rb', line 36

def view_path
  ::File.join GEM_ROOT, 'app', 'views'
end