sassc-import_once 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eed180fae830b043ab189184845674f819b2d3e0
4
+ data.tar.gz: 2e4ed34ff44fdbb9882d479a5e9c7fe5d6e5b95b
5
+ SHA512:
6
+ metadata.gz: 5def8544d4b752e59df88b8d68295b7c1e7ee8a2599f96852ed6d6948c591c15fd66da47fd44b1d1243a5e4a766414e459decb375e834a9bcdbae770358de299
7
+ data.tar.gz: bccfe939d8e1c34224b8987121fd707688caee21ccd192a1788f505f0a9200060ea176112a81ef75e2b49368e4ed9257929a5f8bdf0e5ba6e26d4363bb04a04e
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ /gemfiles/*.lock
11
+ *.bundle
12
+ *.so
13
+ *.o
14
+ *.a
15
+ mkmf.log
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.2.3
data/.travis.yml ADDED
@@ -0,0 +1,14 @@
1
+ language: ruby
2
+ cache: bundler
3
+ sudo: false
4
+
5
+ rvm:
6
+ - 2.1.5
7
+ - 2.2.3
8
+
9
+ gemfile:
10
+ - gemfiles/sassc_1.8.0.gemfile
11
+ - gemfiles/sassc_1.8.1.gemfile
12
+
13
+ script: 'bundle exec rake'
14
+
data/Appraisals ADDED
@@ -0,0 +1,8 @@
1
+ appraise "sassc 1.8.0" do
2
+ gem "sassc", "1.8.0"
3
+ end
4
+
5
+ appraise "sassc 1.8.1" do
6
+ gem "sassc", "1.8.1"
7
+ end
8
+
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ gem 'appraisal'
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Paul Kmiec
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,39 @@
1
+ # SassC::ImportOnce
2
+ [![Gem Version][gem-badge]][gem]
3
+ [![Build status][build-badge]][build]
4
+
5
+ Changes the behavior of Sassc's @import directive to only import a file once. This is very similar to the functionality provided by https://github.com/Compass/compass/tree/master/import-once for Sass.
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'sassc-import_once', :require => 'sassc/import_once/activate'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install sassc-import_once
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Contributing
28
+
29
+ 1. Fork it ( https://github.com/[my-github-username]/sassc-import_once/fork )
30
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
31
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
32
+ 4. Push to the branch (`git push origin my-new-feature`)
33
+ 5. Create a new Pull Request
34
+
35
+ [gem-badge]: https://badge.fury.io/rb/sassc-import_once.svg
36
+ [gem]: http://badge.fury.io/rb/sassc-import_once
37
+ [build-badge]: https://travis-ci.org/appfolio/sassc-import_once.svg
38
+ [build]: https://travis-ci.org/appfolio/sassc-import_once
39
+
data/Rakefile ADDED
@@ -0,0 +1,13 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ require 'appraisal'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << "test"
8
+ t.test_files = FileList['test/**/*_test.rb']
9
+ t.verbose = true
10
+ end
11
+
12
+ task :default => :test
13
+
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "sassc", "1.8.0"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,8 @@
1
+ # This file was generated by Appraisal
2
+
3
+ source "https://rubygems.org"
4
+
5
+ gem "appraisal"
6
+ gem "sassc", "1.8.1"
7
+
8
+ gemspec :path => "../"
@@ -0,0 +1,19 @@
1
+ require 'sassc'
2
+ require 'sassc/import_once/version'
3
+ require 'sassc/import_once/engine'
4
+ require 'sassc/import_once/importer'
5
+
6
+ module SassC
7
+ module ImportOnce
8
+ extend self
9
+
10
+ def import_tracker
11
+ Thread.current[:sassc_import_once_tracker] ||= {}
12
+ end
13
+
14
+ def activate!
15
+ require 'sassc/import_once/activate'
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,3 @@
1
+ require 'sassc/import_once'
2
+
3
+ SassC::Engine.send(:prepend, SassC::ImportOnce::Engine)
@@ -0,0 +1,26 @@
1
+ module SassC
2
+ module ImportOnce
3
+ module Engine
4
+
5
+ def render
6
+ with_import_once(@options[:filename]) do
7
+ super
8
+ end
9
+ end
10
+
11
+ private
12
+
13
+ def with_import_once(css_filename)
14
+ if @options[:importer] && !@options[:importer].is_a?(SassC::ImportOnce::Importer)
15
+ @options[:importer].send(:prepend, SassC::ImportOnce::Importer)
16
+ end
17
+
18
+ SassC::ImportOnce.import_tracker[css_filename] = Set.new
19
+ yield
20
+ ensure
21
+ SassC::ImportOnce.import_tracker.delete(css_filename)
22
+ end
23
+
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,58 @@
1
+ module SassC
2
+ module ImportOnce
3
+ module Importer
4
+
5
+ def imports(path, parent_path)
6
+ path, force_import = handle_force_import(path)
7
+ reject_already_imported_imports(super(path, parent_path), force_import)
8
+ end
9
+
10
+ private
11
+
12
+ def handle_force_import(path)
13
+ if path.end_with?("!")
14
+ [path[0...-1], true]
15
+ else
16
+ [path, false]
17
+ end
18
+ end
19
+
20
+ def reject_already_imported_imports(imports, force_import)
21
+ return imports unless imports
22
+
23
+ imports = [ imports ] unless imports.is_a?(Enumerable)
24
+ imports.reject do |import|
25
+ reject_already_imported_import(import, force_import)
26
+ end
27
+ rescue => e
28
+ puts e
29
+ []
30
+ end
31
+
32
+ def reject_already_imported_import(import, force_import)
33
+ return true unless import
34
+ return true if !force_import && imported?(import)
35
+
36
+ imported!(import)
37
+ false
38
+ end
39
+
40
+ def tracker
41
+ SassC::ImportOnce.import_tracker[options[:filename]] ||= Set.new
42
+ end
43
+
44
+ def import_tracker_key(import)
45
+ import.path
46
+ end
47
+
48
+ def imported?(import)
49
+ tracker.include?(import_tracker_key(import))
50
+ end
51
+
52
+ def imported!(import)
53
+ tracker << import_tracker_key(import)
54
+ end
55
+
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ module SassC
2
+ module ImportOnce
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,25 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'sassc/import_once/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "sassc-import_once"
8
+ spec.version = SassC::ImportOnce::VERSION
9
+ spec.authors = ["Paul Kmiec"]
10
+ spec.email = ["paul.kmiec@appfolio.com"]
11
+ spec.summary = %q{Changes the behavior of Sassc's @import directive to only import a file once.}
12
+ spec.description = %q{Changes the behavior of Sassc's @import directive to only import a file once.}
13
+ spec.homepage = "https://github.com/appfolio/sassc-import_once"
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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 "sassc", "~> 1.8"
22
+ spec.add_development_dependency "bundler"
23
+ spec.add_development_dependency "rake"
24
+ spec.add_development_dependency "minitest"
25
+ end
@@ -0,0 +1,3 @@
1
+ .simple {
2
+ times-imported: 1;
3
+ }
@@ -0,0 +1,2 @@
1
+ @import "subfolder/simple_partial";
2
+ @import "subfolder/simple_partial";
@@ -0,0 +1,7 @@
1
+ .text {
2
+ color: #303030;
3
+ }
4
+
5
+ .button {
6
+ color: #303030;
7
+ }
@@ -0,0 +1,10 @@
1
+ @import "component/button";
2
+ @import "component/color";
3
+
4
+ .text {
5
+ color: $text-color;
6
+ }
7
+
8
+ .button {
9
+ color: $button-default-text-color;
10
+ }
@@ -0,0 +1,3 @@
1
+ @import "component/color";
2
+
3
+ $button-default-text-color: $text-color;
@@ -0,0 +1 @@
1
+ $text-color: #303030;
@@ -0,0 +1,3 @@
1
+ .simple {
2
+ times-imported: 1;
3
+ }
@@ -0,0 +1,2 @@
1
+ @import "subfolder/simple_partial!";
2
+ @import "subfolder/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 "subfolder/simple_partial";
2
+ @import "subfolder/simple_partial!";
@@ -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 "subfolder/*";
2
+ @import "subfolder/simple_partial";
@@ -0,0 +1,3 @@
1
+ .simple {
2
+ times-imported: 1;
3
+ }
@@ -0,0 +1,2 @@
1
+ @import "subfolder/*";
2
+ @import "subfolder/*";
@@ -0,0 +1,4 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'sassc/import_once'
4
+ require 'minitest/autorun'
@@ -0,0 +1,99 @@
1
+ # Shamelessly adapted from https://github.com/bolandrm/sassc-rails/blob/master/lib/sassc/rails/importer.rb
2
+
3
+ module SassC
4
+ module ImportOnce
5
+ class TestImporter < SassC::Importer
6
+
7
+ class ScssExtension
8
+ def postfix
9
+ ".scss"
10
+ end
11
+
12
+ def import_for(full_path, parent_dir, options)
13
+ # source = File.open(full_path, 'rb') { |f| f.read }
14
+ SassC::Importer::Import.new(full_path)
15
+ end
16
+ end
17
+
18
+ EXTENSIONS = [
19
+ ScssExtension.new,
20
+ ]
21
+
22
+ PREFIXS = [ "", "_" ]
23
+ GLOB = /(\A|\/)(\*|\*\*\/\*)\z/
24
+
25
+ def imports(path, parent_path)
26
+ parent_dir, _ = File.split(parent_path)
27
+ specified_dir, specified_file = File.split(path)
28
+
29
+ if m = path.match(GLOB)
30
+ path = path.sub(m[0], "")
31
+ base = File.expand_path(path, File.dirname(parent_path))
32
+ return glob_imports(base, m[2], parent_path)
33
+ end
34
+ search_paths = ([parent_dir] + load_paths).uniq
35
+
36
+ if specified_dir != "."
37
+ search_paths.map! do |path|
38
+ File.join(path, specified_dir)
39
+ end
40
+ end
41
+
42
+ search_paths.each do |search_path|
43
+ PREFIXS.each do |prefix|
44
+ file_name = prefix + specified_file
45
+
46
+ EXTENSIONS.each do |extension|
47
+ try_path = File.join(search_path, file_name + extension.postfix)
48
+ if File.exists?(try_path)
49
+ return extension.import_for(try_path, parent_dir, options)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ SassC::Importer::Import.new(path)
55
+
56
+ end
57
+
58
+ private
59
+
60
+ def extension_for_file(file)
61
+ EXTENSIONS.detect do |extension|
62
+ file.include? extension.postfix
63
+ end
64
+ end
65
+
66
+ def load_paths
67
+ @options[:load_paths]
68
+ end
69
+
70
+ def glob_imports(base, glob, current_file)
71
+ files = globbed_files(base, glob)
72
+ files = files.reject { |f| f == current_file }
73
+
74
+ files.map do |filename|
75
+ extension = extension_for_file(filename)
76
+ extension.import_for(filename, base, @options)
77
+ end
78
+ end
79
+
80
+ def globbed_files(base, glob)
81
+ # TODO: Raise an error from SassC here
82
+ raise ArgumentError unless glob == "*" || glob == "**/*"
83
+
84
+ extensions = EXTENSIONS.map(&:postfix)
85
+ exts = extensions.map { |ext| Regexp.escape("#{ext}") }.join("|")
86
+ sass_re = Regexp.compile("(#{exts})$")
87
+
88
+ files = Dir["#{base}/#{glob}"].sort.map do |path|
89
+ if File.directory?(path)
90
+ nil
91
+ elsif sass_re =~ path
92
+ path
93
+ end
94
+ end
95
+ files.compact
96
+ end
97
+ end
98
+ end
99
+ end
@@ -0,0 +1,52 @@
1
+ require 'minitest_helper'
2
+ require 'sassc/import_once/activate'
3
+ require 'sassc/import_once/test_importer'
4
+
5
+ module SassC
6
+ class ImportOnceTest < Minitest::Test
7
+ FIXTURES_DIR = File.expand_path('../../fixtures', __FILE__)
8
+
9
+ def test_basic
10
+ assert_compilation_result('basic')
11
+ end
12
+
13
+ def test_force_import_first
14
+ assert_compilation_result('force_import_first')
15
+ end
16
+
17
+ def test_force_import_last
18
+ assert_compilation_result('force_import_last')
19
+ end
20
+
21
+ def test_with_globbing
22
+ assert_compilation_result('with_globbing')
23
+ end
24
+
25
+ def test_with_lots_globbing
26
+ assert_compilation_result('with_lots_globbing')
27
+ end
28
+
29
+ def test_component
30
+ assert_compilation_result('component')
31
+ end
32
+
33
+ private
34
+
35
+ def assert_compilation_result(fixture_name)
36
+ sass_file = File.join(FIXTURES_DIR, "#{fixture_name}.scss")
37
+ css_file = File.join(FIXTURES_DIR, "#{fixture_name}.css")
38
+
39
+ options = {
40
+ style: :expanded,
41
+ filename: sass_file,
42
+ importer: SassC::ImportOnce::TestImporter,
43
+ load_paths: [ FIXTURES_DIR ]
44
+ }
45
+
46
+ actual_result = SassC::Engine.new(File.read(sass_file), options).render
47
+ expected_result = File.read(css_file)
48
+ assert_equal expected_result, actual_result
49
+ end
50
+ end
51
+ end
52
+
metadata ADDED
@@ -0,0 +1,153 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sassc-import_once
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Paul Kmiec
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sassc
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
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: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ description: Changes the behavior of Sassc's @import directive to only import a file
70
+ once.
71
+ email:
72
+ - paul.kmiec@appfolio.com
73
+ executables: []
74
+ extensions: []
75
+ extra_rdoc_files: []
76
+ files:
77
+ - ".gitignore"
78
+ - ".ruby-version"
79
+ - ".travis.yml"
80
+ - Appraisals
81
+ - Gemfile
82
+ - LICENSE.txt
83
+ - README.md
84
+ - Rakefile
85
+ - gemfiles/sassc_1.8.0.gemfile
86
+ - gemfiles/sassc_1.8.1.gemfile
87
+ - lib/sassc/import_once.rb
88
+ - lib/sassc/import_once/activate.rb
89
+ - lib/sassc/import_once/engine.rb
90
+ - lib/sassc/import_once/importer.rb
91
+ - lib/sassc/import_once/version.rb
92
+ - sassc-import_once.gemspec
93
+ - test/fixtures/basic.css
94
+ - test/fixtures/basic.scss
95
+ - test/fixtures/component.css
96
+ - test/fixtures/component.scss
97
+ - test/fixtures/component/_button.scss
98
+ - test/fixtures/component/_color.scss
99
+ - test/fixtures/force_import_first.css
100
+ - test/fixtures/force_import_first.scss
101
+ - test/fixtures/force_import_last.css
102
+ - test/fixtures/force_import_last.scss
103
+ - test/fixtures/subfolder/_simple_partial.scss
104
+ - test/fixtures/with_globbing.css
105
+ - test/fixtures/with_globbing.scss
106
+ - test/fixtures/with_lots_globbing.css
107
+ - test/fixtures/with_lots_globbing.scss
108
+ - test/minitest_helper.rb
109
+ - test/sassc/import_once/test_importer.rb
110
+ - test/sassc/import_once_test.rb
111
+ homepage: https://github.com/appfolio/sassc-import_once
112
+ licenses:
113
+ - MIT
114
+ metadata: {}
115
+ post_install_message:
116
+ rdoc_options: []
117
+ require_paths:
118
+ - lib
119
+ required_ruby_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ required_rubygems_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ requirements: []
130
+ rubyforge_project:
131
+ rubygems_version: 2.4.8
132
+ signing_key:
133
+ specification_version: 4
134
+ summary: Changes the behavior of Sassc's @import directive to only import a file once.
135
+ test_files:
136
+ - test/fixtures/basic.css
137
+ - test/fixtures/basic.scss
138
+ - test/fixtures/component.css
139
+ - test/fixtures/component.scss
140
+ - test/fixtures/component/_button.scss
141
+ - test/fixtures/component/_color.scss
142
+ - test/fixtures/force_import_first.css
143
+ - test/fixtures/force_import_first.scss
144
+ - test/fixtures/force_import_last.css
145
+ - test/fixtures/force_import_last.scss
146
+ - test/fixtures/subfolder/_simple_partial.scss
147
+ - test/fixtures/with_globbing.css
148
+ - test/fixtures/with_globbing.scss
149
+ - test/fixtures/with_lots_globbing.css
150
+ - test/fixtures/with_lots_globbing.scss
151
+ - test/minitest_helper.rb
152
+ - test/sassc/import_once/test_importer.rb
153
+ - test/sassc/import_once_test.rb