compass-connector 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/compass-connector.rb +84 -0
- data/lib/compass-connector/configuration.rb +13 -0
- data/lib/compass-connector/importer.rb +40 -0
- data/lib/compass-connector/patches/compiler.rb +54 -0
- data/lib/compass-connector/patches/image_size.rb +7 -0
- data/lib/compass-connector/patches/inline_images.rb +22 -0
- data/lib/compass-connector/patches/sprite_image.rb +13 -0
- data/lib/compass-connector/patches/sprite_importer.rb +22 -0
- data/lib/compass-connector/patches/sprite_map.rb +13 -0
- data/lib/compass-connector/patches/urls.rb +72 -0
- metadata +73 -0
@@ -0,0 +1,84 @@
|
|
1
|
+
require 'compass'
|
2
|
+
require 'json'
|
3
|
+
|
4
|
+
require 'compass-connector/importer'
|
5
|
+
|
6
|
+
module CompassConnector
|
7
|
+
|
8
|
+
class Resolver
|
9
|
+
|
10
|
+
@process = nil
|
11
|
+
|
12
|
+
private_class_method
|
13
|
+
def self.resolver(method, *args)
|
14
|
+
if @process == nil
|
15
|
+
cmd = ENV["COMPASS_CONNECTOR"]
|
16
|
+
if cmd == nil
|
17
|
+
raise Compass::Error, "You have to define COMPASS_CONNECTOR env variable"
|
18
|
+
end
|
19
|
+
@process = IO.popen(cmd, "r+")
|
20
|
+
end
|
21
|
+
|
22
|
+
data_in = JSON::dump({'method' => method, 'args' => args})
|
23
|
+
#$stdout.puts "Process input: " + data_in
|
24
|
+
@process << data_in << "\n"
|
25
|
+
out = @process.gets
|
26
|
+
#$stdout.puts "Process output: " + out
|
27
|
+
ret = JSON::load(out)
|
28
|
+
if ret.kind_of?(Hash) and ret.has_key?("error")
|
29
|
+
raise Compass::Error, "Remote process error: " + ret["error"]
|
30
|
+
end
|
31
|
+
return ret
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
def self.find_scss(uri)
|
36
|
+
resolver("find_scss", uri)
|
37
|
+
end
|
38
|
+
def self.list_main_files()
|
39
|
+
resolver("list_main_files")
|
40
|
+
end
|
41
|
+
def self.image_url(path)
|
42
|
+
resolver("get_image_url", path)
|
43
|
+
end
|
44
|
+
def self.find_image(path)
|
45
|
+
resolver("find_image", path)
|
46
|
+
end
|
47
|
+
def self.generated_image_url(path)
|
48
|
+
resolver("get_generated_image_url", path)
|
49
|
+
end
|
50
|
+
def self.find_generated_image(path)
|
51
|
+
resolver("find_generated_image", path)
|
52
|
+
end
|
53
|
+
def self.find_sprites_matching(uri)
|
54
|
+
resolver("find_sprites_matching", uri)
|
55
|
+
end
|
56
|
+
def self.find_sprite(file)
|
57
|
+
resolver("find_sprite", file)
|
58
|
+
end
|
59
|
+
def self.find_font(path)
|
60
|
+
resolver("find_font", path)
|
61
|
+
end
|
62
|
+
def self.font_url(path)
|
63
|
+
resolver("get_font_url", path)
|
64
|
+
end
|
65
|
+
def self.stylesheet_url(path)
|
66
|
+
resolver("get_stylesheet_url", path)
|
67
|
+
end
|
68
|
+
|
69
|
+
def self.configuration()
|
70
|
+
resolver("get_configuration")
|
71
|
+
end
|
72
|
+
|
73
|
+
end
|
74
|
+
|
75
|
+
end
|
76
|
+
|
77
|
+
require 'compass-connector/configuration'
|
78
|
+
require 'compass-connector/patches/compiler'
|
79
|
+
require 'compass-connector/patches/urls'
|
80
|
+
require 'compass-connector/patches/sprite_image'
|
81
|
+
require 'compass-connector/patches/sprite_map'
|
82
|
+
require 'compass-connector/patches/sprite_importer'
|
83
|
+
require 'compass-connector/patches/image_size'
|
84
|
+
require 'compass-connector/patches/inline_images'
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "compass/configuration"
|
2
|
+
|
3
|
+
CompassConnector::Resolver.configuration().each do |key,value|
|
4
|
+
if value.is_a?String and value.start_with?(":")
|
5
|
+
value[0]=''
|
6
|
+
value = value.to_sym
|
7
|
+
end
|
8
|
+
Compass.configuration.send(key+"=", value)
|
9
|
+
end
|
10
|
+
|
11
|
+
Compass.configuration.http_path = "/"
|
12
|
+
Compass.configuration.relative_assets = false
|
13
|
+
Compass.configuration.cache_path = Compass.configuration.project_path + "/.sass-cache"
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'compass'
|
2
|
+
|
3
|
+
module CompassConnector
|
4
|
+
|
5
|
+
class Importer < Sass::Importers::Base
|
6
|
+
def to_s()
|
7
|
+
"CompassConnector::Importer"
|
8
|
+
end
|
9
|
+
|
10
|
+
def find(uri, options)
|
11
|
+
f = CompassConnector::Resolver.find_scss(uri)
|
12
|
+
|
13
|
+
if f
|
14
|
+
f = f.to_s
|
15
|
+
syntax = (f =~ /\.(s[ac]ss)$/) && $1.to_sym || :sass
|
16
|
+
opts = options.merge(:syntax => syntax, :importer => self, :filename => f)
|
17
|
+
return Sass::Engine.new(open(f).read, opts)
|
18
|
+
end
|
19
|
+
|
20
|
+
nil
|
21
|
+
end
|
22
|
+
|
23
|
+
def find_relative(uri, base, options)
|
24
|
+
nil
|
25
|
+
end
|
26
|
+
|
27
|
+
def mtime(name, options)
|
28
|
+
file, s = find_real_file(name)
|
29
|
+
File.mtime(file) if file
|
30
|
+
rescue Errno::ENOENT
|
31
|
+
nil
|
32
|
+
end
|
33
|
+
|
34
|
+
def key(name, options)
|
35
|
+
[self.class.name + ":" + File.dirname(File.expand_path(name)),
|
36
|
+
File.basename(name)]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,54 @@
|
|
1
|
+
require 'compass/compiler'
|
2
|
+
|
3
|
+
module Compass
|
4
|
+
class Compiler
|
5
|
+
|
6
|
+
attr_accessor(:django_sass)
|
7
|
+
attr_accessor :sass_options
|
8
|
+
|
9
|
+
def sass_files(options = {})
|
10
|
+
exclude_partials = options.fetch(:exclude_partials, true)
|
11
|
+
|
12
|
+
if self.options[:sass_files] != nil
|
13
|
+
@sass_files = self.options[:sass_files]
|
14
|
+
else
|
15
|
+
@sass_files = []
|
16
|
+
out = CompassConnector::Resolver.list_main_files
|
17
|
+
out.to_enum.each do |item|
|
18
|
+
@sass_files << item.to_s
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
@sass_files
|
24
|
+
end
|
25
|
+
|
26
|
+
def stylesheet_name(sass_file)
|
27
|
+
sass_file[0..-6].sub(/\.css$/,'')
|
28
|
+
end
|
29
|
+
|
30
|
+
# A sass engine for compiling a single file.
|
31
|
+
def engine(sass_filename, css_filename)
|
32
|
+
sass_filename = CompassConnector::Resolver.find_scss(sass_filename).to_s
|
33
|
+
syntax = (sass_filename =~ /\.(s[ac]ss)$/) && $1.to_sym || :sass
|
34
|
+
opts = sass_options.merge(:filename => sass_filename, :css_filename => css_filename, :syntax => syntax)
|
35
|
+
Sass::Engine.new(open(sass_filename).read, opts)
|
36
|
+
end
|
37
|
+
|
38
|
+
def sass_options
|
39
|
+
@sass_options[:load_paths] ||= []
|
40
|
+
unless @sass_options[:load_paths].any? {|k| k.is_a?(::CompassConnector::Importer) }
|
41
|
+
@sass_options[:load_paths] << ::CompassConnector::Importer.new()
|
42
|
+
end
|
43
|
+
@sass_options
|
44
|
+
end
|
45
|
+
|
46
|
+
def corresponding_css_file(sass_file)
|
47
|
+
if sass_file.start_with? from
|
48
|
+
sass_file = sass_file[from.length+1 .. -1]
|
49
|
+
end
|
50
|
+
|
51
|
+
"#{to}/#{stylesheet_name(sass_file)}.css"
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "compass/sass_extensions/functions/inline_image"
|
2
|
+
|
3
|
+
module Compass::SassExtensions::Functions::InlineImage
|
4
|
+
|
5
|
+
def inline_image(path, mime_type = nil)
|
6
|
+
path = path.value
|
7
|
+
real_path = CompassConnector::Resolver.find_image(path)
|
8
|
+
inline_image_string(data(real_path), compute_mime_type(path, mime_type))
|
9
|
+
end
|
10
|
+
|
11
|
+
def inline_font_files(*args)
|
12
|
+
raise Sass::SyntaxError, "An even number of arguments must be passed to font_files()" unless args.size % 2 == 0
|
13
|
+
files = []
|
14
|
+
while args.size > 0
|
15
|
+
path = args.shift.value
|
16
|
+
real_path = CompassConnector::Resolver.find_font(path)
|
17
|
+
url = inline_image_string(data(real_path), compute_mime_type(path))
|
18
|
+
files << "#{url} format('#{args.shift}')"
|
19
|
+
end
|
20
|
+
Sass::Script::String.new(files.join(", "))
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "compass/sprite_importer"
|
2
|
+
|
3
|
+
module Compass
|
4
|
+
class SpriteImporter
|
5
|
+
# Returns the Glob of image files for the uri
|
6
|
+
def self.files(uri)
|
7
|
+
|
8
|
+
files = []
|
9
|
+
|
10
|
+
CompassConnector::Resolver.find_sprites_matching(uri).to_enum.each do |item|
|
11
|
+
files << item.to_s
|
12
|
+
end
|
13
|
+
|
14
|
+
if not files.empty?
|
15
|
+
return files
|
16
|
+
end
|
17
|
+
|
18
|
+
raise Compass::SpriteException, %Q{No files were found in the load path matching "#{uri}".}
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'compass/sass_extensions/functions/urls'
|
2
|
+
|
3
|
+
module Compass::SassExtensions::Functions::Urls
|
4
|
+
module ImageUrl
|
5
|
+
def image_url(path, only_path = Sass::Script::Bool.new(false), cache_buster = Sass::Script::Bool.new(true))
|
6
|
+
path = path.value
|
7
|
+
|
8
|
+
real_path = CompassConnector::Resolver.find_image(path)
|
9
|
+
path = CompassConnector::Resolver.image_url(path)
|
10
|
+
|
11
|
+
# Compute and append the cache buster if there is one.
|
12
|
+
if cache_buster.to_bool
|
13
|
+
if cache_buster.is_a?(Sass::Script::String)
|
14
|
+
path += "?#{cache_buster.value}"
|
15
|
+
else
|
16
|
+
path = cache_busted_path(path, real_path)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
if only_path.to_bool
|
21
|
+
Sass::Script::String.new(clean_path(path))
|
22
|
+
else
|
23
|
+
clean_url(path)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
module FontUrl
|
28
|
+
def font_url(path, only_path = Sass::Script::Bool.new(false))
|
29
|
+
path = path.value # get to the string value of the literal.
|
30
|
+
|
31
|
+
path = CompassConnector::Resolver.font_url(path)
|
32
|
+
|
33
|
+
if only_path.to_bool
|
34
|
+
Sass::Script::String.new(clean_path(path))
|
35
|
+
else
|
36
|
+
clean_url(path)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
module StylesheetUrl
|
41
|
+
def stylesheet_url(path, only_path = Sass::Script::Bool.new(false))
|
42
|
+
path = path.value # get to the string value of the literal.
|
43
|
+
|
44
|
+
path = CompassConnector::Resolver.stylesheet_url(path)
|
45
|
+
|
46
|
+
if only_path.to_bool
|
47
|
+
Sass::Script::String.new(clean_path(path))
|
48
|
+
else
|
49
|
+
clean_url(path)
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
module GeneratedImageUrl
|
54
|
+
def generated_image_url(path, cache_buster = Sass::Script::Bool.new(false))
|
55
|
+
path = path.value # get to the string value of the literal.
|
56
|
+
|
57
|
+
real_path = CompassConnector::Resolver.find_generated_image(path)
|
58
|
+
path = CompassConnector::Resolver.generated_image_url(path)
|
59
|
+
|
60
|
+
# Compute and append the cache buster if there is one.
|
61
|
+
if cache_buster.to_bool
|
62
|
+
if cache_buster.is_a?(Sass::Script::String)
|
63
|
+
path += "?#{cache_buster.value}"
|
64
|
+
else
|
65
|
+
path = cache_busted_path(path, real_path)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
clean_url(path)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
metadata
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: compass-connector
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Arkadiusz Dzięgiel
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-04-08 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: compass
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Allows integration between Compass and any other framework with corresponding
|
31
|
+
other-framework connector.
|
32
|
+
email: admin@glorpen.pl
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- lib/compass-connector/configuration.rb
|
38
|
+
- lib/compass-connector/importer.rb
|
39
|
+
- lib/compass-connector/patches/compiler.rb
|
40
|
+
- lib/compass-connector/patches/sprite_map.rb
|
41
|
+
- lib/compass-connector/patches/inline_images.rb
|
42
|
+
- lib/compass-connector/patches/sprite_importer.rb
|
43
|
+
- lib/compass-connector/patches/urls.rb
|
44
|
+
- lib/compass-connector/patches/sprite_image.rb
|
45
|
+
- lib/compass-connector/patches/image_size.rb
|
46
|
+
- lib/compass-connector.rb
|
47
|
+
homepage: http://bitbucket.org/glorpen/compass-connector
|
48
|
+
licenses:
|
49
|
+
- GPL-3
|
50
|
+
post_install_message: To fully utilize this gem you should install connector app for
|
51
|
+
your project
|
52
|
+
rdoc_options: []
|
53
|
+
require_paths:
|
54
|
+
- lib
|
55
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
requirements: []
|
68
|
+
rubyforge_project:
|
69
|
+
rubygems_version: 1.8.24
|
70
|
+
signing_key:
|
71
|
+
specification_version: 3
|
72
|
+
summary: Compass integration with any framework
|
73
|
+
test_files: []
|