sass-switcheroo 1.0.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.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +9 -0
- data/Guardfile +12 -0
- data/LICENSE.txt +22 -0
- data/README.md +177 -0
- data/Rakefile +26 -0
- data/lib/sass/switcheroo.rb +10 -0
- data/lib/sass/switcheroo/dsl.rb +12 -0
- data/lib/sass/switcheroo/importer.rb +110 -0
- data/lib/sass/switcheroo/version.rb +5 -0
- data/sass-switcheroo.gemspec +24 -0
- data/test/dsl_test.rb +149 -0
- data/test/fixtures/around/_some_after_file.scss +3 -0
- data/test/fixtures/around/_some_before_file.scss +3 -0
- data/test/fixtures/around/foo/_after_one.scss +3 -0
- data/test/fixtures/around/foo/_before_one.scss +3 -0
- data/test/fixtures/replacement/bar/one-alternate.scss +3 -0
- data/test/fixtures/replacement/bar/one.scss +3 -0
- data/test/fixtures/replacement/foo/one.scss +3 -0
- data/test/fixtures/replacement/foo/two.scss +3 -0
- metadata +117 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: c81e51374d4ab075534f9d5540a8aa66ae5baf40
|
4
|
+
data.tar.gz: 2a220f39011253d2ad784336450b8c573921e5ee
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 539d3812a24ea25c172ba2f7ade3ef7c24cbd384cc2d4d0d79b090831e5c61cbe60dfaff2cec014579dce810a07e2bb170a1994d4fb8a26578482fe738a09a38
|
7
|
+
data.tar.gz: f0ca77de44e2d8e53b55b7ba3ccf3c9c05ad36e2778ec8a6b770393e28ceeb9885a3fa03251522b9adad0eedbc5e69ca7199545a725fa473f215c975f0993325
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
#
|
4
|
+
guard :test
|
5
|
+
|
6
|
+
guard :test do
|
7
|
+
watch(%r{^test/.+_test\.rb$})
|
8
|
+
watch('test/test_helper.rb') { 'test' }
|
9
|
+
|
10
|
+
# Non-rails
|
11
|
+
watch(%r{^lib/sass/switcheroo/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
|
12
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 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,177 @@
|
|
1
|
+
# Sass Switcheroo
|
2
|
+
|
3
|
+
Sass Switcheroo is a work around to the fact that you cannot dynamically
|
4
|
+
control your imports from within a sass file.
|
5
|
+
|
6
|
+
This Sass add-on gives you the ability to define import rules. You can:
|
7
|
+
|
8
|
+
* Rewrite import statements
|
9
|
+
* Specify a file should be imported before or after another sass file.
|
10
|
+
|
11
|
+
What is this useful for?
|
12
|
+
|
13
|
+
* Making a project work across different versions of libraries
|
14
|
+
* Managing Sass version differences
|
15
|
+
|
16
|
+
## Installation
|
17
|
+
|
18
|
+
Add this line to your application's Gemfile:
|
19
|
+
|
20
|
+
gem 'sass-switcheroo'
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install sass-switcheroo
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
The easiest way to make switcheroo work is in a compass configuration file:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
importer = Sass::Switcheroo.rules(sass_path) do
|
36
|
+
# custom rules go here. These are just examples.
|
37
|
+
replace("**/setup*", %r{(.*)/setup} => 'sass3.4/\1/setup')
|
38
|
+
before("**/variables*", %r{.*} => 'sass3.4/variable_defaults')
|
39
|
+
after("**/variables*", %r{.*} => 'sass3.4/variable_adapaters')
|
40
|
+
end
|
41
|
+
add_import_path importer
|
42
|
+
```
|
43
|
+
|
44
|
+
### Declaring import rules
|
45
|
+
|
46
|
+
`Sass::Switcheroo.rules` - This method takes two arguments. A root
|
47
|
+
directory within which to find sass imports and and an optional value
|
48
|
+
for glob options which defaults to `File::FNM_EXTGLOB |
|
49
|
+
File::FNM_PATHNAME`. Docs on ruby globs and the glob options can be [found
|
50
|
+
here][globs].
|
51
|
+
|
52
|
+
### Import rewriting (The `replace` directive)
|
53
|
+
|
54
|
+
The first argument is a ruby glob. **Import statements** that match this
|
55
|
+
glob will rewritten. Note that the import statements are made relative
|
56
|
+
to the import root for the purpose of rewriting, even if they are
|
57
|
+
specified relative to the sass file.
|
58
|
+
|
59
|
+
The second argument is a hash of transformations where the keys are
|
60
|
+
iteratively substituted by the values. The keys can be strings or
|
61
|
+
regular expressions. If the regular expression has captures, those can
|
62
|
+
be accessed with the escapes \1 through \9 (This uses the ruby
|
63
|
+
[String#sub][sub] method) so it's not a global replace. Note
|
64
|
+
that, because of ruby's syntax the hash does not require curly braces
|
65
|
+
when the third argument is omitted.
|
66
|
+
|
67
|
+
This directive accepts the `:glob_options` option, which will override
|
68
|
+
the [glob option value][globs] that was specified globally for the rules.
|
69
|
+
|
70
|
+
Replacements can interact with each other. That is, once a replacement
|
71
|
+
is matched, the resulting import will be checked against the remaining
|
72
|
+
replacements.
|
73
|
+
|
74
|
+
#### `replace` Examples:
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
# Given these rules:
|
78
|
+
|
79
|
+
importer = Sass::Switcheroo.rules(sass_path) do
|
80
|
+
replace("**/test-a*", "/test-a" => "/test-b")
|
81
|
+
replace("**/theme-1/**/*", "/theme-1" => "/theme-2")
|
82
|
+
replace("**/*-config", %r{^(.*)/([^/]+)-config} => 'config/\1/\2')
|
83
|
+
end
|
84
|
+
```
|
85
|
+
|
86
|
+
The following import rewrites would occur:
|
87
|
+
|
88
|
+
* `@import "my-app/test-a-sidebar" => my-app/test-b-sidebar`
|
89
|
+
* `@import "my-app/theme-1/colors" => my-app/theme-2/colors`
|
90
|
+
* `@import "typography/font-config" => config/typography/font`
|
91
|
+
* `@import "tests/theme-1/test-a-config" =>
|
92
|
+
tests/theme-1/test-b-config =>
|
93
|
+
tests/theme-2/test-b-config =>
|
94
|
+
config/tests/theme-1/test-b`
|
95
|
+
|
96
|
+
|
97
|
+
### Co-imports (The `before` and `after` directives)
|
98
|
+
|
99
|
+
Once rewriting is performed the actual sass file that is being imported
|
100
|
+
is matched for co-imports. Co-imports are import statements that are
|
101
|
+
added either to the top or the bottom of the imported file's contents.
|
102
|
+
Multiple co-imports can end up being injected and files imported as a
|
103
|
+
co-import can themselves have their own co-imports.
|
104
|
+
|
105
|
+
Like `replace`, the first argument of `before` and `after` is a glob
|
106
|
+
pattern. Unlike `replace` the glob pattern is matched against the actual
|
107
|
+
sass file (relative to root directory of the imported file). This means
|
108
|
+
that the filename will include extension and for partials, the leading
|
109
|
+
underscore.
|
110
|
+
|
111
|
+
The second argument to `before` and `after` can either be a string or a
|
112
|
+
hash. When the second argument is a string, this is the import that
|
113
|
+
should be injected when importing files matching the glob. If the second
|
114
|
+
argument is a hash, the keys much be regular expressions that can
|
115
|
+
capture values from the matched file to construct imports. The captures
|
116
|
+
from the regular expression are referenced in the values of the hash
|
117
|
+
using the `\1`..`\9` references. If several key/value pairs are in the
|
118
|
+
hash, they will all be checked if they match the file. If none of the
|
119
|
+
regular expression keys match, then no import will be created. Note
|
120
|
+
that, because of ruby's syntax the hash does not require curly braces
|
121
|
+
when the third argument is omitted.
|
122
|
+
|
123
|
+
Like `replace`, these directives allow the `:glob_options` option to be
|
124
|
+
passed if you need to override the glob options specified by the `rules` block.
|
125
|
+
|
126
|
+
If you want to conditionally peform a co-import if the co-import file
|
127
|
+
exists, pass `:if_exists => true` as an option to the `before` or
|
128
|
+
`after` directives.
|
129
|
+
|
130
|
+
**Caveat**: Because co-imports mangle the source of the sass file and inject
|
131
|
+
`@import` directives, the column numbers of the first line (in an scss
|
132
|
+
file) as reported by sourcemaps and in error messages will be incorrect.
|
133
|
+
In the indented syntax, the line numbers of sourcemaps and errors will
|
134
|
+
be incorrectly reported.
|
135
|
+
|
136
|
+
#### `before` and `after` Examples:
|
137
|
+
|
138
|
+
```ruby
|
139
|
+
# Given these definitions:
|
140
|
+
importer = Sass::Switcheroo.rules(sass_path) do
|
141
|
+
before("config/setup", "config/sass-34-defaults")
|
142
|
+
after("config/setup", "config/sass-34-config-adapter")
|
143
|
+
after("app/**/*", %r{/_?([^/]+)\.s[ac]ss$} => 'config/app/\1', :if_exists => true)
|
144
|
+
end
|
145
|
+
```
|
146
|
+
|
147
|
+
The following co-imports occur:
|
148
|
+
|
149
|
+
* `@import "config/setup"` is equivalent to
|
150
|
+
`@import "config/sass-34-defaults"; @import "config/setup"; @import "config/sass-34-config-adapter"`
|
151
|
+
* `@import "app/foo"` is equivalent to
|
152
|
+
`@import "@import "app/foo"; @import "config/app/foo"` if the import of `config/app/foo` exists.
|
153
|
+
|
154
|
+
|
155
|
+
### Miscellaneous Notes
|
156
|
+
|
157
|
+
* Since `\` is an escape in a double quoted string(`"..."`), it is usually better
|
158
|
+
to use a single quoted string (`'...'`) which treats `\` as a literal backslash.
|
159
|
+
* Since `/` is a regular expression delimiter it is easier to define
|
160
|
+
regular expressions involving `/` using ruby's `%r{...}` syntax instead
|
161
|
+
so that `/` doesn't have any particular meaning and doesn't need to be
|
162
|
+
escaped.
|
163
|
+
* It is possible to create co-import loops so be careful to avoid that
|
164
|
+
unless you have [import-once][import-once] enabled.
|
165
|
+
|
166
|
+
|
167
|
+
## Contributing
|
168
|
+
|
169
|
+
1. Fork it ( http://github.com/<my-github-username>/sass-switcheroo/fork )
|
170
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
171
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
172
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
173
|
+
5. Create new Pull Request
|
174
|
+
|
175
|
+
[globs]: http://www.ruby-doc.org/core-2.1.3/File.html#method-c-fnmatch
|
176
|
+
[sub]: http://www.ruby-doc.org/core-2.1.3/String.html#method-i-sub
|
177
|
+
[import-once]: https://github.com/Compass/compass/tree/master/import-once
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'rake/testtask'
|
3
|
+
|
4
|
+
|
5
|
+
Rake::TestTask.new do |t|
|
6
|
+
t.libs << "lib"
|
7
|
+
t.libs << "test"
|
8
|
+
t.test_files = FileList['test/**/*_test.rb']
|
9
|
+
t.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
def run(command)
|
13
|
+
puts command
|
14
|
+
sh command
|
15
|
+
raise "FAILED: #{command}" unless $?.success?
|
16
|
+
end
|
17
|
+
|
18
|
+
task :release do
|
19
|
+
$: << File.expand_path("lib", File.dirname(__FILE__))
|
20
|
+
require 'sass/switcheroo/version'
|
21
|
+
run %Q{gem build sass-switcheroo.gemspec}
|
22
|
+
run %Q{git tag -a -m "#{Sass::Switcheroo::VERSION}" #{Sass::Switcheroo::VERSION}}
|
23
|
+
run %Q{git push --tags origin master}
|
24
|
+
run %Q{gem build sass-switcheroo.gemspec}
|
25
|
+
run %Q{gem push --host http://artifactory.corp.linkedin.com:8081/artifactory/api/gems/rubygems --key artifactory sass-switcheroo-#{Sass::Switcheroo::VERSION}.gem}
|
26
|
+
end
|
@@ -0,0 +1,110 @@
|
|
1
|
+
class Sass::Switcheroo::Importer < Sass::Importers::Filesystem
|
2
|
+
|
3
|
+
def initialize(root, options = {})
|
4
|
+
super(root)
|
5
|
+
@default_glob_options = options.fetch(:glob_options, File::FNM_EXTGLOB | File::FNM_PATHNAME)
|
6
|
+
@fallback_to_original = options.fetch(:fallback, false)
|
7
|
+
@globs = {}
|
8
|
+
end
|
9
|
+
|
10
|
+
def replace(glob, conversions)
|
11
|
+
glob_options = conversions.delete(:glob_options) || @default_glob_options
|
12
|
+
@globs[glob] ||= {}
|
13
|
+
@globs[glob][:replace] = [conversions, glob_options]
|
14
|
+
end
|
15
|
+
|
16
|
+
def co_import(type, glob, import, options = {})
|
17
|
+
glob_options = import.delete(:glob_options) if import.is_a?(Hash)
|
18
|
+
glob_options ||= options.delete(:glob_options)
|
19
|
+
glob_options ||= @default_glob_options
|
20
|
+
if_exists = import.delete(:if_exists) if import.is_a?(Hash)
|
21
|
+
if_exists ||= options.delete(:if_exists)
|
22
|
+
@globs[glob] ||= {}
|
23
|
+
@globs[glob][type] = [import, glob_options, if_exists]
|
24
|
+
end
|
25
|
+
|
26
|
+
def before(glob, import, options = {})
|
27
|
+
co_import(:before, glob, import, options)
|
28
|
+
end
|
29
|
+
|
30
|
+
def after(glob, import, options = {})
|
31
|
+
co_import(:after, glob, import, options)
|
32
|
+
end
|
33
|
+
|
34
|
+
def find_real_file(dir, name, options)
|
35
|
+
dir = dir.gsub(File::ALT_SEPARATOR, File::SEPARATOR) unless File::ALT_SEPARATOR.nil?
|
36
|
+
name = name.gsub(File::ALT_SEPARATOR, File::SEPARATOR) unless File::ALT_SEPARATOR.nil?
|
37
|
+
absolute_name = remove_root(File.join(dir, remove_root(name)))
|
38
|
+
matched_globs = {}
|
39
|
+
loop do
|
40
|
+
glob = @globs.keys.find do |possible_glob|
|
41
|
+
conversions, glob_options = @globs[possible_glob][:replace]
|
42
|
+
next unless conversions
|
43
|
+
next if matched_globs[possible_glob]
|
44
|
+
File.fnmatch(possible_glob, absolute_name, glob_options)
|
45
|
+
end
|
46
|
+
break unless glob
|
47
|
+
matched_globs[glob] = true
|
48
|
+
conversions, _glob_options = @globs[glob][:replace]
|
49
|
+
absolute_name = conversions.inject(absolute_name) {|n, (from, to)| n.sub(from, to) }
|
50
|
+
end
|
51
|
+
if result = super(dir, absolute_name, options)
|
52
|
+
result
|
53
|
+
elsif @fallback_to_original
|
54
|
+
super(dir, name, options)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def _find(dir, name, options)
|
59
|
+
engine = super
|
60
|
+
return unless engine
|
61
|
+
filename = remove_root(engine.options[:filename])
|
62
|
+
syntax = engine.options[:syntax]
|
63
|
+
befores = []
|
64
|
+
afters = []
|
65
|
+
@globs.keys.each do |possible_glob|
|
66
|
+
before_import, before_glob_options, before_if_exists = @globs[possible_glob][:before]
|
67
|
+
after_import, after_glob_options, after_if_exists = @globs[possible_glob][:after]
|
68
|
+
if before_import
|
69
|
+
resolved_import = resolve_match(possible_glob, filename, before_import, before_glob_options, before_if_exists, options)
|
70
|
+
befores << resolved_import
|
71
|
+
end
|
72
|
+
if after_import
|
73
|
+
resolved_import = resolve_match(possible_glob, filename, after_import, after_glob_options, after_if_exists, options)
|
74
|
+
afters << resolved_import
|
75
|
+
end
|
76
|
+
end
|
77
|
+
template = engine.instance_variable_get("@template")
|
78
|
+
if befores.any?
|
79
|
+
imports = befores.inject("") {|s, f| s + %Q{@import "#{f}"#{syntax == :scss ? ";" : "\n"}} }
|
80
|
+
template.replace(imports + template)
|
81
|
+
end
|
82
|
+
if afters.any?
|
83
|
+
imports = afters.inject("") {|s, f| s + %Q{#{syntax == :scss ? ";" : "\n"}@import "#{f}"} }
|
84
|
+
template.replace(template + imports)
|
85
|
+
end
|
86
|
+
engine
|
87
|
+
end
|
88
|
+
|
89
|
+
def resolve_match(possible_glob, filename, import, glob_options, if_exists, options)
|
90
|
+
if File.fnmatch(possible_glob, filename, glob_options)
|
91
|
+
case import
|
92
|
+
when Hash
|
93
|
+
import.each do |regex, pattern|
|
94
|
+
if match_data = filename.match(regex)
|
95
|
+
match_data.captures.each_with_index do |capture, i|
|
96
|
+
pattern = pattern.gsub("\\#{i + 1}", capture)
|
97
|
+
end
|
98
|
+
return pattern if if_exists && find_real_file(root, pattern, options) || !if_exists
|
99
|
+
return nil
|
100
|
+
end
|
101
|
+
end
|
102
|
+
when String
|
103
|
+
import
|
104
|
+
else
|
105
|
+
raise ArgumentError, "Unknown argument: #{possible_glob.inspect}"
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
110
|
+
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'sass/switcheroo/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "sass-switcheroo"
|
8
|
+
spec.version = Sass::Switcheroo::VERSION
|
9
|
+
spec.authors = ["Chris Eppstein"]
|
10
|
+
spec.email = ["chris@eppsteins.net"]
|
11
|
+
spec.summary = %q{Pull a switcheroo on your sass imports}
|
12
|
+
spec.description = %q{Rewrite import paths, define automatic co-imports before or after other imports.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", ">= 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_dependency "sass"
|
24
|
+
end
|
data/test/dsl_test.rb
ADDED
@@ -0,0 +1,149 @@
|
|
1
|
+
require 'sass/switcheroo'
|
2
|
+
require 'test/unit'
|
3
|
+
|
4
|
+
class DSLTest < Test::Unit::TestCase
|
5
|
+
FIXTURES_DIR = File.expand_path("fixtures", File.join(File.dirname(__FILE__)))
|
6
|
+
|
7
|
+
def test_basic_dsl
|
8
|
+
importer = Sass::Switcheroo.rules(FIXTURES_DIR) do
|
9
|
+
replace("**/foo/*", "/foo/" => "/bar/")
|
10
|
+
end
|
11
|
+
assert_equal Sass::Switcheroo::Importer, importer.class
|
12
|
+
file, syntax = importer.find_real_file(FIXTURES_DIR, "replacement/foo/one", {})
|
13
|
+
assert_equal File.join(FIXTURES_DIR, *%w(replacement bar one.scss)), file
|
14
|
+
assert_equal :scss, syntax
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_missing_replacement
|
18
|
+
importer = Sass::Switcheroo.rules(FIXTURES_DIR) do
|
19
|
+
replace("**/foo/*", "/foo/" => "/bar/")
|
20
|
+
end
|
21
|
+
assert_equal Sass::Switcheroo::Importer, importer.class
|
22
|
+
# missing here
|
23
|
+
file, _syntax = importer.find_real_file(FIXTURES_DIR, "replacement/foo/two", {})
|
24
|
+
assert_nil file
|
25
|
+
end
|
26
|
+
|
27
|
+
def test_skipped_replacement
|
28
|
+
importer = Sass::Switcheroo.rules(FIXTURES_DIR, :fallback => true) do
|
29
|
+
replace("**/foo/*", "/foo/" => "/bar/")
|
30
|
+
end
|
31
|
+
assert_equal Sass::Switcheroo::Importer, importer.class
|
32
|
+
file, syntax = importer.find_real_file(FIXTURES_DIR, "replacement/foo/two", {})
|
33
|
+
assert_equal File.join(FIXTURES_DIR, *%w(replacement foo two.scss)), file
|
34
|
+
assert_equal :scss, syntax
|
35
|
+
end
|
36
|
+
|
37
|
+
def test_interacting_replacement
|
38
|
+
importer = Sass::Switcheroo.rules(FIXTURES_DIR) do
|
39
|
+
replace("**/foo/*", "/foo/" => "/bar/")
|
40
|
+
replace("**/one", "/one" => "/one-alternate")
|
41
|
+
end
|
42
|
+
assert_equal Sass::Switcheroo::Importer, importer.class
|
43
|
+
file, syntax = importer.find_real_file(FIXTURES_DIR, "replacement/foo/one", {})
|
44
|
+
assert_equal File.join(FIXTURES_DIR, *%w(replacement bar one-alternate.scss)), file
|
45
|
+
assert_equal :scss, syntax
|
46
|
+
end
|
47
|
+
|
48
|
+
def test_replacement_doesnt_keep_matching
|
49
|
+
importer = Sass::Switcheroo.rules(FIXTURES_DIR) do
|
50
|
+
# this glob matches itself, shouldn't infinite loop.
|
51
|
+
replace("**/one*", "/one" => "/one-alternate")
|
52
|
+
end
|
53
|
+
assert_equal Sass::Switcheroo::Importer, importer.class
|
54
|
+
file, syntax = importer.find_real_file(FIXTURES_DIR, "replacement/bar/one", {})
|
55
|
+
assert_equal File.join(FIXTURES_DIR, *%w(replacement bar one-alternate.scss)), file
|
56
|
+
assert_equal :scss, syntax
|
57
|
+
end
|
58
|
+
|
59
|
+
def test_returns_engine_with_replaced_contents
|
60
|
+
importer = Sass::Switcheroo.rules(FIXTURES_DIR) do
|
61
|
+
replace("**/foo/*", "/foo/" => "/bar/")
|
62
|
+
end
|
63
|
+
engine = importer.find("replacement/foo/one", {})
|
64
|
+
assert_equal <<CSS, engine.render
|
65
|
+
.bar .one {
|
66
|
+
color: blue; }
|
67
|
+
CSS
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_before_import
|
71
|
+
importer = Sass::Switcheroo.rules(FIXTURES_DIR) do
|
72
|
+
before("**/foo/*", "around/some_before_file")
|
73
|
+
end
|
74
|
+
engine = importer.find("replacement/foo/one", {:load_paths => [importer]})
|
75
|
+
assert_equal <<CSS, engine.render
|
76
|
+
.before {
|
77
|
+
border: 1px solid green; }
|
78
|
+
|
79
|
+
.foo .one {
|
80
|
+
color: red; }
|
81
|
+
CSS
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_after_import
|
85
|
+
importer = Sass::Switcheroo.rules(FIXTURES_DIR) do
|
86
|
+
after("**/foo/*", "around/some_after_file")
|
87
|
+
end
|
88
|
+
engine = importer.find("replacement/foo/one", {:load_paths => [importer]})
|
89
|
+
assert_equal <<CSS, engine.render
|
90
|
+
.foo .one {
|
91
|
+
color: red; }
|
92
|
+
|
93
|
+
.after {
|
94
|
+
border: 1px solid red; }
|
95
|
+
CSS
|
96
|
+
end
|
97
|
+
|
98
|
+
def test_before_and_after_import
|
99
|
+
importer = Sass::Switcheroo.rules(FIXTURES_DIR) do
|
100
|
+
before("**/foo/*", "around/some_before_file")
|
101
|
+
after("**/foo/*", "around/some_after_file")
|
102
|
+
end
|
103
|
+
engine = importer.find("replacement/foo/one", {:load_paths => [importer]})
|
104
|
+
assert_equal <<CSS, engine.render
|
105
|
+
.before {
|
106
|
+
border: 1px solid green; }
|
107
|
+
|
108
|
+
.foo .one {
|
109
|
+
color: red; }
|
110
|
+
|
111
|
+
.after {
|
112
|
+
border: 1px solid red; }
|
113
|
+
CSS
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_before_and_after_patterns
|
117
|
+
importer = Sass::Switcheroo.rules(FIXTURES_DIR) do
|
118
|
+
before("replacement/**/foo/*", %r{/foo/(.*)} => 'around/foo/before_\1')
|
119
|
+
after("replacement/**/foo/*", %r{/foo/(.*)} => 'around/foo/after_\1')
|
120
|
+
end
|
121
|
+
|
122
|
+
engine = importer.find("replacement/foo/one", {:load_paths => [importer]})
|
123
|
+
|
124
|
+
assert_equal <<CSS, engine.render
|
125
|
+
.before .one-foo {
|
126
|
+
border-width: 1px; }
|
127
|
+
|
128
|
+
.foo .one {
|
129
|
+
color: red; }
|
130
|
+
|
131
|
+
.after .one-foo {
|
132
|
+
border-width: 1px; }
|
133
|
+
CSS
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_before_and_after_patterns_only_when_existing
|
137
|
+
importer = Sass::Switcheroo.rules(FIXTURES_DIR) do
|
138
|
+
before("replacement/**/foo/*", %r{/foo/(.*)} => 'around/foo/before_\1', :if_exists => true)
|
139
|
+
after("replacement/**/foo/*", %r{/foo/(.*)} => 'around/foo/after_\1', :if_exists => true)
|
140
|
+
end
|
141
|
+
|
142
|
+
engine = importer.find("replacement/foo/two", {:load_paths => [importer]})
|
143
|
+
|
144
|
+
assert_equal <<CSS, engine.render
|
145
|
+
.foo .two {
|
146
|
+
background-color: red; }
|
147
|
+
CSS
|
148
|
+
end
|
149
|
+
end
|
metadata
ADDED
@@ -0,0 +1,117 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sass-switcheroo
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Chris Eppstein
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-16 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: sass
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
description: Rewrite import paths, define automatic co-imports before or after other
|
56
|
+
imports.
|
57
|
+
email:
|
58
|
+
- chris@eppsteins.net
|
59
|
+
executables: []
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- .gitignore
|
64
|
+
- Gemfile
|
65
|
+
- Guardfile
|
66
|
+
- LICENSE.txt
|
67
|
+
- README.md
|
68
|
+
- Rakefile
|
69
|
+
- lib/sass/switcheroo.rb
|
70
|
+
- lib/sass/switcheroo/dsl.rb
|
71
|
+
- lib/sass/switcheroo/importer.rb
|
72
|
+
- lib/sass/switcheroo/version.rb
|
73
|
+
- sass-switcheroo.gemspec
|
74
|
+
- test/dsl_test.rb
|
75
|
+
- test/fixtures/around/_some_after_file.scss
|
76
|
+
- test/fixtures/around/_some_before_file.scss
|
77
|
+
- test/fixtures/around/foo/_after_one.scss
|
78
|
+
- test/fixtures/around/foo/_before_one.scss
|
79
|
+
- test/fixtures/replacement/bar/one-alternate.scss
|
80
|
+
- test/fixtures/replacement/bar/one.scss
|
81
|
+
- test/fixtures/replacement/foo/one.scss
|
82
|
+
- test/fixtures/replacement/foo/two.scss
|
83
|
+
homepage: ''
|
84
|
+
licenses:
|
85
|
+
- MIT
|
86
|
+
metadata: {}
|
87
|
+
post_install_message:
|
88
|
+
rdoc_options: []
|
89
|
+
require_paths:
|
90
|
+
- lib
|
91
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - '>='
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 2.0.3
|
104
|
+
signing_key:
|
105
|
+
specification_version: 4
|
106
|
+
summary: Pull a switcheroo on your sass imports
|
107
|
+
test_files:
|
108
|
+
- test/dsl_test.rb
|
109
|
+
- test/fixtures/around/_some_after_file.scss
|
110
|
+
- test/fixtures/around/_some_before_file.scss
|
111
|
+
- test/fixtures/around/foo/_after_one.scss
|
112
|
+
- test/fixtures/around/foo/_before_one.scss
|
113
|
+
- test/fixtures/replacement/bar/one-alternate.scss
|
114
|
+
- test/fixtures/replacement/bar/one.scss
|
115
|
+
- test/fixtures/replacement/foo/one.scss
|
116
|
+
- test/fixtures/replacement/foo/two.scss
|
117
|
+
has_rdoc:
|