sass-globbing 1.0.0.rc.1

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in sass-globbing.gemspec
4
+ gemspec
5
+
6
+ gem 'rake'
7
+ gem 'sass', :path => "/Users/chris/Projects/sass"
data/README.markdown ADDED
@@ -0,0 +1,40 @@
1
+ # Sass Globbing Plugin
2
+
3
+ ## Installation
4
+
5
+ $ gem install sass-globbing
6
+
7
+ ## Use with the Sass command line
8
+
9
+ $ sass -r sass-globbing --watch sass_dir:css_dir
10
+
11
+ ## Use with compass
12
+
13
+ Add the following to your compass configuration:
14
+
15
+ require 'sass-globbing'
16
+
17
+ ## Use with Ruby on Rails
18
+
19
+ Ruby on Rails has this capability out of the box starting in Rails 3.1. Do not install this plugin if you use Rails 3.1 or greater.
20
+
21
+ ## Stylesheet Syntax
22
+
23
+ Import a folder of files:
24
+
25
+ @import "library/mixins/*"
26
+
27
+ Import a tree of files:
28
+
29
+ @import "library/**/*"
30
+
31
+ Globbed files are sorted alphabetically before importing them.
32
+
33
+ Globs are always relative to the current file. The ruby glob file syntax is used, read the [docs][globbing_docs] for more that you can do with it.
34
+
35
+ ## Caveats
36
+
37
+ CSS is order dependent, as such, using this approach within your stylesheets to import styles that depend on the stylesheet's cascade creates an opportunity for styles to change more unpredictably than a manually asserted order. It is recommended that you only use globbing where order is unimportant; E.g. importing of library files.
38
+
39
+
40
+ [globbing_docs]: http://ruby-doc.org/core/classes/Dir.html#M000629
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 @@
1
+ require 'sass/globbing'
@@ -0,0 +1,7 @@
1
+ module Sass
2
+ module Globbing
3
+ end
4
+ end
5
+
6
+ require 'sass/globbing/importer';
7
+ require 'sass/globbing/monkey_patches';
@@ -0,0 +1,79 @@
1
+ require 'pathname'
2
+
3
+ class Sass::Globbing::Importer < Sass::Importers::Filesystem
4
+
5
+ include Singleton
6
+
7
+ GLOB = /\*/
8
+
9
+ SASS_EXTENSIONS = {
10
+ ".sass" => :sass,
11
+ ".scss" => :scss
12
+ }
13
+
14
+ def initialize
15
+ super(".")
16
+ end
17
+
18
+ def sass_file?(filename)
19
+ SASS_EXTENSIONS.has_key?(File.extname(filename.to_s))
20
+ end
21
+
22
+ def syntax(filename)
23
+ SASS_EXTENSIONS[File.extname(filename.to_s)]
24
+ end
25
+
26
+ def find_relative(name, base, options)
27
+ if name =~ GLOB
28
+ contents = ""
29
+ base_pathname = Pathname.new(base)
30
+ each_globbed_file(name, base_pathname, options) do |filename|
31
+ contents << "@import #{Pathname.new(filename).relative_path_from(base_pathname.dirname).to_s.inspect};\n"
32
+ end
33
+ return nil if contents.empty?
34
+ Sass::Engine.new(contents, options.merge(
35
+ :filename => base_pathname.to_s,
36
+ :importer => self,
37
+ :syntax => :scss
38
+ ))
39
+ else
40
+ super
41
+ end
42
+ end
43
+
44
+ def find(name, options)
45
+ if options[:filename] # globs must be relative
46
+ find_relative(name, options[:filename], options)
47
+ end
48
+ end
49
+
50
+ def each_globbed_file(glob, base_pathname, options)
51
+ Dir["#{base_pathname.dirname}/#{glob}"].sort.each do |filename|
52
+ next if filename == options[:filename]
53
+ yield filename if sass_file?(filename)
54
+ end
55
+ end
56
+
57
+ def mtime(name, options)
58
+ if name =~ GLOB && options[:filename]
59
+ mtime = nil
60
+ each_globbed_file(name, Pathname.new(options[:filename]), options) do |p|
61
+ if mtime.nil?
62
+ mtime = File.mtime(p)
63
+ else
64
+ mtime = [mtime, File.mtime(p)].max
65
+ end
66
+ end
67
+ mtime
68
+ end
69
+ end
70
+
71
+ def key(name, options)
72
+ ["Glob:" + File.dirname(File.expand_path(name)), File.basename(name)]
73
+ end
74
+
75
+ def to_s
76
+ "Sass::Globbing::Importer"
77
+ end
78
+
79
+ end
@@ -0,0 +1,12 @@
1
+ require 'sass'
2
+
3
+ class Sass::Engine
4
+ alias old_initialize initialize
5
+
6
+ def initialize(template, options={})
7
+ old_initialize(template, options)
8
+ unless self.options[:load_paths].include?(Sass::Globbing::Importer.instance)
9
+ self.options[:load_paths].unshift Sass::Globbing::Importer.instance
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module Sass
2
+ module Globbing
3
+ VERSION = "1.0.0.rc.1"
4
+ end
5
+ end
@@ -0,0 +1,21 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "sass/globbing/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "sass-globbing"
7
+ s.version = Sass::Globbing::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 use of globs in Sass @import directives.}
13
+ s.description = %q{Allows use of globs in 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
+
21
+ end
@@ -0,0 +1 @@
1
+ @import "partials/*"
@@ -0,0 +1,4 @@
1
+ @import "nested/**/*"
2
+
3
+ .partial-1
4
+ color: black
@@ -0,0 +1,2 @@
1
+ .nested
2
+ color: red
@@ -0,0 +1,2 @@
1
+ .nested-2
2
+ color: brown
@@ -0,0 +1,3 @@
1
+ .deeply-nested {
2
+ color: blue;
3
+ }
@@ -0,0 +1,22 @@
1
+ require 'test/unit'
2
+ require 'sass'
3
+ require 'sass-globbing'
4
+
5
+ class SassGlobbingTest < Test::Unit::TestCase
6
+
7
+ def test_can_import_globbed_files
8
+ css = render_file("all.sass")
9
+ assert_match css, /deeply-nested/
10
+ end
11
+
12
+ private
13
+ def render_file(filename)
14
+ full_filename = File.expand_path("fixtures/#{filename}", File.dirname(__FILE__))
15
+ syntax = File.extname(full_filename)[1..-1].to_sym
16
+ Sass::Engine.new(File.read(full_filename),
17
+ :syntax => syntax,
18
+ :filename => full_filename,
19
+ :cache => false,
20
+ :read_cache => false).render
21
+ end
22
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sass-globbing
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: 6
5
+ version: 1.0.0.rc.1
6
+ platform: ruby
7
+ authors:
8
+ - Chris Eppstein
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-04 00:00:00 -07:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: sass
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ">="
23
+ - !ruby/object:Gem::Version
24
+ version: "3.1"
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: Allows use of globs in Sass @import directives.
28
+ email:
29
+ - chris@eppsteins.net
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - .gitignore
38
+ - Gemfile
39
+ - README.markdown
40
+ - Rakefile
41
+ - lib/sass-globbing.rb
42
+ - lib/sass/globbing.rb
43
+ - lib/sass/globbing/importer.rb
44
+ - lib/sass/globbing/monkey_patches.rb
45
+ - lib/sass/globbing/version.rb
46
+ - sass-globbing.gemspec
47
+ - test/fixtures/all.sass
48
+ - test/fixtures/partials/_partial1.sass
49
+ - test/fixtures/partials/nested/_nested.sass
50
+ - test/fixtures/partials/nested/_nested_2.sass
51
+ - test/fixtures/partials/nested/deeply_nested/_deeply.scss
52
+ - test/sass_globbing_test.rb
53
+ has_rdoc: true
54
+ homepage: http://chriseppstein.github.com/
55
+ licenses: []
56
+
57
+ post_install_message:
58
+ rdoc_options: []
59
+
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ">="
66
+ - !ruby/object:Gem::Version
67
+ version: "0"
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ">"
72
+ - !ruby/object:Gem::Version
73
+ version: 1.3.1
74
+ requirements: []
75
+
76
+ rubyforge_project:
77
+ rubygems_version: 1.5.3
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Allows use of globs in Sass @import directives.
81
+ test_files:
82
+ - test/fixtures/all.sass
83
+ - test/fixtures/partials/_partial1.sass
84
+ - test/fixtures/partials/nested/_nested.sass
85
+ - test/fixtures/partials/nested/_nested_2.sass
86
+ - test/fixtures/partials/nested/deeply_nested/_deeply.scss
87
+ - test/sass_globbing_test.rb