diff --git a/middleman-core/lib/middleman-core/renderers/sass.rb b/middleman-core/lib/middleman-core/renderers/sass.rb index dcbe0bf3..5db51c34 100644 --- a/middleman-core/lib/middleman-core/renderers/sass.rb +++ b/middleman-core/lib/middleman-core/renderers/sass.rb @@ -78,7 +78,10 @@ module Middleman filename: eval_file, line: line, 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] diff --git a/middleman-core/lib/middleman-core/renderers/sass_functions.rb b/middleman-core/lib/middleman-core/renderers/sass_functions.rb index a28dcc69..899dadd6 100644 --- a/middleman-core/lib/middleman-core/renderers/sass_functions.rb +++ b/middleman-core/lib/middleman-core/renderers/sass_functions.rb @@ -1,6 +1,11 @@ module Middleman module Sass module Functions + def asset_path(source, options) + # current_resource + + end + # Using Middleman::Util#asset_path, return the full path # for the given +source+ as a Sass String. This supports keyword # arguments that mirror the +options+. @@ -81,36 +86,47 @@ module Middleman options[:custom][:middleman_context] 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 # and the values are unwrapped Sass literals. def map_options(options={}) # :nodoc: ::Sass::Util.map_hash(options) do |key, value| [key.to_sym, value.respond_to?(:value) ? value.value : value] end + + options[:current_resource] = current_resource + + options end end end end -module ::Sass::Script::Functions - include ::Middleman::Sass::Functions +::SassC::Script::Functions.send :include, ::Middleman::Sass::Functions - # # Hack to ensure previous API declarations (by Compass or whatever) - # # don't take precedence. - # [:asset_path, :asset_url, :image_path, :image_url, :font_path, :font_url, :asset_data_uri].each do |method| - # defined?(@signatures) && @signatures.delete(method) - # end +# module SASS_MODULE::Script::Functions +# include ::Middleman::Sass::Functions - # declare :asset_path, [:source], var_kwargs: true - # declare :asset_path, [:source, :kind] - # declare :asset_url, [:source], var_kwargs: true - # declare :asset_url, [:source, :kind] - # declare :image_path, [:source], var_kwargs: true - # declare :image_url, [:source], var_kwargs: true - # 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 +# # # Hack to ensure previous API declarations (by Compass or whatever) +# # # don't take precedence. +# # [: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 +# # declare :asset_path, [:source, :kind] +# # declare :asset_url, [:source], var_kwargs: true +# # declare :asset_url, [:source, :kind] +# # declare :image_path, [:source], var_kwargs: true +# # declare :image_url, [:source], var_kwargs: true +# # 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 diff --git a/middleman-core/lib/middleman-core/template_context.rb b/middleman-core/lib/middleman-core/template_context.rb index 6771ddbe..f424c2b1 100644 --- a/middleman-core/lib/middleman-core/template_context.rb +++ b/middleman-core/lib/middleman-core/template_context.rb @@ -152,6 +152,18 @@ module Middleman partial_file || nil 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 # Render a path with locs, opts and contents block. @@ -188,17 +200,5 @@ module Middleman content 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