Fix sass helpers in SassC context

This commit is contained in:
Thomas Reynolds 2015-09-30 11:16:57 -07:00
parent 0698d7f5aa
commit d828067189
3 changed files with 52 additions and 33 deletions

View file

@ -78,7 +78,10 @@ module Middleman
filename: eval_file, filename: eval_file,
line: line, line: line,
syntax: syntax, syntax: syntax,
custom: (options[:custom] || {}).merge(middleman_context: ctx.app) custom: (options[:custom] || {}).merge(
middleman_context: ctx.app,
current_resource: ctx.current_resource
)
} }
if ctx.config[:sass_source_maps] if ctx.config[:sass_source_maps]

View file

@ -1,6 +1,11 @@
module Middleman module Middleman
module Sass module Sass
module Functions module Functions
def asset_path(source, options)
# current_resource
end
# Using Middleman::Util#asset_path, return the full path # Using Middleman::Util#asset_path, return the full path
# for the given +source+ as a Sass String. This supports keyword # for the given +source+ as a Sass String. This supports keyword
# arguments that mirror the +options+. # arguments that mirror the +options+.
@ -81,36 +86,47 @@ module Middleman
options[:custom][:middleman_context] options[:custom][:middleman_context]
end end
# Returns a reference to Middleman's current resource.
def current_resource # :nodoc:
options[:custom][:current_resource]
end
# Returns an options hash where the keys are symbolized # Returns an options hash where the keys are symbolized
# and the values are unwrapped Sass literals. # and the values are unwrapped Sass literals.
def map_options(options={}) # :nodoc: def map_options(options={}) # :nodoc:
::Sass::Util.map_hash(options) do |key, value| ::Sass::Util.map_hash(options) do |key, value|
[key.to_sym, value.respond_to?(:value) ? value.value : value] [key.to_sym, value.respond_to?(:value) ? value.value : value]
end end
options[:current_resource] = current_resource
options
end end
end end
end end
end end
module ::Sass::Script::Functions ::SassC::Script::Functions.send :include, ::Middleman::Sass::Functions
include ::Middleman::Sass::Functions
# # Hack to ensure previous API declarations (by Compass or whatever) # module SASS_MODULE::Script::Functions
# # don't take precedence. # include ::Middleman::Sass::Functions
# [:asset_path, :asset_url, :image_path, :image_url, :font_path, :font_url, :asset_data_uri].each do |method|
# defined?(@signatures) && @signatures.delete(method)
# end
# declare :asset_path, [:source], var_kwargs: true # # # Hack to ensure previous API declarations (by Compass or whatever)
# declare :asset_path, [:source, :kind] # # # don't take precedence.
# declare :asset_url, [:source], var_kwargs: true # # [:asset_path, :asset_url, :image_path, :image_url, :font_path, :font_url, :asset_data_uri].each do |method|
# declare :asset_url, [:source, :kind] # # defined?(@signatures) && @signatures.delete(method)
# declare :image_path, [:source], var_kwargs: true # # end
# declare :image_url, [:source], var_kwargs: true
# declare :image_url, [:source, :only_path] # # declare :asset_path, [:source], var_kwargs: true
# declare :image_url, [:source, :only_path, :cache_buster] # # declare :asset_path, [:source, :kind]
# declare :font_path, [:source], var_kwargs: true # # declare :asset_url, [:source], var_kwargs: true
# declare :font_url, [:source], var_kwargs: true # # declare :asset_url, [:source, :kind]
# declare :font_url, [:source, :only_path] # # declare :image_path, [:source], var_kwargs: true
# declare :asset_data_uri, [:source] # # declare :image_url, [:source], var_kwargs: true
end # # declare :image_url, [:source, :only_path]
# # declare :image_url, [:source, :only_path, :cache_buster]
# # declare :font_path, [:source], var_kwargs: true
# # declare :font_url, [:source], var_kwargs: true
# # declare :font_url, [:source, :only_path]
# # declare :asset_data_uri, [:source]
# end

View file

@ -152,6 +152,18 @@ module Middleman
partial_file || nil partial_file || nil
end end
def current_path
@locs[:current_path]
end
# Get the resource object for the current path
# @return [Middleman::Sitemap::Resource]
def current_resource
return nil unless current_path
sitemap.find_resource_by_destination_path(current_path)
end
alias_method :current_page, :current_resource
protected protected
# Render a path with locs, opts and contents block. # Render a path with locs, opts and contents block.
@ -188,17 +200,5 @@ module Middleman
content content
end end
def current_path
@locs[:current_path]
end
# Get the resource object for the current path
# @return [Middleman::Sitemap::Resource]
def current_resource
return nil unless current_path
sitemap.find_resource_by_destination_path(current_path)
end
alias_method :current_page, :current_resource
end end
end end