--- /dev/null
+# Nick's web site: Helper to retrieve global style variables in ruby.
+#
+# Copyright © 2020 Nick Bowler
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <https://www.gnu.org/licenses/>.
+
+require 'sass'
+
+class GetSCSSGlobals < Sass::Tree::Visitors::Perform
+ def self.visit(root, name = nil)
+ x = new(nil)
+ x.send(:visit, root)
+ result = x.instance_variable_get(:@globals)
+ if name.nil?
+ return result.freeze
+ else
+ return result[name]
+ end
+ end
+
+ protected
+
+ def initialize(environment)
+ @globals = {}
+ @globals.default_proc = proc { |h, k|
+ if h.key? k.to_s then h[k.to_s] end }
+ super
+ end
+
+ def visit_variable(node)
+ super
+
+ x = @environment.global_env.var(node.name)
+ if !x.nil?
+ @globals[node.name] = x
+ end
+ end
+end
+
+def scss_get_var(variable, item = @items["/style.scss"])
+ engine = Sass::Engine.for_file(item.raw_filename, { :syntax => :scss })
+ return GetSCSSGlobals.visit(engine.to_tree, variable)
+end