texture_packer 1.1.2 → 1.2.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA256:
3
- metadata.gz: 182eddac5fdc4d392f7f281a18181dec92c274a6acb6a300bbcd83da4613dded
4
- data.tar.gz: cfbd0051b402a0d214fd7fc6276856ef8e02a1cd4c6f1b6e0f9b7dd033ff2e3b
2
+ SHA1:
3
+ metadata.gz: 8dc38cd32c0b72a13abfdf07a46d636efba1b851
4
+ data.tar.gz: 8dbb0c5b77dab3c9efaa3eb8c5c29ba73fb0b786
5
5
  SHA512:
6
- metadata.gz: 6dd1cee6ec2aba542872d3b0b3322e9347a1ffb9f6704a14aaff17f0dfefe5bdcd2c6fab983dec24a76c5a2191df68f0932d80ed539fea7abd9aec617bf91e1f
7
- data.tar.gz: dc87d8d596108a10b3968165de5e7707b186c67076264553b57db2d13da8bfd24890cbf3ddd12ca68ce4d3e8307e4940f4d4ed79a99e284be256fa1804ee3359
6
+ metadata.gz: '0049b77322f41e5de83714b099b59982de5fb75334df7d8015f47d144f95851e3ef407c4b15cb758677cd399375005d9b2a772af9477012d2f2bd36a5942c067'
7
+ data.tar.gz: fb284485f416de0e4a75719f4ba705a078695eab063f70e46e6c7f6103ed922464775417c71eafba40d0f609f6d4da676910f81b75c9520297fe89f440727746
@@ -34,6 +34,12 @@ def get_mixin(func, css)
34
34
  return "@mixin #{func}{ #{css} }\n"
35
35
  end
36
36
 
37
+ if File.exists?('packed_mobile.css') # 向下相容
38
+ exec_cmd('mv packed_mobile.css packed_m.css')
39
+ exec_cmd('mv packed_mobile.png packed_m.png')
40
+ end
41
+ $has_mobile = true if File.exists?('packed_m.css')
42
+
37
43
  # ----------------------------------------------------------------
38
44
  # ● 由路徑計算 class 名字
39
45
  # ----------------------------------------------------------------
@@ -42,11 +48,12 @@ base_dir_name = File.basename(dir_name)
42
48
  theme = base_dir_name[/[^_]+$/]
43
49
  dir_without_theme = base_dir_name[0...-(theme.size + 1)]
44
50
 
45
- content = File.read('packed.css')
46
- if File.exists?('packed_mobile.css')
47
- content += File.read('packed_mobile.css')
48
- $has_mobile = true
49
- end
51
+ output_paths_mapping = Dir['*.css'].map do |path|
52
+ name = File.basename(path, '.css')
53
+ next [name[/packed_(.*)/, 1], name]
54
+ end.to_h
55
+
56
+ content = output_paths_mapping.map{|_, path| File.read("#{path}.css") }.join
50
57
 
51
58
  Dir['images/**/'].map{|s| s[/images\/(.*)\//, 1] }.compact.map{|s| "#{s.gsub('/', '-')}-" }.each do |path| #"images/aaa/bbb/ccc.png" => "aaa-bbb-"
52
59
  content.gsub!(path, path.gsub('-', '_')) #aaa-bbb => aaa_bbb
@@ -83,18 +90,28 @@ loop do
83
90
  end
84
91
  # data = {selector => {nil => 'xxx', ':disabeld' => 'xxx', '[m]' => 'xxx'}}
85
92
  output1 = "" #mixin的output
86
- output1 += get_mixin("#{base_dir_name}_sprite", "background-image: image-url('#{dir_name}.png');")
87
- output1 += get_mixin("#{base_dir_name}_sprite_m", "background-image: image-url('#{dir_name}_m.png');") if $has_mobile
93
+ output_paths_mapping.map do |kind, name|
94
+ if kind == nil
95
+ output1 += get_mixin("#{base_dir_name}_sprite", "background-image: image-url('#{dir_name}.png');")
96
+ else
97
+ output1 += get_mixin("#{base_dir_name}_sprite_#{kind}", "background-image: image-url('#{dir_name}_#{kind}.png');")
98
+ end
99
+ end
88
100
  output2 = "" #scss的output
89
101
  output2 += "body[theme='#{theme}']{\n"
90
102
  output2 += " .#{dir_without_theme}_sprite{\n"
91
103
  if $has_mobile
92
- output2 += " @include desktop{ @include #{base_dir_name}_sprite(); }\n"
93
- output2 += " @include mobile{ @include #{base_dir_name}_sprite_m(); }\n"
104
+ output2 += " @include desktop{ @include #{base_dir_name}_sprite; }\n"
105
+ output2 += " @include mobile{ @include #{base_dir_name}_sprite_m; }\n"
106
+ elsif output_paths_mapping.size > 1
107
+ output2 += output_paths_mapping.map do |kind, name|
108
+ next " @include #{base_dir_name}_sprite;\n" if kind == nil
109
+ next " &[kind=\"#{kind}\"] { @include #{base_dir_name}_sprite_#{kind}; }\n"
110
+ end.join
94
111
  else
95
- output2 += " @include #{base_dir_name}_sprite();\n"
112
+ output2 += " @include #{base_dir_name}_sprite;\n"
96
113
  end
97
- # output2 += " &.split_mobile{ @include mobile{ @include #{base_dir_name}_sprite_m(); }}\n" if $has_mobile
114
+ # output2 += " &.split_mobile{ @include mobile{ @include #{base_dir_name}_sprite_m; }}\n" if $has_mobile
98
115
  class CssRule
99
116
  def initialize
100
117
  @hash = {}
@@ -130,7 +147,7 @@ for selector, css_data in data
130
147
  rules.add(prefixs, css)
131
148
  }
132
149
  output1 << get_mixin(func, rules.generate_css)
133
- output2 << " &.#{selector}{ @include #{func}(); }\n"
150
+ output2 << " &.#{selector} { @include #{func}; }\n"
134
151
  end
135
152
  output2 += " }\n"
136
153
  output2 += "}\n"
@@ -139,23 +156,30 @@ output = output0 + output1 + output2
139
156
  # ----------------------------------------------------------------
140
157
  # ● 壓縮圖片
141
158
  # ----------------------------------------------------------------
142
- exec_cmd('pngquant packed.png --force')
143
- exec_cmd('pngquant packed_mobile.png --force') if $has_mobile
159
+ output_paths_mapping.each do |_, path|
160
+ exec_cmd("pngquant #{path}.png --force")
161
+ end
162
+
144
163
  write_to_file('packed.scss', output)
145
164
 
146
165
  # ----------------------------------------------------------------
147
166
  # ● 自動輸出到專案
148
167
  # ----------------------------------------------------------------
149
168
  if SETTING['project_dir']
169
+ css_pre_lines = ["@import './mixin.scss';"]
170
+ css_pre_lines.unshift("@import 'global_mixins';") if $has_mobile
171
+
150
172
  sub_dirs = dir_name.split(File::Separator)[0...-1]
151
173
  css_path = Pathname.new(SETTING['project_dir']).join('app', 'assets', 'stylesheets', 'packed_sprites', *sub_dirs, dir_without_theme)
152
174
  img_path = Pathname.new(SETTING['project_dir']).join('app', 'assets', 'images', *sub_dirs)
153
175
  FileUtils.mkdir_p(css_path)
154
176
  FileUtils.mkdir_p(img_path)
155
177
  write_to_file(css_path.join('mixin.scss'), output1)
156
- write_to_file(css_path.join('ocean.scss'), "@import './mixin.scss';\n\n#{output2}")
157
- FileUtils.cp('packed-fs8.png', img_path.join(base_dir_name + '.png'))
158
- FileUtils.cp('packed_mobile-fs8.png', img_path.join(base_dir_name + '_m.png')) if $has_mobile
178
+ write_to_file(css_path.join('ocean.scss'), "#{css_pre_lines.join("\n")}\n\n#{output2}")
179
+ output_paths_mapping.each do |_, path|
180
+ FileUtils.cp("#{path}-fs8.png", img_path.join("#{path.sub('packed', base_dir_name)}.png"))
181
+ exec_cmd("pngquant #{path}.png --force")
182
+ end
159
183
  end
160
184
 
161
185
 
@@ -1,3 +1,3 @@
1
1
  module TexturePacker
2
- VERSION = "1.1.2"
2
+ VERSION = "1.2.0"
3
3
  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.1.2
4
+ version: 1.2.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: 2018-07-18 00:00:00.000000000 Z
11
+ date: 2019-08-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -74,7 +74,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
74
  version: '0'
75
75
  requirements: []
76
76
  rubyforge_project:
77
- rubygems_version: 2.7.6
77
+ rubygems_version: 2.6.14
78
78
  signing_key:
79
79
  specification_version: 4
80
80
  summary: texture packer