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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 28356398d2a27b45b10a9aae7eb1fbeec2a568e9
4
- data.tar.gz: 23eb22bb38f164387cc88b6ff8fac5da6bafb547
3
+ metadata.gz: 825c1e7a5a56ce0cae657a9e9661392dac08d61e
4
+ data.tar.gz: 628287d731a7cf7a2b42938239f7e79f4e524bed
5
5
  SHA512:
6
- metadata.gz: 9ab758d4054121d87c2080b28318eefbe2bc27aabfb7d1aa4eeba0fef84ea0e854b40304dc5eead62a23e65c9c760e5a6a29f03c0d2c3622269ac295d1c7ec90
7
- data.tar.gz: 8ef7009ab864f4459abfa0e3415e6255f4d4fa4a7242a233b2976cad109b10e9966573a6af172cf8f471b218822950054903efde053eae521421b416edbcf083
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?( file_path )
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 += ( spacing + file_info[:height] )
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(<%= static_url("#{result[:image_scope_name]}") %>) no-repeat;
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]}") %>) no-repeat;
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
 
@@ -1,3 +1,3 @@
1
1
  module RailsSprite
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
@@ -65,3 +65,105 @@ RailsSpriteTest: test_truth
65
65
  RailsSpriteTest: test_perform
66
66
  -----------------------------
67
67
   (0.2ms) rollback transaction
68
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
69
+  (1.0ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
70
+  (0.1ms) select sqlite_version(*)
71
+  (1.0ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
72
+  (0.2ms) SELECT version FROM "schema_migrations"
73
+  (0.8ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
74
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
75
+  (0.1ms) begin transaction
76
+ -----------------------------
77
+ RailsSpriteTest: test_perform
78
+ -----------------------------
79
+  (0.1ms) rollback transaction
80
+  (0.0ms) begin transaction
81
+ ---------------------------
82
+ RailsSpriteTest: test_truth
83
+ ---------------------------
84
+  (0.0ms) rollback transaction
85
+ ActiveRecord::SchemaMigration Load (0.3ms) SELECT "schema_migrations".* FROM "schema_migrations"
86
+  (0.9ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
87
+  (0.1ms) select sqlite_version(*)
88
+  (0.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
89
+  (0.1ms) SELECT version FROM "schema_migrations"
90
+  (0.6ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
91
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
92
+  (0.1ms) begin transaction
93
+ -----------------------------
94
+ RailsSpriteTest: test_perform
95
+ -----------------------------
96
+  (0.1ms) rollback transaction
97
+  (0.1ms) begin transaction
98
+ ---------------------------
99
+ RailsSpriteTest: test_truth
100
+ ---------------------------
101
+  (0.0ms) rollback transaction
102
+ ActiveRecord::SchemaMigration Load (0.4ms) SELECT "schema_migrations".* FROM "schema_migrations"
103
+  (0.8ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
104
+  (0.1ms) select sqlite_version(*)
105
+  (0.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
106
+  (0.1ms) SELECT version FROM "schema_migrations"
107
+  (0.6ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
108
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
109
+  (0.1ms) begin transaction
110
+ -----------------------------
111
+ RailsSpriteTest: test_perform
112
+ -----------------------------
113
+  (0.1ms) rollback transaction
114
+  (0.1ms) begin transaction
115
+ ---------------------------
116
+ RailsSpriteTest: test_truth
117
+ ---------------------------
118
+  (0.0ms) rollback transaction
119
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
120
+  (1.4ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
121
+  (0.1ms) select sqlite_version(*)
122
+  (0.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
123
+  (0.1ms) SELECT version FROM "schema_migrations"
124
+  (0.6ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
125
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
126
+  (0.1ms) begin transaction
127
+ -----------------------------
128
+ RailsSpriteTest: test_perform
129
+ -----------------------------
130
+  (0.2ms) rollback transaction
131
+  (0.1ms) begin transaction
132
+ ---------------------------
133
+ RailsSpriteTest: test_truth
134
+ ---------------------------
135
+  (0.1ms) rollback transaction
136
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
137
+  (3.3ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
138
+  (0.1ms) select sqlite_version(*)
139
+  (1.6ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
140
+  (0.2ms) SELECT version FROM "schema_migrations"
141
+  (1.1ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
142
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
143
+  (0.1ms) begin transaction
144
+ -----------------------------
145
+ RailsSpriteTest: test_perform
146
+ -----------------------------
147
+  (0.1ms) rollback transaction
148
+  (0.1ms) begin transaction
149
+ ---------------------------
150
+ RailsSpriteTest: test_truth
151
+ ---------------------------
152
+  (0.0ms) rollback transaction
153
+ ActiveRecord::SchemaMigration Load (0.2ms) SELECT "schema_migrations".* FROM "schema_migrations"
154
+  (0.9ms) CREATE TABLE "schema_migrations" ("version" varchar NOT NULL) 
155
+  (0.1ms) select sqlite_version(*)
156
+  (0.7ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
157
+  (0.1ms) SELECT version FROM "schema_migrations"
158
+  (0.6ms) INSERT INTO "schema_migrations" (version) VALUES ('0')
159
+ ActiveRecord::SchemaMigration Load (0.1ms) SELECT "schema_migrations".* FROM "schema_migrations"
160
+  (0.1ms) begin transaction
161
+ -----------------------------
162
+ RailsSpriteTest: test_perform
163
+ -----------------------------
164
+  (0.2ms) rollback transaction
165
+  (0.1ms) begin transaction
166
+ ---------------------------
167
+ RailsSpriteTest: test_truth
168
+ ---------------------------
169
+  (0.2ms) rollback transaction
@@ -1,15 +1,23 @@
1
1
  .rails_xxx-icon {
2
- background: url(<%= image_path("rails_xxx/sprite/icons/32x32.png") %>) no-repeat;
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 -42px;
14
+ background-position: 0px -21px;
15
+ height: 16px;
16
+ width: 16px;
11
17
  }
12
18
 
13
19
  .icons-32x32-mail {
14
- background-position: 0px -84px;
20
+ background-position: 0px -42px;
21
+ height: 16px;
22
+ width: 16px;
15
23
  }
@@ -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.6
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.14
140
+ rubygems_version: 2.6.13
141
141
  signing_key:
142
142
  specification_version: 4
143
143
  summary: Rails CSS Sprite Utils.