apropos 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +13 -5
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/CHANGELOG.md +4 -0
- data/README.md +4 -0
- data/lib/apropos/functions.rb +1 -1
- data/lib/apropos/set.rb +6 -1
- data/lib/apropos/version.rb +1 -1
- data/spec/apropos/functions_spec.rb +20 -7
- data/spec/stylesheets_spec.rb +27 -14
- metadata +15 -13
checksums.yaml
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
2
|
+
!binary "U0hBMQ==":
|
3
|
+
metadata.gz: !binary |-
|
4
|
+
ZDRiY2QyOWQwNzJiODdlNTE1OTdkZDFlOWM3NDhhOTM3MGIzMjZlNg==
|
5
|
+
data.tar.gz: !binary |-
|
6
|
+
YzFkYmUzZWM0YTgwZDM5MjdhZDgyYTVmYjZkOTY2YmYzODUwZDJjMw==
|
5
7
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
|
8
|
+
metadata.gz: !binary |-
|
9
|
+
NDk0ZTA2MmVmNmRlYzFiN2Y1ZGE0YzQ3YjVjMTNhOWI0ZmQyMDIzZWRmZmE3
|
10
|
+
ZWM3NjEyNjNmY2JmNzUwYjk0MjViYjViODVhZTg2NjE1YzEzMTk5OGQwNmUx
|
11
|
+
ZmIzNGVmMmRiNzRiMmFhZDc0YjAwNDJiMWRkZmQ1MWJlNGM0OGU=
|
12
|
+
data.tar.gz: !binary |-
|
13
|
+
ZjUwYjM3ZWQ2ZjI0ZWViZTllZDVhZDdhMTMzOTIwY2QxZmUzNTI0ZTkyMjA4
|
14
|
+
YWFjZGY3ZDI0M2ZiOGYxMjU3YWZjYjM1ZGVmZDA0ZjU2NDExNzljNDFhMjU0
|
15
|
+
YWJjYjhhY2ZhNmViY2RlYjhmNjY4ZWI5YmEwN2QxYzcwNzc3YTE=
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--order rand
|
data/.travis.yml
ADDED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -2,8 +2,12 @@
|
|
2
2
|
|
3
3
|
Apropos helps your site serve up the appropriate image for every visitor. Serving multiple versions of an image in responsive and/or localized web sites can be a chore, but Apropos simplifies and automates this task. Instead of manually writing a lot of CSS rules to swap different images, Apropos generates CSS for you based on a simple file naming convention.
|
4
4
|
|
5
|
+
[![Build Status](https://travis-ci.org/square/apropos.png)](https://travis-ci.org/square/apropos)
|
6
|
+
|
5
7
|
## Installation
|
6
8
|
|
9
|
+
Apropos requires Ruby 1.9 or greater.
|
10
|
+
|
7
11
|
Add this line to your application's Gemfile:
|
8
12
|
|
9
13
|
gem 'apropos'
|
data/lib/apropos/functions.rb
CHANGED
data/lib/apropos/set.rb
CHANGED
@@ -19,7 +19,7 @@ module Apropos
|
|
19
19
|
|
20
20
|
def variant_paths
|
21
21
|
paths = {}
|
22
|
-
|
22
|
+
self.class.glob(@basedir.join(variant_path_glob)).each do |path|
|
23
23
|
key = code_fragment(path)
|
24
24
|
paths[key] = remove_basedir(path)
|
25
25
|
end
|
@@ -54,5 +54,10 @@ module Apropos
|
|
54
54
|
def extname
|
55
55
|
@extname ||= File.extname(@path)
|
56
56
|
end
|
57
|
+
|
58
|
+
# Wrapper for Dir.glob to make test stubbing cleaner
|
59
|
+
def self.glob(path)
|
60
|
+
Dir.glob(path)
|
61
|
+
end
|
57
62
|
end
|
58
63
|
end
|
data/lib/apropos/version.rb
CHANGED
@@ -2,20 +2,20 @@ require_relative "../spec_helper.rb"
|
|
2
2
|
|
3
3
|
describe Apropos do
|
4
4
|
def stub_files(*files)
|
5
|
-
|
5
|
+
Apropos::Set.stub(:glob).with(Pathname.new("#{images_dir}/foo.*.jpg")).and_return(files)
|
6
6
|
end
|
7
7
|
|
8
|
+
let(:images_dir) { '/project/images' }
|
9
|
+
let(:project_dir) { nil }
|
8
10
|
let(:rules) { Apropos.image_variant_rules("foo.jpg") }
|
9
11
|
|
10
|
-
before
|
11
|
-
Compass.configuration.stub(:
|
12
|
-
Compass.configuration.stub(:
|
12
|
+
before do
|
13
|
+
Compass.configuration.stub(:images_path).and_return(images_dir) if images_dir
|
14
|
+
Compass.configuration.stub(:project_path).and_return(project_dir) if project_dir
|
13
15
|
end
|
14
16
|
|
15
17
|
describe ".add_class_image_variant" do
|
16
|
-
after
|
17
|
-
Apropos.clear_image_variants
|
18
|
-
end
|
18
|
+
after { Apropos.clear_image_variants }
|
19
19
|
|
20
20
|
it "adds a simple class variant" do
|
21
21
|
Apropos.add_class_image_variant('alt', 'alternate')
|
@@ -182,4 +182,17 @@ describe Apropos do
|
|
182
182
|
}.to raise_exception
|
183
183
|
end
|
184
184
|
end
|
185
|
+
|
186
|
+
describe ".images_dir" do
|
187
|
+
context "with images_path defined" do
|
188
|
+
let(:images_dir) { '/path/to/images' }
|
189
|
+
it { Apropos.images_dir.to_s.should == images_dir }
|
190
|
+
end
|
191
|
+
|
192
|
+
context "with images_path undefined" do
|
193
|
+
let(:images_dir) { nil }
|
194
|
+
let(:project_dir) { '/path/to/project' }
|
195
|
+
it { Apropos.images_dir.to_s.should == project_dir }
|
196
|
+
end
|
197
|
+
end
|
185
198
|
end
|
data/spec/stylesheets_spec.rb
CHANGED
@@ -1,18 +1,31 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'tmpdir'
|
2
4
|
|
3
5
|
describe 'stylesheets' do
|
4
|
-
let(:import_options) {
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
6
|
+
let(:import_options) { {style: :compact, load_paths: [Apropos::STYLESHEETS_DIR], syntax: :scss} }
|
7
|
+
let(:css_file) { Sass::Engine.new(@scss_file, import_options).render }
|
8
|
+
let(:images_dir) {
|
9
|
+
Dir.mktmpdir('apropos').tap do |dir|
|
10
|
+
at_exit { FileUtils.remove_entry_secure(dir) }
|
11
|
+
end
|
9
12
|
}
|
10
13
|
|
11
|
-
|
12
|
-
|
14
|
+
before do
|
15
|
+
Compass.configuration.stub(:images_path).and_return(images_dir)
|
16
|
+
Compass.configuration.stub(:asset_cache_buster).and_return( lambda { |path| nil } )
|
17
|
+
end
|
18
|
+
|
19
|
+
after { Apropos.clear_image_variants }
|
20
|
+
|
21
|
+
def stub_files(files)
|
22
|
+
FileUtils.cd(images_dir) do
|
23
|
+
FileUtils.touch(files)
|
24
|
+
end
|
13
25
|
end
|
14
26
|
|
15
27
|
it "can be imported" do
|
28
|
+
stub_files(%w[hero.jpg])
|
16
29
|
@scss_file = %Q{
|
17
30
|
@import "apropos";
|
18
31
|
.foo {
|
@@ -24,7 +37,7 @@ describe 'stylesheets' do
|
|
24
37
|
|
25
38
|
describe "hidpi stylesheet" do
|
26
39
|
it "generates default hidpi rules" do
|
27
|
-
stub_files(
|
40
|
+
stub_files(%w[hero.jpg hero.2x.jpg])
|
28
41
|
@scss_file = %Q{
|
29
42
|
@import "apropos";
|
30
43
|
.foo {
|
@@ -36,7 +49,7 @@ describe 'stylesheets' do
|
|
36
49
|
end
|
37
50
|
|
38
51
|
it "allows customizing hidpi extension and query" do
|
39
|
-
stub_files(
|
52
|
+
stub_files(%w[hero.jpg hero.hidpi.jpg])
|
40
53
|
@scss_file = %Q{
|
41
54
|
$apropos-hidpi-extension: 'hidpi';
|
42
55
|
$apropos-hidpi-query: '(min-resolution: 300dpi)';
|
@@ -53,7 +66,7 @@ describe 'stylesheets' do
|
|
53
66
|
|
54
67
|
describe "breakpoints stylesheet" do
|
55
68
|
before :each do
|
56
|
-
stub_files(
|
69
|
+
stub_files(%w[hero.jpg hero.medium.jpg hero.large.jpg])
|
57
70
|
end
|
58
71
|
|
59
72
|
it "doesn't generate any defaults" do
|
@@ -68,7 +81,7 @@ describe 'stylesheets' do
|
|
68
81
|
end
|
69
82
|
|
70
83
|
it "allows setting breakpoints" do
|
71
|
-
stub_files(
|
84
|
+
stub_files(%w[hero.jpg hero.medium.jpg hero.large.jpg])
|
72
85
|
@scss_file = %Q{
|
73
86
|
$apropos-breakpoints: (medium, 768px), (large, 1024px);
|
74
87
|
@import "apropos";
|
@@ -83,7 +96,7 @@ describe 'stylesheets' do
|
|
83
96
|
|
84
97
|
describe "breakpoints and hidpi" do
|
85
98
|
it "can be combined" do
|
86
|
-
stub_files(
|
99
|
+
stub_files(%w[hero.jpg hero.large.2x.jpg hero.medium.2x.jpg])
|
87
100
|
@scss_file = %Q{
|
88
101
|
$apropos-breakpoints: (medium, 768px), (large, 1024px);
|
89
102
|
@import "apropos";
|
@@ -97,8 +110,8 @@ describe 'stylesheets' do
|
|
97
110
|
|
98
111
|
it "sorts breakpoints vs. retina correctly" do
|
99
112
|
# filesystem sort order
|
100
|
-
files = %w[2x large.2x large medium.2x medium].map {|f| "
|
101
|
-
stub_files(
|
113
|
+
files = %w[2x large.2x large medium.2x medium].map {|f| "hero.#{f}.jpg" } + %w[hero.jpg]
|
114
|
+
stub_files(files)
|
102
115
|
@scss_file = %Q{
|
103
116
|
$apropos-breakpoints: (medium, 768px), (large, 1024px);
|
104
117
|
@import "apropos";
|
metadata
CHANGED
@@ -1,27 +1,27 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apropos
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Gilder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-11-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: compass
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - '>='
|
17
|
+
- - ! '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - '>='
|
24
|
+
- - ! '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
@@ -42,14 +42,14 @@ dependencies:
|
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- - '>='
|
45
|
+
- - ! '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- - '>='
|
52
|
+
- - ! '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
@@ -70,28 +70,28 @@ dependencies:
|
|
70
70
|
name: cane
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - '>='
|
73
|
+
- - ! '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- - '>='
|
80
|
+
- - ! '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
|
-
- - '>='
|
87
|
+
- - ! '>='
|
88
88
|
- !ruby/object:Gem::Version
|
89
89
|
version: '0'
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
|
-
- - '>='
|
94
|
+
- - ! '>='
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0'
|
97
97
|
description: Apropos helps your site serve up the appropriate image for every visitor.
|
@@ -106,6 +106,8 @@ extensions: []
|
|
106
106
|
extra_rdoc_files: []
|
107
107
|
files:
|
108
108
|
- .gitignore
|
109
|
+
- .rspec
|
110
|
+
- .travis.yml
|
109
111
|
- CHANGELOG.md
|
110
112
|
- Gemfile
|
111
113
|
- LICENSE.txt
|
@@ -144,17 +146,17 @@ require_paths:
|
|
144
146
|
- lib
|
145
147
|
required_ruby_version: !ruby/object:Gem::Requirement
|
146
148
|
requirements:
|
147
|
-
- - '>='
|
149
|
+
- - ! '>='
|
148
150
|
- !ruby/object:Gem::Version
|
149
151
|
version: '0'
|
150
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
151
153
|
requirements:
|
152
|
-
- - '>='
|
154
|
+
- - ! '>='
|
153
155
|
- !ruby/object:Gem::Version
|
154
156
|
version: '0'
|
155
157
|
requirements: []
|
156
158
|
rubyforge_project:
|
157
|
-
rubygems_version: 2.
|
159
|
+
rubygems_version: 2.1.3
|
158
160
|
signing_key:
|
159
161
|
specification_version: 4
|
160
162
|
summary: Apropos helps your site serve up the appropriate image for every visitor.
|