Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper: file_exist (in sass-extension) #1957

Open
wants to merge 1 commit into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion core/lib/compass/core/sass_extensions/functions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def declare(*args)
inline_image image_size constants gradient_support
font_files lists colors math
env cross_browser_support configuration
files
files file_exist
).each do |func|
require "compass/core/sass_extensions/functions/#{func}"
end
Expand All @@ -33,6 +33,7 @@ module Sass::Script::Functions
include Compass::Core::SassExtensions::Functions::Math
include Compass::Core::SassExtensions::Functions::CrossBrowserSupport
include Compass::Core::SassExtensions::Functions::Env
include Compass::Core::SassExtensions::Functions::FileExist
end

# Wierd that this has to be re-included to pick up sub-modules. Ruby bug?
Expand Down
24 changes: 24 additions & 0 deletions core/lib/compass/core/sass_extensions/functions/file_exist.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
module Compass::SassExtensions::Functions::FileExist
def file_exist(image_file)
image_file = image_file.value # get to the string value of the literal.

# Compute the real path to the image on the file stystem if the generated_images_dir is set.
real_path = if Compass.configuration.images_path
images_path = Compass.configuration.images_path
if Pathname.new(images_path).relative? && Rails.present? && Rails.root.present?
File.join(Rails.root, "app", "assets", images_path, image_file)
else
File.join(images_path, image_file)
end
else
images_path = Compass.configuration.project_path
if Pathname.new(images_path).relative? && Rails.present? && Rails.root.present?
File.join(Rails.root, "public", images_path, image_file)
else
File.join(images_path, image_file)
end
end

return Sass::Script::Bool.new(File.exist?(real_path))
end
end