extract-sass-vars 1.0.0.alpha.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +14 -0
- data/Rakefile +1 -0
- data/bin/extract-sass-vars +17 -0
- data/extract-sass-vars.gemspec +19 -0
- data/lib/extract-sass-vars.rb +34 -0
- data/lib/extract-sass-vars/version.rb +7 -0
- metadata +55 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Chris Eppstein
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
# extract-sass-vars
|
2
|
+
|
3
|
+
Extracts global variables from a Sass file into a json object.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install extract-sass-vars
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
$ extract-sass-vars <sass_filename> <json_filename>
|
12
|
+
|
13
|
+
This will create a json file containing all the global variables defined
|
14
|
+
in your sass file (or the files imported therein).
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
require 'extract-sass-vars'
|
3
|
+
require 'optparse'
|
4
|
+
require 'json'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
parser = OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: extract-sass-vars sass_file json_file"
|
9
|
+
end
|
10
|
+
|
11
|
+
options = parser.parse(ARGV)
|
12
|
+
sass_file, json_file = ARGV
|
13
|
+
|
14
|
+
vars = VariableExtractor.new(sass_file).extract
|
15
|
+
File.open(json_file, "w") do |f|
|
16
|
+
f.puts vars.to_json
|
17
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'extract-sass-vars/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "extract-sass-vars"
|
8
|
+
gem.version = Extract::Sass::Vars::VERSION
|
9
|
+
gem.authors = ["Chris Eppstein"]
|
10
|
+
gem.email = ["chris@eppsteins.net"]
|
11
|
+
gem.description = %q{Extracts global variables from a Sass file into a json object.}
|
12
|
+
gem.summary = %q{Extracts global variables from a Sass file into a json object.}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'sass'
|
2
|
+
require "extract-sass-vars/version"
|
3
|
+
|
4
|
+
# We need access to the environment's children created in the perform visitor
|
5
|
+
class Sass::Environment
|
6
|
+
attr_accessor :children
|
7
|
+
alias old_initialize initialize
|
8
|
+
def initialize(parent = nil, options = nil)
|
9
|
+
old_initialize(parent,options)
|
10
|
+
self.children = []
|
11
|
+
if parent
|
12
|
+
parent.children << self
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
class VariableExtractor
|
18
|
+
def initialize(filename)
|
19
|
+
@filename = filename
|
20
|
+
end
|
21
|
+
|
22
|
+
def extract
|
23
|
+
engine = Sass::Engine.for_file(@filename, {})
|
24
|
+
tree = engine.to_tree
|
25
|
+
environment = Sass::Environment.new
|
26
|
+
visitor = Sass::Tree::Visitors::Perform.new(environment)
|
27
|
+
visitor.send(:visit, tree)
|
28
|
+
environment.children.each do |child_env|
|
29
|
+
vars = child_env.instance_variable_get("@vars")
|
30
|
+
return vars
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: extract-sass-vars
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0.alpha.0
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Eppstein
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-17 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Extracts global variables from a Sass file into a json object.
|
15
|
+
email:
|
16
|
+
- chris@eppsteins.net
|
17
|
+
executables:
|
18
|
+
- extract-sass-vars
|
19
|
+
extensions: []
|
20
|
+
extra_rdoc_files: []
|
21
|
+
files:
|
22
|
+
- .gitignore
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- bin/extract-sass-vars
|
28
|
+
- extract-sass-vars.gemspec
|
29
|
+
- lib/extract-sass-vars.rb
|
30
|
+
- lib/extract-sass-vars/version.rb
|
31
|
+
homepage: ''
|
32
|
+
licenses: []
|
33
|
+
post_install_message:
|
34
|
+
rdoc_options: []
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ! '>='
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '0'
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ! '>'
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: 1.3.1
|
49
|
+
requirements: []
|
50
|
+
rubyforge_project:
|
51
|
+
rubygems_version: 1.8.10
|
52
|
+
signing_key:
|
53
|
+
specification_version: 3
|
54
|
+
summary: Extracts global variables from a Sass file into a json object.
|
55
|
+
test_files: []
|