overrides.rb 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. # These overrides add support for variable-exists(), mixin-exists() and function-exists()
  2. # to SASS 3.1.7. These functions are added to SASS in 3.3, so when Sencha Cmd is upgraded
  3. # to use SASS 3.3 these overrides should be removed.
  4. # Some monkey patching was required to get these methods working, specifically, we had to
  5. # add the "environment" instance variable to EvaluationContext. These patches should be
  6. # removed when Cmd is upgraded to use SASS 3.3. Additionally, if Cmd is upgraded to use
  7. # SASS 3.2, these patches may need to be updated, because the _perform() method underwent
  8. # changes from 3.1 - 3.2
  9. # These functions are not currently included in the build. To use them, add this file
  10. # to the ruby path. e.g.
  11. # package.sass.rubypath=${package.dir}/sass/utils.rb,${package.dir}/sass/overrides.rb
  12. module Sass::Script
  13. class Funcall
  14. def _perform(environment)
  15. args = @args.map {|a| a.perform(environment)}
  16. if fn = environment.function(@name)
  17. keywords = Sass::Util.map_hash(@keywords) {|k, v| [k, v.perform(environment)]}
  18. return perform_sass_fn(fn, args, keywords)
  19. end
  20. ruby_name = @name.tr('-', '_')
  21. args = construct_ruby_args(ruby_name, args, environment)
  22. unless Functions.callable?(ruby_name)
  23. opts(to_literal(args))
  24. else
  25. ###############################################################################
  26. # BEGIN PATCH
  27. ###############################################################################
  28. context = Functions::EvaluationContext.new(environment.options)
  29. context.instance_variable_set('@environment', environment)
  30. opts(context.send(ruby_name, *args))
  31. ###############################################################################
  32. # END PATCH
  33. ###############################################################################
  34. end
  35. rescue ArgumentError => e
  36. raise e unless e.backtrace.any? {|t| t =~ /:in `(block in )?(#{name}|perform)'$/}
  37. raise Sass::SyntaxError.new("#{e.message} for `#{name}'")
  38. end
  39. end
  40. module Functions
  41. ###################################################################################
  42. # BEGIN PATCH
  43. ###################################################################################
  44. class EvaluationContext
  45. attr_reader :environment
  46. end
  47. ###################################################################################
  48. # END PATCH
  49. ###################################################################################
  50. def variable_exists(variable_name)
  51. if(environment.var(variable_name.value))
  52. Sass::Script::Bool.new(true)
  53. else
  54. Sass::Script::Bool.new(false)
  55. end
  56. end
  57. def mixin_exists(mixin_name)
  58. if(environment.mixin(mixin_name.value))
  59. Sass::Script::Bool.new(true)
  60. else
  61. Sass::Script::Bool.new(false)
  62. end
  63. end
  64. def function_exists(function_name)
  65. if(environment.function(function_name.value))
  66. Sass::Script::Bool.new(true)
  67. else
  68. Sass::Script::Bool.new(false)
  69. end
  70. end
  71. end
  72. end