From edddebd4f1c8c33da767909ce20ed27b9f8eddf4 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Mon, 12 Mar 2012 23:03:16 -0400 Subject: [PATCH 1/2] added support for images in compass --- lib/attentive/compass_patches.rb | 21 +++++++++++++++++++++ lib/attentive/server.rb | 20 +++++++++++++++++++- 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 lib/attentive/compass_patches.rb diff --git a/lib/attentive/compass_patches.rb b/lib/attentive/compass_patches.rb new file mode 100644 index 0000000..8d74caf --- /dev/null +++ b/lib/attentive/compass_patches.rb @@ -0,0 +1,21 @@ +module Compass::RailsImageFunctionPatch + private + + def image_path_for_size(image_file) + begin + file = ::Attentive::Server.sprockets_env.find_asset(image_file) + return file + rescue ::Sprockets::FileOutsidePaths + return super(image_file) + end + end +end + +module Sass::Script::Functions + include Compass::RailsImageFunctionPatch +end + +# Wierd that this has to be re-included to pick up sub-modules. Ruby bug? +class Sass::Script::Functions::EvaluationContext + include Sass::Script::Functions +end \ No newline at end of file diff --git a/lib/attentive/server.rb b/lib/attentive/server.rb index c66f2da..7d896ca 100644 --- a/lib/attentive/server.rb +++ b/lib/attentive/server.rb @@ -2,6 +2,7 @@ require 'sprockets' require 'sprockets-vendor_gems' require 'sprockets-sass' require 'compass' +require 'attentive/compass_patches' require 'sinatra' require 'nokogiri' require 'rdiscount' @@ -13,7 +14,23 @@ require 'rack/builder' require 'forwardable' module Attentive + module Helpers + def image_path(path, options) + if resolve(path, options) + return "/assets/#{path}" + end + + nil + end + + + end class Server < Rack::Builder + + def self.sprockets_env + @sprockets_env ||= Sprockets::EnvironmentWithVendoredGems.new + end + def self.start(options) require 'rack' require 'pygments' @@ -31,12 +48,13 @@ module Attentive def self.call(env) @app ||= Rack::Builder.new do map '/assets' do - env = Sprockets::EnvironmentWithVendoredGems.new + env = ::Attentive::Server.sprockets_env env.append_path 'assets/javascripts' env.append_path 'assets/stylesheets' env.append_path 'assets/images' env.append_path Attentive.root.join('lib/assets/javascripts') env.append_path Attentive.root.join('lib/assets/stylesheets') + env.context_class.send(:include, ::Attentive::Helpers) run env end From 5ccb9e192307fc1585ddd73a494bb8c0373bc798 Mon Sep 17 00:00:00 2001 From: Scott Davis Date: Mon, 12 Mar 2012 23:03:28 -0400 Subject: [PATCH 2/2] updated layout --- views/index.haml | 1 + views/layout.haml | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/views/index.haml b/views/index.haml index 478fb00..ae23d9b 100644 --- a/views/index.haml +++ b/views/index.haml @@ -1,3 +1,4 @@ #slides-container #slides= slides + = haml :"_footer" diff --git a/views/layout.haml b/views/layout.haml index 724e235..98fff56 100644 --- a/views/layout.haml +++ b/views/layout.haml @@ -3,8 +3,8 @@ %head %title= Attentive.title %script{:type => 'text/javascript', :src => 'assets/application.js'} - %link{:rel => 'stylesheet', :href => 'assets/application.css', :type => 'text/css'}/ %style{:type => 'text/css'}= Pygments.css + %link{:rel => 'stylesheet', :href => 'assets/application.css', :type => 'text/css'}/ = haml :"_header" %body.loading = yield