polymer 1.0.0.beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (47) hide show
  1. data/Gemfile +8 -0
  2. data/History.md +126 -0
  3. data/LICENSE +28 -0
  4. data/README.md +229 -0
  5. data/Rakefile +186 -0
  6. data/bin/polymer +10 -0
  7. data/lib/polymer/cache.rb +106 -0
  8. data/lib/polymer/cli.rb +340 -0
  9. data/lib/polymer/core_ext.rb +78 -0
  10. data/lib/polymer/css_generator.rb +32 -0
  11. data/lib/polymer/deviant_finder.rb +76 -0
  12. data/lib/polymer/dsl.rb +283 -0
  13. data/lib/polymer/man/polymer-bond.1 +60 -0
  14. data/lib/polymer/man/polymer-bond.1.txt +66 -0
  15. data/lib/polymer/man/polymer-init.1 +33 -0
  16. data/lib/polymer/man/polymer-init.1.txt +42 -0
  17. data/lib/polymer/man/polymer-optimise.1 +23 -0
  18. data/lib/polymer/man/polymer-optimise.1.txt +25 -0
  19. data/lib/polymer/man/polymer-position.1 +39 -0
  20. data/lib/polymer/man/polymer-position.1.txt +42 -0
  21. data/lib/polymer/man/polymer.1 +50 -0
  22. data/lib/polymer/man/polymer.1.txt +60 -0
  23. data/lib/polymer/man/polymer.5 +130 -0
  24. data/lib/polymer/man/polymer.5.txt +145 -0
  25. data/lib/polymer/optimisation.rb +130 -0
  26. data/lib/polymer/project.rb +164 -0
  27. data/lib/polymer/sass_generator.rb +38 -0
  28. data/lib/polymer/source.rb +55 -0
  29. data/lib/polymer/sprite.rb +130 -0
  30. data/lib/polymer/templates/polymer.tt +28 -0
  31. data/lib/polymer/templates/sass_mixins.erb +29 -0
  32. data/lib/polymer/templates/sources/one/book.png +0 -0
  33. data/lib/polymer/templates/sources/one/box-label.png +0 -0
  34. data/lib/polymer/templates/sources/one/calculator.png +0 -0
  35. data/lib/polymer/templates/sources/one/calendar-month.png +0 -0
  36. data/lib/polymer/templates/sources/one/camera.png +0 -0
  37. data/lib/polymer/templates/sources/one/eraser.png +0 -0
  38. data/lib/polymer/templates/sources/two/inbox-image.png +0 -0
  39. data/lib/polymer/templates/sources/two/magnet.png +0 -0
  40. data/lib/polymer/templates/sources/two/newspaper.png +0 -0
  41. data/lib/polymer/templates/sources/two/television.png +0 -0
  42. data/lib/polymer/templates/sources/two/wand-hat.png +0 -0
  43. data/lib/polymer/templates/sources/two/wooden-box-label.png +0 -0
  44. data/lib/polymer/version.rb +4 -0
  45. data/lib/polymer.rb +49 -0
  46. data/polymer.gemspec +94 -0
  47. metadata +206 -0
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gemspec
4
+
5
+ group(:quality) do
6
+ gem 'bluecloth', '>= 2.0.7'
7
+ gem 'yard', '>= 0.6'
8
+ end
data/History.md ADDED
@@ -0,0 +1,126 @@
1
+ v1.0.0 / HEAD (Unreleased)
2
+ --------------------------
3
+
4
+ * Montage has been renamed to Polymer and is now released under the BSD
5
+ three-clause license.
6
+
7
+ * The Polymer configuration must now be located at the project root and
8
+ should be named either ".polymer" or, for Windows users, "polymer.yml".
9
+ You should rename your existing ".montage" file to ".polymer", and
10
+ ".montage\_cache" should be changed to ".polymer-cache".
11
+
12
+ * The Polymer configuration file no longer uses YAML, but instead opts
13
+ for a simple Ruby-based DSL. See `polymer help .polymer` for full
14
+ documentation.
15
+
16
+ * The Sass mixin has changed slightly; instead of generating separate
17
+ mixins for each of your sprites, all of your sprites are available
18
+ using the global "polymer()" mixin. This should be called as such:
19
+
20
+ .my_selector
21
+ +polymer("sprite_name/source_name")
22
+
23
+ Mixins still permit you to supply an optional x-offset and y-offset as
24
+ the second and third parameters. the "polymer-pos()" mixin is also
25
+ available as an alternative to the old "sprite-name-pos()" mixins.
26
+
27
+ * A new "position" command shows information about a source within a
28
+ sprite, and provides useful CSS for use when building your own
29
+ styleesheets.
30
+
31
+ * Documentation of each command is now available by running `polymer
32
+ help` or `polymer help [COMMAND]`.
33
+
34
+ * The Polymer configuration no longer allows a "config.root" option and
35
+ the library will not work correctly if this is present in your config
36
+ file. Please move your ".polymer" file to your project root and remove
37
+ this option.
38
+
39
+ * The library internals have been substantially changed with Thor now
40
+ being used to handle all CLI commands.
41
+
42
+ * When creating a new Polymer project, you may suppress the copying of
43
+ example sources by passing the --no-examples option.
44
+
45
+ * The polymer init command no longer uses Highline to prompt for your
46
+ preferred paths to your source and output files. If you need to change
47
+ the defaults you may instead use the --source and --sprites options.
48
+
49
+ * All CLI commands are now tested with Cucumber.
50
+
51
+ * Jeweler has been replaced with plain rake tasks inspired by Rakegem --
52
+ [http://github.com/mojombo/rakegem](http://github.com/mojombo/rakegem).
53
+
54
+ v0.4.0 (18th August, 2010)
55
+ --------------------------
56
+
57
+ * You no longer need to specify a :name option in your sprite defintions
58
+ when supplying a full output filename.
59
+
60
+ v0.3.0 (12th April, 2010)
61
+ -------------------------
62
+
63
+ * The "montage.yml" file has been replaced with ".montage" which should
64
+ be located in your project root. In addition, the file is now rather
65
+ different, and in most cases will never need to be edited when you
66
+ want to add new sources to the sprite.
67
+
68
+ * By default Montage will now save sprites to public/images, expected
69
+ source images to be in public/images/subdir -- where "subdir" will
70
+ become the name of the sprite. All sources in a subdirectory will be
71
+ added to the same sprite.
72
+
73
+ This behavior is entirely customisable in the .montage file.
74
+
75
+ * The ".montage\_cache" file which was previously saved in the same
76
+ directory as sprites is now saved in the project root.
77
+
78
+ * The `montage` command now allows you to specify a path to a Montage
79
+ configuration file; for example `montage path/to/montage.yml`. When
80
+ using a non-standard directory structure, you can specify a
81
+ "config.root" option in the configuration file, containing the path to
82
+ the project root.
83
+
84
+ v0.2.0 (8th April, 2010)
85
+ ------------------------
86
+
87
+ * Running `montage` will now generate `_montage.sass` in the specified
88
+ config.sass directory. A separate mixin will be generated for each
89
+ sprite, with the mixin accepting three arguments: the name of the
90
+ source image, an optional horizontal offset, and an optional vertical
91
+ offset. Disable the Sass generation by setting config.sass to false.
92
+
93
+ * If pngout or pngout-darwin is available (run `which pngout
94
+ pngout-darwin` to find out), Montage will compress the generated
95
+ sprites. Installing pngout is strongly recommended; significant
96
+ savings can be made on larger PNGs.
97
+
98
+ * The `montage` command accepts a '--force' option which will regenerate
99
+ all sprites even if they haven't been changed since the last run.
100
+
101
+ * Sprites will be regenerated if the file has been deleted.
102
+
103
+ v0.1.2 (6th April, 2010)
104
+ ------------------------
105
+
106
+ * Sprites will only be regenerated when their definition (in
107
+ montage.yml) has changed, or if the contents of the source files have
108
+ changed.
109
+
110
+ * The `montage init` command now uses the highline gem to ask for the
111
+ paths to a project's source files, and the intended sprite output
112
+ directory.
113
+
114
+ * Running `montage init` will copy some sample source files into the
115
+ source directory. This allows running `montage` immediately after
116
+ creating the project, to see how things work.
117
+
118
+ v0.1.1 (5th April, 2010)
119
+ ------------------------
120
+
121
+ * Small fix for Ruby 1.9.1, which doesn't define String#inject.
122
+
123
+ v0.1.0 (5th April, 2010)
124
+ ------------------------
125
+
126
+ * Initial release. Supports creation of sprites and not much else.
data/LICENSE ADDED
@@ -0,0 +1,28 @@
1
+ Copyright (c) 2009-2010, Anthony Williams
2
+ All rights reserved.
3
+
4
+ Redistribution and use in source and binary forms, with or without
5
+ modification, are permitted provided that the following conditions are met:
6
+
7
+ * Redistributions of source code must retain the above copyright notice,
8
+ this list of conditions and the following disclaimer.
9
+
10
+ * Redistributions in binary form must reproduce the above copyright
11
+ notice, this list of conditions and the following disclaimer in the
12
+ documentation and/or other materials provided with the distribution.
13
+
14
+ * Neither the name of the Anthony Williams nor the names of its
15
+ contributors may be used to endorse or promote products derived from
16
+ this software without specific prior written permission.
17
+
18
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
21
+ DISCLAIMED. IN NO EVENT SHALL ANTHONY WILLIAMS BE LIABLE FOR ANY DIRECT,
22
+ INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23
+ BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
24
+ DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
25
+ OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
26
+ NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
27
+ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28
+
data/README.md ADDED
@@ -0,0 +1,229 @@
1
+ POLYMER
2
+ =======
3
+
4
+ DESCRIPTION
5
+ -----------
6
+
7
+ Polymer is a tool for creating sprite images which combine many smaller
8
+ sources into a single larger image. Spriting allows you to reduce the
9
+ number of HTTP requests required to load a web page, and as such can
10
+ result in reduced load times.
11
+
12
+ Polymer also creates the necessary CSS to position the sprite within an
13
+ HTML element so that only the desired source appears. Those writing
14
+ their website or application in Ruby can make use of Polymer's Sass
15
+ builder which creates a Sass mixin, further simplifying the use of your
16
+ sprites.
17
+
18
+ In order to reduce the amount of data transferred to clients loading
19
+ your pages, Polymer optimises the sprites it generates using PNGOUT,
20
+ OptiPNG, and PNGCrush.
21
+
22
+ INSTALLATION
23
+ ------------
24
+
25
+ The recommended way to install Polymer is with Rubygems:
26
+
27
+ $ [sudo] gem install polymer
28
+
29
+ Polymer currently uses RMagick/ImageMagick in order to read and write
30
+ images. Eventually, I want to offer support for ChunkyPNG also, which
31
+ should substantially ease installation.
32
+
33
+ Most Linux and BSD distributions include ImageMagick in their packaging
34
+ system; while Mac OS X users can install it with [Homebrew][homebrew]:
35
+
36
+ $ brew install ghostscript
37
+ $ brew install imagemagick
38
+
39
+ If you wish to install Polymer from source:
40
+
41
+ $ git clone http://github.com/antw/polymer.git && cd polymer
42
+ $ gem build polymer.gemspec
43
+ $ [sudo] gem install --local polymer-VERSION.gem
44
+
45
+ (Where "VERSION" is the current version of Polymer). If you do not have
46
+ Git installed, the latest versions can be [downloaded instead][download].
47
+
48
+ GETTING STARTED
49
+ ---------------
50
+
51
+ In order for Polymer to create sprites from your source images, it must
52
+ first create a "project" -- this is a `.polymer` file which is placed
53
+ into your project's root directory. This file comes with some sensible
54
+ defaults which should suffice for most cases. This file is generated by
55
+ running `polymer init`.
56
+
57
+ 1. Run `polymer init` to create a ".polymer" file in the current
58
+ directory. Prior to running the command, you may want to glance at
59
+ the [polymer-init(1)][polymer-init] manpage to get an overview of the
60
+ supported options. `polymer init` also places some example source
61
+ images into your project.
62
+
63
+ 2. Run `polymer bond`: this is the main task which converts the source
64
+ images into the final sprites. If you have PNGOUT, OptiPNG, or
65
+ PNGCrush installed, Polymer will also optimise the generates sprites
66
+ to reduce them to the smallest possible filesize.
67
+
68
+ 3. Run `polymer bond` again. Nothing happens! Polymer maintains a cache
69
+ of your sprite images so that it only generates them again if any of
70
+ the sources have changed; pretty handy since optimising large sprites
71
+ can take some time. See [polymer(5)][polymer-5] to learn how to
72
+ disable this.
73
+
74
+ USING YOUR SPRITES
75
+ ------------------
76
+
77
+ ### Updating Sprites
78
+
79
+ Having created some example sprites in "Getting Started", you can now
80
+ add completely new sprites by adding new directories alongside "one" and
81
+ "two", alter existing sprites by adding, changing, or removing source
82
+ images, then once again running `polymer bond`.
83
+
84
+ If this isn't sufficiently flexible, see [polymer(5)][polymer-5] to
85
+ learn how to define your own sprites in the ".polymer" file.
86
+
87
+ ### Sass / SCSS Stylesheets
88
+
89
+ Out-of-the-box, Polymer generates a Sass stylesheet containing a mixin.
90
+ This stylesheet is created at the path given to "config.sass" in
91
+ ".polymer".
92
+
93
+ This mixin can be used thusly: (in this case, "main" is the name of the
94
+ sprite, "home" and "products" are the names of source images
95
+ sans-extension).
96
+
97
+ Assuming directory structure:
98
+
99
+ public/images/sprites/
100
+ messages/
101
+ new.png
102
+ reply.png
103
+
104
+ Your Sass stylesheet like:
105
+
106
+ @import polymer.sass
107
+
108
+ .buttons
109
+ a#compose, a#reply
110
+ +polymer("messages/new")
111
+ a#reply
112
+ +polymer-pos("messages/reply")
113
+
114
+ Which creates:
115
+
116
+ .buttons a#compose, .buttons a#reply {
117
+ background: url(/path/to/sprite.ext) 0 0 no-repeat; }
118
+
119
+ .buttons a#products {
120
+ background-position: 0 -40px; }
121
+
122
+ With the latest versions of the Haml library, you may use SCSS instead:
123
+
124
+ @import("polymer.sass")
125
+
126
+ .buttons {
127
+ a#compose, a#reply {
128
+ @include polymer("messages/new") }
129
+ a#reply {
130
+ @include polymer-pos("messages/reply") } }
131
+
132
+ You can disable creation of the Sass mixin file by setting `config.sass
133
+ false` in the ".polymer" file.
134
+
135
+ ### CSS Stylesheets
136
+
137
+ ... are not yet implemented. Hold tight; these should be around before
138
+ Polymer hits v1.0.
139
+
140
+ PNG OPTIMISATION
141
+ ----------------
142
+
143
+ ... needs to be written up.
144
+
145
+ CONTRIBUTING
146
+ ------------
147
+
148
+ A Bundler Gemfile is provided to simplify installing Polymer's
149
+ dependencies. Running `bundle install` will install everything needed to
150
+ contribute. Bundler is not used in the Polymer library itself.
151
+
152
+ * Fork the project, taking care not to get any in your eyes.
153
+
154
+ * Make your feature addition or bug fix.
155
+
156
+ * Add tests for it. This is especially important not only because it
157
+ helps ensure that I don't unintentionally break it in a future
158
+ version, but also since it appeases Epidity, God of Potatoes, who has
159
+ been known to shower rancid cucumbers upon those who fail to test.
160
+
161
+ * Commit, but please do not mess with the Rakefile or history. If you
162
+ want to have your own version, _that is fine_, but bump the version in
163
+ a commit by itself so that I can ignore it when I pull.
164
+
165
+ * Send me a pull request. Bonus points for topic branches (although
166
+ "everything is made up, and the points don't matter...").
167
+
168
+ Polymer specs are run against:
169
+
170
+ * Ruby (MRI) 1.8.7 p302,
171
+ * Ruby (YARV) 1.9.1 p378,
172
+ * Ruby (YARV) 1.9.2 p0.
173
+
174
+ GETTING HELP
175
+ ------------
176
+
177
+ Polymer comes complete with some manpages which document the various
178
+ commands:
179
+
180
+ * **[polymer(1)][polymer-1]** -- `polymer help`
181
+ * **[polymer(5)][polymer-5]** -- `polymer help .polymer`
182
+ * **[polymer-init(1)][polymer-init]** -- `polymer help init`
183
+ * **[polymer-bond(1)][polymer-bond]** -- `polymer help bond`
184
+ * **[polymer-optimise(1)][polymer-optimise]** -- `polymer help optimise`
185
+ * **[polymer-position(1)][polymer-position]** -- `polymer help position`
186
+
187
+ If you've encountered a bug, or Polymer isn't behaving as you expect,
188
+ please [file an issue report][issues].
189
+
190
+ DETAILS
191
+ -------
192
+
193
+ **Source**
194
+ : [http://github.com/antw/polymer][polymer]
195
+
196
+ **Author**
197
+ : Anthony Williams
198
+
199
+ **Copyright**
200
+ : 2009-2010
201
+
202
+ **License**
203
+ : BSD License
204
+
205
+ Polymer © 2009-2010 by [Anthony Williams](mailto:hi@antw.me).
206
+ Polymer is free software, released under the BSD license. Please see the
207
+ LICENSE file for more information.
208
+
209
+ The sample sources in lib/polymer/templates/sources are courtesy of
210
+ [Yusuke Kamiyamane][yusuke], whose extraordinary generosity in releasing
211
+ three-thousand royalty-free icons cannot be stated enough.
212
+
213
+ [montage]: http://github.com/antw/montage
214
+ [polymer]: http://github.com/antw/polymer
215
+ [homebrew]: http://mxcl.github.com/homebrew/
216
+ [pngout]: http://advsys.net/ken/utils.htm
217
+ [download]: http://github.com/antw/polymer/downloads
218
+ [kin]: http://github.com/antw/kin
219
+ [semver]: http://semver.org/
220
+ [yard]: http://yardoc.org/
221
+ [issues]: http://github.com/antw/polymer/issues
222
+ [yusuke]: http://p.yusukekamiyamane.com
223
+
224
+ [polymer-1]: http://antw.github.com/polymer/polymer.1.html
225
+ [polymer-5]: http://antw.github.com/polymer/polymer.5.html
226
+ [polymer-init]: http://antw.github.com/polymer/polymer-init.1.html
227
+ [polymer-bond]: http://antw.github.com/polymer/polymer-bond.1.html
228
+ [polymer-optimise]: http://antw.github.com/polymer/polymer-optimise.1.html
229
+ [polymer-position]: http://antw.github.com/polymer/polymer-position.1.html
data/Rakefile ADDED
@@ -0,0 +1,186 @@
1
+ require 'rake'
2
+ require 'rake/clean'
3
+
4
+ $LOAD_PATH.unshift File.expand_path('../lib', __FILE__)
5
+ require 'polymer/version'
6
+
7
+ CLOBBER.include %w( pkg *.gem documentation coverage
8
+ measurements lib/polymer/man )
9
+
10
+ # === Helpers ================================================================
11
+
12
+ require 'date'
13
+
14
+ def replace_header(head, header_name, value)
15
+ head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{value}'" }
16
+ end
17
+
18
+ # === Tasks ==================================================================
19
+
20
+ # --- Build ------------------------------------------------------------------
21
+
22
+ desc 'Build the gem, and push to Github'
23
+ task :release => :build do
24
+ unless system('git branch') =~ /^\* master$/
25
+ puts "You must be on the master branch to release!"
26
+ exit!
27
+ end
28
+
29
+ sh "git commit --allow-empty -a -m 'Release #{Polymer::VERSION}'"
30
+ sh "git tag v#{Polymer::VERSION}"
31
+ sh "git push origin master"
32
+ sh "git push origin v#{Polymer::VERSION}"
33
+
34
+ puts "Push to Rubygems.org with"
35
+ puts " gem push pkg/polymer-#{Polymer::VERSION}.gem"
36
+ end
37
+
38
+ desc 'Builds the gem'
39
+ task :build => [:man, :gemspec] do
40
+ sh "mkdir -p pkg"
41
+ sh "gem build polymer.gemspec"
42
+ sh "mv polymer-#{Polymer::VERSION}.gem pkg"
43
+ end
44
+
45
+ desc 'Create a fresh gemspec'
46
+ task :gemspec => :validate do
47
+ gemspec_file = File.expand_path('../polymer.gemspec', __FILE__)
48
+
49
+ # Read spec file and split out the manifest section.
50
+ spec = File.read(gemspec_file)
51
+ head, manifest, tail = spec.split(" # = MANIFEST =\n")
52
+
53
+ # Replace name version and date.
54
+ replace_header head, :name, 'polymer'
55
+ replace_header head, :rubyforge_project, 'polymer'
56
+ replace_header head, :version, Polymer::VERSION
57
+ replace_header head, :date, Date.today.to_s
58
+
59
+ # Determine file list from git ls-files.
60
+ files = `git ls-files`.
61
+ split("\n").
62
+ sort.
63
+ reject { |file| file =~ /^\./ }.
64
+ reject { |file| file =~ /^(rdoc|pkg|spec|tasks|features|man)/ }
65
+
66
+ # Add man pages.
67
+ files += Dir['lib/polymer/man/*']
68
+
69
+ # Format list for the gemspec.
70
+ files = files.map { |file| " #{file}" }.join("\n")
71
+
72
+ # Piece file back together and write.
73
+ manifest = " s.files = %w[\n#{files}\n ]\n"
74
+ spec = [head, manifest, tail].join(" # = MANIFEST =\n")
75
+ File.open(gemspec_file, 'w') { |io| io.write(spec) }
76
+
77
+ puts "Updated #{gemspec_file}"
78
+ end
79
+
80
+ task :validate do
81
+ unless Dir['lib/*'] - %w(lib/polymer.rb lib/polymer)
82
+ puts 'The lib/ directory should only contain a polymer.rb file, and a ' \
83
+ 'polymer/ directory'
84
+ exit!
85
+ end
86
+
87
+ unless Dir['VERSION*'].empty?
88
+ puts 'A VERSION file at root level violates Gem best practices'
89
+ exit!
90
+ end
91
+ end
92
+
93
+ # --- Tests ------------------------------------------------------------------
94
+
95
+ require 'rspec/core/rake_task'
96
+ require 'cucumber/rake/task'
97
+
98
+ RSpec::Core::RakeTask.new(:spec) do |spec|
99
+ spec.pattern = 'spec/**/*_spec.rb'
100
+ end
101
+
102
+ Cucumber::Rake::Task.new(:features) do |features|
103
+ features.cucumber_opts = '--format progress --tag ~@pending'
104
+ end
105
+
106
+ desc 'Run RSpec examples followed by the Cucumber features'
107
+ task :test => [:spec, :features]
108
+ task :default => :test
109
+
110
+ # --- Man Pages --------------------------------------------------------------
111
+
112
+ desc 'Builds the Polymer manual pages'
113
+ task :man do
114
+ require 'pathname'
115
+
116
+ source_dir = Pathname.new('man')
117
+ dest_dir = Pathname.new('lib/polymer/man')
118
+
119
+ dest_dir.rmtree if dest_dir.directory?
120
+ dest_dir.mkpath
121
+
122
+ Pathname.glob(source_dir + '*.ronn').each do |source|
123
+ destination = dest_dir + source.basename('.ronn')
124
+
125
+ # Create the man page.
126
+ sh "ronn --roff --manual='Polymer Manual' " \
127
+ "--organization='POLYMER #{Polymer::VERSION.upcase}' " \
128
+ "--pipe #{source} > #{destination}"
129
+
130
+ # Set man pages to be left-aligned (not justified).
131
+ sh "sed -i '' -e '3i\\\n.ad l\n' #{destination}"
132
+
133
+ # Create a text-only version of the man page.
134
+ sh "groff -Wall -mtty-char -mandoc -Tascii " \
135
+ "#{destination} | col -b > #{destination}.txt"
136
+ end
137
+ end
138
+
139
+ desc 'Builds HTML for Github Pages, then publishes'
140
+ task :pages do
141
+ # Cheers to rtomayko/ronn/Rakefile
142
+ sh "ronn -5 --manual='Polymer Manual' " \
143
+ "--organization='POLYMER #{Polymer::VERSION.upcase}' " \
144
+ "-s toc -w man/*.ronn"
145
+
146
+ puts '-' * 50
147
+ puts 'Rebuilding pages ...'
148
+
149
+ verbose(false) do
150
+ rm_rf 'pages'
151
+ push_url = `git remote show origin`.lines.grep(/Push.*URL/).first[/git@.*/]
152
+ sh 'git fetch -q origin'
153
+ sh 'rev=$(git rev-parse origin/gh-pages)'
154
+ sh 'git clone -q -b gh-pages . pages'
155
+ cd 'pages'
156
+ sh 'git reset --hard $rev'
157
+ sh 'rm -f polymer*.html index.html'
158
+ sh 'cp -rp ../man/polymer*.html ../man/index.html ./'
159
+ sh 'git add *.html'
160
+ sh 'git commit -m "Rebuild manual."'
161
+ sh "git push #{push_url} gh-pages"
162
+ end
163
+ end
164
+
165
+ # --- YARD -------------------------------------------------------------------
166
+
167
+ begin
168
+ require 'yard'
169
+ YARD::Rake::YardocTask.new do |doc|
170
+ doc.options << '--no-highlight'
171
+ end
172
+ rescue LoadError
173
+ desc 'yard task requires that the yard gem is installed'
174
+ task :yard do
175
+ abort 'YARD is not available. In order to run yard, you must: gem ' \
176
+ 'install yard'
177
+ end
178
+ end
179
+
180
+ # --- Console ----------------------------------------------------------------
181
+
182
+ desc 'Open an irb session preloaded with Polymer'
183
+ task :console do
184
+ sh 'irb -I ./lib -rubygems -r ./lib/polymer.rb'
185
+ end
186
+
data/bin/polymer ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ unless $:.include? File.expand_path('../../lib', __FILE__)
4
+ $:.unshift File.expand_path('../../lib', __FILE__)
5
+ end
6
+
7
+ require 'polymer'
8
+ require 'polymer/cli'
9
+
10
+ Polymer::CLI.start
@@ -0,0 +1,106 @@
1
+ module Polymer
2
+ # Represents a cache file. Keeps track of the contents of each sprite and
3
+ # provides an easy means of determining if the sprite has been changed since
4
+ # the cache was last generated.
5
+ class Cache
6
+
7
+ # Returns the path to the cache file.
8
+ #
9
+ # @return [Pathname]
10
+ #
11
+ attr_reader :path
12
+
13
+ # Creates a new Cache.
14
+ #
15
+ # If the given +path+ does not exist, an empty cache instance will be
16
+ # created, and calling +write+ will create a new file at +path+.
17
+ #
18
+ # @param [Pathname] path
19
+ # Path to the cache file to be loaded. If no +path+ is given, the cache
20
+ # will operate in-memory only and +write+ is disabled.
21
+ #
22
+ def initialize(path = nil)
23
+ @path = path
24
+
25
+ if @path and @path.file?
26
+ @cache = YAML.load_file @path
27
+ else
28
+ @cache = { :cache_version => 2, :sprites => {} }
29
+ end
30
+ end
31
+
32
+ # Checks whether the given +sprite+ is different to the cached version.
33
+ #
34
+ # @param [Polymer::Sprite] sprite
35
+ # The sprite whose "freshness" is to be checked.
36
+ #
37
+ # @return [Boolean]
38
+ #
39
+ def stale?(sprite)
40
+ not fresh?(sprite)
41
+ end
42
+
43
+ # Checks whether the given +sprite+ is identical to the cached version.
44
+ #
45
+ # @param [Polymer::Sprite] sprite
46
+ # The sprite whose "freshness" is to be checked.
47
+ #
48
+ # @return [Boolean]
49
+ #
50
+ def fresh?(sprite)
51
+ sprite.save_path.file? and
52
+ @cache[:sprites].has_key?(sprite.name) and
53
+ @cache[:sprites][sprite.name] == sprite.digest
54
+ end
55
+
56
+ # Updates the cached value of +sprite+.
57
+ #
58
+ # @param [Polymer::Sprite] sprite
59
+ # The sprite whose digest is to be stored in the cache.
60
+ #
61
+ def set(sprite)
62
+ @cache[:sprites][sprite.name] = sprite.digest
63
+ end
64
+
65
+ # Removes a +sprite+'s cached values.
66
+ #
67
+ # @param [Polymer::Sprite] sprite
68
+ # The sprite whose digest is to be removed from the cache.
69
+ #
70
+ def remove(sprite)
71
+ @cache[:sprites].delete(sprite.name)
72
+ end
73
+
74
+ # Removes all sprite cache entries, except those in +retain+.
75
+ #
76
+ # @param [Array<Polymer::Cache>] retain
77
+ # An array of cache entries which are _not_ to be removed.
78
+ #
79
+ def remove_all_except(retain)
80
+ names = retain.map { |sprite| sprite.name }
81
+
82
+ @cache[:sprites].delete_if do |key, _|
83
+ not names.include?(key)
84
+ end
85
+ end
86
+
87
+ # Writes the cache file to disk.
88
+ #
89
+ # @return [true]
90
+ # Returnss true once the file has been written.
91
+ # @return [false]
92
+ # Returns false if the Cache was initialized without a path (and, as
93
+ # such, nothing can be saved).
94
+ #
95
+ def write
96
+ return false unless @path
97
+
98
+ @path.open('w') do |file|
99
+ file.puts YAML.dump(@cache)
100
+ end
101
+
102
+ true
103
+ end
104
+
105
+ end # Cache
106
+ end # Polymer