compass-connector 0.5.2 → 0.6
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/compass-connector.rb +43 -26
- data/lib/compass-connector/importer.rb +3 -8
- data/lib/compass-connector/patches/actions.rb +28 -0
- data/lib/compass-connector/patches/compiler.rb +22 -14
- data/lib/compass-connector/patches/image_size.rb +1 -1
- data/lib/compass-connector/patches/inline_images.rb +3 -3
- data/lib/compass-connector/patches/sprite_image.rb +1 -1
- data/lib/compass-connector/patches/sprite_methods.rb +49 -0
- data/lib/compass-connector/patches/urls.rb +8 -7
- metadata +4 -2
data/lib/compass-connector.rb
CHANGED
@@ -1,63 +1,69 @@
|
|
1
1
|
require 'compass'
|
2
|
+
|
2
3
|
require 'json'
|
4
|
+
require 'base64'
|
3
5
|
|
4
6
|
require 'compass-connector/importer'
|
5
7
|
|
6
8
|
module CompassConnector
|
7
9
|
|
10
|
+
class FakeFile < File
|
11
|
+
def initialize(data)
|
12
|
+
path = "/tmp/"+data["hash"]+"."+data["ext"]
|
13
|
+
super path, "w+b"
|
14
|
+
write(Base64.decode64(data["data"]))
|
15
|
+
rewind()
|
16
|
+
File.utime(Time.new, Time.at(data["mtime"]), path)
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.from_response(response)
|
20
|
+
if response
|
21
|
+
FakeFile.new(response)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
8
27
|
class Resolver
|
9
28
|
|
10
29
|
@process = nil
|
11
30
|
|
12
31
|
private_class_method
|
13
32
|
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
33
|
data_in = JSON::dump({'method' => method, 'args' => args})
|
23
|
-
|
24
|
-
|
25
|
-
out =
|
26
|
-
#$stdout.puts "Process output: " + out
|
34
|
+
STDOUT.puts data_in << "\n"
|
35
|
+
STDOUT.flush
|
36
|
+
out = STDIN.gets
|
27
37
|
ret = JSON::load(out)
|
28
38
|
if ret.kind_of?(Hash) and ret.has_key?("error")
|
29
|
-
raise
|
39
|
+
raise "Remote process error: " + ret["error"]
|
30
40
|
end
|
31
41
|
return ret
|
32
42
|
end
|
33
43
|
|
34
|
-
|
35
|
-
|
36
|
-
resolver("find_scss", uri)
|
37
|
-
end
|
38
|
-
def self.list_main_files()
|
39
|
-
resolver("list_main_files")
|
44
|
+
def self.find_import(uri)
|
45
|
+
FakeFile.from_response(resolver("find_import", uri))
|
40
46
|
end
|
41
47
|
def self.image_url(path)
|
42
48
|
resolver("get_image_url", path)
|
43
49
|
end
|
44
|
-
def self.
|
45
|
-
resolver("
|
50
|
+
def self.get_image(path)
|
51
|
+
FakeFile.from_response(resolver("get_file", path, "image"))
|
46
52
|
end
|
47
53
|
def self.generated_image_url(path)
|
48
54
|
resolver("get_generated_image_url", path)
|
49
55
|
end
|
50
|
-
def self.
|
51
|
-
resolver("
|
56
|
+
def self.get_generated_image(path)
|
57
|
+
FakeFile.from_response(resolver("get_file", path, "generated_image"))
|
52
58
|
end
|
53
59
|
def self.find_sprites_matching(uri)
|
54
60
|
resolver("find_sprites_matching", uri)
|
55
61
|
end
|
56
62
|
def self.find_sprite(file)
|
57
|
-
resolver("
|
63
|
+
FakeFile.from_response(resolver("get_file", file, "sprite"))
|
58
64
|
end
|
59
|
-
def self.
|
60
|
-
resolver("
|
65
|
+
def self.get_font(path)
|
66
|
+
FakeFile.from_response(resolver("get_file", path, "font"))
|
61
67
|
end
|
62
68
|
def self.font_url(path)
|
63
69
|
resolver("get_font_url", path)
|
@@ -65,6 +71,15 @@ module CompassConnector
|
|
65
71
|
def self.stylesheet_url(path)
|
66
72
|
resolver("get_stylesheet_url", path)
|
67
73
|
end
|
74
|
+
def self.put_sprite(filename, f)
|
75
|
+
resolver("put_file", filename, "sprite", Base64.encode64(f.read))
|
76
|
+
end
|
77
|
+
def self.put_output_css(filename, data)
|
78
|
+
resolver("put_file", filename, "css", Base64.encode64(data))
|
79
|
+
end
|
80
|
+
def self.get_output_css(filename)
|
81
|
+
FakeFile.from_response(resolver("get_file", filename, "out_stylesheet"))
|
82
|
+
end
|
68
83
|
|
69
84
|
def self.configuration()
|
70
85
|
resolver("get_configuration")
|
@@ -75,10 +90,12 @@ module CompassConnector
|
|
75
90
|
end
|
76
91
|
|
77
92
|
require 'compass-connector/configuration'
|
93
|
+
require 'compass-connector/patches/actions'
|
78
94
|
require 'compass-connector/patches/compiler'
|
79
95
|
require 'compass-connector/patches/urls'
|
80
96
|
require 'compass-connector/patches/sprite_image'
|
81
97
|
require 'compass-connector/patches/sprite_map'
|
98
|
+
require 'compass-connector/patches/sprite_methods'
|
82
99
|
require 'compass-connector/patches/sprite_importer'
|
83
100
|
require 'compass-connector/patches/image_size'
|
84
101
|
require 'compass-connector/patches/inline_images'
|
@@ -8,13 +8,11 @@ module CompassConnector
|
|
8
8
|
end
|
9
9
|
|
10
10
|
def find(uri, options)
|
11
|
-
f = CompassConnector::Resolver.
|
11
|
+
f = CompassConnector::Resolver.find_import(uri)
|
12
12
|
|
13
13
|
if f
|
14
|
-
|
15
|
-
|
16
|
-
opts = options.merge(:syntax => syntax, :importer => self, :filename => f)
|
17
|
-
return Sass::Engine.new(open(f).read, opts)
|
14
|
+
opts = options.merge(:syntax => :scss, :importer => self, :filename => uri)
|
15
|
+
return Sass::Engine.new(f.read, opts)
|
18
16
|
end
|
19
17
|
|
20
18
|
nil
|
@@ -25,9 +23,6 @@ module CompassConnector
|
|
25
23
|
end
|
26
24
|
|
27
25
|
def mtime(name, options)
|
28
|
-
file, s = find_real_file(name)
|
29
|
-
File.mtime(file) if file
|
30
|
-
rescue Errno::ENOENT
|
31
26
|
nil
|
32
27
|
end
|
33
28
|
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Compass
|
2
|
+
module Actions
|
3
|
+
|
4
|
+
# Write a file given the file contents as a string
|
5
|
+
def write_file(file_name, contents, options = nil, binary = false)
|
6
|
+
options[:force] = false
|
7
|
+
options ||= self.options if self.respond_to?(:options)
|
8
|
+
skip_write = options[:dry_run]
|
9
|
+
contents = process_erb(contents, options[:erb]) if options[:erb]
|
10
|
+
old_file = CompassConnector::Resolver.get_output_css(file_name)
|
11
|
+
if old_file != nil
|
12
|
+
existing_contents = old_file.read()
|
13
|
+
if existing_contents == contents
|
14
|
+
log_action :identical, basename(file_name), options
|
15
|
+
skip_write = true
|
16
|
+
else options[:force]
|
17
|
+
log_action :overwrite, basename(file_name), options
|
18
|
+
end
|
19
|
+
else
|
20
|
+
log_action :create, basename(file_name), options
|
21
|
+
end
|
22
|
+
if not skip_write
|
23
|
+
CompassConnector::Resolver.put_output_css(file_name, contents)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
@@ -10,14 +10,12 @@ module Compass
|
|
10
10
|
exclude_partials = options.fetch(:exclude_partials, true)
|
11
11
|
|
12
12
|
if self.options[:sass_files] != nil
|
13
|
-
@sass_files = self.options[:sass_files]
|
14
|
-
else
|
15
13
|
@sass_files = []
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
14
|
+
self.options[:sass_files].each { |f|
|
15
|
+
@sass_files << shorten_path(f)
|
16
|
+
}
|
17
|
+
else
|
18
|
+
raise "Cannot compile project, only single files are supported"
|
21
19
|
end
|
22
20
|
|
23
21
|
@sass_files
|
@@ -27,12 +25,26 @@ module Compass
|
|
27
25
|
sass_file[0..-6].sub(/\.css$/,'')
|
28
26
|
end
|
29
27
|
|
28
|
+
def shorten_path(path)
|
29
|
+
if path.start_with?(Dir.pwd)
|
30
|
+
path[Dir.pwd.length+1..-1]
|
31
|
+
else
|
32
|
+
path
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
30
36
|
# A sass engine for compiling a single file.
|
31
37
|
def engine(sass_filename, css_filename)
|
32
|
-
sass_filename =
|
38
|
+
sass_filename = shorten_path(sass_filename)
|
39
|
+
css_filename = corresponding_css_file(sass_filename)
|
40
|
+
|
41
|
+
sass_file = CompassConnector::Resolver.find_import(sass_filename)
|
42
|
+
if not sass_file
|
43
|
+
raise "File '#{sass_filename}' was not found"
|
44
|
+
end
|
33
45
|
syntax = (sass_filename =~ /\.(s[ac]ss)$/) && $1.to_sym || :sass
|
34
46
|
opts = sass_options.merge(:filename => sass_filename, :css_filename => css_filename, :syntax => syntax)
|
35
|
-
Sass::Engine.new(
|
47
|
+
Sass::Engine.new(sass_file.read, opts)
|
36
48
|
end
|
37
49
|
|
38
50
|
def sass_options
|
@@ -44,11 +56,7 @@ module Compass
|
|
44
56
|
end
|
45
57
|
|
46
58
|
def corresponding_css_file(sass_file)
|
47
|
-
|
48
|
-
sass_file = sass_file[from.length+1 .. -1]
|
49
|
-
end
|
50
|
-
|
51
|
-
"#{to}/#{stylesheet_name(sass_file)}.css"
|
59
|
+
"#{stylesheet_name(sass_file)}.css"
|
52
60
|
end
|
53
61
|
end
|
54
62
|
end
|
@@ -4,8 +4,8 @@ module Compass::SassExtensions::Functions::InlineImage
|
|
4
4
|
|
5
5
|
def inline_image(path, mime_type = nil)
|
6
6
|
path = path.value
|
7
|
-
|
8
|
-
inline_image_string(data(
|
7
|
+
my_file = CompassConnector::Resolver.get_image(path)
|
8
|
+
inline_image_string(data(my_file.to_path), compute_mime_type(path, mime_type))
|
9
9
|
end
|
10
10
|
|
11
11
|
def inline_font_files(*args)
|
@@ -13,7 +13,7 @@ module Compass::SassExtensions::Functions::InlineImage
|
|
13
13
|
files = []
|
14
14
|
while args.size > 0
|
15
15
|
path = args.shift.value
|
16
|
-
real_path = CompassConnector::Resolver.
|
16
|
+
real_path = CompassConnector::Resolver.get_font(path)
|
17
17
|
url = inline_image_string(data(real_path), compute_mime_type(path))
|
18
18
|
files << "#{url} format('#{args.shift}')"
|
19
19
|
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require "compass/sass_extensions/sprites/sprite_methods"
|
2
|
+
require "tempfile"
|
3
|
+
|
4
|
+
module Compass
|
5
|
+
module SassExtensions
|
6
|
+
module Sprites
|
7
|
+
module SpriteMethods
|
8
|
+
|
9
|
+
def tmp_filename
|
10
|
+
fname = File.join(Compass.configuration.generated_images_path, name_and_hash)
|
11
|
+
f = CompassConnector::Resolver.get_generated_image(fname)
|
12
|
+
f && f.to_path || nil
|
13
|
+
end
|
14
|
+
|
15
|
+
def generation_required?
|
16
|
+
!(tmp_filename && File.exists?(tmp_filename)) || outdated?
|
17
|
+
end
|
18
|
+
|
19
|
+
def outdated?
|
20
|
+
if tmp_filename && File.exists?(tmp_filename)
|
21
|
+
return @images.any? {|image|
|
22
|
+
image.mtime.to_i > self.mtime.to_i
|
23
|
+
}
|
24
|
+
end
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
def mtime
|
29
|
+
@mtime ||= File.mtime(tmp_filename)
|
30
|
+
end
|
31
|
+
|
32
|
+
def save!
|
33
|
+
f=Tempfile.new("sprite")
|
34
|
+
engine.save(f.to_path)
|
35
|
+
f.rewind
|
36
|
+
saved = CompassConnector::Resolver.put_sprite(filename, f)
|
37
|
+
f.close!
|
38
|
+
|
39
|
+
#saved = true engine.save(filename)
|
40
|
+
log :create, filename
|
41
|
+
Compass.configuration.run_sprite_saved(filename)
|
42
|
+
@mtime = nil if saved
|
43
|
+
saved
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -3,16 +3,17 @@ require 'compass/sass_extensions/functions/urls'
|
|
3
3
|
module Compass::SassExtensions::Functions::Urls
|
4
4
|
module ImageUrl
|
5
5
|
def image_url(path, only_path = Sass::Script::Bool.new(false), cache_buster = Sass::Script::Bool.new(true))
|
6
|
-
|
6
|
+
org_path = path.value
|
7
7
|
|
8
|
-
|
9
|
-
path = CompassConnector::Resolver.image_url(path)
|
8
|
+
path = CompassConnector::Resolver.image_url(org_path)
|
10
9
|
|
11
10
|
# Compute and append the cache buster if there is one.
|
12
11
|
if cache_buster.to_bool
|
13
12
|
if cache_buster.is_a?(Sass::Script::String)
|
14
13
|
path += "?#{cache_buster.value}"
|
15
14
|
else
|
15
|
+
data = CompassConnector::Resolver.get_image(org_path)
|
16
|
+
real_path = data.to_path
|
16
17
|
path = cache_busted_path(path, real_path)
|
17
18
|
end
|
18
19
|
end
|
@@ -52,16 +53,16 @@ module Compass::SassExtensions::Functions::Urls
|
|
52
53
|
end
|
53
54
|
module GeneratedImageUrl
|
54
55
|
def generated_image_url(path, cache_buster = Sass::Script::Bool.new(false))
|
55
|
-
|
56
|
+
org_path = path.value # get to the string value of the literal.
|
56
57
|
|
57
|
-
|
58
|
-
path = CompassConnector::Resolver.generated_image_url(path)
|
58
|
+
path = CompassConnector::Resolver.generated_image_url(org_path)
|
59
59
|
|
60
60
|
# Compute and append the cache buster if there is one.
|
61
61
|
if cache_buster.to_bool
|
62
62
|
if cache_buster.is_a?(Sass::Script::String)
|
63
63
|
path += "?#{cache_buster.value}"
|
64
64
|
else
|
65
|
+
real_path = CompassConnector::Resolver.get_generated_image(org_path).to_path
|
65
66
|
path = cache_busted_path(path, real_path)
|
66
67
|
end
|
67
68
|
end
|
@@ -69,4 +70,4 @@ module Compass::SassExtensions::Functions::Urls
|
|
69
70
|
clean_url(path)
|
70
71
|
end
|
71
72
|
end
|
72
|
-
end
|
73
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: compass-connector
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.6'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-05-18 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: compass
|
@@ -37,9 +37,11 @@ files:
|
|
37
37
|
- lib/compass-connector/configuration.rb
|
38
38
|
- lib/compass-connector/importer.rb
|
39
39
|
- lib/compass-connector/patches/compiler.rb
|
40
|
+
- lib/compass-connector/patches/actions.rb
|
40
41
|
- lib/compass-connector/patches/sprite_map.rb
|
41
42
|
- lib/compass-connector/patches/inline_images.rb
|
42
43
|
- lib/compass-connector/patches/sprite_importer.rb
|
44
|
+
- lib/compass-connector/patches/sprite_methods.rb
|
43
45
|
- lib/compass-connector/patches/urls.rb
|
44
46
|
- lib/compass-connector/patches/sprite_image.rb
|
45
47
|
- lib/compass-connector/patches/image_size.rb
|