artwork 0.1.1 → 0.2.0
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/README.md +3 -12
- data/artwork.gemspec +1 -0
- data/lib/artwork.rb +4 -0
- data/lib/artwork/configuration.rb +2 -2
- data/lib/artwork/version.rb +1 -1
- data/lib/artwork/view.rb +9 -0
- data/lib/assets/javascripts/artwork.js +49 -62
- metadata +19 -7
- data/generators/artwork/USAGE +0 -7
- data/generators/artwork/artwork_assets_generator.rb +0 -26
data/README.md
CHANGED
@@ -33,10 +33,9 @@ you have a _2x versions of your thumbs, the helper will choose the _2x one.
|
|
33
33
|
|
34
34
|
## Requirements
|
35
35
|
|
36
|
+
- Ruby 1.8.7 or newer
|
36
37
|
- Rails 2.3 or newer
|
37
38
|
- Paperclip 2.3 or newer
|
38
|
-
- jQuery
|
39
|
-
- The jQuery.cookie plugin
|
40
39
|
|
41
40
|
## Installation
|
42
41
|
|
@@ -52,17 +51,9 @@ Or install it yourself as:
|
|
52
51
|
|
53
52
|
$ gem install artwork
|
54
53
|
|
55
|
-
Add the following
|
54
|
+
Add the following line at the top of your `<head>` section:
|
56
55
|
|
57
|
-
|
58
|
-
|
59
|
-
If you're using an older version of Rails which does not support the asset
|
60
|
-
pipeline, run the following command from within the app to copy the necessary
|
61
|
-
asset files in your `public/` folder first:
|
62
|
-
|
63
|
-
./script/generate artwork_assets
|
64
|
-
|
65
|
-
And then manually include them with `javascript_include_tag` in your layout(s).
|
56
|
+
<%= activate_resolution_independence %>
|
66
57
|
|
67
58
|
## Configuration
|
68
59
|
|
data/artwork.gemspec
CHANGED
data/lib/artwork.rb
CHANGED
@@ -57,11 +57,11 @@ module Artwork
|
|
57
57
|
end
|
58
58
|
|
59
59
|
def fetch_2x_images_flag_from(request)
|
60
|
-
request.cookies['
|
60
|
+
request.cookies['_retina'].to_i > 0
|
61
61
|
end
|
62
62
|
|
63
63
|
def current_resolution_from(request)
|
64
|
-
browser_width = request.cookies['
|
64
|
+
browser_width = request.cookies['_width'].to_i
|
65
65
|
|
66
66
|
return default_resolution if browser_width.zero?
|
67
67
|
|
data/lib/artwork/version.rb
CHANGED
data/lib/artwork/view.rb
CHANGED
@@ -1,5 +1,14 @@
|
|
1
1
|
module Artwork
|
2
2
|
module View
|
3
|
+
def activate_resolution_independence
|
4
|
+
content_tag :script do
|
5
|
+
Thread.current[:artwork_script] ||= begin
|
6
|
+
artwork_script_path = Artwork.root_path + '/assets/javascripts/artwork.js'
|
7
|
+
Uglifier.compile(File.read(artwork_script_path)).html_safe
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
3
12
|
def artwork_tag(record, attachment_name, size, options = {})
|
4
13
|
image_tag_options = options[:image] || {}
|
5
14
|
img_holder_options = options[:img_holder] || {}
|
@@ -1,62 +1,49 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
if (cookiesWork && (pixelRatioChanged || browserResolutionChanged)) {
|
51
|
-
// Force reload without using the cache
|
52
|
-
window.location.reload(true);
|
53
|
-
return;
|
54
|
-
}
|
55
|
-
|
56
|
-
$(window).resize(self.setBrowserResolutionCookie);
|
57
|
-
}
|
58
|
-
|
59
|
-
self.activateResolutionIndependance();
|
60
|
-
};
|
61
|
-
|
62
|
-
Artwork.instance = new Artwork();
|
1
|
+
(function (window, documentElement) {
|
2
|
+
var cookieValidity = 365,
|
3
|
+
cookieDomain = location.host.toString().split('.').slice(-2).join('.'),
|
4
|
+
isRetina = (window.devicePixelRatio || 1.0) >= 1.5;
|
5
|
+
|
6
|
+
var getCookie = function (name) {
|
7
|
+
return (result = new RegExp('(?:^|; )_' + name + '=([^;]*)').exec(document.cookie)) ? result[1] : null;
|
8
|
+
}
|
9
|
+
|
10
|
+
var setCookie = function (name, value) {
|
11
|
+
var expires = new Date();
|
12
|
+
expires.setDate(expires.getDate() + cookieValidity);
|
13
|
+
|
14
|
+
document.cookie = [
|
15
|
+
'_' + name, '=', String(value),
|
16
|
+
'; expires=' + expires.toUTCString(),
|
17
|
+
'; domain=' + cookieDomain
|
18
|
+
].join('');
|
19
|
+
};
|
20
|
+
|
21
|
+
var setSize = function () {
|
22
|
+
setCookie('width', window.innerWidth || documentElement.clientWidth);
|
23
|
+
};
|
24
|
+
|
25
|
+
var addEventHandlerTo = function (element, type, handler) {
|
26
|
+
if (element.addEventListener) {
|
27
|
+
element.addEventListener(type, handler, false);
|
28
|
+
} else if (element.attachEvent) {
|
29
|
+
element.attachEvent('on' + type, handler);
|
30
|
+
}
|
31
|
+
};
|
32
|
+
|
33
|
+
var oldRetina = getCookie('retina'),
|
34
|
+
oldWidth = getCookie('width');
|
35
|
+
|
36
|
+
setCookie('retina', isRetina ? 1 : 0);
|
37
|
+
setSize();
|
38
|
+
|
39
|
+
var cookiesWork = getCookie('retina') !== null,
|
40
|
+
retinaChanged = oldRetina !== getCookie('retina'),
|
41
|
+
widthChanged = oldWidth !== getCookie('width');
|
42
|
+
|
43
|
+
if (cookiesWork && (retinaChanged || widthChanged)) {
|
44
|
+
window.location.reload(true);
|
45
|
+
return;
|
46
|
+
}
|
47
|
+
|
48
|
+
addEventHandlerTo(window, 'resize', setSize);
|
49
|
+
})(window, document.documentElement);
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: artwork
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 23
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 0.
|
8
|
+
- 2
|
9
|
+
- 0
|
10
|
+
version: 0.2.0
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Dimitar Dimitrov
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2014-06-
|
18
|
+
date: 2014-06-11 00:00:00 +03:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -77,6 +77,20 @@ dependencies:
|
|
77
77
|
version: "2.3"
|
78
78
|
type: :runtime
|
79
79
|
version_requirements: *id004
|
80
|
+
- !ruby/object:Gem::Dependency
|
81
|
+
name: uglifier
|
82
|
+
prerelease: false
|
83
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
85
|
+
requirements:
|
86
|
+
- - ">="
|
87
|
+
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
89
|
+
segments:
|
90
|
+
- 0
|
91
|
+
version: "0"
|
92
|
+
type: :runtime
|
93
|
+
version_requirements: *id005
|
80
94
|
description: Automated user resolution based image size choosing for your Rails views, but done at the backend.
|
81
95
|
email:
|
82
96
|
- dimitar@live.bg
|
@@ -93,8 +107,6 @@ files:
|
|
93
107
|
- README.md
|
94
108
|
- Rakefile
|
95
109
|
- artwork.gemspec
|
96
|
-
- generators/artwork/USAGE
|
97
|
-
- generators/artwork/artwork_assets_generator.rb
|
98
110
|
- lib/artwork.rb
|
99
111
|
- lib/artwork/configuration.rb
|
100
112
|
- lib/artwork/controller.rb
|
data/generators/artwork/USAGE
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
require 'fileutils'
|
2
|
-
|
3
|
-
class ArtworkAssetsGenerator < Rails::Generator::Base
|
4
|
-
def manifest
|
5
|
-
record do |m|
|
6
|
-
has_assets = begin
|
7
|
-
Rails.configuration.assets
|
8
|
-
rescue
|
9
|
-
nil
|
10
|
-
end
|
11
|
-
|
12
|
-
if has_assets
|
13
|
-
puts <<-MESSAGE
|
14
|
-
The version of Rails you're using (#{Rails.version}) supports
|
15
|
-
the asset pipeline and the required assets will be automatically
|
16
|
-
available for your app. You just need to require them in your
|
17
|
-
manifest files. See how in the readme.
|
18
|
-
MESSAGE
|
19
|
-
else
|
20
|
-
assets_root = File.expand_path('../../../lib/assets', __FILE__)
|
21
|
-
FileUtils.cp_r Dir.glob("#{assets_root}/*"), Rails.root.join('public'), :verbose => true
|
22
|
-
puts 'Done.'
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|