texture_packer 1.5.0 → 1.7.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1174 -0
- data/CHANGELOG.md +20 -0
- data/README.md +10 -0
- data/Rakefile +6 -5
- data/lib/texture_packer.rb +45 -27
- data/lib/texture_packer/cli.rb +15 -15
- data/lib/texture_packer/cli/options.rb +2 -2
- data/lib/texture_packer/version.rb +1 -1
- data/texture_packer.gemspec +13 -13
- metadata +4 -3
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,25 @@
|
|
1
1
|
## Change Log
|
2
2
|
|
3
|
+
### [v1.7.0](https://github.com/khiav223577/texture_packer/compare/v1.6.3...v1.7.0) 2020/04/17
|
4
|
+
- [#20](https://github.com/khiav223577/texture_packer/pull/20) Make sure some selector ordered as specified (@khiav223577)
|
5
|
+
|
6
|
+
### [v1.6.3](https://github.com/khiav223577/texture_packer/compare/v1.6.2...v1.6.3) 2020/04/17
|
7
|
+
- [#19](https://github.com/khiav223577/texture_packer/pull/19) Fix: It will generate wrong scss where there is an image named `xxx-disabled-m` (@khiav223577)
|
8
|
+
|
9
|
+
### [v1.6.2](https://github.com/khiav223577/texture_packer/compare/v1.6.1...v1.6.2) 2020/04/14
|
10
|
+
- [#18](https://github.com/khiav223577/texture_packer/pull/18) Fix: it needs global mixins when split type is by i18n + mobile (@khiav223577)
|
11
|
+
|
12
|
+
### [v1.6.1](https://github.com/khiav223577/texture_packer/compare/v1.6.0...v1.6.1) 2020/04/13
|
13
|
+
- [#17](https://github.com/khiav223577/texture_packer/pull/17) auto correct coding style by rubocop (@khiav223577)
|
14
|
+
|
15
|
+
### [v1.6.0](https://github.com/khiav223577/texture_packer/compare/v1.5.0...v1.6.0) 2020/04/13
|
16
|
+
- [#16](https://github.com/khiav223577/texture_packer/pull/16) Support split images by i18n + mobile. (@khiav223577)
|
17
|
+
- [#15](https://github.com/khiav223577/texture_packer/pull/15) Fix: the return value of Dir#[] method is different in different environments. (@khiav223577)
|
18
|
+
|
19
|
+
### [v1.5.0](https://github.com/khiav223577/texture_packer/compare/v1.4.1...v1.5.0) 2020/04/08
|
20
|
+
- [#13](https://github.com/khiav223577/texture_packer/pull/13) Update version.rb (@Fatmylin)
|
21
|
+
- [#12](https://github.com/khiav223577/texture_packer/pull/12) Support using `-en`, `-tw`, `-cn` to set i18n. And support split pngs by i18n. (@khiav223577)
|
22
|
+
|
3
23
|
### [v1.4.0](https://github.com/khiav223577/texture_packer/compare/v1.3.0...v1.4.0) 2020/03/11
|
4
24
|
- [#11](https://github.com/khiav223577/texture_packer/pull/11) Add options to export packed scss files and images to your project (@khiav223577)
|
5
25
|
- [#10](https://github.com/khiav223577/texture_packer/pull/10) Remove backward compatibility of name as `packed_mobile` (@khiav223577)
|
data/README.md
CHANGED
@@ -5,3 +5,13 @@
|
|
5
5
|
[![RubyGems](http://img.shields.io/gem/dt/texture_packer.svg?style=flat)](https://rubygems.org/gems/texture_packer)
|
6
6
|
[![Code Climate](https://codeclimate.com/github/khiav223577/texture_packer/badges/gpa.svg)](https://codeclimate.com/github/khiav223577/texture_packer)
|
7
7
|
[![Test Coverage](https://codeclimate.com/github/khiav223577/texture_packer/badges/coverage.svg)](https://codeclimate.com/github/khiav223577/texture_packer/coverage)
|
8
|
+
|
9
|
+
|
10
|
+
### Usage:
|
11
|
+
|
12
|
+
```
|
13
|
+
pack_scss [options]
|
14
|
+
-v, --version show the version number
|
15
|
+
-h, --help Prints this help
|
16
|
+
-p, --project_dir=PATH Copy the generated scss files / images to specified project
|
17
|
+
```
|
data/Rakefile
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require 'bundler/gem_tasks'
|
2
|
+
require 'rake/testtask'
|
3
3
|
|
4
4
|
Rake::TestTask.new(:test) do |t|
|
5
|
-
t.libs <<
|
6
|
-
t.libs <<
|
5
|
+
t.libs << 'test'
|
6
|
+
t.libs << 'lib'
|
7
7
|
t.test_files = FileList['test/**/*_test.rb']
|
8
|
+
t.ruby_opts += ['-W1']
|
8
9
|
end
|
9
10
|
|
10
|
-
task :
|
11
|
+
task default: :test
|
data/lib/texture_packer.rb
CHANGED
@@ -8,8 +8,10 @@ class TexturePacker
|
|
8
8
|
attr_reader :dir_without_theme
|
9
9
|
attr_reader :output_paths_mapping
|
10
10
|
|
11
|
-
SPLIT_BY_MOBILE
|
12
|
-
SPLIT_BY_I18N
|
11
|
+
SPLIT_BY_MOBILE = 'mobile'
|
12
|
+
SPLIT_BY_I18N = 'i18n'
|
13
|
+
SPLIT_BY_I18N_AND_MOBILE = 'i18n_and_mobile'
|
14
|
+
SELECTOR_ORDER = %w[:hover :active :disabled].freeze
|
13
15
|
|
14
16
|
def initialize(dir_name, output_paths_mapping, content, split_type = nil)
|
15
17
|
@output_paths_mapping = output_paths_mapping
|
@@ -23,45 +25,58 @@ class TexturePacker
|
|
23
25
|
end
|
24
26
|
|
25
27
|
def parse!
|
26
|
-
Dir['images/**/'].map{|s| s[/
|
27
|
-
@content.gsub!(path, path.
|
28
|
+
Dir['images/**/'].map{|s| s[%r{images/(.*)/}, 1] }.compact.map{|s| "#{s.tr('/', '-')}-" }.each do |path| # "images/aaa/bbb/ccc.png" => "aaa-bbb-"
|
29
|
+
@content.gsub!(path, path.tr('-', '_')) # aaa-bbb => aaa_bbb
|
28
30
|
end
|
29
31
|
|
30
32
|
data = {}
|
31
33
|
@content.gsub!(/-disabled \{/, ':disabled {') #-disabled => :disabled
|
32
34
|
loop{ break if @content.gsub!(/-([\w]+)((?:[^\w][\w]+)*) \{/, '[\1]\2 {') == nil }
|
33
35
|
output0 = @content
|
34
|
-
output0.sub!(
|
36
|
+
output0.sub!(%r{(/\*(.|\n)*?\*/)}, '') # 去掉註解
|
35
37
|
output0 = $1 + "\n"
|
36
38
|
|
37
39
|
loop do
|
38
|
-
selector,
|
40
|
+
selector, string_prefix, css = extract_rule!
|
39
41
|
break if selector == nil
|
40
|
-
next if selector ==
|
41
|
-
prefixs =
|
42
|
+
next if selector == 'sprite'
|
43
|
+
prefixs = string_prefix.scan(/\[\w+\]|\:\w+/) # [m]:disabled => ['[m]', ':disabled']
|
42
44
|
prefixs.map! do |prefix|
|
43
45
|
case prefix
|
44
|
-
when '[active]'
|
45
|
-
when '[hover]'
|
46
|
-
|
46
|
+
when '[active]' then ':active' # 因為 TexturePacker 會把 xxx-active-hover 轉成 xxx-active:hover 而不是 xxx:active:hover
|
47
|
+
when '[hover]' then ':hover'
|
48
|
+
when '[disabled]' then ':disabled'
|
49
|
+
else prefix
|
47
50
|
end
|
48
51
|
end
|
49
52
|
# p [selector, prefix, css]
|
50
53
|
(data[selector] ||= {})[prefixs] = "#{css};"
|
51
54
|
end
|
52
55
|
# data = {selector => {nil => 'xxx', ':disabeld' => 'xxx', '[m]' => 'xxx'}}
|
53
|
-
output1 =
|
54
|
-
@output_paths_mapping.map do |kind,
|
56
|
+
output1 = '' # mixin的output
|
57
|
+
@output_paths_mapping.map do |kind, _name|
|
55
58
|
if kind == nil
|
56
59
|
output1 += get_mixin("#{base_dir_name}_sprite", "background-image: image-url('#{@dir_name}.png');")
|
57
60
|
else
|
58
61
|
output1 += get_mixin("#{base_dir_name}_sprite_#{kind}", "background-image: image-url('#{@dir_name}_#{kind}.png');")
|
59
62
|
end
|
60
63
|
end
|
61
|
-
output2 =
|
64
|
+
output2 = '' # scss的output
|
62
65
|
output2 += "body[theme='#{@theme}']{\n"
|
63
66
|
output2 += " .#{@dir_without_theme}_sprite{\n"
|
64
67
|
case @split_type
|
68
|
+
when SPLIT_BY_I18N_AND_MOBILE
|
69
|
+
output2 += " @include desktop{\n"
|
70
|
+
output2 += " &:lang(zh-TW){ @include #{base_dir_name}_sprite_tw; }\n"
|
71
|
+
output2 += " &:lang(zh-CN){ @include #{base_dir_name}_sprite_cn; }\n"
|
72
|
+
output2 += " &:lang(en){ @include #{base_dir_name}_sprite_en; }\n"
|
73
|
+
output2 += " }\n"
|
74
|
+
|
75
|
+
output2 += " @include mobile{\n"
|
76
|
+
output2 += " &:lang(zh-TW){ @include #{base_dir_name}_sprite_tw_m; }\n"
|
77
|
+
output2 += " &:lang(zh-CN){ @include #{base_dir_name}_sprite_cn_m; }\n"
|
78
|
+
output2 += " &:lang(en){ @include #{base_dir_name}_sprite_en_m; }\n"
|
79
|
+
output2 += " }\n"
|
65
80
|
when SPLIT_BY_MOBILE
|
66
81
|
output2 += " @include desktop{ @include #{base_dir_name}_sprite; }\n"
|
67
82
|
output2 += " @include mobile{ @include #{base_dir_name}_sprite_m; }\n"
|
@@ -71,7 +86,7 @@ class TexturePacker
|
|
71
86
|
output2 += " &:lang(en){ @include #{base_dir_name}_sprite_en; }\n"
|
72
87
|
else
|
73
88
|
if @output_paths_mapping.size > 1
|
74
|
-
output2 += @output_paths_mapping.map do |kind,
|
89
|
+
output2 += @output_paths_mapping.map do |kind, _name|
|
75
90
|
next " @include #{base_dir_name}_sprite;\n" if kind == nil
|
76
91
|
next " &[kind=\"#{kind}\"] { @include #{base_dir_name}_sprite_#{kind}; }\n"
|
77
92
|
end.join
|
@@ -80,12 +95,12 @@ class TexturePacker
|
|
80
95
|
end
|
81
96
|
end
|
82
97
|
# output2 += " &.split_mobile{ @include mobile{ @include #{base_dir_name}_sprite_m; }}\n" if @split_type == SPLIT_BY_MOBILE
|
83
|
-
|
98
|
+
data.each do |selector, css_data|
|
84
99
|
func = "#{base_dir_name}_#{selector}"
|
85
100
|
rules = CssRule.new
|
86
|
-
css_data.each
|
101
|
+
css_data.each do |prefixs, css| # EX: prefixs == [':hover']
|
87
102
|
rules.add(prefixs, css)
|
88
|
-
|
103
|
+
end
|
89
104
|
output1 << get_mixin(func, rules.generate_css)
|
90
105
|
output2 << " &.#{parse_language_selector!(selector)} { @include #{func}; }\n"
|
91
106
|
end
|
@@ -95,8 +110,8 @@ class TexturePacker
|
|
95
110
|
end
|
96
111
|
|
97
112
|
def extract_rule!
|
98
|
-
@content.sub!(/^\.([a-zA-Z0-9_-]+)((?:\:\w+|\[\w+\])*) \{(.*?)\}/, '')
|
99
|
-
return [$1, $2, $3]
|
113
|
+
@content.sub!(/^\.([a-zA-Z0-9_-]+)((?:\:\w+|\[\w+\])*) \{(.*?)\}/, '') # 抓 rule
|
114
|
+
return [$1, $2, $3] # $1 = selector, $2 = prefix, $3 = css
|
100
115
|
end
|
101
116
|
|
102
117
|
def get_mixin(func, css)
|
@@ -119,6 +134,7 @@ class TexturePacker
|
|
119
134
|
|
120
135
|
def need_global_mixins?
|
121
136
|
return true if @split_type == SPLIT_BY_MOBILE
|
137
|
+
return true if @split_type == SPLIT_BY_I18N_AND_MOBILE
|
122
138
|
return false
|
123
139
|
end
|
124
140
|
|
@@ -126,6 +142,7 @@ class TexturePacker
|
|
126
142
|
def initialize
|
127
143
|
@hash = {}
|
128
144
|
end
|
145
|
+
|
129
146
|
def add(prefixs, css)
|
130
147
|
if prefixs.size > 0
|
131
148
|
(@hash[prefixs.first] ||= CssRule.new).add(prefixs[1..-1], css)
|
@@ -133,23 +150,24 @@ class TexturePacker
|
|
133
150
|
@css = css
|
134
151
|
end
|
135
152
|
end
|
153
|
+
|
136
154
|
def generate_css
|
137
|
-
inner_css = @hash.map do |prefix, obj|
|
155
|
+
inner_css = @hash.sort_by{|prefix, obj| SELECTOR_ORDER.index(prefix) || SELECTOR_ORDER.size }.map do |prefix, obj|
|
138
156
|
case prefix
|
139
157
|
when nil, ''
|
140
158
|
[obj.generate_css]
|
141
159
|
when /\A:/
|
142
|
-
["&#{prefix}, &.#{prefix[1..-1]}{ ", obj.generate_css,
|
160
|
+
["&#{prefix}, &.#{prefix[1..-1]}{ ", obj.generate_css, ' }']
|
143
161
|
when '[m]'
|
144
|
-
[
|
162
|
+
['@include mobile{ ', obj.generate_css, ' }']
|
145
163
|
when '[tw]'
|
146
|
-
[
|
164
|
+
['&:lang(zh-TW){ ', obj.generate_css, ' }']
|
147
165
|
when '[cn]'
|
148
|
-
[
|
166
|
+
['&:lang(zh-CN){ ', obj.generate_css, ' }']
|
149
167
|
when '[en]'
|
150
|
-
[
|
168
|
+
['&:lang(en){ ', obj.generate_css, ' }']
|
151
169
|
else
|
152
|
-
["&#{prefix}{ ", obj.generate_css,
|
170
|
+
["&#{prefix}{ ", obj.generate_css, ' }']
|
153
171
|
end
|
154
172
|
end
|
155
173
|
inner = inner_css.size == 0 ? '' : " #{inner_css.join('')}"
|
data/lib/texture_packer/cli.rb
CHANGED
@@ -37,23 +37,25 @@ class TexturePacker::Cli
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
40
|
+
def calculate_split_type
|
41
|
+
case
|
42
|
+
when File.exist?('packed_tw_m.css') ; return TexturePacker::SPLIT_BY_I18N_AND_MOBILE
|
43
|
+
when File.exist?('packed_m.css') ; return TexturePacker::SPLIT_BY_MOBILE
|
44
|
+
when File.exist?('packed_tw.css') ; return TexturePacker::SPLIT_BY_I18N
|
45
|
+
end
|
46
|
+
end
|
46
47
|
|
48
|
+
def create_packer
|
47
49
|
# 由路徑計算 class 名字
|
48
|
-
dir_name = File.expand_path(Dir.pwd).gsub(
|
50
|
+
dir_name = File.expand_path(Dir.pwd).gsub(%r{.*/Texture-Packer/.*?/(.*)}, '\1')
|
49
51
|
|
50
52
|
content = output_paths_mapping.map{|_, path| File.read("#{path}.css") }.join
|
51
|
-
return TexturePacker.new(dir_name, output_paths_mapping, content,
|
53
|
+
return TexturePacker.new(dir_name, output_paths_mapping, content, calculate_split_type)
|
52
54
|
end
|
53
55
|
|
54
56
|
def output_paths_mapping
|
55
57
|
@output_paths_mapping ||= begin
|
56
|
-
Dir['*.css'].map do |path|
|
58
|
+
Dir['*.css'].sort.map do |path|
|
57
59
|
name = File.basename(path, '.css')
|
58
60
|
next [name[/packed_(.*)/, 1], name]
|
59
61
|
end.to_h
|
@@ -82,12 +84,10 @@ class TexturePacker::Cli
|
|
82
84
|
end
|
83
85
|
|
84
86
|
def exec_cmd(*args)
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
puts e
|
90
|
-
end
|
87
|
+
puts args.join(' ')
|
88
|
+
puts system(*args)
|
89
|
+
rescue => e
|
90
|
+
puts e
|
91
91
|
end
|
92
92
|
|
93
93
|
def write_to_file(path, content)
|
@@ -12,11 +12,11 @@ class TexturePacker::Cli::Options
|
|
12
12
|
@hook_run = ->{ puts(TexturePacker::VERSION) }
|
13
13
|
end
|
14
14
|
|
15
|
-
opts.on(
|
15
|
+
opts.on('-h', '--help', 'Prints this help') do
|
16
16
|
@hook_run = ->{ puts(opts) }
|
17
17
|
end
|
18
18
|
|
19
|
-
opts.on(
|
19
|
+
opts.on('-pPATH', '--project_dir=PATH', 'Copy the generated scss files / images to specified project') do |val|
|
20
20
|
@project_dir = val
|
21
21
|
end
|
22
22
|
end.parse!(argv)
|
data/texture_packer.gemspec
CHANGED
@@ -4,28 +4,28 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'texture_packer/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
-
spec.name =
|
7
|
+
spec.name = 'texture_packer'
|
8
8
|
spec.version = TexturePacker::VERSION
|
9
|
-
spec.authors = [
|
10
|
-
spec.email = [
|
9
|
+
spec.authors = ['khiav reoy']
|
10
|
+
spec.email = ['mrtmrt15xn@yahoo.com.tw']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
-
spec.homepage =
|
15
|
-
spec.license =
|
12
|
+
spec.summary = 'texture packer'
|
13
|
+
spec.description = 'texture packer'
|
14
|
+
spec.homepage = 'https://github.com/khiav223577/texture_packer'
|
15
|
+
spec.license = 'MIT'
|
16
16
|
|
17
17
|
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
18
|
# delete this section to allow pushing this gem to any host.
|
19
|
-
#if spec.respond_to?(:metadata)
|
19
|
+
# if spec.respond_to?(:metadata)
|
20
20
|
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
-
#else
|
21
|
+
# else
|
22
22
|
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
-
#end
|
23
|
+
# end
|
24
24
|
|
25
|
-
spec.files = `git ls-files -z`.split("\x0").reject
|
26
|
-
spec.bindir =
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject{|f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = 'executables'
|
27
27
|
spec.executables = ['pack_scss']
|
28
|
-
spec.require_paths = [
|
28
|
+
spec.require_paths = ['lib']
|
29
29
|
|
30
30
|
spec.add_development_dependency 'bundler', '>= 1.17', '< 3.x'
|
31
31
|
spec.add_development_dependency 'rake', '~> 12.0'
|
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
|
+
version: 1.7.1
|
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-
|
11
|
+
date: 2020-05-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -81,6 +81,7 @@ extensions: []
|
|
81
81
|
extra_rdoc_files: []
|
82
82
|
files:
|
83
83
|
- ".gitignore"
|
84
|
+
- ".rubocop.yml"
|
84
85
|
- ".travis.yml"
|
85
86
|
- CHANGELOG.md
|
86
87
|
- CODE_OF_CONDUCT.md
|
@@ -113,7 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
114
|
- !ruby/object:Gem::Version
|
114
115
|
version: '0'
|
115
116
|
requirements: []
|
116
|
-
rubygems_version: 3.0.
|
117
|
+
rubygems_version: 3.0.3
|
117
118
|
signing_key:
|
118
119
|
specification_version: 4
|
119
120
|
summary: texture packer
|