texture_packer 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/LICENSE.txt +21 -0
- data/README.md +1 -0
- data/Rakefile +10 -0
- data/executables/pack_scss +144 -0
- data/lib/texture_packer/version.rb +3 -0
- data/texture_packer.gemspec +32 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 64f180197b5792e32077e24720bf9e1eabc71b95
|
4
|
+
data.tar.gz: 88e8d4ce8219d973af5c1a9cdfb36aed63f0db68
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7fc23109a106fe632604e973424c77cddf213cbbcfc3a87cff792b0c0fec2cb2c1969a19473372199279f01cb10a7c2114c555dae0513a19371032929dc1fdff
|
7
|
+
data.tar.gz: 0b488c4eb51ca48a4d01889236283f7d3eb731e300fba681ca046bedacf79efa87c9c956c414168e73ffab2bda36cc97f41b1448ccec85f2a58a03e8f71a3cb5
|
data/.gitignore
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at mrtmrt15xn@yahoo.com.tw. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 khiav reoy
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# texture_packer
|
data/Rakefile
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
require 'yaml'
|
3
|
+
require 'pathname'
|
4
|
+
require 'fileutils'
|
5
|
+
# ----------------------------------------------------------------
|
6
|
+
# ● 載入 yaml
|
7
|
+
# ----------------------------------------------------------------
|
8
|
+
def load_yaml(path)
|
9
|
+
begin
|
10
|
+
return YAML.load_file(Pathname.new(__dir__).join(path)) || {}
|
11
|
+
rescue Errno::ENOENT
|
12
|
+
return {}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
SETTING = load_yaml('setting.yml')
|
17
|
+
|
18
|
+
def exec_cmd(cmd)
|
19
|
+
puts cmd
|
20
|
+
puts `#{cmd}`
|
21
|
+
end
|
22
|
+
|
23
|
+
def write_to_file(path, content)
|
24
|
+
puts "output: #{path} #{File.write(path, content)} bytes"
|
25
|
+
end
|
26
|
+
|
27
|
+
exec_cmd('TexturePacker packer.tps')
|
28
|
+
|
29
|
+
def get_mixin(func, css)
|
30
|
+
return "@mixin #{func}{ #{css} }\n"
|
31
|
+
end
|
32
|
+
|
33
|
+
# ----------------------------------------------------------------
|
34
|
+
# ● 由路徑計算 class 名字
|
35
|
+
# ----------------------------------------------------------------
|
36
|
+
dir_name = File.expand_path(Dir.pwd).gsub(/.*\/Texture-Packer\/.*?\/(.*)/, '\1')
|
37
|
+
base_dir_name = File.basename(dir_name)
|
38
|
+
theme = base_dir_name[/[^_]+$/]
|
39
|
+
dir_without_theme = base_dir_name[0...-(theme.size + 1)]
|
40
|
+
|
41
|
+
content = File.read('packed.css')
|
42
|
+
|
43
|
+
Dir['images/**/'].map{|s| s[/images\/(.*)\//, 1] }.compact.map{|s| "#{s.gsub('/', '-')}-" }.each do |path| #"images/aaa/bbb/ccc.png" => "aaa-bbb-"
|
44
|
+
content.gsub!(path, path.gsub('-', '_')) #aaa-bbb => aaa_bbb
|
45
|
+
end
|
46
|
+
|
47
|
+
data = {}
|
48
|
+
content.gsub!(/-disabled \{/, ':disabled {') #-disabled => :disabled
|
49
|
+
content.gsub!(/-([\w]+)([^\w][\w]+|) \{/, '[\1]\2 {')
|
50
|
+
output0 = content
|
51
|
+
output0.sub!(/(\/\*(.|\n)*?\*\/)/, '') #去掉註解
|
52
|
+
output0 = $1 + "\n"
|
53
|
+
# puts content
|
54
|
+
def extract_rule!(content)
|
55
|
+
content.sub!(/^\.([a-zA-Z0-9_-]+)((?:\:\w+|\[\w+\])*) \{(.*?)\}/, '') #抓 rule
|
56
|
+
return [$1, $2, $3] #$1 = selector, $2 = prefix, $3 = css
|
57
|
+
end
|
58
|
+
def split_prefixs(selector)
|
59
|
+
selector.sub!(/^\.([a-zA-Z0-9_-]+)(:\w+|\[\w+\])?/, '') #抓 rule
|
60
|
+
end
|
61
|
+
loop do
|
62
|
+
selector, prefix, css = extract_rule!(content)
|
63
|
+
break if selector == nil
|
64
|
+
next if selector == "sprite"
|
65
|
+
prefixs = prefix.scan(/\[\w+\]|\:\w+/) #[m]:disabled => ['[m]', ':disabled']
|
66
|
+
prefixs.map! do |prefix|
|
67
|
+
case prefix
|
68
|
+
when '[active]' ; ':active' # 因為 TexturePacker 會把 xxx-active-hover 轉成 xxx-active:hover 而不是 xxx:active:hover
|
69
|
+
when '[hover]' ; ':hover'
|
70
|
+
else ; prefix
|
71
|
+
end
|
72
|
+
end
|
73
|
+
# p [selector, prefix, css]
|
74
|
+
(data[selector] ||= {})[prefixs] = "#{css};"
|
75
|
+
end
|
76
|
+
# data = {selector => {nil => 'xxx', ':disabeld' => 'xxx', '[m]' => 'xxx'}}
|
77
|
+
output1 = "" #mixin的output
|
78
|
+
output1 += get_mixin("#{base_dir_name}_sprite", "background-image: image-url('#{dir_name}.png')")
|
79
|
+
output2 = "" #scss的output
|
80
|
+
output2 += "body[theme='#{theme}']{\n"
|
81
|
+
output2 += " .#{dir_without_theme}_sprite{\n"
|
82
|
+
output2 += " @include #{base_dir_name}_sprite();\n"
|
83
|
+
class CssRule
|
84
|
+
def initialize
|
85
|
+
@hash = {}
|
86
|
+
end
|
87
|
+
def add(prefixs, css)
|
88
|
+
if prefixs.size > 0
|
89
|
+
(@hash[prefixs.first] ||= CssRule.new).add(prefixs[1..-1], css)
|
90
|
+
else
|
91
|
+
@css = css
|
92
|
+
end
|
93
|
+
end
|
94
|
+
def generate_css
|
95
|
+
inner_css = @hash.map do |prefix, obj|
|
96
|
+
case
|
97
|
+
when (prefix == nil || prefix == '')
|
98
|
+
[obj.generate_css]
|
99
|
+
when prefix[0] == ':'
|
100
|
+
["&#{prefix}, &.#{prefix[1..-1]}{ ", obj.generate_css, " }"]
|
101
|
+
when prefix == '[m]'
|
102
|
+
["@media(max-width: $mobile_width){ ", obj.generate_css, " }"]
|
103
|
+
else
|
104
|
+
["&#{prefix}{ ", obj.generate_css, " }"]
|
105
|
+
end
|
106
|
+
end
|
107
|
+
inner = inner_css.size == 0 ? '' : " #{inner_css.join('')}"
|
108
|
+
return "#{@css}#{inner}"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
for selector, css_data in data
|
112
|
+
func = "#{base_dir_name}_#{selector}"
|
113
|
+
rules = CssRule.new
|
114
|
+
css_data.each{|prefixs, css| #EX: prefixs == [':hover']
|
115
|
+
rules.add(prefixs, css)
|
116
|
+
}
|
117
|
+
output1 << get_mixin(func, rules.generate_css)
|
118
|
+
output2 << " &.#{selector}{ @include #{func}(); }\n"
|
119
|
+
end
|
120
|
+
output2 += " }\n"
|
121
|
+
output2 += "}\n"
|
122
|
+
output = output0 + output1 + output2
|
123
|
+
|
124
|
+
# ----------------------------------------------------------------
|
125
|
+
# ● 壓縮圖片
|
126
|
+
# ----------------------------------------------------------------
|
127
|
+
exec_cmd('pngquant packed.png --force')
|
128
|
+
write_to_file('packed.scss', output)
|
129
|
+
|
130
|
+
# ----------------------------------------------------------------
|
131
|
+
# ● 自動輸出到專案
|
132
|
+
# ----------------------------------------------------------------
|
133
|
+
if SETTING['project_dir']
|
134
|
+
sub_dirs = dir_name.split(File::Separator)[0...-1]
|
135
|
+
css_path = Pathname.new(SETTING['project_dir']).join('app', 'assets', 'stylesheets', 'packed_sprites', *sub_dirs, dir_without_theme)
|
136
|
+
img_path = Pathname.new(SETTING['project_dir']).join('app', 'assets', 'images', *sub_dirs)
|
137
|
+
FileUtils.mkdir_p(css_path)
|
138
|
+
FileUtils.mkdir_p(img_path)
|
139
|
+
write_to_file(css_path.join('mixin.scss'), output1)
|
140
|
+
write_to_file(css_path.join('ocean.scss'), "@import './mixin.scss';\n\n#{output2}")
|
141
|
+
FileUtils.cp('packed-fs8.png', img_path.join(base_dir_name + '.png'))
|
142
|
+
end
|
143
|
+
|
144
|
+
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'texture_packer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "texture_packer"
|
8
|
+
spec.version = TexturePacker::VERSION
|
9
|
+
spec.authors = ["khiav reoy"]
|
10
|
+
spec.email = ["mrtmrt15xn@yahoo.com.tw"]
|
11
|
+
|
12
|
+
spec.summary = %q{texture packer}
|
13
|
+
spec.description = %q{texture packer}
|
14
|
+
spec.homepage = "https://github.com/khiav223577/texture_packer"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
# Prevent pushing this gem to RubyGems.org by setting 'allowed_push_host', or
|
18
|
+
# delete this section to allow pushing this gem to any host.
|
19
|
+
#if spec.respond_to?(:metadata)
|
20
|
+
# spec.metadata['allowed_push_host'] = "TODO: Set to 'http://mygemserver.com'"
|
21
|
+
#else
|
22
|
+
# raise "RubyGems 2.0 or newer is required to protect against public gem pushes."
|
23
|
+
#end
|
24
|
+
|
25
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
26
|
+
spec.bindir = "executables"
|
27
|
+
spec.executables = ['pack_scss']
|
28
|
+
spec.require_paths = ["lib"]
|
29
|
+
|
30
|
+
spec.add_development_dependency "bundler", "~> 1.11"
|
31
|
+
spec.add_development_dependency "minitest", "~> 5.0"
|
32
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: texture_packer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- khiav reoy
|
8
|
+
autorequire:
|
9
|
+
bindir: executables
|
10
|
+
cert_chain: []
|
11
|
+
date: 2018-01-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: minitest
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '5.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '5.0'
|
41
|
+
description: texture packer
|
42
|
+
email:
|
43
|
+
- mrtmrt15xn@yahoo.com.tw
|
44
|
+
executables:
|
45
|
+
- pack_scss
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- CODE_OF_CONDUCT.md
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- executables/pack_scss
|
55
|
+
- lib/texture_packer/version.rb
|
56
|
+
- texture_packer.gemspec
|
57
|
+
homepage: https://github.com/khiav223577/texture_packer
|
58
|
+
licenses:
|
59
|
+
- MIT
|
60
|
+
metadata: {}
|
61
|
+
post_install_message:
|
62
|
+
rdoc_options: []
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '0'
|
70
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0'
|
75
|
+
requirements: []
|
76
|
+
rubyforge_project:
|
77
|
+
rubygems_version: 2.6.13
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: texture packer
|
81
|
+
test_files: []
|