Created
January 24, 2019 01:38
-
-
Save liamwhite/8bbaafc2ded5147c7890065c67f89635 to your computer and use it in GitHub Desktop.
Dump SASS/SCSS variables from a Rails app
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Sass::Tree::Visitors::Perform | |
def visit_variable(node) | |
env = @environment | |
env = env.global_env if node.global | |
if node.guarded | |
var = env.var(node.name) | |
return [] if var && !var.null? | |
end | |
val = node.expr.perform(@environment) | |
puts "#{node.name}: #{val}" | |
if node.expr.source_range | |
val.source_range = node.expr.source_range | |
else | |
val.source_range = node.source_range | |
end | |
env.set_var(node.name, val) | |
[] | |
end | |
end | |
def dump_variables | |
text = File.read("app/assets/stylesheets/application.scss") | |
view_context = ActionView::Base.new | |
engine = Sass::Engine.new(text, { | |
syntax: :scss, cache: false, read_cache: false, | |
load_paths: Rails.application.config.assets.paths, | |
sprockets: { | |
context: view_context, | |
environment: view_context.assets_environment | |
} | |
}) | |
env = Sass::Environment.new | |
nodes = Sass::Tree::Visitors::Perform.visit(engine.to_tree, env) | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading development environment (Rails 5.1.6.1) | |
irb(main):001:0> dump_variables | |
fa-sass-asset-helper: true | |
fa-font-path: "font-awesome" | |
fa-font-size-base: 16px | |
fa-css-prefix: fa | |
fa-version: "5.5.0" | |
fa-border-color: #eee | |
fa-inverse: #fff | |
fa-li-width: 2em | |
fa-fw-width: 1.25em | |
fa-var-500px: | |
fa-var-accessible-icon: | |
fa-var-accusoft: | |
fa-var-acquisitions-incorporated: | |
fa-var-ad: | |
fa-var-address-book: | |
fa-var-address-card: | |
fa-var-adjust: | |
fa-var-adn: | |
fa-var-adversal: | |
fa-var-affiliatetheme: | |
fa-var-air-freshener: | |
fa-var-algolia: | |
fa-var-align-center: | |
fa-var-align-justify: | |
fa-var-align-left: | |
etc. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment