texture_packer 1.4.1 → 1.5.0

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
- SHA1:
3
- metadata.gz: ab7f3e967ebc61b0115b4d3b144798545453d8c6
4
- data.tar.gz: 6957e630fbc4dad6558ae829f2e60d9566737c06
2
+ SHA256:
3
+ metadata.gz: 0270c54ea7b25a4186653eda157aeade991e5baa1313c0c72c2306b16d448713
4
+ data.tar.gz: fe77658cb80970d46cf38e7bfcb370546cd33abc2a7cf469cf181cbfdfaeaa53
5
5
  SHA512:
6
- metadata.gz: 6ad985efd0f9028e1f22ff5ca6ab533a4cf0a43425ad8d8c09b4b79a5a4c929d67a8f073f558fd6ae9e6cd103aaa90af4076ebe2f47d0e9758f0169a2ed9e4cf
7
- data.tar.gz: 818aeb8ae58e26980999084957e7e8a82531580906b5ad13cad418a651c0e272add37d0ab434d0f2e53c4a023da9553f607314144a162b933311bef5a88924bc
6
+ metadata.gz: 160e7d0d84f2573d6337660d0d9ce96da4a13bad66cd4e464c239efd0b1d37d8c15b527b3090196ae6281b3ccef157723980192021be5eac7b0c1bf456b1264f
7
+ data.tar.gz: 88621992c34aebf99778f74ef538099c4a84c31642d48fe8f2a3369c24584597c61ea77dd60613e1b9970de5cc99f7a8a1828168409557095000f023acb0e317
@@ -38,13 +38,17 @@ class TexturePacker::Cli
38
38
  end
39
39
 
40
40
  def create_packer
41
- has_mobile = true if File.exists?('packed_m.css')
41
+ split_type = case
42
+ when File.exists?('packed_m.css') ; TexturePacker::SPLIT_BY_MOBILE
43
+ when File.exists?('packed_tw.css') ; TexturePacker::SPLIT_I18N
44
+ else ; nil
45
+ end
42
46
 
43
47
  # 由路徑計算 class 名字
44
48
  dir_name = File.expand_path(Dir.pwd).gsub(/.*\/Texture-Packer\/.*?\/(.*)/, '\1')
45
49
 
46
50
  content = output_paths_mapping.map{|_, path| File.read("#{path}.css") }.join
47
- return TexturePacker.new(dir_name, output_paths_mapping, content, has_mobile)
51
+ return TexturePacker.new(dir_name, output_paths_mapping, content, split_type)
48
52
  end
49
53
 
50
54
  def output_paths_mapping
@@ -61,7 +65,7 @@ class TexturePacker::Cli
61
65
  # ----------------------------------------------------------------
62
66
  def write_to_project_dir!(packer, output1, output2)
63
67
  css_pre_lines = ["@import './mixin.scss';"]
64
- css_pre_lines.unshift("@import 'global_mixins';") if packer.has_mobile
68
+ css_pre_lines.unshift("@import 'global_mixins';") if packer.need_global_mixins?
65
69
 
66
70
  sub_dirs = packer.dir_name.split(File::Separator)[0...-1]
67
71
 
@@ -1,3 +1,3 @@
1
1
  class TexturePacker
2
- VERSION = "1.4.1"
2
+ VERSION = "1.5.0"
3
3
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'texture_packer/version'
2
4
 
3
5
  class TexturePacker
@@ -5,12 +7,14 @@ class TexturePacker
5
7
  attr_reader :base_dir_name
6
8
  attr_reader :dir_without_theme
7
9
  attr_reader :output_paths_mapping
8
- attr_reader :has_mobile
9
10
 
10
- def initialize(dir_name, output_paths_mapping, content, has_mobile)
11
+ SPLIT_BY_MOBILE = 'mobile'
12
+ SPLIT_BY_I18N = 'i18n'
13
+
14
+ def initialize(dir_name, output_paths_mapping, content, split_type = nil)
11
15
  @output_paths_mapping = output_paths_mapping
12
16
  @content = content.dup
13
- @has_mobile = has_mobile
17
+ @split_type = split_type
14
18
 
15
19
  @dir_name = dir_name
16
20
  @base_dir_name = File.basename(@dir_name)
@@ -57,18 +61,25 @@ class TexturePacker
57
61
  output2 = "" #scss的output
58
62
  output2 += "body[theme='#{@theme}']{\n"
59
63
  output2 += " .#{@dir_without_theme}_sprite{\n"
60
- if @has_mobile
64
+ case @split_type
65
+ when SPLIT_BY_MOBILE
61
66
  output2 += " @include desktop{ @include #{base_dir_name}_sprite; }\n"
62
67
  output2 += " @include mobile{ @include #{base_dir_name}_sprite_m; }\n"
63
- elsif @output_paths_mapping.size > 1
64
- output2 += @output_paths_mapping.map do |kind, name|
65
- next " @include #{base_dir_name}_sprite;\n" if kind == nil
66
- next " &[kind=\"#{kind}\"] { @include #{base_dir_name}_sprite_#{kind}; }\n"
67
- end.join
68
+ when SPLIT_BY_I18N
69
+ output2 += " &:lang(zh-TW){ @include #{base_dir_name}_sprite_tw; }\n"
70
+ output2 += " &:lang(zh-CN){ @include #{base_dir_name}_sprite_cn; }\n"
71
+ output2 += " &:lang(en){ @include #{base_dir_name}_sprite_en; }\n"
68
72
  else
69
- output2 += " @include #{base_dir_name}_sprite;\n"
73
+ if @output_paths_mapping.size > 1
74
+ output2 += @output_paths_mapping.map do |kind, name|
75
+ next " @include #{base_dir_name}_sprite;\n" if kind == nil
76
+ next " &[kind=\"#{kind}\"] { @include #{base_dir_name}_sprite_#{kind}; }\n"
77
+ end.join
78
+ else
79
+ output2 += " @include #{base_dir_name}_sprite;\n"
80
+ end
70
81
  end
71
- # output2 += " &.split_mobile{ @include mobile{ @include #{base_dir_name}_sprite_m; }}\n" if @has_mobile
82
+ # output2 += " &.split_mobile{ @include mobile{ @include #{base_dir_name}_sprite_m; }}\n" if @split_type == SPLIT_BY_MOBILE
72
83
  for selector, css_data in data
73
84
  func = "#{base_dir_name}_#{selector}"
74
85
  rules = CssRule.new
@@ -92,7 +103,7 @@ class TexturePacker
92
103
  return "@mixin #{func}{ #{css} }\n"
93
104
  end
94
105
 
95
- def parse_language_selector!(selector)
106
+ def parse_language_selector!(selector) # 向下相容
96
107
  language_parsed_array = selector.scan(/_(?:tw|cn|en)\z/)
97
108
  return selector if language_parsed_array.count.zero? # 如果沒有語言分類就回傳原本的 selector
98
109
 
@@ -106,6 +117,11 @@ class TexturePacker
106
117
  end
107
118
  end
108
119
 
120
+ def need_global_mixins?
121
+ return true if @split_type == SPLIT_BY_MOBILE
122
+ return false
123
+ end
124
+
109
125
  class CssRule
110
126
  def initialize
111
127
  @hash = {}
@@ -119,13 +135,19 @@ class TexturePacker
119
135
  end
120
136
  def generate_css
121
137
  inner_css = @hash.map do |prefix, obj|
122
- case
123
- when (prefix == nil || prefix == '')
138
+ case prefix
139
+ when nil, ''
124
140
  [obj.generate_css]
125
- when prefix[0] == ':'
141
+ when /\A:/
126
142
  ["&#{prefix}, &.#{prefix[1..-1]}{ ", obj.generate_css, " }"]
127
- when prefix == '[m]'
143
+ when '[m]'
128
144
  ["@include mobile{ ", obj.generate_css, " }"]
145
+ when '[tw]'
146
+ ["&:lang(zh-TW){ ", obj.generate_css, " }"]
147
+ when '[cn]'
148
+ ["&:lang(zh-CN){ ", obj.generate_css, " }"]
149
+ when '[en]'
150
+ ["&:lang(en){ ", obj.generate_css, " }"]
129
151
  else
130
152
  ["&#{prefix}{ ", obj.generate_css, " }"]
131
153
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texture_packer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.4.1
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - khiav reoy
8
8
  autorequire:
9
9
  bindir: executables
10
10
  cert_chain: []
11
- date: 2020-03-11 00:00:00.000000000 Z
11
+ date: 2020-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -113,8 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
113
113
  - !ruby/object:Gem::Version
114
114
  version: '0'
115
115
  requirements: []
116
- rubyforge_project:
117
- rubygems_version: 2.6.14
116
+ rubygems_version: 3.0.6
118
117
  signing_key:
119
118
  specification_version: 4
120
119
  summary: texture packer