compass-import-once-sass37 1.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: dc24e11223eeff68462a2a8250bd4cb8e05d73e95c36c675021ea55cf546bbc9
4
+ data.tar.gz: 131863be38a9cceebf21739c651f196d4dc097910a3613523eb7f69e05656d52
5
+ SHA512:
6
+ metadata.gz: 0f09a8c39875f7003da7808d21313c1bade9ea8cb836ea3ea299f991bba6dd658039a2b3e0a3f6772b51323fff3a49b3ddc681facb1d77bb0c5c99d918d94d7f
7
+ data.tar.gz: 8f1f07066cdaa8fc286c3626b896d559f3c8386bd25ff7d815ea998328b669591378fb4cc9206417289ddc7e7e630274a65e89f3e277d401d7ea21df953d2fae
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile*.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .sass-cache
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'test-unit', '~> 3.6.0'
4
+
5
+ gemspec
data/Gemfile_sass_3_2 ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'sass', '~> 3.2.15'
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,52 @@
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 behave how most people
6
+ expect them to behave and provides a considerable performance improvement
7
+ for some sass projects.
8
+
9
+ **Note**: Although this plugin is maintained by compass, it can be used
10
+ without compass in any Sass-based project.
11
+
12
+ ## Installation
13
+
14
+ Either add this line to your application's Gemfile if you have one:
15
+
16
+ gem 'compass-import-once', :require => 'compass/import-once/activate'
17
+
18
+ And then execute:
19
+
20
+ $ bundle
21
+
22
+ Or install it yourself as:
23
+
24
+ $ gem install compass-import-once
25
+
26
+ ## Usage
27
+
28
+ To use with the Sass command line:
29
+
30
+ ```
31
+ sass -r 'compass/import-once/activate' ...
32
+ ```
33
+
34
+ To enable in non-compass environments there's two options:
35
+
36
+ require 'compass/import-once/activate'
37
+
38
+ or you can activate it conditionally:
39
+
40
+ require 'compass/import-once'
41
+ Compass::ImportOnce.activate!
42
+
43
+ ## Forcing an Import
44
+
45
+ If a file must be imported a second time, you can force it by adding an
46
+ exclamation mark to the end of the import url. E.g.
47
+
48
+
49
+ ```scss
50
+ @import "something";
51
+ @import "something!"; // this will be imported again.
52
+ ```
data/Rakefile ADDED
@@ -0,0 +1,9 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList['test/**/*_test.rb']
8
+ t.verbose = true
9
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.1.0
@@ -0,0 +1,26 @@
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-sass37"
8
+ spec.version = Compass::ImportOnce::VERSION
9
+ spec.authors = ["Vladimir Ivanin", "Chris Eppstein"]
10
+ spec.email = ["ivaninww@gmail.com"]
11
+ spec.description = %q{Changes the behavior of Sass's @import directive to only import a file once. Updated for Sass 3.7 compatibility.}
12
+ spec.summary = %q{Speed up your Sass compilation by making @import only import each file once (Sass 3.7 compatible)}
13
+ spec.homepage = "https://github.com/VladimirIvanin/compass"
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_dependency "sass", ">= 3.7", "< 3.8"
22
+ spec.add_development_dependency "bundler", ">= 1.3"
23
+ spec.add_development_dependency "diff-lcs"
24
+ spec.add_development_dependency "rake"
25
+ spec.add_development_dependency "sass-globbing"
26
+ 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_warn "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,81 @@
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
+ def find_relative(uri, base, options, *args)
6
+ uri, force_import = handle_force_import(uri)
7
+ maybe_replace_with_dummy_engine(super(uri, base, options, *args), options, force_import)
8
+ end
9
+
10
+ def find(uri, options, *args)
11
+ uri, force_import = handle_force_import(uri)
12
+ maybe_replace_with_dummy_engine(super(uri, options, *args), options, force_import)
13
+ end
14
+
15
+ def key(uri, options, *args)
16
+ if uri =~ /^\(NOT IMPORTED\) (.*)$/
17
+ ["(import-once)", $1]
18
+ else
19
+ super
20
+ end
21
+ end
22
+
23
+ def mtime(uri, options, *args)
24
+ if uri =~ /^\(NOT IMPORTED\) (.*)$/
25
+ File.mtime($1) if File.exist?($1)
26
+ else
27
+ super
28
+ end
29
+ end
30
+
31
+ protected
32
+
33
+ # any uri that ends with an exclamation mark will be forced to import
34
+ def handle_force_import(uri)
35
+ if uri.end_with?("!")
36
+ [uri[0...-1], true]
37
+ else
38
+ [uri, false]
39
+ end
40
+ end
41
+
42
+ def maybe_replace_with_dummy_engine(engine, options, force_import)
43
+ if engine && !force_import && imported?(engine, options)
44
+ engine = dummy_engine(engine, options)
45
+ elsif engine
46
+ imported!(engine, options)
47
+ end
48
+ engine
49
+ end
50
+
51
+ def tracker(options)
52
+ Compass::ImportOnce.import_tracker[options[:css_filename]] ||= Set.new
53
+ end
54
+
55
+ # Giant hack to support sass-globbing.
56
+ # Need to find a better fix.
57
+ def normalize_filesystem_importers(key)
58
+ key.map do |part|
59
+ part.sub(/Glob:/, 'Sass::Importers::Filesystem:')
60
+ end
61
+ end
62
+
63
+ def import_tracker_key(engine, options)
64
+ normalize_filesystem_importers(key(engine.options[:filename], options)).join("|").freeze
65
+ end
66
+
67
+ def dummy_engine(engine, options)
68
+ new_options = engine.options.merge(:filename => "(NOT IMPORTED) #{engine.options[:filename]}" )
69
+ Sass::Engine.new("", new_options)
70
+ end
71
+
72
+ def imported?(engine, options)
73
+ tracker(options).include?(import_tracker_key(engine, options))
74
+ end
75
+
76
+ def imported!(engine, options)
77
+ tracker(options) << import_tracker_key(engine, options)
78
+ end
79
+ end
80
+ end
81
+ end
@@ -0,0 +1,5 @@
1
+ module Compass
2
+ module ImportOnce
3
+ VERSION = File.read(File.join(File.dirname(__FILE__), "..", "..", "..", "VERSION")).strip
4
+ end
5
+ end
@@ -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 @@
1
+ require 'compass/import-once'
@@ -0,0 +1,48 @@
1
+ require 'diff/lcs'
2
+ require 'diff/lcs/hunk'
3
+
4
+ module DiffAsString
5
+ #stole this from rspec who stole this from the gem
6
+ def diff_as_string(data_old, data_new)
7
+ data_old = data_old.split(/\n/).map! { |e| e.chomp }
8
+ data_new = data_new.split(/\n/).map! { |e| e.chomp }
9
+ output = ""
10
+ diffs = ::Diff::LCS.diff(data_old, data_new)
11
+ return output if diffs.empty?
12
+ oldhunk = hunk = nil
13
+ file_length_difference = 0
14
+ diffs.each do |piece|
15
+ begin
16
+ hunk = ::Diff::LCS::Hunk.new(
17
+ data_old, data_new, piece, context_lines, file_length_difference
18
+ )
19
+ file_length_difference = hunk.file_length_difference
20
+ next unless oldhunk
21
+ # Hunks may overlap, which is why we need to be careful when our
22
+ # diff includes lines of context. Otherwise, we might print
23
+ # redundant lines.
24
+ if (context_lines > 0) and hunk.overlaps?(oldhunk)
25
+ hunk.unshift(oldhunk)
26
+ else
27
+ output << oldhunk.diff(format)
28
+ end
29
+ ensure
30
+ oldhunk = hunk
31
+ output << "\n"
32
+ end
33
+ end
34
+ #Handle the last remaining hunk
35
+ output << oldhunk.diff(format) << "\n"
36
+ end
37
+
38
+ protected
39
+
40
+ def format
41
+ :unified
42
+ end
43
+
44
+ def context_lines
45
+ 3
46
+ end
47
+
48
+ end
@@ -0,0 +1,5 @@
1
+ $simple-imported: 0 !default;
2
+ $simple-imported: $simple-imported + 1;
3
+ .simple {
4
+ times-imported: $simple-imported;
5
+ }
@@ -0,0 +1,3 @@
1
+ .simple {
2
+ times-imported: 1;
3
+ }
@@ -0,0 +1,2 @@
1
+ @import "simple_partial";
2
+ @import "simple_partial";
@@ -0,0 +1,7 @@
1
+ .simple {
2
+ times-imported: 1;
3
+ }
4
+
5
+ .simple {
6
+ times-imported: 2;
7
+ }
@@ -0,0 +1,2 @@
1
+ @import "simple_partial";
2
+ @import "simple_partial!";
@@ -0,0 +1,3 @@
1
+ .simple {
2
+ times-imported: 1;
3
+ }
@@ -0,0 +1,2 @@
1
+ @import "*_partial*";
2
+ @import "simple_partial";
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ require 'test_helper'
3
+ require 'fileutils'
4
+
5
+ # These are useful in debugging.
6
+ module Sass::Script::Functions
7
+ def filename
8
+ if @options[:filename]
9
+ Sass::Script::String.new(@options[:filename], true)
10
+ else
11
+ Sass::Script::Null.new
12
+ end
13
+ end
14
+ def importer
15
+ if @options[:importer]
16
+ Sass::Script::String.new(@options[:importer].inspect, true)
17
+ else
18
+ Sass::Script::Null.new
19
+ end
20
+ end
21
+ def importer_is_import_onced
22
+ Sass::Script::Bool.new(@options[:importer].is_a?(Compass::ImportOnce::Importer))
23
+ end
24
+ end
25
+
26
+ class ImportOnceTest < Test::Unit::TestCase
27
+ FIXTURES_DIR = File.join(File.expand_path(File.dirname(__FILE__)), "fixtures")
28
+ Dir.glob(File.join(FIXTURES_DIR, "**", "*.scss")).each do |scss_file|
29
+ if ENV["FIXTURE"]
30
+ next unless File.expand_path(ENV["FIXTURE"]) == scss_file
31
+ end
32
+ dir = File.dirname(scss_file)
33
+ basename = File.basename(scss_file, ".scss")
34
+ next if basename.start_with?("_")
35
+ define_method "test_#{basename}" do
36
+ assert_compilation_result(
37
+ File.join(dir, "#{basename}.scss"),
38
+ File.join(dir, "#{basename}.css"))
39
+ end
40
+ end
41
+
42
+ protected
43
+
44
+ def assert_compilation_result(sass_file, css_file, options = {})
45
+ options[:style] ||= :expanded
46
+ actual_result = Sass.compile_file(sass_file, options)
47
+ expected_result = File.read(css_file)
48
+ assert expected_result == actual_result, diff_as_string(expected_result, actual_result)
49
+ FileUtils.rm_f("#{css_file}.error") # cleanup from old tests now that it's passing
50
+ rescue Exception => e
51
+ open("#{css_file}.error", "w") {|f| f.write(actual_result) }
52
+ raise
53
+ end
54
+ end
@@ -0,0 +1,9 @@
1
+ require 'sass'
2
+ require 'compass/import-once/activate'
3
+ require 'sass-globbing'
4
+ require 'test/unit'
5
+ require 'diff_as_string'
6
+
7
+ class Test::Unit::TestCase
8
+ include DiffAsString
9
+ end
metadata ADDED
@@ -0,0 +1,156 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: compass-import-once-sass37
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Vladimir Ivanin
8
+ - Chris Eppstein
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2025-10-13 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: sass
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ">="
19
+ - !ruby/object:Gem::Version
20
+ version: '3.7'
21
+ - - "<"
22
+ - !ruby/object:Gem::Version
23
+ version: '3.8'
24
+ type: :runtime
25
+ prerelease: false
26
+ version_requirements: !ruby/object:Gem::Requirement
27
+ requirements:
28
+ - - ">="
29
+ - !ruby/object:Gem::Version
30
+ version: '3.7'
31
+ - - "<"
32
+ - !ruby/object:Gem::Version
33
+ version: '3.8'
34
+ - !ruby/object:Gem::Dependency
35
+ name: bundler
36
+ requirement: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ type: :development
42
+ prerelease: false
43
+ version_requirements: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '1.3'
48
+ - !ruby/object:Gem::Dependency
49
+ name: diff-lcs
50
+ requirement: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ type: :development
56
+ prerelease: false
57
+ version_requirements: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: rake
64
+ requirement: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ type: :development
70
+ prerelease: false
71
+ version_requirements: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ - !ruby/object:Gem::Dependency
77
+ name: sass-globbing
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ description: Changes the behavior of Sass's @import directive to only import a file
91
+ once. Updated for Sass 3.7 compatibility.
92
+ email:
93
+ - ivaninww@gmail.com
94
+ executables: []
95
+ extensions: []
96
+ extra_rdoc_files: []
97
+ files:
98
+ - ".gitignore"
99
+ - Gemfile
100
+ - Gemfile_sass_3_2
101
+ - LICENSE.txt
102
+ - README.md
103
+ - Rakefile
104
+ - VERSION
105
+ - compass-import-once.gemspec
106
+ - lib/compass-import-once.rb
107
+ - lib/compass/import-once.rb
108
+ - lib/compass/import-once/activate.rb
109
+ - lib/compass/import-once/engine.rb
110
+ - lib/compass/import-once/importer.rb
111
+ - lib/compass/import-once/version.rb
112
+ - test/diff_as_string.rb
113
+ - test/fixtures/_simple_partial.scss
114
+ - test/fixtures/basic.css
115
+ - test/fixtures/basic.scss
116
+ - test/fixtures/force_import.css
117
+ - test/fixtures/force_import.scss
118
+ - test/fixtures/with_globbing.css
119
+ - test/fixtures/with_globbing.scss
120
+ - test/import_once_test.rb
121
+ - test/test_helper.rb
122
+ homepage: https://github.com/VladimirIvanin/compass
123
+ licenses:
124
+ - MIT
125
+ metadata: {}
126
+ post_install_message:
127
+ rdoc_options: []
128
+ require_paths:
129
+ - lib
130
+ required_ruby_version: !ruby/object:Gem::Requirement
131
+ requirements:
132
+ - - ">="
133
+ - !ruby/object:Gem::Version
134
+ version: '0'
135
+ required_rubygems_version: !ruby/object:Gem::Requirement
136
+ requirements:
137
+ - - ">="
138
+ - !ruby/object:Gem::Version
139
+ version: '0'
140
+ requirements: []
141
+ rubygems_version: 3.3.7
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Speed up your Sass compilation by making @import only import each file once
145
+ (Sass 3.7 compatible)
146
+ test_files:
147
+ - test/diff_as_string.rb
148
+ - test/fixtures/_simple_partial.scss
149
+ - test/fixtures/basic.css
150
+ - test/fixtures/basic.scss
151
+ - test/fixtures/force_import.css
152
+ - test/fixtures/force_import.scss
153
+ - test/fixtures/with_globbing.css
154
+ - test/fixtures/with_globbing.scss
155
+ - test/import_once_test.rb
156
+ - test/test_helper.rb