sass-zip-importer 1.0.0.beta.0

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: 7117fdfdec658ecd9994319991df2e62b82babcd
4
+ data.tar.gz: 54588a76bb42bfed64c6ee26f3220f75ac0e3851
5
+ SHA512:
6
+ metadata.gz: 9f873013a9289cdc9b2f2983eca75fe680194a7709c937982d681eb831cf8494f58bad5823ccd1426d3f8053d8425f8cd85688624744b8492b93d99fb5b2d42f
7
+ data.tar.gz: ab192e0c9d3175b8bbe1dd666cc1a6ff25984dfcbadb231e846ea5a732e5a4a60b526b98c7525624faa7a0004dfc70273989c0a2a3c730143b5897e7cd2bce67
data/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
@@ -0,0 +1,3 @@
1
+ # 1.0.0
2
+
3
+ Initial release.
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'rake'
data/Gemfile.lock ADDED
@@ -0,0 +1,18 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ sass-css-importer (1.0.0.beta.0)
5
+ sass (>= 3.1)
6
+
7
+ GEM
8
+ remote: http://rubygems.org/
9
+ specs:
10
+ rake (10.1.0)
11
+ sass (3.2.9)
12
+
13
+ PLATFORMS
14
+ ruby
15
+
16
+ DEPENDENCIES
17
+ rake
18
+ sass-css-importer!
data/README.markdown ADDED
@@ -0,0 +1,31 @@
1
+ # Sass CSS Importer Plugin
2
+
3
+ The Sass Zip Importer allows you to import CSS, Sass, and SCSS files
4
+ from a zip file without unpacking it.
5
+
6
+ ## Stylesheet Syntax
7
+
8
+ This importer works with the standard filesystem based import syntax,
9
+ allowing you to import from a folder or zip file with the same code.
10
+ This allows you to develop against an unpacked version of a library but
11
+ also compile the stylesheets against a pre-built zip file (for example,
12
+ during a build process).
13
+
14
+ ## Installation
15
+
16
+ $ gem install --pre sass-zip-importer
17
+
18
+ ## Use with the Sass command line
19
+
20
+ $ sass -r sass-zip-importer -I path/to/file.zip --watch sass_dir:css_dir
21
+
22
+ Note: several -r options can be given to the sass command line if you
23
+ need to require several libraries.
24
+
25
+ ## Use with Compass
26
+
27
+ Add the following to your compass configuration:
28
+
29
+ require 'sass-zip-importer'
30
+ # Note: you can call add_import_path more than once.
31
+ add_import_path "#{File.dirname(__FILE__)}/path/to/file.zip"
data/Rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rake/testtask'
5
+
6
+ Rake::TestTask.new(:test) do |t|
7
+ t.libs << 'lib'
8
+ t.libs << 'test'
9
+ t.pattern = 'test/**/*_test.rb'
10
+ t.verbose = false
11
+ end
@@ -0,0 +1,124 @@
1
+
2
+ class Sass::ZipImporter::Importer < Sass::Importers::Base
3
+
4
+ attr_reader :zip_file
5
+
6
+ def extensions
7
+ {
8
+ ".scss" => :scss,
9
+ ".css" => :scss,
10
+ ".sass" => :sass
11
+ }
12
+ end
13
+
14
+ def initialize(zip_file)
15
+ require 'zip/zip'
16
+ require 'pathname'
17
+ @zip_file = File.expand_path(zip_file)
18
+ end
19
+
20
+ # Enable watching of css files in Sass 3.3+
21
+ def watched_directories
22
+ [File.dirname(zip_file)]
23
+ end
24
+
25
+ # Enable watching of css files in Sass 3.3+
26
+ def watched_file?(file)
27
+ zip_file == file
28
+ end
29
+
30
+ def find_relative(name, base, options)
31
+ base = base.split("!", 2).last
32
+ if entry = entry_for(name, base)
33
+ engine(entry, options)
34
+ end
35
+ end
36
+
37
+
38
+ def find(name, options)
39
+ if entry = entry_for(name)
40
+ engine(entry, options)
41
+ end
42
+ end
43
+
44
+ def engine(entry, options)
45
+ options[:syntax] = extensions.fetch(File.extname(entry.name), :scss)
46
+ options[:filename] = full_filename(entry)
47
+ options[:importer] = self
48
+ Sass::Engine.new(zip.read(entry), options)
49
+ end
50
+
51
+
52
+ def mtime(name, options)
53
+ if entry = entry_for(name)
54
+ entry.time
55
+ end
56
+ nil
57
+ end
58
+
59
+ def key(name, options)
60
+ name.split("!", 2)
61
+ end
62
+
63
+ def to_s
64
+ zip_file
65
+ end
66
+
67
+ def eql?(other)
68
+ other.class == self.class && other.zip_file == self.zip_file
69
+ end
70
+
71
+ protected
72
+
73
+ def full_filename(entry)
74
+ "#{zip_file}!#{entry.name}"
75
+ end
76
+
77
+ def entry_for(name, base = nil)
78
+ possible_names(name, base).each do |n|
79
+ if entry = zip.find_entry(n)
80
+ return entry
81
+ end
82
+ end
83
+ nil
84
+ end
85
+
86
+ def possible_names(name, base = nil)
87
+ if base
88
+ absolute_root = Pathname.new("/")
89
+ base_path = Pathname.new(base)
90
+ path = Pathname.new(name)
91
+ begin
92
+ name = absolute_root.join(base_path).dirname.join(path).relative_path_from(absolute_root).to_s
93
+ rescue
94
+ # couldn't create a relative path, so we'll just assume it's absolute or for a different importer.
95
+ return []
96
+ end
97
+ end
98
+ d, b = File.split(name)
99
+ names = if b.start_with?("_")
100
+ [name]
101
+ else
102
+ [name, d == "." ? "_#{b}" : "#{d}/_#{b}"]
103
+ end
104
+
105
+ names.map do |n|
106
+ if (ext = File.extname(n)).size > 0 && extensions.keys.include?(ext)
107
+ n
108
+ else
109
+ extensions.keys.map{|k| "#{n}#{k}" }
110
+ end
111
+ end.flatten
112
+ end
113
+
114
+ def zip
115
+ @zip ||= open_zip_file!
116
+ end
117
+
118
+ def open_zip_file!
119
+ z = Zip::ZipFile.open(zip_file)
120
+ at_exit { z.close }
121
+ z
122
+ end
123
+
124
+ end
@@ -0,0 +1,17 @@
1
+ require 'sass'
2
+
3
+ class Sass::Engine
4
+ alias initialize_without_zip_importer initialize
5
+
6
+ def initialize(template, options={})
7
+ if options[:load_paths]
8
+ options[:load_paths].map! do |load_path|
9
+ next load_path unless load_path.is_a?(::String) && load_path =~ /\.zip$/
10
+ Sass::ZipImporter::Importer.new(load_path)
11
+ end
12
+ end
13
+
14
+ initialize_without_zip_importer(template, options)
15
+ end
16
+ end
17
+
@@ -0,0 +1,5 @@
1
+ module Sass
2
+ module ZipImporter
3
+ VERSION = "1.0.0.beta.0"
4
+ end
5
+ end
@@ -0,0 +1,7 @@
1
+ module Sass
2
+ module ZipImporter
3
+ end
4
+ end
5
+
6
+ require 'sass/zip_importer/importer';
7
+ require 'sass/zip_importer/monkey_patches';
@@ -0,0 +1 @@
1
+ require 'sass/zip_importer'
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sass/zip_importer/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sass-zip-importer"
7
+ s.version = Sass::ZipImporter::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Chris Eppstein"]
10
+ s.email = ["chris@eppsteins.net"]
11
+ s.homepage = "http://chriseppstein.github.com/"
12
+ s.summary = %q{Allows importing of css files using Sass @import directives.}
13
+ s.description = %q{Allows importing of css files using Sass @import directives.}
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- test/*`.split("\n")
17
+ s.require_paths = ["lib"]
18
+
19
+ s.add_runtime_dependency 'sass', '>= 3.1'
20
+ s.add_runtime_dependency 'rubyzip', '~> 0.9.9'
21
+
22
+ end
@@ -0,0 +1 @@
1
+ zipped_files.zip
@@ -0,0 +1,7 @@
1
+ @import "css_partial";
2
+ @import "sass_partial";
3
+ @import "scss_partial";
4
+ @import "a_css_file";
5
+ @import "a_sass_file";
6
+ @import "a_scss_file";
7
+ @import "nested/nested";
@@ -0,0 +1,3 @@
1
+ .css-partial {
2
+ color: black;
3
+ }
@@ -0,0 +1,2 @@
1
+ .sass-partial
2
+ partial: yep
@@ -0,0 +1,3 @@
1
+ .scss-partial {
2
+ partial: yes;
3
+ }
@@ -0,0 +1,3 @@
1
+ .css-file {
2
+ css: boring;
3
+ }
@@ -0,0 +1,2 @@
1
+ .sass-file
2
+ indented: yes
@@ -0,0 +1,3 @@
1
+ .scss-file {
2
+ curly-braces: omg;
3
+ }
@@ -0,0 +1,4 @@
1
+ @import "deeply_nested/deeply";
2
+ .nested-class {
3
+ nested: yep;
4
+ }
@@ -0,0 +1,3 @@
1
+ .deeply-nested {
2
+ deeply: nested;
3
+ }
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ lib_dir = File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
3
+ $: << lib_dir unless $:.include?(lib_dir)
4
+ require 'test/unit'
5
+ require 'zip/zip'
6
+ require 'pathname'
7
+ require 'fileutils'
8
+ require 'sass'
9
+ require 'sass-zip-importer'
10
+
11
+ class SassZipImporterTest < Test::Unit::TestCase
12
+ ZIP_FIXTURE_DIR = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "zipped_files"))
13
+ ZIP_FIXTURE = File.expand_path(File.join(File.dirname(__FILE__), "fixtures", "zipped_files.zip"))
14
+
15
+ def setup
16
+ unless $zip_created
17
+ $zip_created = true
18
+ zip_path = Pathname.new(ZIP_FIXTURE_DIR)
19
+ FileUtils.rm_f(ZIP_FIXTURE)
20
+ Zip::ZipOutputStream.open(ZIP_FIXTURE) do |io|
21
+ Dir.glob("#{ZIP_FIXTURE_DIR}/**/*.*").each do |file|
22
+ filename = Pathname.new(file).relative_path_from(zip_path)
23
+ io.put_next_entry(filename.to_s)
24
+ io.write File.read(file)
25
+ end
26
+ end
27
+ end
28
+ end
29
+
30
+ def test_can_import_css_files_files
31
+ css = render_file("imports_from_zip.scss")
32
+ assert_match(/\.css-partial/, css)
33
+ assert_match(/\.css-file/, css)
34
+ assert_match(/\.sass-partial/, css)
35
+ assert_match(/\.sass-file/, css)
36
+ assert_match(/\.scss-partial/, css)
37
+ assert_match(/\.scss-file/, css)
38
+ assert_match(/\.nested-class/, css)
39
+ assert_match(/\.deeply-nested/, css)
40
+ end
41
+
42
+ private
43
+ def render_file(filename)
44
+ fixtures_dir = File.expand_path("fixtures", File.dirname(__FILE__))
45
+ full_filename = File.expand_path(filename, fixtures_dir)
46
+ syntax = File.extname(full_filename)[1..-1].to_sym
47
+ engine = Sass::Engine.new(File.read(full_filename),
48
+ :syntax => syntax,
49
+ :filename => full_filename,
50
+ :cache => false,
51
+ :read_cache => false,
52
+ :load_paths => [ZIP_FIXTURE])
53
+ engine.render
54
+ end
55
+ end
metadata ADDED
@@ -0,0 +1,106 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sass-zip-importer
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.beta.0
5
+ platform: ruby
6
+ authors:
7
+ - Chris Eppstein
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-07-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sass
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '3.1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '3.1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubyzip
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.9
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.9
41
+ description: Allows importing of css files using Sass @import directives.
42
+ email:
43
+ - chris@eppsteins.net
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - CHANGELOG.markdown
50
+ - Gemfile
51
+ - Gemfile.lock
52
+ - README.markdown
53
+ - Rakefile
54
+ - lib/sass-zip-importer.rb
55
+ - lib/sass/zip_importer.rb
56
+ - lib/sass/zip_importer/importer.rb
57
+ - lib/sass/zip_importer/monkey_patches.rb
58
+ - lib/sass/zip_importer/version.rb
59
+ - sass-zip-importer.gemspec
60
+ - test/fixtures/.gitignore
61
+ - test/fixtures/imports_from_zip.scss
62
+ - test/fixtures/zipped_files/_css_partial.css
63
+ - test/fixtures/zipped_files/_sass_partial.sass
64
+ - test/fixtures/zipped_files/_scss_partial.scss
65
+ - test/fixtures/zipped_files/a_css_file.css
66
+ - test/fixtures/zipped_files/a_sass_file.sass
67
+ - test/fixtures/zipped_files/a_scss_file.scss
68
+ - test/fixtures/zipped_files/nested/_nested.scss
69
+ - test/fixtures/zipped_files/nested/deeply_nested/_deeply.scss
70
+ - test/sass_zip_importer_test.rb
71
+ homepage: http://chriseppstein.github.com/
72
+ licenses: []
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - '>'
86
+ - !ruby/object:Gem::Version
87
+ version: 1.3.1
88
+ requirements: []
89
+ rubyforge_project:
90
+ rubygems_version: 2.0.0.rc.2
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Allows importing of css files using Sass @import directives.
94
+ test_files:
95
+ - test/fixtures/.gitignore
96
+ - test/fixtures/imports_from_zip.scss
97
+ - test/fixtures/zipped_files/_css_partial.css
98
+ - test/fixtures/zipped_files/_sass_partial.sass
99
+ - test/fixtures/zipped_files/_scss_partial.scss
100
+ - test/fixtures/zipped_files/a_css_file.css
101
+ - test/fixtures/zipped_files/a_sass_file.sass
102
+ - test/fixtures/zipped_files/a_scss_file.scss
103
+ - test/fixtures/zipped_files/nested/_nested.scss
104
+ - test/fixtures/zipped_files/nested/deeply_nested/_deeply.scss
105
+ - test/sass_zip_importer_test.rb
106
+ has_rdoc: