Module: BrighterPlanetLayout
- Defined in:
- lib/brighter_planet_layout.rb,
lib/brighter_planet_layout/railtie.rb
Defined Under Namespace
Classes: Railtie
Constant Summary collapse
- GEM_ROOT =
::File. ::File.join(::File.dirname(__FILE__), '..')
- VERSION =
::YAML.load ::File.read(::File.join(GEM_ROOT, 'VERSION'))
- TWITTER_RSS =
'http://twitter.com/statuses/user_timeline/15042574.rss'
- BLOG_ATOM =
'http://numbers.brighterplanet.com/latest.xml'
- TIMEOUT =
seconds
5
- CDN =
'do1ircpq72156.cloudfront.net'
- S3_BUCKET =
'brighterplanetlayout'
Class Method Summary collapse
- .application_name ⇒ Object
- .copy_static_files? ⇒ Boolean
-
.copy_static_files_to_web_server_document_root ⇒ Object
sabshere 11/17/10 now this is only really useful for syncing error pages.
-
.get(url) ⇒ Object
sabshere 11/17/10 thanks dkastner.
- .google_analytics_ua_number ⇒ Object
- .helper_file ⇒ Object
- .heroku? ⇒ Boolean
- .install_layout_warning ⇒ Object
- .latest_blog_post ⇒ Object
- .latest_tweet ⇒ Object
- .layout_warning_file ⇒ Object
- .layout_warning_installed? ⇒ Boolean
- .public_path ⇒ Object
- .rails_root ⇒ Object
- .serve_static_files_using_rack? ⇒ Boolean
- .timer ⇒ Object
-
.update_s3 ⇒ Object
sabshere 11/17/10 not worth it –cache-control="public, max-age=7776000".
- .view_path ⇒ Object
Class Method Details
.application_name ⇒ Object
65 66 67 |
# File 'lib/brighter_planet_layout.rb', line 65 def self.application_name (::Rails::VERSION::MAJOR == 3) ? ::Rails.application.name : ::APPLICATION_NAME end |
.copy_static_files? ⇒ Boolean
53 54 55 |
# File 'lib/brighter_planet_layout.rb', line 53 def self.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_root ⇒ Object
sabshere 11/17/10 now this is only really useful for syncing error pages
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/brighter_planet_layout.rb', line 33 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 else ::FileUtils.cp source_path, dest_path end end install_layout_warning end |
.get(url) ⇒ Object
sabshere 11/17/10 thanks dkastner
98 99 100 101 102 103 104 105 106 |
# File 'lib/brighter_planet_layout.rb', line 98 def self.get(url) uri = ::URI.parse url response = timer.timeout(TIMEOUT) do ::Net::HTTP.start(uri.host, uri.port) do |http| http.get [uri.path, uri.query].compact.join('?') end end response.body end |
.google_analytics_ua_number ⇒ Object
69 70 71 |
# File 'lib/brighter_planet_layout.rb', line 69 def self.google_analytics_ua_number (::Rails::VERSION::MAJOR == 3) ? ::Rails.application.google_analytics_ua_number : ::GOOGLE_ANALYTICS_UA_NUMBER end |
.helper_file ⇒ Object
20 21 22 |
# File 'lib/brighter_planet_layout.rb', line 20 def self.helper_file ::File.join GEM_ROOT, 'app', 'helpers', 'brighter_planet_helper.rb' end |
.heroku? ⇒ Boolean
57 58 59 |
# File 'lib/brighter_planet_layout.rb', line 57 def self.heroku? ::File.readable? '/home/heroku_rack/heroku.ru' end |
.install_layout_warning ⇒ Object
45 46 47 |
# File 'lib/brighter_planet_layout.rb', line 45 def self.install_layout_warning ::FileUtils.touch layout_warning_file end |
.latest_blog_post ⇒ Object
85 86 87 88 89 90 91 |
# File 'lib/brighter_planet_layout.rb', line 85 def self.latest_blog_post ::SimpleRSS.parse(get(BLOG_ATOM)).entries.first rescue ::SocketError, ::Timeout::Error, ::Errno::ETIMEDOUT, ::Errno::ENETUNREACH, ::Errno::ECONNRESET, ::Errno::ECONNREFUSED # nil rescue ::NoMethodError # nil end |
.latest_tweet ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/brighter_planet_layout.rb', line 77 def self.latest_tweet ::SimpleRSS.parse(get(TWITTER_RSS)).entries.first rescue ::SocketError, ::Timeout::Error, ::Errno::ETIMEDOUT, ::Errno::ENETUNREACH, ::Errno::ECONNRESET, ::Errno::ECONNREFUSED # nil rescue ::NoMethodError # nil end |
.layout_warning_file ⇒ Object
24 25 26 |
# File 'lib/brighter_planet_layout.rb', line 24 def self.layout_warning_file ::File.join rails_root, 'public', "BRIGHTER_PLANET_LAYOUT_VERSION_#{VERSION}" end |
.layout_warning_installed? ⇒ Boolean
49 50 51 |
# File 'lib/brighter_planet_layout.rb', line 49 def self.layout_warning_installed? ::File.readable? layout_warning_file end |
.public_path ⇒ Object
28 29 30 |
# File 'lib/brighter_planet_layout.rb', line 28 def self.public_path ::File.join GEM_ROOT, 'public' end |
.rails_root ⇒ Object
73 74 75 |
# File 'lib/brighter_planet_layout.rb', line 73 def self.rails_root ::Rails.respond_to?(:root) ? ::Rails.root : ::RAILS_ROOT end |
.serve_static_files_using_rack? ⇒ Boolean
61 62 63 |
# File 'lib/brighter_planet_layout.rb', line 61 def self.serve_static_files_using_rack? not ::Rails.env.production? and not heroku? end |
.timer ⇒ Object
93 94 95 |
# File 'lib/brighter_planet_layout.rb', line 93 def self.timer defined?(::SystemTimer) ? ::SystemTimer : ::Timeout end |
.update_s3 ⇒ Object
sabshere 11/17/10 not worth it –cache-control="public, max-age=7776000"
109 110 111 112 113 114 115 116 117 |
# File 'lib/brighter_planet_layout.rb', line 109 def self.update_s3 # ENV['AWS_ACCESS_KEY_ID'] = # ENV['AWS_SECRET_ACCESS_KEY'] = # ENV['SSL_CERT_DIR'] = # ENV['S3SYNC_DIR'] = ::ENV['S3SYNC_NATIVE_CHARSET'] = 'UTF-8' cmd = "ruby #{ENV['S3SYNC_DIR']}/s3sync.rb --exclude=\"\\.ai\" --exclude=\"\\.psd\" -v -r --ssl --public-read #{public_path}/ #{S3_BUCKET}:#{VERSION}/" `#{cmd}` end |
.view_path ⇒ Object
16 17 18 |
# File 'lib/brighter_planet_layout.rb', line 16 def self.view_path ::File.join GEM_ROOT, 'app', 'views' end |