polymer 1.0.0.beta.4 → 1.0.0.beta.5
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/History.md +11 -0
- data/README.md +7 -0
- data/lib/polymer/dsl.rb +19 -9
- 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 +14 -1
- data/lib/polymer/man/polymer.5.txt +12 -1
- data/lib/polymer/project.rb +27 -1
- data/lib/polymer/sass_generator.rb +6 -0
- data/lib/polymer/sprite.rb +6 -3
- data/lib/polymer/templates/sass_mixins.erb +10 -0
- data/lib/polymer/version.rb +1 -1
- data/polymer.gemspec +2 -2
- metadata +3 -3
data/History.md
CHANGED
@@ -25,6 +25,17 @@ v1.0.0 / HEAD (Unreleased)
|
|
25
25
|
also available as an alternative to the old "sprite-name-pos()"
|
26
26
|
mixins.
|
27
27
|
|
28
|
+
* Sprites can now be included "inline" in your Sass files by setting the
|
29
|
+
sprite path to :data\_uri in your .polymer file. This further reduces
|
30
|
+
the number of HTTP requests required at the expense of slightly
|
31
|
+
greater data transfer.
|
32
|
+
|
33
|
+
Polymer adds the data URI to the Sass file by using a selector (such
|
34
|
+
as ".my\_sprite\_data"), and then uses Sass' @extend feature so that
|
35
|
+
the data is only added to the CSS file once. Your own Sass files do
|
36
|
+
not need to be modified to make use of this feature; the @polymer
|
37
|
+
mixin suffices.
|
38
|
+
|
28
39
|
* The "polymer-pos" Sass mixin, which sets only the background position
|
29
40
|
of a source, without including the background-image property, has been
|
30
41
|
renamed to "polymer-position".
|
data/README.md
CHANGED
@@ -132,6 +132,13 @@ With the latest versions of the Haml library, you may use SCSS instead:
|
|
132
132
|
You can disable creation of the Sass mixin file by setting `config.sass
|
133
133
|
false` in the ".polymer" file.
|
134
134
|
|
135
|
+
Sass users can make use of data URIs; the sprite contents will, instead
|
136
|
+
of being written to disk, be inlined into your CSS files. This reduces
|
137
|
+
the number of HTTP requests required to load your pages, but results in
|
138
|
+
slightly more data having to be transferred to your users. See
|
139
|
+
[polymer(5)][polymer-5] for instructions.
|
140
|
+
|
141
|
+
|
135
142
|
### CSS Stylesheets
|
136
143
|
|
137
144
|
... are not yet implemented. Hold tight; these should be around before
|
data/lib/polymer/dsl.rb
CHANGED
@@ -114,7 +114,7 @@ module Polymer
|
|
114
114
|
raise Polymer::DslError,
|
115
115
|
"Sprite '#{source} => #{sprite}' has both a :name path segment " \
|
116
116
|
"and a :name option; please use only one."
|
117
|
-
elsif sprite !~ /:name/
|
117
|
+
elsif sprite != :data_uri and sprite !~ /:name/
|
118
118
|
raise Polymer::MissingName,
|
119
119
|
"Sprite '#{source} => #{sprite}' requires a :name segment in " \
|
120
120
|
"the sprite path."
|
@@ -138,7 +138,7 @@ module Polymer
|
|
138
138
|
project_config = @config.to_h
|
139
139
|
|
140
140
|
Project.new(@root, @sprites.map do |definition|
|
141
|
-
|
141
|
+
_create_sprite(definition, project_config)
|
142
142
|
end, project_config)
|
143
143
|
end
|
144
144
|
|
@@ -178,7 +178,9 @@ module Polymer
|
|
178
178
|
# existing sprite.
|
179
179
|
#
|
180
180
|
def _define_sprite(sources, sprite, options)
|
181
|
-
sources
|
181
|
+
sources = @root + sources
|
182
|
+
sprite = @root + sprite unless sprite == :data_uri
|
183
|
+
|
182
184
|
name = options[:name] || sprite.basename(sprite.extname).to_s
|
183
185
|
|
184
186
|
if @sprites.detect { |definition| definition[:name] == name }
|
@@ -193,7 +195,7 @@ module Polymer
|
|
193
195
|
@sprites << options.merge(
|
194
196
|
:name => name,
|
195
197
|
:sources => Pathname.glob(sources),
|
196
|
-
:save_path =>
|
198
|
+
:save_path => sprite
|
197
199
|
)
|
198
200
|
end
|
199
201
|
|
@@ -216,7 +218,8 @@ module Polymer
|
|
216
218
|
sprite_opts[:name] = entry.basename.to_s # Use directory as the name
|
217
219
|
|
218
220
|
source_path = "#{leading}#{sprite_opts[:name]}#{trailing}"
|
219
|
-
sprite_path = sprite
|
221
|
+
sprite_path = (sprite == :data_uri) ?
|
222
|
+
:data_uri : sprite.gsub(/:name/, sprite_opts[:name])
|
220
223
|
|
221
224
|
_define_sprite(source_path, sprite_path, sprite_opts)
|
222
225
|
end
|
@@ -232,16 +235,23 @@ module Polymer
|
|
232
235
|
# @return [Polymer::Sprite]
|
233
236
|
#
|
234
237
|
def _create_sprite(definition, project_config)
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
+
if definition[:save_path] == :data_uri and not project_config[:sass]
|
239
|
+
raise DslError, "The `#{definition[:name]}' sprite wants to use a " \
|
240
|
+
"data URI, but you have disabled Sass"
|
241
|
+
end
|
242
|
+
|
243
|
+
unless definition[:save_path] == :data_uri
|
244
|
+
url = definition.fetch(:url, project_config[:url]).dup
|
245
|
+
url.gsub!(/:name/, definition[:name])
|
246
|
+
url.gsub!(/:filename/, definition[:save_path].basename.to_s)
|
247
|
+
end
|
238
248
|
|
239
249
|
Polymer::Sprite.new \
|
240
250
|
definition[:name],
|
241
251
|
definition[:sources],
|
242
252
|
definition[:save_path],
|
243
253
|
definition.fetch(:padding, project_config[:padding]),
|
244
|
-
url
|
254
|
+
url || ''
|
245
255
|
end
|
246
256
|
|
247
257
|
# Provides the DSL for the global configuration options.
|
@@ -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" "October 2010" "POLYMER 1.0.0.BETA.5" "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" "October 2010" "POLYMER 1.0.0.BETA.5" "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" "October 2010" "POLYMER 1.0.0.BETA.5" "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" "October 2010" "POLYMER 1.0.0.BETA.5" "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" "October 2010" "POLYMER 1.0.0.BETA.5" "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" "October 2010" "POLYMER 1.0.0.BETA.5" "Polymer Manual"
|
6
6
|
.
|
7
7
|
.SH "NAME"
|
8
8
|
\fB\.polymer\fR \- a format for describing image sprites and their sources
|
@@ -110,6 +110,19 @@ sources/
|
|
110
110
|
\&\.\.\. Polymer will create two sprites in the "sprites/" directory: one\.png will contain "book" and "calculator", while two\.png will contain "magnet" and "television"\.
|
111
111
|
.
|
112
112
|
.P
|
113
|
+
You may instead prefer to set the save path to :data_uri; Polymer will place the sprite contents into your CSS file\. This reduces the number of HTTP requests requires to load your pages at the expense of slightly greater data transfer\.
|
114
|
+
.
|
115
|
+
.IP "" 4
|
116
|
+
.
|
117
|
+
.nf
|
118
|
+
|
119
|
+
sprites "sources/:name/*" => :data_uri
|
120
|
+
.
|
121
|
+
.fi
|
122
|
+
.
|
123
|
+
.IP "" 0
|
124
|
+
.
|
125
|
+
.P
|
113
126
|
There may be cases where you need to customise an individual sprite and you don\'t want to change the global setting; \fBsprite\fR allows you to specify any of the global settings with the exception of "sass" and "css" like so:
|
114
127
|
.
|
115
128
|
.IP "" 4
|
@@ -122,6 +122,17 @@ DEFINING SPRITES
|
|
122
122
|
one.png will contain "book" and "calculator", while two.png will con-
|
123
123
|
tain "magnet" and "television".
|
124
124
|
|
125
|
+
You may instead prefer to set the save path to :data_uri; Polymer will
|
126
|
+
place the sprite contents into your CSS file. This reduces the number
|
127
|
+
of HTTP requests requires to load your pages at the expense of slightly
|
128
|
+
greater data transfer.
|
129
|
+
|
130
|
+
|
131
|
+
|
132
|
+
sprites "sources/:name/*" => :data_uri
|
133
|
+
|
134
|
+
|
135
|
+
|
125
136
|
There may be cases where you need to customise an individual sprite and
|
126
137
|
you don't want to change the global setting; sprite allows you to spec-
|
127
138
|
ify any of the global settings with the exception of "sass" and "css"
|
@@ -145,4 +156,4 @@ SEE ALSO
|
|
145
156
|
|
146
157
|
|
147
158
|
|
148
|
-
POLYMER 1.0.0.BETA.
|
159
|
+
POLYMER 1.0.0.BETA.5 October 2010 .POLYMER(5)
|
data/lib/polymer/project.rb
CHANGED
@@ -43,6 +43,13 @@ module Polymer
|
|
43
43
|
#
|
44
44
|
attr_reader :sprites
|
45
45
|
|
46
|
+
# Returns a subset of +sprites+ containing sprites which are to be written
|
47
|
+
# as a data URI in a Sass file.
|
48
|
+
#
|
49
|
+
# @return [Array<Polymer::Sprite>]
|
50
|
+
#
|
51
|
+
attr_reader :data_uri_sprites
|
52
|
+
|
46
53
|
# Creates a new Project.
|
47
54
|
#
|
48
55
|
# Note that +new+ does not validation of the given paths or options; it
|
@@ -72,6 +79,14 @@ module Polymer
|
|
72
79
|
@sass = extract_path :sass, options
|
73
80
|
@css = extract_path :css, options
|
74
81
|
@cachefile = extract_path :cache, options
|
82
|
+
|
83
|
+
# Sprites which are to be saved as a data URI need to have a save
|
84
|
+
# path explicitly set.
|
85
|
+
@data_uri_sprites = @sprites.select do |sprite|
|
86
|
+
if sprite.save_path == :data_uri
|
87
|
+
sprite.save_path = tmpdir.join("#{sprite.name.to_s}.png")
|
88
|
+
end
|
89
|
+
end
|
75
90
|
end
|
76
91
|
|
77
92
|
# Returns the sprite whose name is +name+.
|
@@ -80,7 +95,7 @@ module Polymer
|
|
80
95
|
# The name of the sprite to be retrieved.
|
81
96
|
#
|
82
97
|
# @return [Polymer::Sprite] The sprite.
|
83
|
-
# @return [nil]
|
98
|
+
# @return [nil] If no such sprite exists.
|
84
99
|
#
|
85
100
|
def sprite(name)
|
86
101
|
sprites.detect { |sprite| sprite.name == name }
|
@@ -103,6 +118,17 @@ module Polymer
|
|
103
118
|
@cache ||= Polymer::Cache.new(@cachefile)
|
104
119
|
end
|
105
120
|
|
121
|
+
# Returns a path to a temporary directory which may be used by this
|
122
|
+
# project.
|
123
|
+
#
|
124
|
+
# The temporary directory will be created if it does not already exist.
|
125
|
+
#
|
126
|
+
# @return [Pathname] Path to the temporary directory.
|
127
|
+
#
|
128
|
+
def tmpdir
|
129
|
+
@tmpdir ||= Pathname.new(Dir.mktmpdir).tap { |p| p.mkpath }
|
130
|
+
end
|
131
|
+
|
106
132
|
private # ================================================================
|
107
133
|
|
108
134
|
# Extracts a path, typically specified in the DSL, and converts it to
|
@@ -27,6 +27,12 @@ module Polymer
|
|
27
27
|
save_to = project.sass + '_polymer.sass'
|
28
28
|
end
|
29
29
|
|
30
|
+
data_uris = project.data_uri_sprites.inject({}) do |memo, sprite|
|
31
|
+
data = [sprite.save_path.read].pack('m').strip
|
32
|
+
memo[sprite.name] = "data:image/png;base64,#{data}"
|
33
|
+
memo
|
34
|
+
end
|
35
|
+
|
30
36
|
File.open(save_to, 'w') do |file|
|
31
37
|
file.puts ERB.new(File.read(TEMPLATE), nil, '<>').result(binding)
|
32
38
|
end
|
data/lib/polymer/sprite.rb
CHANGED
@@ -2,7 +2,8 @@ module Polymer
|
|
2
2
|
# Represents a collection of images which will be used to make a sprite.
|
3
3
|
#
|
4
4
|
class Sprite
|
5
|
-
attr_reader
|
5
|
+
attr_reader :name, :url, :padding, :sources
|
6
|
+
attr_accessor :save_path
|
6
7
|
|
7
8
|
# Creates a new Sprite instance.
|
8
9
|
#
|
@@ -10,8 +11,10 @@ module Polymer
|
|
10
11
|
# The name of the sprite.
|
11
12
|
# @param [Array<Pathname>] sources
|
12
13
|
# An array of Pathname instances to be used as sources.
|
13
|
-
# @param [Pathname] save_path
|
14
|
-
# The location at which the sprite should be saved.
|
14
|
+
# @param [Pathname, Symbol] save_path
|
15
|
+
# The location at which the sprite should be saved. When being used with
|
16
|
+
# a Project, this may instead be :data_uri; adding the sprite to the
|
17
|
+
# project will set the correct path.
|
15
18
|
# @param [Integer] padding
|
16
19
|
# The amount of transparent space, in pixels, to be inserted between
|
17
20
|
# each source image.
|
@@ -2,6 +2,11 @@
|
|
2
2
|
// command provided by the polymer gem. Don't edit this file directly;
|
3
3
|
// change the polymer.rb configuration file, then re-run 'polymer'.
|
4
4
|
|
5
|
+
<% project.data_uri_sprites.each do |sprite| %>
|
6
|
+
.<%= sprite.name %>_data
|
7
|
+
background: url(<%= data_uris[sprite.name] %>) 0 0 no-repeat
|
8
|
+
<% end %>
|
9
|
+
|
5
10
|
@mixin polymer($source, $x-offset: 0px, $y-offset: 0px)
|
6
11
|
<% project.sprites.each_with_index do |sprite, sprite_index| %>
|
7
12
|
<% sprite.sources.each_with_index do |source, source_index| %>
|
@@ -10,10 +15,15 @@
|
|
10
15
|
<% else %>
|
11
16
|
@else if $source == "<%= sprite.name %>/<%= source.name %>"
|
12
17
|
<% end %>
|
18
|
+
<% if project.data_uri_sprites.include?(sprite) %>
|
19
|
+
@extend .<%= sprite.name %>_data
|
20
|
+
@include polymer-position($source, $x-offset, $y-offset)
|
21
|
+
<% else %>
|
13
22
|
$y-offset: $y-offset - <%= sprite.position_of(source) %>px
|
14
23
|
background: url(<%= sprite.url %>) $x-offset $y-offset no-repeat
|
15
24
|
<% end %>
|
16
25
|
<% end %>
|
26
|
+
<% end %>
|
17
27
|
|
18
28
|
@mixin polymer-position($source, $x-offset: 0px, $y-offset: 0px)
|
19
29
|
<% project.sprites.each_with_index do |sprite, sprite_index| %>
|
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.5'
|
12
|
+
s.date = '2010-10-31'
|
13
13
|
s.rubyforge_project = 'polymer'
|
14
14
|
|
15
15
|
# You may safely edit the section below.
|
metadata
CHANGED
@@ -7,8 +7,8 @@ version: !ruby/object:Gem::Version
|
|
7
7
|
- 0
|
8
8
|
- 0
|
9
9
|
- beta
|
10
|
-
-
|
11
|
-
version: 1.0.0.beta.
|
10
|
+
- 5
|
11
|
+
version: 1.0.0.beta.5
|
12
12
|
platform: ruby
|
13
13
|
authors:
|
14
14
|
- Anthony Williams
|
@@ -16,7 +16,7 @@ autorequire:
|
|
16
16
|
bindir: bin
|
17
17
|
cert_chain: []
|
18
18
|
|
19
|
-
date: 2010-
|
19
|
+
date: 2010-10-31 00:00:00 +01:00
|
20
20
|
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|