apropos 0.1.3 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: a962f1179e0409d400951f76f62f6c27ecf3e718
4
- data.tar.gz: a7514086b04b178327d6a14c89c6ffd036a466d4
3
+ metadata.gz: ad98be4a87f9fb9605a909f04e23568f1b145c46
4
+ data.tar.gz: 924c293bb77515903932e9d113de7a32a2de367e
5
5
  SHA512:
6
- metadata.gz: 43c755d4b4c123e5bddf399e4aefee29635724adf031a46ffdcdafd0857a1821690df4444f81f04b1cdfb48f9134de3d38564550618db98e624fefd8672f87f6
7
- data.tar.gz: 031ddabc39cf60f8d590008e90eb465c0128ce72d23c6ad171a244420a1ea852b141ea1fc3709d70eef3e8233ccc7bd7d5dee906b1d5fb6160a6f8d6a6d189cb
6
+ metadata.gz: c22b53d22e056c57a2fcd326f2df8e4d41a6bc1795f598050683bcef5e44258df65bfbd45605fc093ec5ddfe36d50e63c16713911dc5c121235c5697e6c9fd51
7
+ data.tar.gz: 74621277cb2190c35a8f575a6725db5a9e6b405f4faf848092c1176c59983a58a4d6881aea326e0524b4fe785645736b20658c0629a0857fdfde38feb45df38c
@@ -1,5 +1,10 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.1.4 (2015-03-27)
4
+
5
+ Bug fix where extension variants would match substrings (e.g. "extra-small"
6
+ would accidentally match "small" in a file name).
7
+
3
8
  ## 0.1.3 (2014-10-16)
4
9
 
5
10
  Bug fix for compatiblity with Sass 3.3.
@@ -21,7 +21,7 @@ module Apropos
21
21
  attr_reader :pattern
22
22
 
23
23
  def initialize(pattern, &block)
24
- @pattern = pattern
24
+ @pattern = generate_pattern(pattern)
25
25
  @match_block = block
26
26
  end
27
27
 
@@ -31,5 +31,16 @@ module Apropos
31
31
  @match_block.call(matchdata)
32
32
  end
33
33
  end
34
+
35
+ private
36
+
37
+ def generate_pattern(pattern)
38
+ case pattern
39
+ when String
40
+ %r(^#{Regexp.escape(pattern)}$)
41
+ else
42
+ pattern
43
+ end
44
+ end
34
45
  end
35
46
  end
@@ -1,3 +1,3 @@
1
1
  module Apropos
2
- VERSION = "0.1.3"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -31,41 +31,60 @@ describe Apropos::ExtensionParser do
31
31
  described_class.each_parser do |parser|
32
32
  vals << parser.pattern
33
33
  end
34
- vals.should == %w[2x medium fr]
34
+ vals.should == [
35
+ /^2x$/,
36
+ /^medium$/,
37
+ /^fr$/,
38
+ ]
35
39
  end
36
40
  end
37
41
 
38
42
  describe "#match" do
39
43
  let(:locale_pattern) { /^([a-z]{2})$/ }
40
44
 
41
- it "calls the block when the extension matches" do
42
- lastmatch = nil
43
- parser = described_class.new(locale_pattern) do |match|
44
- lastmatch = match
45
+ context "with a string pattern" do
46
+ let(:pattern) { 'extra-small' }
47
+ let(:parser) { described_class.new(pattern) { |_| true } }
48
+
49
+ it "matches the exact string" do
50
+ parser.match(pattern).should == true
51
+ end
52
+
53
+ it "does not match a substring" do
54
+ parser.match('small').should be_nil
45
55
  end
46
- parser.match('fr')
47
- lastmatch[1].should == 'fr'
48
56
  end
49
57
 
50
- it "doesn't call the block when there is no match" do
51
- expect {
52
- parser = described_class.new(/^fr$/) do |match|
53
- raise
58
+ context "with a regular expression pattern" do
59
+ it "calls the block when the extension matches" do
60
+ lastmatch = nil
61
+ parser = described_class.new(locale_pattern) do |match|
62
+ lastmatch = match
54
63
  end
55
- parser.match('en').should be_nil
56
- }.to_not raise_error
57
- end
64
+ parser.match('fr')
65
+ lastmatch[1].should == 'fr'
66
+ end
67
+
68
+ it "doesn't call the block when there is no match" do
69
+ expect {
70
+ parser = described_class.new(/^fr$/) do |match|
71
+ raise
72
+ end
73
+ parser.match('en').should be_nil
74
+ }.to_not raise_error
75
+ end
58
76
 
59
- it "allows the block to return a nil value" do
60
- parser = described_class.new(locale_pattern) do |match|
61
- if match[1] == 'fr'
62
- true
63
- else
64
- nil
77
+ it "allows the block to return a nil value" do
78
+ parser = described_class.new(locale_pattern) do |match|
79
+ if match[1] == 'fr'
80
+ true
81
+ else
82
+ nil
83
+ end
65
84
  end
85
+ parser.match('fr').should == true
86
+ parser.match('en').should be_nil
66
87
  end
67
- parser.match('fr').should == true
68
- parser.match('en').should be_nil
69
88
  end
70
89
  end
71
90
  end
@@ -98,16 +98,20 @@ describe 'stylesheets' do
98
98
  end
99
99
 
100
100
  it "allows setting breakpoints" do
101
- stub_files(%w[hero.jpg hero.medium.jpg hero.large.jpg])
101
+ stub_files(%w[hero.jpg hero.extra-small.jpg hero.small.jpg hero.medium.jpg hero.large.jpg hero.extra-large.jpg])
102
102
  @scss_file = %Q{
103
- $apropos-breakpoints: (medium, 768px), (large, 1024px);
103
+ $apropos-breakpoints: ("extra-small", 374px), ("small", 480px), ("medium", 768px), ("large", 1024px), ("extra-large", 1292px);
104
104
  @import "apropos";
105
105
  .foo {
106
106
  @include apropos-bg-variants('hero.jpg');
107
107
  }
108
108
  }
109
+ css_file.should include(".foo { background-image: url('/hero.jpg'); }")
110
+ css_file.should include("@media (min-width: 374px) { .foo { background-image: url('/hero.extra-small.jpg'); } }")
111
+ css_file.should include("@media (min-width: 480px) { .foo { background-image: url('/hero.small.jpg'); } }")
109
112
  css_file.should include("@media (min-width: 768px) { .foo { background-image: url('/hero.medium.jpg'); } }")
110
113
  css_file.should include("@media (min-width: 1024px) { .foo { background-image: url('/hero.large.jpg'); } }")
114
+ css_file.should include("@media (min-width: 1292px) { .foo { background-image: url('/hero.extra-large.jpg'); } }")
111
115
  end
112
116
  end
113
117
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: apropos
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Gilder
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-17 00:00:00.000000000 Z
11
+ date: 2015-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: compass