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__), '..')
TWITTER_RSS =
'http://twitter.com/statuses/user_timeline/15042574.rss'
BLOG_ATOM =
'http://numbers.brighterplanet.com/latest.xml'
TIMEOUT =

seconds

5
S3_BUCKET =
'brighterplanetlayout'
VERSION =
'0.5.5'

Instance Method Summary collapse

Instance Method Details

#application_nameObject



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

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

#cdn_host(protocol) ⇒ Object



24
25
26
27
28
29
30
31
# File 'lib/brighter_planet_layout.rb', line 24

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



33
34
35
36
37
38
39
40
# File 'lib/brighter_planet_layout.rb', line 33

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)


79
80
81
# File 'lib/brighter_planet_layout.rb', line 79

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



59
60
61
62
63
64
65
66
67
68
69
# File 'lib/brighter_planet_layout.rb', line 59

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



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

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

#helper_fileObject



46
47
48
# File 'lib/brighter_planet_layout.rb', line 46

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

#heroku?Boolean

Returns:

  • (Boolean)


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

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

#include_application_javascript?Boolean

Returns:

  • (Boolean)


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

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

#include_application_stylesheet?Boolean

Returns:

  • (Boolean)


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

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

#install_layout_warningObject



71
72
73
# File 'lib/brighter_planet_layout.rb', line 71

def install_layout_warning
  ::FileUtils.touch layout_warning_file
end

#latest_blog_postObject



123
124
125
126
127
128
129
# File 'lib/brighter_planet_layout.rb', line 123

def latest_blog_post
  ::SimpleRSS.parse(eat(BLOG_ATOM)).entries.first
rescue ::SocketError, ::Timeout::Error, ::Errno::ETIMEDOUT, ::Errno::ENETUNREACH, ::Errno::ECONNRESET, ::Errno::ECONNREFUSED
  # nil
rescue ::NoMethodError
  # nil
end

#latest_tweetObject



115
116
117
118
119
120
121
# File 'lib/brighter_planet_layout.rb', line 115

def latest_tweet
  ::SimpleRSS.parse(eat(TWITTER_RSS)).entries.first
rescue ::SocketError, ::Timeout::Error, ::Errno::ETIMEDOUT, ::Errno::ENETUNREACH, ::Errno::ECONNRESET, ::Errno::ECONNREFUSED
  # nil
rescue ::NoMethodError
  # nil
end

#layout_warning_fileObject



50
51
52
# File 'lib/brighter_planet_layout.rb', line 50

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

#layout_warning_installed?Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/brighter_planet_layout.rb', line 75

def layout_warning_installed?
  ::File.readable? layout_warning_file
end

#public_pathObject



54
55
56
# File 'lib/brighter_planet_layout.rb', line 54

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

#rails_rootObject



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

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

#serve_static_files_using_rack?Boolean

Returns:

  • (Boolean)


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

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

#supports_asset_pipeline?Boolean

Returns:

  • (Boolean)


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

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

#view_pathObject



42
43
44
# File 'lib/brighter_planet_layout.rb', line 42

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