jquery_picture_tag-rails 0.0.1

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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source :rubygems
2
+
3
+ # Specify your gem's dependencies in jquery_picture_tag-rails.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 G5
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,139 @@
1
+ # jQuery Picture Tag for Rails
2
+
3
+ Ruby Gem to include the [jQuery Picture Tag](https://github.com/G5/jquery-picture-tag) source code in your Rails application.
4
+ Works great with [Picture Tag Rails](https://github.com/G5/picture_tag-rails)!
5
+
6
+
7
+ ## Current Version
8
+
9
+ 0.0.1
10
+
11
+
12
+ ## Requirements
13
+
14
+ * [jQuery](http://jquery.com)
15
+ * [matchMedia.js](https://github.com/paulirish/matchMedia.js) for older browsers
16
+ * [rubygems](http://rubygems.org) >= 1.3.6
17
+ * [railties](http://rubygems.org/gems/railties) >= 3.1.0, < 5.0
18
+ * [thor](http://rubygems.org/gems/thor) ~> 0.14
19
+
20
+
21
+ ## Installation
22
+
23
+ ### Gemfile
24
+
25
+ Add this line to your application's Gemfile:
26
+
27
+ ```ruby
28
+ gem 'jquery_picture_tag-rails'
29
+ ```
30
+
31
+ ### Manual
32
+
33
+ Or install it yourself as:
34
+
35
+ ```bash
36
+ gem install jquery_picture_tag-rails
37
+ ```
38
+
39
+ ### Rails 3.1 or greater (with asset pipeline enabled)
40
+
41
+ The jquery-picture-tag file will be added to the asset pipeline and available for you to use.
42
+
43
+ Add this line in `app/assets/javascripts/application.js`:
44
+
45
+ ```javascript
46
+ //= require jquery-picture-tag
47
+ ```
48
+
49
+ ### Rails 3.0 (or greated with asset pipeline disabled)
50
+
51
+ Copy the jquery-picture-tag file into `public/javascripts`:
52
+
53
+ ```bash
54
+ rails generate jquery_picture_tag:install
55
+ ```
56
+
57
+ Include the jquery-picture-tag into your application:
58
+
59
+ ```erb
60
+ <%= javascript_include_tag "jquery-picture-tag" %>
61
+ ```
62
+
63
+
64
+ ## Usage
65
+
66
+ Use the [W3C Picture Element Proposal](http://www.w3.org/community/respimg/)'s `<picture>` tag syntax.
67
+ ProTip™: Use [picture_tag-rails](https://github.com/G5/picture_tag-rails) to generate it for you.
68
+
69
+ ```html
70
+ <picture alt="Kitty cat!">
71
+ <source media="(min-width: 1600px)" srcset="cat-large.jpg 1x, cat-large@2x.jpg 2x">
72
+ <source media="(min-width: 1000px)" srcset="cat-medium.jpg 1x, cat-medium@2x.jpg 2x">
73
+ <source media="(min-width: 768px)" srcset="cat-small.jpg 1x, cat-small@2x.jpg 2x">
74
+ <source media="(min-width: 480px)" srcset="cat-tiny.jpg 1x, cat-tiny@2x.jpg 2x">
75
+ <source srcset="cat-tiny.jpg 1x, cat-tiny@2x.jpg 2x">
76
+ <img alt="Kitty cat!" src="cat-tiny.jpg">
77
+ </picture>
78
+ ```
79
+
80
+ Put this Javascript somewhere to apply it to all `<picture>` tags.
81
+
82
+ ```javascript
83
+ $(function() {
84
+ $('picture').pictureTag();
85
+ });
86
+ ```
87
+
88
+ Or this to apply it to just some `<picture>` tags.
89
+
90
+ ```javascript
91
+ $(function() {
92
+ $('.gallery picture').pictureTag();
93
+ });
94
+ ```
95
+
96
+
97
+ ## Authors
98
+
99
+ * Jessica Lynn Suttles / [@jlsuttles](https://github.com/jlsuttles)
100
+
101
+
102
+ ## Contributing
103
+
104
+ 1. Fork it
105
+ 2. Get it running
106
+ 3. Create your feature branch (`git checkout -b my-new-feature`)
107
+ 4. Write your code and **specs**
108
+ 5. Commit your changes (`git commit -am 'Add some feature'`)
109
+ 6. Push to the branch (`git push origin my-new-feature`)
110
+ 7. Create new Pull Request
111
+
112
+ If you find bugs, have feature requests or questions, please
113
+ [file an issue](https://github.com/G5/jquery_picture_tag-rails/issues).
114
+
115
+
116
+ ## License
117
+
118
+ Copyright (c) 2012 G5
119
+
120
+ MIT License
121
+
122
+ Permission is hereby granted, free of charge, to any person obtaining
123
+ a copy of this software and associated documentation files (the
124
+ "Software"), to deal in the Software without restriction, including
125
+ without limitation the rights to use, copy, modify, merge, publish,
126
+ distribute, sublicense, and/or sell copies of the Software, and to
127
+ permit persons to whom the Software is furnished to do so, subject to
128
+ the following conditions:
129
+
130
+ The above copyright notice and this permission notice shall be
131
+ included in all copies or substantial portions of the Software.
132
+
133
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
134
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
135
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
136
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
137
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
138
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
139
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'jquery_picture_tag/rails/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "jquery_picture_tag-rails"
8
+ gem.version = JqueryPictureTag::Rails::VERSION
9
+ gem.authors = ["Jessica Lynn Suttles"]
10
+ gem.email = ["jlsuttles@gmail.com"]
11
+ gem.description = %q{Ruby Gem to Automate Using JQuery Picture Tag with Rails}
12
+ gem.summary = %q{Ruby Gem to Automate Using JQuery Picture Tag with Rails}
13
+ gem.homepage = ""
14
+
15
+ gem.required_rubygems_version = ">= 1.3.6"
16
+
17
+ gem.add_dependency "railties", ">= 3.1.0", "< 5.0"
18
+ gem.add_dependency "thor", "~> 0.14"
19
+
20
+ gem.files = `git ls-files`.split($/)
21
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
22
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
23
+ gem.require_paths = ["lib"]
24
+ end
@@ -0,0 +1,35 @@
1
+ require 'rails'
2
+
3
+ # Supply generator for Rails 3.0.x or if asset pipeline is not enabled
4
+ if ::Rails.version < "3.1" || !::Rails.application.config.assets.enabled
5
+ module JqueryPictureTag
6
+ module Generators
7
+ class InstallGenerator < ::Rails::Generators::Base
8
+ desc "This generator installs jQuery Picture Tag #{JqueryPictureTag::Rails::VERSION}"
9
+ source_root File.expand_path('../../../../../vendor/assets/javascripts', __FILE__)
10
+
11
+ def copy_jquery_picture_tag
12
+ say_status "copying", "jQuery Picture Tag #{JqueryPictureTag::Rails::VERSION}", :green
13
+ copy_file "jquery-picture-tag-#{JqueryPictureTag::Rails::VERSION}.js", "public/javascripts/jquery-picture-tag.js"
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ else
20
+ module JqueryPictureTag
21
+ module Generators
22
+ class InstallGenerator < ::Rails::Generators::Base
23
+ desc "Just show instructions so people will know what to do when mistakenly using generator for Rails 3.1 apps"
24
+
25
+ def do_nothing
26
+ say_status("deprecated", "You are using Rails with the asset pipeline enabled, so this generator is not needed.")
27
+ say_status("", "The necessary files are already in your asset pipeline.")
28
+ say_status("", "Just add `//= require jquery-picture-tag-#{JqueryPictureTag::Rails::VERSION}` to your app/assets/javascripts/application.js")
29
+ say_status("", "If you do not want the asset pipeline enabled, you may turn it off in application.rb and re-run this generator.")
30
+ # ok, nothing
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1 @@
1
+ require "jquery_picture_tag/rails"
@@ -0,0 +1,7 @@
1
+ require 'jquery_picture_tag/rails/engine'
2
+ require 'jquery_picture_tag/rails/version'
3
+
4
+ module JQueryPictureTag
5
+ module Rails
6
+ end
7
+ end
@@ -0,0 +1,6 @@
1
+ module JqueryPictureTag
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ module JqueryPictureTag
2
+ module Rails
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,152 @@
1
+ /*
2
+ jQuery Picture Tag 0.0.1
3
+ Built by Bookis Smuin: https://github.com/bookis
4
+ Built by Jessica Lynn Suttles: https://github.com/jlsuttles
5
+ Details and source: https://github.com/g5/jquery-picture-tag
6
+ Demo: https://g5.github.com/jquery-picture-tag
7
+ */
8
+
9
+ // Generated by CoffeeScript 1.3.3
10
+ (function() {
11
+ var __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
12
+
13
+ this.PictureTag = {};
14
+
15
+ $.fn.pictureTag = function() {
16
+ return this.each(function() {
17
+ return new PictureTag.Picture($(this));
18
+ });
19
+ };
20
+
21
+ this.PictureTag.Picture = (function() {
22
+
23
+ function Picture($el) {
24
+ this.$el = $el;
25
+ this._img = __bind(this._img, this);
26
+
27
+ this._displayBest = __bind(this._displayBest, this);
28
+
29
+ this.sources = new PictureTag.Sources(this.$el.children("source"));
30
+ this._displayBest();
31
+ $(window).resize(this._displayBest);
32
+ }
33
+
34
+ Picture.prototype._displayBest = function() {
35
+ return this._img().display(this.sources.best());
36
+ };
37
+
38
+ Picture.prototype._img = function() {
39
+ return new PictureTag.Img(this.$el.children("img:first"));
40
+ };
41
+
42
+ return Picture;
43
+
44
+ })();
45
+
46
+ this.PictureTag.Img = (function() {
47
+
48
+ function Img($el) {
49
+ this.$el = $el;
50
+ this._replace = __bind(this._replace, this);
51
+
52
+ }
53
+
54
+ Img.prototype.display = function(value) {
55
+ if (value !== this.$el.attr("src")) {
56
+ this.$el2 = this.$el.clone();
57
+ this.$el2.attr("src", value);
58
+ return this.$el2.load(this._replace);
59
+ }
60
+ };
61
+
62
+ Img.prototype._replace = function() {
63
+ return this.$el.replaceWith(this.$el2);
64
+ };
65
+
66
+ return Img;
67
+
68
+ })();
69
+
70
+ this.PictureTag.Sources = (function() {
71
+
72
+ function Sources($els) {
73
+ this.$els = $els;
74
+ this._newSource = __bind(this._newSource, this);
75
+
76
+ this.best = __bind(this.best, this);
77
+
78
+ this.defaultSource = new PictureTag.Source(this.$els.filter(":not([media])"));
79
+ this.mediaSources = this.$els.filter("[media]").map(this._newSource);
80
+ }
81
+
82
+ Sources.prototype.best = function() {
83
+ var bestSoFar,
84
+ _this = this;
85
+ bestSoFar = this.defaultSource;
86
+ this.mediaSources.each(function(i, mediaSource) {
87
+ if (mediaSource.isBetterThan(bestSoFar)) {
88
+ return bestSoFar = mediaSource;
89
+ }
90
+ });
91
+ return bestSoFar.src();
92
+ };
93
+
94
+ Sources.prototype._newSource = function(i, el) {
95
+ return new PictureTag.Source($(el));
96
+ };
97
+
98
+ return Sources;
99
+
100
+ })();
101
+
102
+ this.PictureTag.Source = (function() {
103
+
104
+ function Source($el) {
105
+ this.$el = $el;
106
+ this.media = new PictureTag.Media(this.$el.attr("media"));
107
+ this.srcset = this.$el.attr("srcset");
108
+ }
109
+
110
+ Source.prototype.isBetterThan = function(other) {
111
+ return this.media.isBetterThan(other.media);
112
+ };
113
+
114
+ Source.prototype.src = function() {
115
+ if (this.srcset) {
116
+ return this.srcset.match(/^\S+?(?=,|\s)/)[0];
117
+ }
118
+ };
119
+
120
+ return Source;
121
+
122
+ })();
123
+
124
+ this.PictureTag.Media = (function() {
125
+
126
+ function Media(query) {
127
+ this.query = query;
128
+ }
129
+
130
+ Media.prototype.isBetterThan = function(other) {
131
+ if (this._matches() && !other._matches()) {
132
+ return true;
133
+ } else if (this._matches() && other._matches()) {
134
+ return this._minWidth >= other.minWidth;
135
+ } else {
136
+ return false;
137
+ }
138
+ };
139
+
140
+ Media.prototype._matches = function() {
141
+ return this.query && matchMedia(this.query).matches;
142
+ };
143
+
144
+ Media.prototype._minWidth = function() {
145
+ return parseInt(this.query.match(/\d+/)[0]);
146
+ };
147
+
148
+ return Media;
149
+
150
+ })();
151
+
152
+ }).call(this);
metadata ADDED
@@ -0,0 +1,117 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jquery_picture_tag-rails
3
+ version: !ruby/object:Gem::Version
4
+ hash: 29
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 0
9
+ - 1
10
+ version: 0.0.1
11
+ platform: ruby
12
+ authors:
13
+ - Jessica Lynn Suttles
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2012-09-26 00:00:00 Z
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: railties
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ none: false
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ hash: 3
29
+ segments:
30
+ - 3
31
+ - 1
32
+ - 0
33
+ version: 3.1.0
34
+ - - <
35
+ - !ruby/object:Gem::Version
36
+ hash: 31
37
+ segments:
38
+ - 5
39
+ - 0
40
+ version: "5.0"
41
+ type: :runtime
42
+ version_requirements: *id001
43
+ - !ruby/object:Gem::Dependency
44
+ name: thor
45
+ prerelease: false
46
+ requirement: &id002 !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ~>
50
+ - !ruby/object:Gem::Version
51
+ hash: 23
52
+ segments:
53
+ - 0
54
+ - 14
55
+ version: "0.14"
56
+ type: :runtime
57
+ version_requirements: *id002
58
+ description: Ruby Gem to Automate Using JQuery Picture Tag with Rails
59
+ email:
60
+ - jlsuttles@gmail.com
61
+ executables: []
62
+
63
+ extensions: []
64
+
65
+ extra_rdoc_files: []
66
+
67
+ files:
68
+ - .gitignore
69
+ - CHANGELOG.md
70
+ - Gemfile
71
+ - LICENSE
72
+ - README.md
73
+ - Rakefile
74
+ - jquery_picture_tag-rails.gemspec
75
+ - lib/generators/jquery_picture_tag/install/install_generator.rb
76
+ - lib/jquery_picture_tag-rails.rb
77
+ - lib/jquery_picture_tag/rails.rb
78
+ - lib/jquery_picture_tag/rails/engine.rb
79
+ - lib/jquery_picture_tag/rails/version.rb
80
+ - vendor/assets/javascripts/jquery.picture-tag-0.0.1.js
81
+ homepage: ""
82
+ licenses: []
83
+
84
+ post_install_message:
85
+ rdoc_options: []
86
+
87
+ require_paths:
88
+ - lib
89
+ required_ruby_version: !ruby/object:Gem::Requirement
90
+ none: false
91
+ requirements:
92
+ - - ">="
93
+ - !ruby/object:Gem::Version
94
+ hash: 3
95
+ segments:
96
+ - 0
97
+ version: "0"
98
+ required_rubygems_version: !ruby/object:Gem::Requirement
99
+ none: false
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ hash: 23
104
+ segments:
105
+ - 1
106
+ - 3
107
+ - 6
108
+ version: 1.3.6
109
+ requirements: []
110
+
111
+ rubyforge_project:
112
+ rubygems_version: 1.8.24
113
+ signing_key:
114
+ specification_version: 3
115
+ summary: Ruby Gem to Automate Using JQuery Picture Tag with Rails
116
+ test_files: []
117
+