apropos 0.1.1 → 0.1.2
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.
- checksums.yaml +5 -13
- data/Rakefile +1 -1
- data/lib/apropos/functions.rb +5 -4
- data/lib/apropos/sass_functions.rb +8 -2
- data/lib/apropos/set.rb +12 -0
- data/lib/apropos/variant.rb +20 -7
- data/lib/apropos/version.rb +1 -1
- data/spec/apropos/extension_parser_spec.rb +4 -4
- data/spec/apropos/functions_spec.rb +4 -7
- data/spec/apropos/set_spec.rb +6 -3
- data/spec/apropos/variant_spec.rb +3 -0
- data/spec/stylesheets_spec.rb +24 -0
- metadata +20 -20
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
YzFkYmUzZWM0YTgwZDM5MjdhZDgyYTVmYjZkOTY2YmYzODUwZDJjMw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8cbde75867c5ff6dcd09a8af5b4b2ec1efad48ca
|
4
|
+
data.tar.gz: a715f82b9671766874ef9309a89212742cb4c061
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
ZWM3NjEyNjNmY2JmNzUwYjk0MjViYjViODVhZTg2NjE1YzEzMTk5OGQwNmUx
|
11
|
-
ZmIzNGVmMmRiNzRiMmFhZDc0YjAwNDJiMWRkZmQ1MWJlNGM0OGU=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZjUwYjM3ZWQ2ZjI0ZWViZTllZDVhZDdhMTMzOTIwY2QxZmUzNTI0ZTkyMjA4
|
14
|
-
YWFjZGY3ZDI0M2ZiOGYxMjU3YWZjYjM1ZGVmZDA0ZjU2NDExNzljNDFhMjU0
|
15
|
-
YWJjYjhhY2ZhNmViY2RlYjhmNjY4ZWI5YmEwN2QxYzcwNzc3YTE=
|
6
|
+
metadata.gz: 0270ef1ee44405a6021ffc6569e340d893b91c32be77a42004463e3a03ff0fe68c49931215876a26e9e9905fa4a86a718f986a65714700a5df3c368f78248723
|
7
|
+
data.tar.gz: 3672e7ac58743e3e6def005222faa7bf5baa07997fb7e6fb8dc929f7987d254df9fc3a3a420ed60ce5dff929002fda1f3311bd51bfbcc6b06df2540cefe6ca79
|
data/Rakefile
CHANGED
data/lib/apropos/functions.rb
CHANGED
@@ -6,11 +6,12 @@
|
|
6
6
|
module Apropos
|
7
7
|
module_function
|
8
8
|
|
9
|
+
def image_set(path)
|
10
|
+
Set.new(path, images_dir)
|
11
|
+
end
|
12
|
+
|
9
13
|
def image_variant_rules(path)
|
10
|
-
|
11
|
-
set.variants.select(&:valid?).map do |variant|
|
12
|
-
variant.rule
|
13
|
-
end
|
14
|
+
image_set(path).valid_variants.map(&:rule)
|
14
15
|
end
|
15
16
|
|
16
17
|
def add_dpi_image_variant(id, query, order=0)
|
@@ -27,8 +27,14 @@ module Apropos
|
|
27
27
|
|
28
28
|
def image_variants(path)
|
29
29
|
assert_type path, :String
|
30
|
-
|
31
|
-
|
30
|
+
set = ::Apropos.image_set(path.value)
|
31
|
+
set.invalid_variants.each do |variant|
|
32
|
+
message = "Ignoring unknown extensions " +
|
33
|
+
"'#{variant.invalid_codes.join("', '")}' (#{variant.path})"
|
34
|
+
Sass.logger.info message
|
35
|
+
$stderr.puts message
|
36
|
+
end
|
37
|
+
::Apropos.convert_to_sass_value(set.valid_variant_rules)
|
32
38
|
end
|
33
39
|
|
34
40
|
def add_dpi_image_variant(id, query, sort=0)
|
data/lib/apropos/set.rb
CHANGED
@@ -17,6 +17,18 @@ module Apropos
|
|
17
17
|
end.sort
|
18
18
|
end
|
19
19
|
|
20
|
+
def valid_variants
|
21
|
+
variants.select(&:valid?)
|
22
|
+
end
|
23
|
+
|
24
|
+
def invalid_variants
|
25
|
+
variants.reject(&:valid?)
|
26
|
+
end
|
27
|
+
|
28
|
+
def valid_variant_rules
|
29
|
+
valid_variants.map(&:rule)
|
30
|
+
end
|
31
|
+
|
20
32
|
def variant_paths
|
21
33
|
paths = {}
|
22
34
|
self.class.glob(@basedir.join(variant_path_glob)).each do |path|
|
data/lib/apropos/variant.rb
CHANGED
@@ -14,6 +14,7 @@ module Apropos
|
|
14
14
|
def initialize(code_fragment, path)
|
15
15
|
@code_fragment = code_fragment
|
16
16
|
@path = path
|
17
|
+
@_invalid_codes = []
|
17
18
|
end
|
18
19
|
|
19
20
|
def codes
|
@@ -21,12 +22,11 @@ module Apropos
|
|
21
22
|
end
|
22
23
|
|
23
24
|
def conditions
|
24
|
-
@_conditions
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
end.compact
|
25
|
+
parse_codes && @_conditions
|
26
|
+
end
|
27
|
+
|
28
|
+
def invalid_codes
|
29
|
+
parse_codes && @_invalid_codes
|
30
30
|
end
|
31
31
|
|
32
32
|
def conditions_by_type
|
@@ -42,7 +42,7 @@ module Apropos
|
|
42
42
|
end
|
43
43
|
|
44
44
|
def valid?
|
45
|
-
!conditions.empty?
|
45
|
+
!conditions.empty? && @_invalid_codes.empty?
|
46
46
|
end
|
47
47
|
|
48
48
|
def rule
|
@@ -63,5 +63,18 @@ module Apropos
|
|
63
63
|
def <=>(other)
|
64
64
|
aggregate_sort_value <=> other.aggregate_sort_value
|
65
65
|
end
|
66
|
+
|
67
|
+
private
|
68
|
+
def parse_codes
|
69
|
+
@_conditions ||= codes.map do |code|
|
70
|
+
ExtensionParser.each_parser.inject(nil) do |_, parser|
|
71
|
+
query_or_selector = parser.match(code)
|
72
|
+
break query_or_selector if query_or_selector
|
73
|
+
end.tap do |match|
|
74
|
+
# Track codes not recognized by any parser
|
75
|
+
@_invalid_codes << code unless match
|
76
|
+
end
|
77
|
+
end.compact
|
78
|
+
end
|
66
79
|
end
|
67
80
|
end
|
data/lib/apropos/version.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
require_relative "../spec_helper.rb"
|
2
2
|
|
3
3
|
describe Apropos::ExtensionParser do
|
4
|
-
before
|
5
|
-
|
6
|
-
|
4
|
+
before { described_class.parsers.clear }
|
5
|
+
|
6
|
+
after { described_class.parsers.clear }
|
7
7
|
|
8
8
|
describe ".parsers" do
|
9
9
|
it "keeps track of variant parsers" do
|
@@ -16,7 +16,7 @@ describe Apropos::ExtensionParser do
|
|
16
16
|
|
17
17
|
describe ".add_parser" do
|
18
18
|
it "overrides previously defined parsers with the same extension" do
|
19
|
-
|
19
|
+
described_class.add_parser('2x')
|
20
20
|
new_parser = described_class.add_parser('2x')
|
21
21
|
described_class.parsers['2x'].should == new_parser
|
22
22
|
end
|
@@ -12,11 +12,12 @@ describe Apropos do
|
|
12
12
|
before do
|
13
13
|
Compass.configuration.stub(:images_path).and_return(images_dir) if images_dir
|
14
14
|
Compass.configuration.stub(:project_path).and_return(project_dir) if project_dir
|
15
|
+
Apropos.clear_image_variants
|
15
16
|
end
|
16
17
|
|
17
|
-
|
18
|
-
after { Apropos.clear_image_variants }
|
18
|
+
after { Apropos.clear_image_variants }
|
19
19
|
|
20
|
+
describe ".add_class_image_variant" do
|
20
21
|
it "adds a simple class variant" do
|
21
22
|
Apropos.add_class_image_variant('alt', 'alternate')
|
22
23
|
stub_files("/foo.alt.jpg")
|
@@ -60,7 +61,7 @@ describe Apropos do
|
|
60
61
|
end
|
61
62
|
|
62
63
|
describe ".image_variant_rules" do
|
63
|
-
before
|
64
|
+
before do
|
64
65
|
Apropos.add_dpi_image_variant('2x', "(-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi)", 0.5)
|
65
66
|
Apropos.add_breakpoint_image_variant('medium', 'min-width: 768px', 1)
|
66
67
|
Apropos.add_breakpoint_image_variant('large', 'min-width: 1024px', 2)
|
@@ -79,10 +80,6 @@ describe Apropos do
|
|
79
80
|
end
|
80
81
|
end
|
81
82
|
|
82
|
-
after :all do
|
83
|
-
Apropos.clear_image_variants
|
84
|
-
end
|
85
|
-
|
86
83
|
it "ignores invalid variants" do
|
87
84
|
stub_files("/foo.1x.jpg", "/foo.de.jpg", "/foo.ca.jpg")
|
88
85
|
rules.should == [
|
data/spec/apropos/set_spec.rb
CHANGED
@@ -1,9 +1,7 @@
|
|
1
1
|
require_relative "../spec_helper.rb"
|
2
2
|
|
3
3
|
describe Apropos::Set do
|
4
|
-
|
5
|
-
@subject ||= described_class.new("foo.jpg", "/dir")
|
6
|
-
end
|
4
|
+
subject { described_class.new("foo.jpg", "/dir") }
|
7
5
|
|
8
6
|
it "detects paths with indicators before the base file extension" do
|
9
7
|
subject.variant_path_glob.should == Pathname.new("foo.*.jpg")
|
@@ -31,4 +29,9 @@ describe Apropos::Set do
|
|
31
29
|
set = described_class.new("foo.jpg", "/foo/bar")
|
32
30
|
set.remove_basedir("/Users/bob/foo/bar/foo.fr.jpg").should == "foo.fr.jpg"
|
33
31
|
end
|
32
|
+
|
33
|
+
it "detects valid variants" do
|
34
|
+
subject.should_receive(:variants).and_return([double(valid?: false), double(valid?: true)])
|
35
|
+
subject.valid_variants.length.should == 1
|
36
|
+
end
|
34
37
|
end
|
@@ -12,6 +12,8 @@ describe Apropos::Variant do
|
|
12
12
|
end
|
13
13
|
|
14
14
|
before :all do
|
15
|
+
Apropos::ExtensionParser.parsers.clear
|
16
|
+
|
15
17
|
Apropos::ExtensionParser.add_parser('2x') do |match|
|
16
18
|
dpi_selector
|
17
19
|
end
|
@@ -40,6 +42,7 @@ describe Apropos::Variant do
|
|
40
42
|
v = variant("1x")
|
41
43
|
v.conditions.should == []
|
42
44
|
v.should_not be_valid
|
45
|
+
v.invalid_codes.should == %w[1x]
|
43
46
|
v2 = variant("2x")
|
44
47
|
v2.should be_valid
|
45
48
|
end
|
data/spec/stylesheets_spec.rb
CHANGED
@@ -124,4 +124,28 @@ describe 'stylesheets' do
|
|
124
124
|
images.should == ["hero.jpg"] + sorted_images
|
125
125
|
end
|
126
126
|
end
|
127
|
+
|
128
|
+
describe "invalid variants" do
|
129
|
+
let(:log) { '' }
|
130
|
+
|
131
|
+
before :each do
|
132
|
+
stub_files(%w[hero.jpg hero.foo.jpg hero.bar.jpg])
|
133
|
+
Sass.logger.stub(:info) do |message|
|
134
|
+
log << message << "\n"
|
135
|
+
end
|
136
|
+
end
|
137
|
+
|
138
|
+
it "logs invalid variants during compilation" do
|
139
|
+
@scss_file = %Q{
|
140
|
+
@import "apropos";
|
141
|
+
.foo {
|
142
|
+
@include apropos-bg-variants('hero.jpg');
|
143
|
+
}
|
144
|
+
}
|
145
|
+
css_file.should_not include('/hero.foo.jpg')
|
146
|
+
css_file.should_not include('/hero.bar.jpg')
|
147
|
+
log.should include("unknown extensions 'foo'")
|
148
|
+
log.should include("unknown extensions 'bar'")
|
149
|
+
end
|
150
|
+
end
|
127
151
|
end
|
metadata
CHANGED
@@ -1,97 +1,97 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gabriel Gilder
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-03-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
|
28
28
|
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - ~>
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '1.3'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - ~>
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '1.3'
|
41
41
|
- !ruby/object:Gem::Dependency
|
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
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - ~>
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '2.13'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - ~>
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '2.13'
|
69
69
|
- !ruby/object:Gem::Dependency
|
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.
|
@@ -105,9 +105,9 @@ executables: []
|
|
105
105
|
extensions: []
|
106
106
|
extra_rdoc_files: []
|
107
107
|
files:
|
108
|
-
- .gitignore
|
109
|
-
- .rspec
|
110
|
-
- .travis.yml
|
108
|
+
- ".gitignore"
|
109
|
+
- ".rspec"
|
110
|
+
- ".travis.yml"
|
111
111
|
- CHANGELOG.md
|
112
112
|
- Gemfile
|
113
113
|
- LICENSE.txt
|
@@ -146,17 +146,17 @@ require_paths:
|
|
146
146
|
- lib
|
147
147
|
required_ruby_version: !ruby/object:Gem::Requirement
|
148
148
|
requirements:
|
149
|
-
- -
|
149
|
+
- - ">="
|
150
150
|
- !ruby/object:Gem::Version
|
151
151
|
version: '0'
|
152
152
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
153
153
|
requirements:
|
154
|
-
- -
|
154
|
+
- - ">="
|
155
155
|
- !ruby/object:Gem::Version
|
156
156
|
version: '0'
|
157
157
|
requirements: []
|
158
158
|
rubyforge_project:
|
159
|
-
rubygems_version: 2.
|
159
|
+
rubygems_version: 2.2.2
|
160
160
|
signing_key:
|
161
161
|
specification_version: 4
|
162
162
|
summary: Apropos helps your site serve up the appropriate image for every visitor.
|