sassmagic 0.1.3 → 0.1.4

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 CHANGED
@@ -1,50 +1,60 @@
1
- ### sassmagic
2
-
3
-
4
- description:Sass extention tool
5
-
6
-
7
- ### install
8
-
9
-
10
- sudo gem install sassmagic
11
-
12
-
13
- ### use
14
-
15
-
16
- same to sass
17
-
18
- eg: sassmagic --style nested --x test.scss test.css
19
-
20
- ### configuration
21
-
22
-
23
- sassmagic.json 配置文件:
24
-
25
-
26
-
27
-
28
- {
29
- "isNeedPxToRem": true,
30
- "browserDefaultFontSize": "75px",
31
- "ignore": [
32
- "1px",
33
- "[data-dpr=",
34
- "font-size"
35
- ],
36
- "outputExtra": [
37
- "1x",
38
- "2x",
39
- "3x"
40
- ],
41
- "imageMaxSize": "5120",
42
- "imageLoader": "imageuploader.js",
43
- "imagesPath": {
44
- },
45
- "remoteStylesheet":"",
46
- "tinypngKye",""
47
- }
48
-
49
- imageuploader.js
50
- 图片上传
1
+ ### sassmagic
2
+
3
+
4
+ description:Sass extention tool
5
+
6
+
7
+ ### install
8
+
9
+
10
+ sudo gem install sassmagic
11
+
12
+
13
+ ### use
14
+
15
+ start:
16
+
17
+ ####sassmagic init
18
+
19
+ or
20
+
21
+ ####sassmagic creat [project]
22
+
23
+ other
24
+
25
+ same to sass
26
+
27
+ eg: sassmagic --style nested --x test.scss test.css
28
+
29
+ ### configuration
30
+
31
+
32
+ sassmagic.json 配置文件:
33
+
34
+
35
+
36
+
37
+ {
38
+ "isNeedPxToRem": true,//是否自动转rem
39
+ "browserDefaultFontSize": "75px",//rem设置
40
+ "devicePixelRatio":"2",//dpr设置
41
+ "ignore": [//过滤不需要转rem的内容
42
+ "1px",
43
+ "[data-dpr=",
44
+ "font-size"
45
+ ],
46
+ "outputExtra": [//额外输出1x 2x 3x样式表
47
+ "1x",
48
+ "2x",
49
+ "3x"
50
+ ],
51
+ "imageMaxSize": "5120",//图片时候上传阀值
52
+ "imageLoader": "../config/imageuploader.js",//上传任务nodeJs
53
+ "imagesPath": {//上传文件缓存
54
+ },
55
+ "remoteStylesheet":"",//远程stylesheet路径
56
+ "tinypngKye",""//tinypngApiKey
57
+ }
58
+
59
+ imageuploader.js
60
+ 图片上传
@@ -259,7 +259,8 @@ class Sass::Tree::Visitors::ToCss < Sass::Tree::Visitors::Base
259
259
 
260
260
  # Avoid allocating lots of new strings for `#output`. This is important
261
261
  # because `#output` is called all the time.
262
- NEWLINE = "\n"
262
+ # 注释常量重复声明
263
+ # NEWLINE = "\n"
263
264
 
264
265
  # Add `s` to the output string and update the line and offset information
265
266
  # accordingly.
@@ -520,6 +521,10 @@ class Sass::Tree::Visitors::ToCss < Sass::Tree::Visitors::Base
520
521
  str.scan(/([\.\d]+)+(px)+([;\s]+|$)/i){ |c,v|
521
522
  if !(ignore.include? c+v) && (c != '1') && c =~ /^[^0]+/
522
523
  ret = ret.gsub(c.to_s,(format("%.3f",c.to_f/rem).to_f).to_s).gsub(v,'rem')
524
+ else
525
+ # debugger
526
+ ret = ret.gsub(/^0+/,'0').gsub(/(^0+)(\d+)/,'\2')
527
+ # ret = ret.to_s.gsub(/(^0+)(\d+)/,'\2')
523
528
  end
524
529
  }
525
530
  end
@@ -813,7 +818,8 @@ module Sass::Exec
813
818
  @options[:input], @options[:output] = input, output
814
819
  end
815
820
 
816
- COLORS = {:red => 31, :green => 32, :yellow => 33}
821
+ # 注释常量重复声明
822
+ # COLORS = {:red => 31, :green => 32, :yellow => 33}
817
823
 
818
824
  # Prints a status message about performing the given action,
819
825
  # colored using the given color (via terminal escapes) if possible.
@@ -250,7 +250,7 @@ module Sass::Script::Functions
250
250
  ts = timestamp(kwargs['timestamp'])
251
251
 
252
252
  paths = paths.map { |path| sass_to_ruby(path) }.flatten
253
- .map { |path| compress_img(path);to_url(path, encode, ts) }
253
+ .map { |path| compress_img(path, encode, ts); }
254
254
 
255
255
  list(paths, :comma)
256
256
  end
@@ -258,55 +258,65 @@ module Sass::Script::Functions
258
258
 
259
259
 
260
260
  private
261
- def compress_img(path)
262
- #图片压缩
261
+ def compress_img(path,encode,ts)
263
262
  # debugger
264
- # 未设置tinypngKye或者url图片,则不优化
265
- if !$configHash.has_key?('tinypngKye') || $configHash['tinypngKye'] == '' || path =~ /^(http:|https:)\/\//
266
-
267
- else
268
- output = path.gsub(/\.(png|jpg)$/,'_tinypng.\1')
269
- if File.exist?("#{File.dirname(options[:filename])}/#{output}")
270
- path.gsub!(/\.(png|jpg)$/,'_tinypng.\1')
271
- return
272
- end
273
-
274
- require "net/https"
275
- require "uri"
276
-
277
- key = $configHash['tinypngKye'] || ''
278
- input = path
279
- # real_path = File.expand_path("#{File.dirname(path)}/#{path}")
280
- # output = "tiny-output.png"
281
-
282
- uri = URI.parse("https://api.tinypng.com/shrink")
283
-
284
- http = Net::HTTP.new(uri.host, uri.port)
285
- http.use_ssl = true
286
-
287
- # Uncomment below if you have trouble validating our SSL certificate.
288
- # Download cacert.pem from: http://curl.haxx.se/ca/cacert.pem
289
- # http.ca_file = File.join(File.dirname(__FILE__), "cacert.pem")
263
+ if path.is_a?(String) && path =~ PATH_REGEX
290
264
 
291
- request = Net::HTTP::Post.new(uri.request_uri)
292
- request.basic_auth("api", key)
265
+ path, ext, query, anchor = $1 + $2, $2[1..-1].downcase.to_sym, $3, $4
293
266
 
294
- response = http.request(request, File.binread("#{File.dirname(options[:filename])}/#{input}"))
295
- # debugger
296
- if response.code == "201"
297
- # Compression was successful, retrieve output from Location header.
267
+ if MIME_TYPES.key? ext
268
+ #图片压缩
298
269
  # debugger
299
- output = path
300
- path.gsub!(/\.(png|jpg)$/,'_tinypng.\1')
301
- # output['.png'] = '_tinypng.png'
302
- # output['.jpg'] = '_tinypng.jpg'
303
- File.binwrite("#{File.dirname(options[:filename])}/#{output}", http.get(response["location"]).body)
304
- else
305
- # Something went wrong! You can parse the JSON body for details.
306
- puts "Compression failed"
270
+ # 未设置tinypngKye或者url图片,则不优化
271
+ if !$configHash.has_key?('tinypngKye') || $configHash['tinypngKye'] == '' || path =~ /^(http:|https:)\/\//
272
+
273
+ else
274
+ output = path.dup.gsub(/\.(png|jpg)$/,'_tinypng.\1')
275
+ if File.exist?("#{File.dirname(options[:filename])}/#{output}")
276
+ # debug exception while processing events: can't modify frozen String , Backtrace:
277
+ path.gsub!(/\.(png|jpg)$/,'_tinypng.\1')
278
+ else
279
+ require "net/https"
280
+ require "uri"
281
+
282
+ key = $configHash['tinypngKye'] || ''
283
+ input = path
284
+ # real_path = File.expand_path("#{File.dirname(path)}/#{path}")
285
+ # output = "tiny-output.png"
286
+
287
+ uri = URI.parse("https://api.tinypng.com/shrink")
288
+
289
+ http = Net::HTTP.new(uri.host, uri.port)
290
+ http.use_ssl = true
291
+
292
+ # Uncomment below if you have trouble validating our SSL certificate.
293
+ # Download cacert.pem from: http://curl.haxx.se/ca/cacert.pem
294
+ # http.ca_file = File.join(File.dirname(__FILE__), "cacert.pem")
295
+
296
+ request = Net::HTTP::Post.new(uri.request_uri)
297
+ request.basic_auth("api", key)
298
+
299
+ response = http.request(request, File.binread("#{File.dirname(options[:filename])}/#{input}"))
300
+ # debugger
301
+ if response.code == "201"
302
+ # Compression was successful, retrieve output from Location header.
303
+ # debugger
304
+ output = path
305
+ path.gsub!(/\.(png|jpg)$/,'_tinypng.\1')
306
+ # output['.png'] = '_tinypng.png'
307
+ # output['.jpg'] = '_tinypng.jpg'
308
+ File.binwrite("#{File.dirname(options[:filename])}/#{output}", http.get(response["location"]).body)
309
+ else
310
+ # Something went wrong! You can parse the JSON body for details.
311
+ puts "Compression failed"
312
+ end
313
+ end
314
+ end
307
315
  end
308
316
  end
309
317
 
318
+ #调用to_url函数
319
+ to_url(path, encode, ts)
310
320
  end
311
321
  def timestamp(ts)
312
322
  # no kwargs
@@ -415,22 +425,22 @@ module Sass::Script::Functions
415
425
  # puts 'nodetask success'
416
426
  $configHash = load_json(File.expand_path("#{File.dirname(options[:filename])}/../config/sassmagic.json"))
417
427
  $configHash["imagesPath"] ||= Hash.new
418
- if $configHash["imagesPath"].has_key?(path)
419
- return $configHash["imagesPath"][path]
428
+ if $configHash["imagesPath"].has_key?(taskargs)
429
+ return $configHash["imagesPath"][taskargs]
420
430
  else
421
431
  return path
422
432
  end
423
433
  else
424
434
  # puts 'nodetask faile'
425
- if $configHash["imagesPath"].has_key?(path)
426
- return $configHash["imagesPath"][path]
435
+ if $configHash["imagesPath"].has_key?(taskargs)
436
+ return $configHash["imagesPath"][taskargs]
427
437
  else
428
438
  return path
429
439
  end
430
440
  end
431
441
  else
432
- if $configHash["imagesPath"].has_key?(path)
433
- return $configHash["imagesPath"][path]
442
+ if $configHash["imagesPath"].has_key?(taskargs)
443
+ return $configHash["imagesPath"][taskargs]
434
444
  else
435
445
  return path
436
446
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sassmagic
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
- - ringself
8
+ - ring
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-02-11 00:00:00.000000000 Z
12
+ date: 2015-03-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sass
@@ -34,7 +34,7 @@ dependencies:
34
34
  - !ruby/object:Gem::Version
35
35
  version: '3.5'
36
36
  description: Awesome features that you wanted
37
- email: ringself@163.com
37
+ email: ring.wangh@alibaba-inc.com
38
38
  executables:
39
39
  - sassmagic
40
40
  extensions: []