rails-sprite 0.0.6 → 0.0.7
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 +4 -4
- data/lib/rails_sprite/sprite_util.rb +6 -5
- data/lib/rails_sprite/stylesheet_generator.rb +32 -8
- data/lib/rails_sprite/version.rb +1 -1
- data/test/dummy/log/test.log +102 -0
- data/test/fixtures/testing/app/assets/stylesheets/rails_xxx/sprite/icons/32x32.css.scss.erb +11 -3
- data/test/rails_sprite_test.rb +2 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 825c1e7a5a56ce0cae657a9e9661392dac08d61e
|
4
|
+
data.tar.gz: 628287d731a7cf7a2b42938239f7e79f4e524bed
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ce713cb639aaab16c70bc6c401833e850ffe344d17ab5848eba6465a696d586ecb10d5b71effad9e25ec01423e1bf8838e09c3839c075bc99eeb7e516bb3b9c
|
7
|
+
data.tar.gz: bc0938793c37a42b0293124853f8c9006450088547aa0e14e02003201125e6fdcad78822b6d1db8af7b9583c34b9b4d6436c6f0a082ff0930647538af34fd494
|
@@ -6,7 +6,7 @@ module RailsSprite
|
|
6
6
|
:spacing, :image_to_folder, :image_source_folder,
|
7
7
|
:stylesheet_to, :image_to_file_path, :css_class_prefix, :css_class_shared,
|
8
8
|
:image_scope_name, :stylesheet_scope_name,
|
9
|
-
:css_extend, :file_extend_name
|
9
|
+
:css_extend, :file_extend_name, :zoom
|
10
10
|
|
11
11
|
#
|
12
12
|
# :css_extend => "",
|
@@ -51,6 +51,8 @@ module RailsSprite
|
|
51
51
|
|
52
52
|
@css_class_shared = options.fetch(:css_class_shared, "rs-#{@scope_str}")
|
53
53
|
@css_class_prefix = options.fetch(:css_class_prefix, "rs-#{@scope_str}-#{@recipe_str}-")
|
54
|
+
|
55
|
+
@zoom = options.fetch(:zoom, 1).to_i
|
54
56
|
end
|
55
57
|
|
56
58
|
def perform
|
@@ -71,9 +73,7 @@ module RailsSprite
|
|
71
73
|
if file_name != '.' && file_name != '..' && file_name.end_with?(file_extend)
|
72
74
|
file_path = "#{image_source_folder}/#{file_name}"
|
73
75
|
|
74
|
-
if ::File.file?(
|
75
|
-
# puts "#{file_path}"
|
76
|
-
|
76
|
+
if ::File.file?(file_path)
|
77
77
|
file_name_split = file_name.split('.')
|
78
78
|
file_name_split.pop
|
79
79
|
file_purename = file_name_split.join('.')
|
@@ -90,7 +90,7 @@ module RailsSprite
|
|
90
90
|
file_info[:x] = x
|
91
91
|
file_info[:y] = y
|
92
92
|
|
93
|
-
y += (
|
93
|
+
y += (spacing + file_info[:height])
|
94
94
|
|
95
95
|
max_w = [max_w, file_info[:width]].max
|
96
96
|
max_h = y
|
@@ -118,6 +118,7 @@ module RailsSprite
|
|
118
118
|
|
119
119
|
def _composite_css file_infos
|
120
120
|
stylesheet_generator.generate(
|
121
|
+
:zoom => zoom,
|
121
122
|
:css_class_shared => css_class_shared,
|
122
123
|
:css_class_prefix => css_class_prefix,
|
123
124
|
:file_infos => file_infos,
|
@@ -2,6 +2,7 @@ module RailsSprite
|
|
2
2
|
class StylesheetGenerator
|
3
3
|
|
4
4
|
def self.generate options={}
|
5
|
+
zoom = options.fetch(:zoom, 1).to_i
|
5
6
|
css_class_prefix = options[:css_class_prefix]
|
6
7
|
css_class_shared = options[:css_class_shared]
|
7
8
|
css_extend = options[:css_extend]
|
@@ -10,26 +11,34 @@ module RailsSprite
|
|
10
11
|
stylesheet_to = options[:stylesheet_to]
|
11
12
|
|
12
13
|
result = {}
|
13
|
-
|
14
14
|
styles = []
|
15
15
|
|
16
16
|
file_infos.each do |file_info|
|
17
17
|
style = {}
|
18
18
|
|
19
|
-
style[:width] = "#{file_info[:width]}px"
|
20
|
-
style[:height] = "#{file_info[:height]}px"
|
21
|
-
style[:x] = "#{file_info[:x]}px"
|
22
|
-
style[:y] = "#{file_info[:y]}px"
|
19
|
+
style[:width] = "#{file_info[:width] / zoom}px"
|
20
|
+
style[:height] = "#{file_info[:height] / zoom}px"
|
21
|
+
style[:x] = "#{file_info[:x] / zoom}px"
|
22
|
+
style[:y] = "#{file_info[:y] / zoom}px"
|
23
23
|
style[:class] = "#{css_class_prefix}#{file_info[:file_purename]}"
|
24
24
|
|
25
25
|
styles << style
|
26
26
|
end
|
27
27
|
|
28
|
-
|
29
28
|
result[:styles] = styles
|
30
29
|
result[:image_scope_name] = image_scope_name
|
31
30
|
result[:css_class_shared] = css_class_shared
|
32
31
|
|
32
|
+
## 高度取总和
|
33
|
+
result[:background_y] = file_infos.map do |file_info|
|
34
|
+
file_info[:height]
|
35
|
+
end.sum / zoom
|
36
|
+
|
37
|
+
## 宽度取最大值
|
38
|
+
result[:background_x] = file_infos.map do |file_info|
|
39
|
+
file_info[:width]
|
40
|
+
end.max / zoom
|
41
|
+
|
33
42
|
css_filt_content = case css_extend
|
34
43
|
when '.css.scss.erb', '.scss.erb'
|
35
44
|
composite_css_scss_erb(result)
|
@@ -53,17 +62,28 @@ module RailsSprite
|
|
53
62
|
styles << <<-END_CSS
|
54
63
|
// 将下面3行,放入页面中(仅供参考)
|
55
64
|
// .#{result[:css_class_shared]} {
|
56
|
-
// background: url(<%=
|
65
|
+
// background-image: url(<%= image_path("#{result[:image_scope_name]}") %>);
|
57
66
|
// }
|
67
|
+
END_CSS
|
68
|
+
|
69
|
+
styles << <<-END_CSS
|
70
|
+
.#{result[:css_class_shared]} {
|
71
|
+
background-repeat: no-repeat;
|
72
|
+
background-size: #{result[:background_x]}px #{result[:background_y]}px;
|
73
|
+
}
|
58
74
|
END_CSS
|
59
75
|
|
60
76
|
result[:styles].each do |style|
|
61
77
|
styles << <<-END_CSS
|
62
78
|
.#{style[:class]} {
|
63
79
|
background-position: #{style[:x]} -#{style[:y]};
|
80
|
+
height: #{style[:height]};
|
81
|
+
width: #{style[:width]};
|
64
82
|
}
|
65
83
|
END_CSS
|
66
84
|
end
|
85
|
+
|
86
|
+
styles.join("\n")
|
67
87
|
end
|
68
88
|
|
69
89
|
def self.composite_css_scss_erb result
|
@@ -71,7 +91,9 @@ END_CSS
|
|
71
91
|
|
72
92
|
styles << <<-END_CSS
|
73
93
|
.#{result[:css_class_shared]} {
|
74
|
-
background: url(<%= image_path("#{result[:image_scope_name]}") %>)
|
94
|
+
background-image: url(<%= image_path("#{result[:image_scope_name]}") %>);
|
95
|
+
background-repeat: no-repeat;
|
96
|
+
background-size: #{result[:background_x]}px #{result[:background_y]}px;
|
75
97
|
}
|
76
98
|
END_CSS
|
77
99
|
|
@@ -79,6 +101,8 @@ END_CSS
|
|
79
101
|
styles << <<-END_CSS
|
80
102
|
.#{style[:class]} {
|
81
103
|
background-position: #{style[:x]} -#{style[:y]};
|
104
|
+
height: #{style[:height]};
|
105
|
+
width: #{style[:width]};
|
82
106
|
}
|
83
107
|
END_CSS
|
84
108
|
|
data/lib/rails_sprite/version.rb
CHANGED
data/test/dummy/log/test.log
CHANGED
@@ -65,3 +65,105 @@ RailsSpriteTest: test_truth
|
|
65
65
|
RailsSpriteTest: test_perform
|
66
66
|
-----------------------------
|
67
67
|
[1m[35m (0.2ms)[0m rollback transaction
|
68
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
69
|
+
[1m[36m (1.0ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
70
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
71
|
+
[1m[36m (1.0ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
72
|
+
[1m[35m (0.2ms)[0m SELECT version FROM "schema_migrations"
|
73
|
+
[1m[36m (0.8ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
74
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
75
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
76
|
+
-----------------------------
|
77
|
+
RailsSpriteTest: test_perform
|
78
|
+
-----------------------------
|
79
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
80
|
+
[1m[36m (0.0ms)[0m [1mbegin transaction[0m
|
81
|
+
---------------------------
|
82
|
+
RailsSpriteTest: test_truth
|
83
|
+
---------------------------
|
84
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
85
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.3ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
86
|
+
[1m[36m (0.9ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
87
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
88
|
+
[1m[36m (0.7ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
89
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
90
|
+
[1m[36m (0.6ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
91
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
92
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
93
|
+
-----------------------------
|
94
|
+
RailsSpriteTest: test_perform
|
95
|
+
-----------------------------
|
96
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
97
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
98
|
+
---------------------------
|
99
|
+
RailsSpriteTest: test_truth
|
100
|
+
---------------------------
|
101
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
102
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.4ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
103
|
+
[1m[36m (0.8ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
104
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
105
|
+
[1m[36m (0.7ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
106
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
107
|
+
[1m[36m (0.6ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
108
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
109
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
110
|
+
-----------------------------
|
111
|
+
RailsSpriteTest: test_perform
|
112
|
+
-----------------------------
|
113
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
114
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
115
|
+
---------------------------
|
116
|
+
RailsSpriteTest: test_truth
|
117
|
+
---------------------------
|
118
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
119
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
120
|
+
[1m[36m (1.4ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
121
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
122
|
+
[1m[36m (0.7ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
123
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
124
|
+
[1m[36m (0.6ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
125
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
126
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
127
|
+
-----------------------------
|
128
|
+
RailsSpriteTest: test_perform
|
129
|
+
-----------------------------
|
130
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
131
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
132
|
+
---------------------------
|
133
|
+
RailsSpriteTest: test_truth
|
134
|
+
---------------------------
|
135
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
136
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.1ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
137
|
+
[1m[36m (3.3ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
138
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
139
|
+
[1m[36m (1.6ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
140
|
+
[1m[35m (0.2ms)[0m SELECT version FROM "schema_migrations"
|
141
|
+
[1m[36m (1.1ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
142
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.2ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
143
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
144
|
+
-----------------------------
|
145
|
+
RailsSpriteTest: test_perform
|
146
|
+
-----------------------------
|
147
|
+
[1m[35m (0.1ms)[0m rollback transaction
|
148
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
149
|
+
---------------------------
|
150
|
+
RailsSpriteTest: test_truth
|
151
|
+
---------------------------
|
152
|
+
[1m[35m (0.0ms)[0m rollback transaction
|
153
|
+
[1m[36mActiveRecord::SchemaMigration Load (0.2ms)[0m [1mSELECT "schema_migrations".* FROM "schema_migrations"[0m
|
154
|
+
[1m[36m (0.9ms)[0m [1mCREATE TABLE "schema_migrations" ("version" varchar NOT NULL) [0m
|
155
|
+
[1m[35m (0.1ms)[0m select sqlite_version(*)
|
156
|
+
[1m[36m (0.7ms)[0m [1mCREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")[0m
|
157
|
+
[1m[35m (0.1ms)[0m SELECT version FROM "schema_migrations"
|
158
|
+
[1m[36m (0.6ms)[0m [1mINSERT INTO "schema_migrations" (version) VALUES ('0')[0m
|
159
|
+
[1m[35mActiveRecord::SchemaMigration Load (0.1ms)[0m SELECT "schema_migrations".* FROM "schema_migrations"
|
160
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
161
|
+
-----------------------------
|
162
|
+
RailsSpriteTest: test_perform
|
163
|
+
-----------------------------
|
164
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
165
|
+
[1m[36m (0.1ms)[0m [1mbegin transaction[0m
|
166
|
+
---------------------------
|
167
|
+
RailsSpriteTest: test_truth
|
168
|
+
---------------------------
|
169
|
+
[1m[35m (0.2ms)[0m rollback transaction
|
@@ -1,15 +1,23 @@
|
|
1
1
|
.rails_xxx-icon {
|
2
|
-
background: url(<%= image_path("rails_xxx/sprite/icons/32x32.png") %>)
|
2
|
+
background-image: url(<%= image_path("rails_xxx/sprite/icons/32x32.png") %>);
|
3
|
+
background-repeat: no-repeat;
|
4
|
+
background-size: 16px 48px;
|
3
5
|
}
|
4
6
|
|
5
7
|
.icons-32x32-avatar {
|
6
8
|
background-position: 0px -0px;
|
9
|
+
height: 16px;
|
10
|
+
width: 16px;
|
7
11
|
}
|
8
12
|
|
9
13
|
.icons-32x32-heart-rose {
|
10
|
-
background-position: 0px -
|
14
|
+
background-position: 0px -21px;
|
15
|
+
height: 16px;
|
16
|
+
width: 16px;
|
11
17
|
}
|
12
18
|
|
13
19
|
.icons-32x32-mail {
|
14
|
-
background-position: 0px -
|
20
|
+
background-position: 0px -42px;
|
21
|
+
height: 16px;
|
22
|
+
width: 16px;
|
15
23
|
}
|
data/test/rails_sprite_test.rb
CHANGED
@@ -11,7 +11,8 @@ class RailsSpriteTest < ActiveSupport::TestCase
|
|
11
11
|
:scope_name => "rails_xxx/",
|
12
12
|
:recipe_path => "icons/32x32",
|
13
13
|
:css_class_shared => 'rails_xxx-icon',
|
14
|
-
:css_class_prefix => 'icons-32x32-'
|
14
|
+
:css_class_prefix => 'icons-32x32-',
|
15
|
+
:zoom => 2
|
15
16
|
|
16
17
|
# :root_path => '.',
|
17
18
|
# :scope_name => "rails_xxx",
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rails-sprite
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- happy
|
@@ -137,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
137
|
version: '0'
|
138
138
|
requirements: []
|
139
139
|
rubyforge_project:
|
140
|
-
rubygems_version: 2.6.
|
140
|
+
rubygems_version: 2.6.13
|
141
141
|
signing_key:
|
142
142
|
specification_version: 4
|
143
143
|
summary: Rails CSS Sprite Utils.
|