compass-import-once 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.
- data/.gitignore +17 -0
- data/Gemfile +3 -0
- data/LICENSE.txt +22 -0
- data/README.md +30 -0
- data/Rakefile +1 -0
- data/VERSION +1 -0
- data/compass-import-once.gemspec +23 -0
- data/lib/compass-import-once.rb +1 -0
- data/lib/compass/import-once.rb +28 -0
- data/lib/compass/import-once/activate.rb +20 -0
- data/lib/compass/import-once/engine.rb +36 -0
- data/lib/compass/import-once/importer.rb +68 -0
- data/lib/compass/import-once/version.rb +5 -0
- metadata +107 -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,30 @@
|
|
1
|
+
# Import Once
|
2
|
+
|
3
|
+
This plugin changes the behavior of Sass's `@import` directive so that
|
4
|
+
if the same sass file is imported more than once, the second import
|
5
|
+
will be a no-op. This allows dependencies to be
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Or add this line to your application's Gemfile if you have one:
|
10
|
+
|
11
|
+
gem 'compass-import-once', :require => "compass/import-once/activate"
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install compass-import-once
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
To enable in non-compass environments there's two options:
|
24
|
+
|
25
|
+
require 'compass/import-once/activate'
|
26
|
+
|
27
|
+
or you can activate it conditionally:
|
28
|
+
|
29
|
+
require 'compass/import-once'
|
30
|
+
Compass::ImportOnce.activate!
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.0.0
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'compass/import-once/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "compass-import-once"
|
8
|
+
spec.version = Compass::ImportOnce::VERSION
|
9
|
+
spec.authors = ["Chris Eppstein"]
|
10
|
+
spec.email = ["chris@eppsteins.net"]
|
11
|
+
spec.description = %q{Changes the behavior of Sass's @import directive to only import a file once.}
|
12
|
+
spec.summary = %q{Speed up your Sass compilation by making @import only import each file once.}
|
13
|
+
spec.homepage = "https://github.com/chriseppstein/compass/tree/master/import-once"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files #{File.dirname(__FILE__)}`.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.3"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'compass/import-once'
|
@@ -0,0 +1,28 @@
|
|
1
|
+
require "compass/import-once/version"
|
2
|
+
require "compass/import-once/importer"
|
3
|
+
require "compass/import-once/engine"
|
4
|
+
require 'set'
|
5
|
+
|
6
|
+
module Compass
|
7
|
+
# although this is part of the compass suite of gems, it doesn't depend on compass,
|
8
|
+
# so any sass-based project can use to to get import-once behavior for all of their
|
9
|
+
# importers.
|
10
|
+
module ImportOnce
|
11
|
+
class << self
|
12
|
+
# A map of css filenames to a set of engine cache keys that uniquely identify what has
|
13
|
+
# been imported. The lifecycle of each key is handled by code wrapped around Sass's
|
14
|
+
# render, to_css and render_with_sourcemap methods on the Sass::Engine.
|
15
|
+
#
|
16
|
+
# Ideally, Sass would provide a place in it's public API to put
|
17
|
+
# information that persists for only the duration of a single compile and would be accessible
|
18
|
+
# for all sass engines and sass functions written in ruby.
|
19
|
+
def import_tracker
|
20
|
+
Thread.current[:import_once_tracker] ||= {}
|
21
|
+
end
|
22
|
+
|
23
|
+
def activate!
|
24
|
+
require 'compass/import-once/activate'
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'compass/import-once'
|
2
|
+
module Sass
|
3
|
+
class Engine
|
4
|
+
def self.new(*args)
|
5
|
+
instance = super
|
6
|
+
instance.extend(Compass::ImportOnce::Engine)
|
7
|
+
if i = instance.options[:importer]
|
8
|
+
i.extend(Compass::ImportOnce::Importer) unless i.is_a?(Compass::ImportOnce::Importer)
|
9
|
+
end
|
10
|
+
instance.options[:load_paths].each do |path|
|
11
|
+
if path.is_a?(Sass::Importers::Base) && !path.is_a?(Compass::ImportOnce::Importer)
|
12
|
+
path.extend(Compass::ImportOnce::Importer)
|
13
|
+
elsif !path.is_a?(Sass::Importers::Base)
|
14
|
+
Sass::Util.sass_war "WARNING: #{path.inspect} is on the load path and is not an importer."
|
15
|
+
end
|
16
|
+
end
|
17
|
+
instance
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module Compass
|
2
|
+
# although this is part of the compass suite of gems, it doesn't depend on compass,
|
3
|
+
# so any sass-based project can use to to get import-once behavior for all of their
|
4
|
+
# importers.
|
5
|
+
module ImportOnce
|
6
|
+
# All sass engines will be extended with this module to manage the lifecycle
|
7
|
+
# around each
|
8
|
+
module Engine
|
9
|
+
def to_css
|
10
|
+
with_import_scope(options[:css_filename]) do
|
11
|
+
super
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def render
|
16
|
+
with_import_scope(options[:css_filename]) do
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
def render_with_sourcemap(sourcemap_uri)
|
22
|
+
with_import_scope(options[:css_filename]) do
|
23
|
+
super
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def with_import_scope(css_filename)
|
28
|
+
Compass::ImportOnce.import_tracker[css_filename] = Set.new
|
29
|
+
yield
|
30
|
+
ensure
|
31
|
+
Compass::ImportOnce.import_tracker.delete(css_filename)
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Compass
|
2
|
+
module ImportOnce
|
3
|
+
# Any importer object that is extended with this module will get the import once behavior.
|
4
|
+
module Importer
|
5
|
+
DUMMY_FILENAME = "import_once_dummy_engine".freeze
|
6
|
+
|
7
|
+
def find_relative(uri, base, options)
|
8
|
+
uri, force_import = handle_force_import(uri)
|
9
|
+
maybe_replace_with_dummy_engine(super(uri, base, options), options, force_import)
|
10
|
+
end
|
11
|
+
|
12
|
+
def find(uri, options)
|
13
|
+
uri, force_import = handle_force_import(uri)
|
14
|
+
maybe_replace_with_dummy_engine(super(uri, options), options, force_import)
|
15
|
+
end
|
16
|
+
|
17
|
+
# ensure that all dummy engines share the same sass cache entry.
|
18
|
+
def key(uri, options)
|
19
|
+
if uri == DUMMY_FILENAME
|
20
|
+
["(import-once)", "dummy_engine"]
|
21
|
+
else
|
22
|
+
super
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
protected
|
27
|
+
|
28
|
+
# any uri that ends with an exclamation mark will be forced to import
|
29
|
+
def handle_force_import(uri)
|
30
|
+
if uri.end_with?("!")
|
31
|
+
[uri[0...-1], true]
|
32
|
+
else
|
33
|
+
[uri, false]
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def maybe_replace_with_dummy_engine(engine, options, force_import)
|
38
|
+
if engine && !force_import && imported?(engine, options)
|
39
|
+
engine = dummy_engine(engine, options)
|
40
|
+
elsif engine
|
41
|
+
imported!(engine, options)
|
42
|
+
end
|
43
|
+
engine
|
44
|
+
end
|
45
|
+
|
46
|
+
def tracker(options)
|
47
|
+
Compass::ImportOnce.import_tracker[options[:css_filename]] ||= Set.new
|
48
|
+
end
|
49
|
+
|
50
|
+
def import_tracker_key(engine, options)
|
51
|
+
key(engine.options[:filename], options).join("|").freeze
|
52
|
+
end
|
53
|
+
|
54
|
+
def dummy_engine(engine, options)
|
55
|
+
new_options = engine.options.merge(:filename => DUMMY_FILENAME)
|
56
|
+
Sass::Engine.new("", new_options)
|
57
|
+
end
|
58
|
+
|
59
|
+
def imported?(engine, options)
|
60
|
+
tracker(options).include?(import_tracker_key(engine, options))
|
61
|
+
end
|
62
|
+
|
63
|
+
def imported!(engine, options)
|
64
|
+
tracker(options) << import_tracker_key(engine, options)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: compass-import-once
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Chris Eppstein
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-12-06 00:00:00 Z
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ~>
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
hash: 9
|
29
|
+
segments:
|
30
|
+
- 1
|
31
|
+
- 3
|
32
|
+
version: "1.3"
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rake
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
hash: 3
|
44
|
+
segments:
|
45
|
+
- 0
|
46
|
+
version: "0"
|
47
|
+
type: :development
|
48
|
+
version_requirements: *id002
|
49
|
+
description: Changes the behavior of Sass's @import directive to only import a file once.
|
50
|
+
email:
|
51
|
+
- chris@eppsteins.net
|
52
|
+
executables: []
|
53
|
+
|
54
|
+
extensions: []
|
55
|
+
|
56
|
+
extra_rdoc_files: []
|
57
|
+
|
58
|
+
files:
|
59
|
+
- .gitignore
|
60
|
+
- Gemfile
|
61
|
+
- LICENSE.txt
|
62
|
+
- README.md
|
63
|
+
- Rakefile
|
64
|
+
- VERSION
|
65
|
+
- compass-import-once.gemspec
|
66
|
+
- lib/compass-import-once.rb
|
67
|
+
- lib/compass/import-once.rb
|
68
|
+
- lib/compass/import-once/activate.rb
|
69
|
+
- lib/compass/import-once/engine.rb
|
70
|
+
- lib/compass/import-once/importer.rb
|
71
|
+
- lib/compass/import-once/version.rb
|
72
|
+
homepage: https://github.com/chriseppstein/compass/tree/master/import-once
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
post_install_message:
|
76
|
+
rdoc_options: []
|
77
|
+
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ">="
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
hash: 3
|
86
|
+
segments:
|
87
|
+
- 0
|
88
|
+
version: "0"
|
89
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ">="
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
hash: 3
|
95
|
+
segments:
|
96
|
+
- 0
|
97
|
+
version: "0"
|
98
|
+
requirements: []
|
99
|
+
|
100
|
+
rubyforge_project:
|
101
|
+
rubygems_version: 1.8.15
|
102
|
+
signing_key:
|
103
|
+
specification_version: 3
|
104
|
+
summary: Speed up your Sass compilation by making @import only import each file once.
|
105
|
+
test_files: []
|
106
|
+
|
107
|
+
has_rdoc:
|