base.sass 1.2.0 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +11 -0
- data/Readme.md +36 -22
- data/lib/base.sass.rb +4 -4
- data/lib/base.sass/caniuse.rb +37 -8
- data/lib/base.sass/parse-rules.rb +114 -0
- metadata +4 -4
- data/lib/base.sass/support.rb +0 -120
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a777f11b0ec5eca1853ef7a54af4f3d6c7c77b88
|
4
|
+
data.tar.gz: 1f9cdcf73842dcf6ee94e8b6b27e29238dfbad0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 850350f005243911f36d7a07f81a2200e89214c146eb6d150689ed433204eb49ccb15a97adc832f2ff95c68cdbd93ef5c3968fbd7566112ba6d6d855718f8372
|
7
|
+
data.tar.gz: 2f482394fed7d0009161a7419bdcb502169cbeec313b770374bfd764329d7fd504df1645a3bd5b2e73ef37509a6035329338f671e2269b23040b2e2fcec71a9c
|
data/Changelog.md
CHANGED
data/Readme.md
CHANGED
@@ -10,7 +10,7 @@
|
|
10
10
|
In your [`Gemfile`](http://bundler.io/v1.6/gemfile.html):
|
11
11
|
|
12
12
|
```ruby
|
13
|
-
gem 'base.sass', '~> 1.
|
13
|
+
gem 'base.sass', '~> 1.3'
|
14
14
|
```
|
15
15
|
|
16
16
|
Or in command line:
|
@@ -27,7 +27,7 @@ At top of your Sass file:
|
|
27
27
|
@import 'base.sass/*';
|
28
28
|
```
|
29
29
|
|
30
|
-
|
30
|
+
Then, use `-r` option in command line:
|
31
31
|
|
32
32
|
```sh
|
33
33
|
$ sass --watch -r base.sass src:dist
|
@@ -39,6 +39,10 @@ Or in `config.rb`:
|
|
39
39
|
require 'base.sass'
|
40
40
|
```
|
41
41
|
|
42
|
+
## Examples
|
43
|
+
|
44
|
+
Please refer to [wiki](https://github.com/jsw0528/base.sass/wiki) page.
|
45
|
+
|
42
46
|
## Features
|
43
47
|
|
44
48
|
### Read environment variables (case insensitive)
|
@@ -49,7 +53,7 @@ When you run:
|
|
49
53
|
$ SASS_ENV=production sass --update -r base.sass src:dist
|
50
54
|
```
|
51
55
|
|
52
|
-
Then you can use `env()` in
|
56
|
+
Then you can use `env()` in Sass files to get the value:
|
53
57
|
|
54
58
|
```scss
|
55
59
|
env(SASS_ENV) //=> production
|
@@ -57,7 +61,7 @@ env(sass_env) //=> production
|
|
57
61
|
env(sass-env) //=> production
|
58
62
|
```
|
59
63
|
|
60
|
-
You can use any `KEY=value` if you want.
|
64
|
+
> You can use any `KEY=value` if you want.
|
61
65
|
|
62
66
|
### Parse local json file
|
63
67
|
|
@@ -69,10 +73,10 @@ $pkg: parse-json('package.json');
|
|
69
73
|
|
70
74
|
// Then, you can:
|
71
75
|
map-keys($map)
|
72
|
-
map-get($pkg, '
|
76
|
+
map-get($pkg, 'some key')
|
73
77
|
```
|
74
78
|
|
75
|
-
Now you can use the same configurations both in js and css.
|
79
|
+
> Now you can use the same configurations both in js and css.
|
76
80
|
|
77
81
|
### Parse browser supports (case insensitive)
|
78
82
|
|
@@ -89,18 +93,22 @@ All supported browsers: `chrome`, `firefox`, `safari`, `ie`, `opera`, `ios`, `an
|
|
89
93
|
- `iOS 7` to set browser version directly.
|
90
94
|
|
91
95
|
```scss
|
92
|
-
// You can use
|
93
|
-
parse-rules('last 1 version')
|
94
|
-
|
95
|
-
// Or multi params
|
96
|
-
parse-rules('last 1 version', 'IE >= 8')
|
96
|
+
// You can use multi params
|
97
|
+
$browser-supports: parse-rules('last 1 version', 'IE >= 8');
|
97
98
|
|
98
99
|
// Or a list
|
99
100
|
$rules: 'last 1 version', 'IE >= 8';
|
100
|
-
parse-rules($rules)
|
101
|
-
```
|
101
|
+
$browser-supports: parse-rules($rules);
|
102
102
|
|
103
|
-
|
103
|
+
// Then, you can:
|
104
|
+
@if support-browser(Android) {
|
105
|
+
// ...
|
106
|
+
}
|
107
|
+
|
108
|
+
@if not support-browser(ie 8) {
|
109
|
+
// ...
|
110
|
+
}
|
111
|
+
```
|
104
112
|
|
105
113
|
### Enhanced `url()`
|
106
114
|
|
@@ -130,16 +138,24 @@ url('a.png', $timestamp: '1.0.0')
|
|
130
138
|
//=> url(a.png?1.0.0)
|
131
139
|
```
|
132
140
|
|
133
|
-
Also, you can defined timestamp as a global
|
141
|
+
Also, you can defined timestamp as a global configuration in `app-config` namespace:
|
134
142
|
|
135
143
|
```scss
|
136
|
-
$app-config: (
|
144
|
+
$app-config: (
|
145
|
+
development: (
|
146
|
+
timestamp: '1.1.0.alpha'
|
147
|
+
),
|
148
|
+
production: (
|
149
|
+
timestamp: '1.0.0'
|
150
|
+
)
|
151
|
+
);
|
137
152
|
|
138
153
|
url('a.png')
|
139
|
-
//=> url(a.png?1.0.
|
154
|
+
//=> url(a.png?1.1.0.alpha) if SASS_ENV is development
|
155
|
+
//=> url(a.png?1.0.0) if SASS_ENV is production
|
140
156
|
```
|
141
157
|
|
142
|
-
The data uri is also be supported.
|
158
|
+
The data uri is also be supported.
|
143
159
|
|
144
160
|
```scss
|
145
161
|
url('a.png', $base64: true)
|
@@ -149,9 +165,9 @@ url('a.eot', 'b.woff', $base64: true)
|
|
149
165
|
//=> url(data:application/vnd.ms-fontobject;base64,HAcAA...), url(data:application/font-woff;base64,d09GR...)
|
150
166
|
```
|
151
167
|
|
152
|
-
###
|
168
|
+
### Powerful map functions
|
153
169
|
|
154
|
-
|
170
|
+
> Overrides official map functions to support nest keys.
|
155
171
|
|
156
172
|
```scss
|
157
173
|
map-get($map, a)
|
@@ -193,8 +209,6 @@ Compiles to:
|
|
193
209
|
}
|
194
210
|
```
|
195
211
|
|
196
|
-
### [Read more in Wiki](https://github.com/jsw0528/base.sass/wiki)
|
197
|
-
|
198
212
|
## Test
|
199
213
|
|
200
214
|
```sh
|
data/lib/base.sass.rb
CHANGED
@@ -4,12 +4,12 @@ ENV['SASS_PATH'] = [ENV['SASS_PATH'], load_path].compact.join(File::PATH_SEPARAT
|
|
4
4
|
ENV['SASS_ENV'] ||= 'development'
|
5
5
|
|
6
6
|
require 'base.sass/caniuse'
|
7
|
-
require 'base.sass/ruby-to-sass'
|
8
|
-
require 'base.sass/sass-to-ruby'
|
9
7
|
require 'base.sass/env'
|
10
8
|
require 'base.sass/map'
|
11
9
|
require 'base.sass/parse-json'
|
12
|
-
require 'base.sass/
|
13
|
-
require 'base.sass/
|
10
|
+
require 'base.sass/parse-rules'
|
11
|
+
require 'base.sass/ruby-to-sass'
|
12
|
+
require 'base.sass/sass-to-ruby'
|
14
13
|
require 'base.sass/selector'
|
14
|
+
require 'base.sass/strftime'
|
15
15
|
require 'base.sass/url'
|
data/lib/base.sass/caniuse.rb
CHANGED
@@ -4,19 +4,48 @@ class CanIUse
|
|
4
4
|
include Singleton
|
5
5
|
include Sass::Script::Functions
|
6
6
|
|
7
|
-
DATA_DIR = File.join(File.dirname(__FILE__), '..', '..', 'data')
|
8
|
-
|
9
7
|
def initialize
|
10
|
-
@
|
11
|
-
# @caniuse_supports = load_json(File.join(DATA_DIR, 'supports.json'))
|
8
|
+
@data = load_json(File.join(File.dirname(__FILE__), '..', '..', 'data', 'browsers.json'))
|
12
9
|
end
|
13
10
|
|
14
11
|
def browsers
|
15
|
-
@
|
12
|
+
@data.keys.sort
|
13
|
+
end
|
14
|
+
|
15
|
+
def versions(browser, include_future)
|
16
|
+
return [] unless @data.key? browser
|
17
|
+
|
18
|
+
versions = @data[browser]['versions']
|
19
|
+
return versions unless include_future
|
20
|
+
|
21
|
+
versions + @data[browser]['future'].to_a
|
16
22
|
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
|
24
|
+
end
|
25
|
+
|
26
|
+
|
27
|
+
module Sass::Script::Functions
|
28
|
+
|
29
|
+
# Returns the data in CanIUse which base.sass used.
|
30
|
+
#
|
31
|
+
# Examples:
|
32
|
+
# caniuse(browsers)
|
33
|
+
# caniuse(Chrome versions)
|
34
|
+
# caniuse(Chrome all versions)
|
35
|
+
def caniuse(cond)
|
36
|
+
cond = [sass_to_ruby(cond)].flatten.map { |w| w.downcase }
|
37
|
+
|
38
|
+
output = if cond.first == 'browsers'
|
39
|
+
caniuse_browsers
|
40
|
+
elsif cond.last == 'versions'
|
41
|
+
browser = cond.first
|
42
|
+
assert_valid_browser(browser)
|
43
|
+
caniuse_versions(browser, cond.include?('all'))
|
44
|
+
else
|
45
|
+
raise Sass::SyntaxError, "Unknown condition.\nYou can try `caniuse(browsers)` or `caniuse(Chrome versions)`"
|
46
|
+
end
|
47
|
+
|
48
|
+
ruby_to_sass(output)
|
49
|
+
end
|
21
50
|
|
22
51
|
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
module Sass::Script::Functions
|
2
|
+
|
3
|
+
# Returns the specified browsers and versions associated with the given rules.
|
4
|
+
#
|
5
|
+
# Rules:
|
6
|
+
# 1. last 1 version is last versions for each browser.
|
7
|
+
# 2. last 2 Chrome versions is last versions of the specified browser.
|
8
|
+
# 3. IE > 8 is ie versions newer than 8.
|
9
|
+
# 4. IE >= 8 is ie version 8 or newer.
|
10
|
+
# 5. iOS 7 to set browser version directly.
|
11
|
+
def parse_rules(*rules)
|
12
|
+
rules = rules.map { |r| sass_to_ruby(r) }.flatten.uniq
|
13
|
+
|
14
|
+
# Parse
|
15
|
+
selected = rules.map { |r| rules_parser(r.downcase) }.compact
|
16
|
+
# Merge
|
17
|
+
selected = selected.inject { |memo, p|
|
18
|
+
memo.merge(p) { |k, orig, added| orig + added }
|
19
|
+
}
|
20
|
+
# Uniq & Sort
|
21
|
+
selected.each { |k, v|
|
22
|
+
v.uniq!
|
23
|
+
v.sort!
|
24
|
+
}
|
25
|
+
|
26
|
+
ruby_to_sass(selected)
|
27
|
+
end
|
28
|
+
|
29
|
+
|
30
|
+
protected
|
31
|
+
|
32
|
+
def caniuse_browsers
|
33
|
+
@browsers ||= CanIUse.instance.browsers
|
34
|
+
end
|
35
|
+
|
36
|
+
def caniuse_versions(browser, include_future)
|
37
|
+
@versions ||= {}
|
38
|
+
k = browser.to_s + include_future.to_s
|
39
|
+
@versions[k] ||= CanIUse.instance.versions(browser, include_future)
|
40
|
+
end
|
41
|
+
|
42
|
+
def assert_valid_browser(browser, version = nil)
|
43
|
+
unless caniuse_browsers.include? browser
|
44
|
+
raise Sass::SyntaxError, "Unknown browser name: #{browser}\nYou can find all valid names according to `caniuse(browsers)`"
|
45
|
+
end
|
46
|
+
|
47
|
+
unless version.nil? || caniuse_versions(browser, true).include?(version)
|
48
|
+
raise Sass::SyntaxError, "Unknown version for #{browser}: #{version}\nYou can find all valid versions according to `caniuse(#{browser} all versions)`"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
52
|
+
|
53
|
+
private
|
54
|
+
|
55
|
+
def rules_parser(rule)
|
56
|
+
case rule
|
57
|
+
|
58
|
+
# match `last 1 version`
|
59
|
+
when /^last (\d+) versions?$/
|
60
|
+
last_versions_parser($1)
|
61
|
+
|
62
|
+
# match `last 3 chrome versions`
|
63
|
+
when /^last (\d+) (\w+) versions?$/
|
64
|
+
last_browser_versions_parser($1, $2, true)
|
65
|
+
|
66
|
+
# match `ie > 9`
|
67
|
+
when /^(\w+) (>=?) ([\d\.]+)$/
|
68
|
+
newer_then_parser($1, $2, $3)
|
69
|
+
|
70
|
+
# match `ios 7`
|
71
|
+
when /^(\w+) ([\d\.]+)$/
|
72
|
+
direct_parser($1, $2)
|
73
|
+
|
74
|
+
else
|
75
|
+
raise Sass::SyntaxError, "Unknown rule: `#{rule}`"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def last_versions_parser(num)
|
80
|
+
caniuse_browsers.map { |browser|
|
81
|
+
last_browser_versions_parser(num, browser, false)
|
82
|
+
}.inject :merge
|
83
|
+
end
|
84
|
+
|
85
|
+
def last_browser_versions_parser(num, browser, assert)
|
86
|
+
assert_valid_browser(browser) if assert
|
87
|
+
Hash[browser, caniuse_versions(browser, false).last(num.to_i)]
|
88
|
+
end
|
89
|
+
|
90
|
+
def newer_then_parser(browser, sign, version)
|
91
|
+
assert_valid_browser(browser)
|
92
|
+
|
93
|
+
versions = caniuse_versions(browser, false)
|
94
|
+
versions = case sign
|
95
|
+
when '>='
|
96
|
+
versions.select { |n| n >= version.to_f }
|
97
|
+
when '>'
|
98
|
+
versions.select { |n| n > version.to_f }
|
99
|
+
end
|
100
|
+
|
101
|
+
versions.empty? ? nil : Hash[browser, versions]
|
102
|
+
end
|
103
|
+
|
104
|
+
def direct_parser(browser, version)
|
105
|
+
version = to_if(version)
|
106
|
+
assert_valid_browser(browser, version)
|
107
|
+
Hash[browser, [version]]
|
108
|
+
end
|
109
|
+
|
110
|
+
def to_if(s)
|
111
|
+
s.include?('.') ? s.to_f : s.to_i
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: base.sass
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- junjun.zhang
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-05-
|
11
|
+
date: 2014-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sass
|
@@ -44,11 +44,11 @@ files:
|
|
44
44
|
- lib/base.sass/env.rb
|
45
45
|
- lib/base.sass/map.rb
|
46
46
|
- lib/base.sass/parse-json.rb
|
47
|
+
- lib/base.sass/parse-rules.rb
|
47
48
|
- lib/base.sass/ruby-to-sass.rb
|
48
49
|
- lib/base.sass/sass-to-ruby.rb
|
49
50
|
- lib/base.sass/selector.rb
|
50
51
|
- lib/base.sass/strftime.rb
|
51
|
-
- lib/base.sass/support.rb
|
52
52
|
- lib/base.sass/url.rb
|
53
53
|
- stylesheets/base.sass/_*.scss
|
54
54
|
- stylesheets/base.sass/functions/_list.scss
|
@@ -79,7 +79,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
79
79
|
version: '0'
|
80
80
|
requirements: []
|
81
81
|
rubyforge_project:
|
82
|
-
rubygems_version: 2.2.
|
82
|
+
rubygems_version: 2.2.2
|
83
83
|
signing_key:
|
84
84
|
specification_version: 4
|
85
85
|
summary: Awesome Extensions For Sass
|
data/lib/base.sass/support.rb
DELETED
@@ -1,120 +0,0 @@
|
|
1
|
-
module Sass::Script::Functions
|
2
|
-
|
3
|
-
# Which browsers you wanted support?
|
4
|
-
#
|
5
|
-
# `last 1 version`
|
6
|
-
# is last versions for each browser.
|
7
|
-
# `last 2 Chrome versions`
|
8
|
-
# is last versions of the specified browser.
|
9
|
-
# `IE > 8`
|
10
|
-
# is IE versions newer than 8.
|
11
|
-
# `IE >= 8`
|
12
|
-
# is IE version 8 or newer.
|
13
|
-
# `iOS 7`
|
14
|
-
# to set browser version directly.
|
15
|
-
def parse_rules(*rules)
|
16
|
-
rules = rules.map { |rule| sass_to_ruby(rule) }.flatten.uniq
|
17
|
-
|
18
|
-
@browsers ||= CanIUse.instance.browsers
|
19
|
-
selected_browsers =
|
20
|
-
rules.map { |rule| rules_parser(rule.downcase) }.compact
|
21
|
-
.inject { |memo, versions|
|
22
|
-
memo.merge(versions) { |k, orig, added| orig + added }
|
23
|
-
}
|
24
|
-
|
25
|
-
ruby_to_sass(selected_browsers.each { |k, v| v.uniq!; v.sort! })
|
26
|
-
end
|
27
|
-
|
28
|
-
# Returns `(android, chrome, firefox, ie, ios, opera, safari)`.
|
29
|
-
def browsers
|
30
|
-
ruby_to_sass(CanIUse.instance.browsers.keys.sort)
|
31
|
-
end
|
32
|
-
|
33
|
-
# Returns the versions by the given browser.
|
34
|
-
def browser_versions(browser, include_future = bool(true))
|
35
|
-
assert_type browser, :String
|
36
|
-
|
37
|
-
@browsers ||= CanIUse.instance.browsers
|
38
|
-
browser = browser.value.downcase
|
39
|
-
assert_valid_browser(browser)
|
40
|
-
|
41
|
-
versions = @browsers[browser]['versions']
|
42
|
-
versions += @browsers[browser]['future'].to_a if include_future.to_bool
|
43
|
-
|
44
|
-
ruby_to_sass(versions)
|
45
|
-
end
|
46
|
-
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def assert_valid_browser(browser, version = nil)
|
51
|
-
unless @browsers.key? browser
|
52
|
-
raise Sass::SyntaxError, "Unknown browser name: #{browser}\nYou can find all valid names according to `browsers()`"
|
53
|
-
end
|
54
|
-
|
55
|
-
unless version.nil? || sass_to_ruby(browser_versions(identifier(browser))).include?(version)
|
56
|
-
raise Sass::SyntaxError, "Unknown version for #{browser}: #{version}\nYou can find all valid versions according to `browser-versions(#{browser})`"
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
def rules_parser(rule)
|
61
|
-
case rule
|
62
|
-
|
63
|
-
# match `last 1 version`
|
64
|
-
when /^last (\d+) versions?$/
|
65
|
-
last_versions_parser($1)
|
66
|
-
|
67
|
-
# match `last 3 chrome versions`
|
68
|
-
when /^last (\d+) (\w+) versions?$/
|
69
|
-
last_browser_versions_parser($1, $2)
|
70
|
-
|
71
|
-
# match `ie > 9`
|
72
|
-
when /^(\w+) (>=?) ([\d\.]+)$/
|
73
|
-
newer_then_parser($1, $2, $3)
|
74
|
-
|
75
|
-
# match `ios 7`
|
76
|
-
when /^(\w+) ([\d\.]+)$/
|
77
|
-
direct_parser($1, $2)
|
78
|
-
|
79
|
-
else
|
80
|
-
raise Sass::SyntaxError, "Unknown rule: `#{rule}`"
|
81
|
-
end
|
82
|
-
end
|
83
|
-
|
84
|
-
def last_versions_parser(num)
|
85
|
-
@browsers.inject({}) do |memo, (k, v)|
|
86
|
-
memo[k] = v['versions'].last(num.to_i)
|
87
|
-
memo
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
def last_browser_versions_parser(num, browser)
|
92
|
-
assert_valid_browser(browser)
|
93
|
-
Hash[browser, @browsers[browser]['versions'].last(num.to_i)]
|
94
|
-
end
|
95
|
-
|
96
|
-
def newer_then_parser(browser, sign, version)
|
97
|
-
assert_valid_browser(browser)
|
98
|
-
|
99
|
-
versions = @browsers[browser]['versions']
|
100
|
-
versions = case sign
|
101
|
-
when '>='
|
102
|
-
versions.select { |n| n >= version.to_f }
|
103
|
-
when '>'
|
104
|
-
versions.select { |n| n > version.to_f }
|
105
|
-
end
|
106
|
-
|
107
|
-
versions.empty? ? nil : Hash[browser, versions]
|
108
|
-
end
|
109
|
-
|
110
|
-
def direct_parser(browser, version)
|
111
|
-
version = to_if(version)
|
112
|
-
assert_valid_browser(browser, version)
|
113
|
-
Hash[browser, [version]]
|
114
|
-
end
|
115
|
-
|
116
|
-
def to_if(s)
|
117
|
-
s.include?('.') ? s.to_f : s.to_i
|
118
|
-
end
|
119
|
-
|
120
|
-
end
|