polymer 1.0.0.beta.5 → 1.0.0.beta.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/polymer/cache.rb +27 -14
- data/lib/polymer/cli.rb +1 -4
- data/lib/polymer/man/polymer-bond.1 +1 -1
- data/lib/polymer/man/polymer-bond.1.txt +1 -1
- data/lib/polymer/man/polymer-init.1 +1 -1
- data/lib/polymer/man/polymer-init.1.txt +1 -1
- data/lib/polymer/man/polymer-optimise.1 +1 -1
- data/lib/polymer/man/polymer-optimise.1.txt +1 -1
- data/lib/polymer/man/polymer-position.1 +1 -1
- data/lib/polymer/man/polymer-position.1.txt +1 -1
- data/lib/polymer/man/polymer.1 +1 -1
- data/lib/polymer/man/polymer.1.txt +1 -1
- data/lib/polymer/man/polymer.5 +1 -1
- data/lib/polymer/man/polymer.5.txt +1 -1
- data/lib/polymer/project.rb +9 -2
- data/lib/polymer/sass_generator.rb +34 -2
- data/lib/polymer/sprite.rb +8 -0
- data/lib/polymer/version.rb +1 -1
- data/polymer.gemspec +2 -2
- metadata +12 -3
data/lib/polymer/cache.rb
CHANGED
@@ -14,6 +14,10 @@ module Polymer
|
|
14
14
|
:paths => {}
|
15
15
|
}
|
16
16
|
|
17
|
+
# If the first three characters of a path match this, the path isn't
|
18
|
+
# in a subtree of the project.
|
19
|
+
NON_SUBTREE = '../'.freeze
|
20
|
+
|
17
21
|
# Returns the path to the cache file.
|
18
22
|
#
|
19
23
|
# @return [Pathname]
|
@@ -22,15 +26,16 @@ module Polymer
|
|
22
26
|
|
23
27
|
# Creates a new Cache.
|
24
28
|
#
|
25
|
-
# If the
|
26
|
-
#
|
29
|
+
# If the project's +cache+ method returns a path which does not exist, the
|
30
|
+
# path -- and parent directories -- will be created.
|
27
31
|
#
|
28
|
-
# @param [
|
29
|
-
#
|
30
|
-
# will operate in-memory only and +write+ is disabled.
|
32
|
+
# @param [Polymer::Project] project
|
33
|
+
# The project whose cache file is to be loaded. If no +project+ is
|
34
|
+
# given, the cache will operate in-memory only and +write+ is disabled.
|
31
35
|
#
|
32
|
-
def initialize(
|
33
|
-
@
|
36
|
+
def initialize(project = nil)
|
37
|
+
@project = project
|
38
|
+
@path = project && project.cachefile
|
34
39
|
|
35
40
|
if @path and @path.file?
|
36
41
|
@cache = YAML.load_file @path
|
@@ -59,7 +64,13 @@ module Polymer
|
|
59
64
|
# @return [Boolean]
|
60
65
|
#
|
61
66
|
def fresh?(thing)
|
62
|
-
|
67
|
+
if thing.is_a?(Sprite) and not thing.save_path.file?
|
68
|
+
# If this is a data URI sprite a non-existent file is normal.
|
69
|
+
if ! @project || ! @project.data_uri_sprites.include?(thing)
|
70
|
+
return false
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
63
74
|
return false if thing.is_a?(Pathname) and not thing.cleanpath.file?
|
64
75
|
|
65
76
|
@cache[section(thing)][key(thing)] == digest(thing)
|
@@ -83,19 +94,19 @@ module Polymer
|
|
83
94
|
@cache[section(thing)].delete(key(thing))
|
84
95
|
end
|
85
96
|
|
86
|
-
# Removes any sprites no longer present in
|
97
|
+
# Removes any sprites no longer present in the project, and any cached
|
87
98
|
# images which cannot be located.
|
88
99
|
#
|
89
|
-
|
90
|
-
#
|
91
|
-
def clean!(project)
|
100
|
+
def clean!
|
92
101
|
return false unless @path
|
93
102
|
|
94
103
|
@cache[:paths].delete_if do |key, _|
|
95
|
-
not @path.dirname.join(key).file?
|
104
|
+
not @path.dirname.join(key).file? or
|
105
|
+
# Remove any path to a file not in a subtree (:data_uri images).
|
106
|
+
key[0..2] == NON_SUBTREE
|
96
107
|
end
|
97
108
|
|
98
|
-
sprite_keys = project.sprites.map { |sprite| key(sprite) }
|
109
|
+
sprite_keys = @project.sprites.map { |sprite| key(sprite) }
|
99
110
|
|
100
111
|
@cache[:sprites].delete_if do |key, _|
|
101
112
|
not sprite_keys.include?(key)
|
@@ -113,6 +124,8 @@ module Polymer
|
|
113
124
|
def write
|
114
125
|
return false unless @path
|
115
126
|
|
127
|
+
clean!
|
128
|
+
|
116
129
|
@path.open('w') do |file|
|
117
130
|
file.puts YAML.dump(@cache)
|
118
131
|
end
|
data/lib/polymer/cli.rb
CHANGED
@@ -83,9 +83,6 @@ module Polymer
|
|
83
83
|
end
|
84
84
|
end
|
85
85
|
|
86
|
-
# Clean up the cache, removing sprites which no longer exist.
|
87
|
-
project.cache.clean!(project)
|
88
|
-
|
89
86
|
# Finish by writing the new cache.
|
90
87
|
project.cache.write
|
91
88
|
|
@@ -234,7 +231,7 @@ module Polymer
|
|
234
231
|
end
|
235
232
|
end
|
236
233
|
|
237
|
-
cache.clean!
|
234
|
+
cache.clean! if project
|
238
235
|
cache.write
|
239
236
|
end
|
240
237
|
|
@@ -2,7 +2,7 @@
|
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.ad l
|
4
4
|
.
|
5
|
-
.TH "POLYMER\-BOND" "1" "
|
5
|
+
.TH "POLYMER\-BOND" "1" "November 2010" "POLYMER 1.0.0.BETA.6" "Polymer Manual"
|
6
6
|
.
|
7
7
|
.SH "NAME"
|
8
8
|
\fBpolymer\-bond\fR \- Create sprite images defined in your \.polymer file
|
@@ -2,7 +2,7 @@
|
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.ad l
|
4
4
|
.
|
5
|
-
.TH "POLYMER\-INIT" "1" "
|
5
|
+
.TH "POLYMER\-INIT" "1" "November 2010" "POLYMER 1.0.0.BETA.6" "Polymer Manual"
|
6
6
|
.
|
7
7
|
.SH "NAME"
|
8
8
|
\fBpolymer\-init\fR \- Create a new Polymer project in the current directory
|
@@ -2,7 +2,7 @@
|
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.ad l
|
4
4
|
.
|
5
|
-
.TH "POLYMER\-OPTIMISE" "1" "
|
5
|
+
.TH "POLYMER\-OPTIMISE" "1" "November 2010" "POLYMER 1.0.0.BETA.6" "Polymer Manual"
|
6
6
|
.
|
7
7
|
.SH "NAME"
|
8
8
|
\fBpolymer\-optimise\fR \- Optimise PNG images
|
@@ -2,7 +2,7 @@
|
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.ad l
|
4
4
|
.
|
5
|
-
.TH "POLYMER\-POSITION" "1" "
|
5
|
+
.TH "POLYMER\-POSITION" "1" "November 2010" "POLYMER 1.0.0.BETA.6" "Polymer Manual"
|
6
6
|
.
|
7
7
|
.SH "NAME"
|
8
8
|
\fBpolymer\-position\fR \- Information about your sprite sources
|
data/lib/polymer/man/polymer.1
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.ad l
|
4
4
|
.
|
5
|
-
.TH "POLYMER" "1" "
|
5
|
+
.TH "POLYMER" "1" "November 2010" "POLYMER 1.0.0.BETA.6" "Polymer Manual"
|
6
6
|
.
|
7
7
|
.SH "NAME"
|
8
8
|
\fBpolymer\fR \- Image spriting for web applications
|
data/lib/polymer/man/polymer.5
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
.\" http://github.com/rtomayko/ronn/tree/0.7.3
|
3
3
|
.ad l
|
4
4
|
.
|
5
|
-
.TH "\.POLYMER" "5" "
|
5
|
+
.TH "\.POLYMER" "5" "November 2010" "POLYMER 1.0.0.BETA.6" "Polymer Manual"
|
6
6
|
.
|
7
7
|
.SH "NAME"
|
8
8
|
\fB\.polymer\fR \- a format for describing image sprites and their sources
|
data/lib/polymer/project.rb
CHANGED
@@ -30,13 +30,20 @@ module Polymer
|
|
30
30
|
#
|
31
31
|
attr_reader :sass
|
32
32
|
|
33
|
-
# @return [Pathname
|
33
|
+
# @return [Pathname]
|
34
34
|
# The path to the CSS file.
|
35
35
|
# @return [false]
|
36
36
|
# False if CSS generation has been disabled.
|
37
37
|
#
|
38
38
|
attr_reader :css
|
39
39
|
|
40
|
+
# @return [Pathname]
|
41
|
+
# Returns the path to the project cache file.
|
42
|
+
# @return [false]
|
43
|
+
# Returns false if the project cache is disabled.
|
44
|
+
#
|
45
|
+
attr_reader :cachefile
|
46
|
+
|
40
47
|
# An array containing all of the sprites in the project.
|
41
48
|
#
|
42
49
|
# @return [Array<Polymer::Sprite>]
|
@@ -115,7 +122,7 @@ module Polymer
|
|
115
122
|
# @return [Polymer::Cache]
|
116
123
|
#
|
117
124
|
def cache
|
118
|
-
@cache ||= Polymer::Cache.new(
|
125
|
+
@cache ||= Polymer::Cache.new(self)
|
119
126
|
end
|
120
127
|
|
121
128
|
# Returns a path to a temporary directory which may be used by this
|
@@ -27,9 +27,24 @@ module Polymer
|
|
27
27
|
save_to = project.sass + '_polymer.sass'
|
28
28
|
end
|
29
29
|
|
30
|
+
# We need to keep track of any existing data URI values since, if the
|
31
|
+
# sprite is unchanged, we won't have access to it.
|
32
|
+
existing_data_uris = extract_existing_data_uris(
|
33
|
+
save_to, project.data_uri_sprites)
|
34
|
+
|
30
35
|
data_uris = project.data_uri_sprites.inject({}) do |memo, sprite|
|
31
|
-
|
32
|
-
|
36
|
+
if sprite.save_path.file?
|
37
|
+
data = [sprite.save_path.read].pack('m')
|
38
|
+
|
39
|
+
# Ruby < 1.9 doesn't support pack('m0'),
|
40
|
+
# so we have to do it manually.
|
41
|
+
data.gsub!(/\n/, '')
|
42
|
+
|
43
|
+
memo[sprite.name] = "data:image/png;base64,#{data}"
|
44
|
+
else
|
45
|
+
memo[sprite.name] = existing_data_uris[sprite.name]
|
46
|
+
end
|
47
|
+
|
33
48
|
memo
|
34
49
|
end
|
35
50
|
|
@@ -40,5 +55,22 @@ module Polymer
|
|
40
55
|
true
|
41
56
|
end # self.generate
|
42
57
|
|
58
|
+
# Given a path to a Sass file, extracts the existing data URI strings.
|
59
|
+
#
|
60
|
+
def self.extract_existing_data_uris(path, sprites)
|
61
|
+
return {} unless path.file?
|
62
|
+
|
63
|
+
sass = path.read.split("\n")
|
64
|
+
|
65
|
+
sprites.inject({}) do |memo, sprite|
|
66
|
+
if index = sass.index(".#{sprite.name}_data")
|
67
|
+
# The data is contained on the line following the selector.
|
68
|
+
memo[sprite.name] = sass[index + 1].scan(/url\((.+)\)/).first.first
|
69
|
+
end
|
70
|
+
|
71
|
+
memo
|
72
|
+
end
|
73
|
+
end
|
74
|
+
|
43
75
|
end # SassGenerator
|
44
76
|
end # Polymer
|
data/lib/polymer/sprite.rb
CHANGED
@@ -80,6 +80,14 @@ module Polymer
|
|
80
80
|
Digest::SHA256.hexdigest(sources.map { |source| source.digest }.join)
|
81
81
|
end
|
82
82
|
|
83
|
+
# A sprite is equal to another sprite if the names are the same.
|
84
|
+
#
|
85
|
+
# @return [Boolean]
|
86
|
+
#
|
87
|
+
def ==(other)
|
88
|
+
other.respond_to?(:name) and other.name == name
|
89
|
+
end
|
90
|
+
|
83
91
|
# Saves the composited sprite to disk.
|
84
92
|
#
|
85
93
|
# In the event that the sprite has no sources, +save+ will return false
|
data/lib/polymer/version.rb
CHANGED
data/polymer.gemspec
CHANGED
@@ -8,8 +8,8 @@ Gem::Specification.new do |s|
|
|
8
8
|
# rake task. It it completely safe to edit them, but using the rake task
|
9
9
|
# is easier.
|
10
10
|
s.name = 'polymer'
|
11
|
-
s.version = '1.0.0.beta.
|
12
|
-
s.date = '2010-
|
11
|
+
s.version = '1.0.0.beta.6'
|
12
|
+
s.date = '2010-11-01'
|
13
13
|
s.rubyforge_project = 'polymer'
|
14
14
|
|
15
15
|
# You may safely edit the section below.
|
metadata
CHANGED
@@ -1,14 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: polymer
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 62196367
|
4
5
|
prerelease: true
|
5
6
|
segments:
|
6
7
|
- 1
|
7
8
|
- 0
|
8
9
|
- 0
|
9
10
|
- beta
|
10
|
-
-
|
11
|
-
version: 1.0.0.beta.
|
11
|
+
- 6
|
12
|
+
version: 1.0.0.beta.6
|
12
13
|
platform: ruby
|
13
14
|
authors:
|
14
15
|
- Anthony Williams
|
@@ -16,7 +17,7 @@ autorequire:
|
|
16
17
|
bindir: bin
|
17
18
|
cert_chain: []
|
18
19
|
|
19
|
-
date: 2010-
|
20
|
+
date: 2010-11-01 00:00:00 +00:00
|
20
21
|
default_executable:
|
21
22
|
dependencies:
|
22
23
|
- !ruby/object:Gem::Dependency
|
@@ -27,6 +28,7 @@ dependencies:
|
|
27
28
|
requirements:
|
28
29
|
- - ">="
|
29
30
|
- !ruby/object:Gem::Version
|
31
|
+
hash: 25
|
30
32
|
segments:
|
31
33
|
- 2
|
32
34
|
- 13
|
@@ -41,6 +43,7 @@ dependencies:
|
|
41
43
|
requirements:
|
42
44
|
- - ">="
|
43
45
|
- !ruby/object:Gem::Version
|
46
|
+
hash: 39
|
44
47
|
segments:
|
45
48
|
- 0
|
46
49
|
- 14
|
@@ -56,6 +59,7 @@ dependencies:
|
|
56
59
|
requirements:
|
57
60
|
- - ">="
|
58
61
|
- !ruby/object:Gem::Version
|
62
|
+
hash: 62196421
|
59
63
|
segments:
|
60
64
|
- 2
|
61
65
|
- 0
|
@@ -73,6 +77,7 @@ dependencies:
|
|
73
77
|
requirements:
|
74
78
|
- - ">="
|
75
79
|
- !ruby/object:Gem::Version
|
80
|
+
hash: 53
|
76
81
|
segments:
|
77
82
|
- 0
|
78
83
|
- 8
|
@@ -88,6 +93,7 @@ dependencies:
|
|
88
93
|
requirements:
|
89
94
|
- - ">="
|
90
95
|
- !ruby/object:Gem::Version
|
96
|
+
hash: 35
|
91
97
|
segments:
|
92
98
|
- 3
|
93
99
|
- 0
|
@@ -103,6 +109,7 @@ dependencies:
|
|
103
109
|
requirements:
|
104
110
|
- - ">="
|
105
111
|
- !ruby/object:Gem::Version
|
112
|
+
hash: 5
|
106
113
|
segments:
|
107
114
|
- 0
|
108
115
|
- 7
|
@@ -182,6 +189,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
182
189
|
requirements:
|
183
190
|
- - ">="
|
184
191
|
- !ruby/object:Gem::Version
|
192
|
+
hash: 3
|
185
193
|
segments:
|
186
194
|
- 0
|
187
195
|
version: "0"
|
@@ -190,6 +198,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
198
|
requirements:
|
191
199
|
- - ">"
|
192
200
|
- !ruby/object:Gem::Version
|
201
|
+
hash: 25
|
193
202
|
segments:
|
194
203
|
- 1
|
195
204
|
- 3
|