ase-palette 0.9.1 → 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6361e025b4781e0cacb4f6f8b8f52b0d4b11d489468f06496b0f92c9dc11c9bb
4
- data.tar.gz: 99807b55893ef200819ceb4b2cac53b1321cf99bcdab52d4c0e0680c9a825439
3
+ metadata.gz: a8efd3a8b6e4f148e1b6ef04583e55e2c05f6ed3bb9ba236ff0f3c763789c0a2
4
+ data.tar.gz: 0fd75bad1b0cb5cfa08f9ae199534cbf82d2ba3ddbf1bf634e02fa6290e619f5
5
5
  SHA512:
6
- metadata.gz: 6409fcfa09189d3a50274ef25d4d179fa624b768329b2ef91da7977d9cd006255536b82ff4a2225bd8de18205328a3031666fb82d7a586c8e469d5c9f8245080
7
- data.tar.gz: 76a1cf7733d883941f868a26eeb2b7bbb198b838ab1dc5e35c976533a9460a867f259dd438b1c5701be0379edc3c191fb09c4d35557cfdb3fc0faab17522e9c9
6
+ metadata.gz: 61b554c482bf803f87cb852743ce3e0ab4a6a547662f516db04d55c05b788782597292afdc59dfb8d5c7a5e334e833330b70b4ffa99534b917102dcafa846c95
7
+ data.tar.gz: f232f7e71ed8d260c0f21133843666c76d198dfba892c4ba6f807d8df76fcb69d5f451e5dfa2d25e5b1edce1c4159f49d38d92ac11283e0c1009748811aa486b
data/CHANGELOG.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ `0.9.2`
4
+ - Update dependencies
5
+
3
6
  `0.9.1`
4
7
  - Add ability to read ASE files
5
8
 
data/Gemfile.lock CHANGED
@@ -1,30 +1,30 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ase-palette (0.9.1)
5
- bindata (~> 2.4.4)
4
+ ase-palette (0.9.2)
5
+ bindata (~> 2.4.10)
6
6
  hex_string (~> 1.0.1)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- bindata (2.4.4)
12
- diff-lcs (1.3)
11
+ bindata (2.4.10)
12
+ diff-lcs (1.5.0)
13
13
  hex_string (1.0.1)
14
- rake (11.3.0)
15
- rspec (3.8.0)
16
- rspec-core (~> 3.8.0)
17
- rspec-expectations (~> 3.8.0)
18
- rspec-mocks (~> 3.8.0)
19
- rspec-core (3.8.0)
20
- rspec-support (~> 3.8.0)
21
- rspec-expectations (3.8.2)
14
+ rake (13.0.6)
15
+ rspec (3.10.0)
16
+ rspec-core (~> 3.10.0)
17
+ rspec-expectations (~> 3.10.0)
18
+ rspec-mocks (~> 3.10.0)
19
+ rspec-core (3.10.1)
20
+ rspec-support (~> 3.10.0)
21
+ rspec-expectations (3.10.2)
22
22
  diff-lcs (>= 1.2.0, < 2.0)
23
- rspec-support (~> 3.8.0)
24
- rspec-mocks (3.8.0)
23
+ rspec-support (~> 3.10.0)
24
+ rspec-mocks (3.10.2)
25
25
  diff-lcs (>= 1.2.0, < 2.0)
26
- rspec-support (~> 3.8.0)
27
- rspec-support (3.8.0)
26
+ rspec-support (~> 3.10.0)
27
+ rspec-support (3.10.3)
28
28
 
29
29
  PLATFORMS
30
30
  ruby
@@ -32,8 +32,8 @@ PLATFORMS
32
32
  DEPENDENCIES
33
33
  ase-palette!
34
34
  bundler (~> 2.0)
35
- rake (~> 11.2)
36
- rspec (~> 3.8)
35
+ rake (~> 13.0)
36
+ rspec (~> 3.10)
37
37
 
38
38
  BUNDLED WITH
39
39
  2.0.1
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ASEPalette
1
+ # 🎨 ASEPalette
2
2
 
3
3
  [<img src="https://img.shields.io/gem/v/ase-palette.svg?color=g" />](https://rubygems.org/gems/ase-palette)
4
4
  [<img src="https://img.shields.io/gem/dt/ase-palette.svg?color=g" />](https://rubygems.org/gems/ase-palette)
@@ -15,29 +15,26 @@ gem 'ase-palette'
15
15
 
16
16
  ## Usage
17
17
 
18
- ### Load
18
+ ### 🚀 Load
19
19
 
20
20
  ```ruby
21
21
  require 'ase-palette'
22
22
  ```
23
23
 
24
- ### Write
24
+ ### 📝 Write
25
25
 
26
26
  ```ruby
27
- # Create palette
27
+ # Create a palette
28
28
  palette = ASEPalette.new
29
29
 
30
- # Create color
31
- color = ASEPalette::Color::RGB.new "Red", 255, 0, 0
30
+ # Add a color
31
+ palette.add_color ASEPalette::Color::RGB.new "Red", 255, 0, 0
32
32
 
33
- # Add color to palette
34
- palette.add_color color
35
-
36
- # Add color to group
37
- palette.add_color color, group_name: "Group Name"
33
+ # Add a color to a group
34
+ palette.add_color ASEPalette::Color::CMYK.new "Yellow", 100, 0, 0, 0, group_name: "My Group"
38
35
  ```
39
36
 
40
- ### Read
37
+ ### 📖 Read
41
38
 
42
39
  ```ruby
43
40
  # Access top-level colors
@@ -59,17 +56,17 @@ palette.colors(include_from_groups: true).each do |color|
59
56
  end
60
57
  ```
61
58
 
62
- ### Edit
59
+ ### 🖋 Edit
63
60
 
64
61
  ```ruby
65
62
  # Remove a color, including those from groups
66
63
  palette.remove_color_with_name "Red"
67
64
 
68
- # Remove a group and all of the colors it contains
65
+ # Remove a group and all of the colors in it
69
66
  palette.remove_group_with_name "Group Name"
70
67
  ```
71
68
 
72
- ### Export
69
+ ### ⬆️ Export
73
70
 
74
71
  ```ruby
75
72
  # Store file
@@ -83,7 +80,7 @@ respond_to do |format|
83
80
  end
84
81
  ```
85
82
 
86
- ### Import
83
+ ### ⬇️ Import
87
84
 
88
85
  ```ruby
89
86
  # Open palette from file
@@ -100,11 +97,14 @@ puts palette
100
97
  # Violet, RGB: 90/0/255, :global
101
98
  # Blue, RGB: 0/0/255, :global
102
99
  # Green, RGB: 50/255/50, :global
103
- # Red, RGB: 240/0/20, :global
104
100
  #
105
101
  # Group 2
106
102
  # Orange CMYK, CMYK: 0/80/100/0, :global
107
103
  # Yellow CMYK, CMYK: 0/20/100/0, :global
104
+ #
105
+ # Group 3
106
+ # PANTONE Yellow C, LAB: 89/-1/111, :spot
107
+ # PANTONE Orange 021 C, LAB: 61/66/85, :spot
108
108
  #
109
109
  # --------------
110
110
  # 7 colors, 2 groups
data/ase-palette.gemspec CHANGED
@@ -37,10 +37,10 @@ Gem::Specification.new do |spec|
37
37
  spec.require_paths = ["lib"]
38
38
  spec.required_ruby_version = ">= 2.5.0"
39
39
 
40
- spec.add_dependency "bindata", "~>2.4.4"
40
+ spec.add_dependency "bindata", "~>2.4.10"
41
41
  spec.add_dependency "hex_string", "~>1.0.1"
42
42
 
43
43
  spec.add_development_dependency "bundler", "~> 2.0"
44
- spec.add_development_dependency "rake", "~> 11.2"
45
- spec.add_development_dependency "rspec", "~> 3.8"
44
+ spec.add_development_dependency "rake", "~> 13.0"
45
+ spec.add_development_dependency "rspec", "~> 3.10"
46
46
  end
@@ -1,7 +1,5 @@
1
1
  module ASEPalette
2
- class Palette
3
- # TODO: Consider removing 'with_name' from method signatures
4
-
2
+ class Palette
5
3
  # Initialize palette
6
4
  def initialize(path = nil)
7
5
  @version_major = 1
@@ -71,7 +69,21 @@ module ASEPalette
71
69
  raise Error, "A color named #{color.name} already exists"
72
70
  end
73
71
  else
74
- raise Error, "Argument 'color' is not of type #{ASEPalette::Color}"
72
+ raise Error, "Argument 'color' must be of type #{ASEPalette::Color}"
73
+ end
74
+ end
75
+
76
+ # Add multiple colors to palette
77
+ # 'colors' must be an array of Color objects
78
+ # Optionally provide 'group_name' to place color in group
79
+ # Group will be created if it does not exist
80
+ def add_colors(colors, group_name: nil)
81
+ if colors.is_a? Array
82
+ colors.each do |color|
83
+ add_color(color, group_name: group_name)
84
+ end
85
+ else
86
+ raise Error, "Argument 'colors' must be of type #{Array}"
75
87
  end
76
88
  end
77
89
 
@@ -183,13 +195,13 @@ module ASEPalette
183
195
  end
184
196
  end
185
197
 
186
- # Returns an array of all colors in the palette,
198
+ # Returns a copied array of all colors in palette,
187
199
  # including those in groups
188
200
  def all_colors
189
201
  @colors + @groups.map { |group| group.colors }.flatten
190
202
  end
191
203
 
192
- # Determines whether or not a color exists in the palette,
204
+ # Determines whether color exists in palette,
193
205
  # including those in groups
194
206
  def color_does_not_exist(name)
195
207
  all_colors.select { |color| color.name == name }.length == 0
@@ -20,6 +20,34 @@ module ASEPalette
20
20
 
21
21
  class ASEBinData < BinData::Record
22
22
  endian :big
23
+
24
+ class String16Null < BinData::Primitive
25
+ endian :big
26
+
27
+ uint16 :len, value: -> { data.length / 2 + 1 }
28
+ string :data, read_length: -> { (len - 1) * 2 }
29
+ uint16 :null_terminator, value: 0
30
+
31
+ # Force UTF-16 string encoding
32
+ # when anonymous bytes are naively read in,
33
+ # then encode for UTF-8, which the user expects
34
+ def get
35
+ self.data.force_encoding(Encoding::UTF_16BE).encode(Encoding::UTF_8)
36
+ end
37
+
38
+ # Expect to receive UTF-8 string when setting
39
+ def set(string)
40
+ self.data = string.encode(Encoding::UTF_16BE)
41
+ end
42
+
43
+ # Calculate total size, in bytes, of:
44
+ # - UTF-16-encoded string
45
+ # - uint16 length of string (2 bytes)
46
+ # - null terminator (2 bytes)
47
+ def size
48
+ self.data.length + 4
49
+ end
50
+ end
23
51
 
24
52
  string :signature, value: "ASEF", read_length: 4
25
53
  uint16 :version_major, initial_value: DEFAULT_VERSION_MAJOR
@@ -28,14 +56,17 @@ module ASEPalette
28
56
 
29
57
  array :blocks, initial_length: -> { block_count } do
30
58
  uint16 :block_type
59
+
31
60
  uint32 :block_length, value: -> {
32
61
  block_length = 0
33
- if block_type == BLOCK_TYPE_COLOR ||
34
- block_type == BLOCK_TYPE_GROUP_START
35
- block_length += block_data.name.length
62
+ if block_type == BLOCK_TYPE_GROUP_START ||
63
+ block_type == BLOCK_TYPE_COLOR
64
+ block_length += block_data.name.size
36
65
  end
37
66
  if block_type == BLOCK_TYPE_COLOR
38
- block_length += 10
67
+ # Add length of color_model string (4 bytes) +
68
+ # color_type uint16 (2 bytes)
69
+ block_length += 6
39
70
  case block_data.color_model
40
71
  when COLOR_MODEL_RGB
41
72
  block_length += 4 * 3
@@ -44,52 +75,47 @@ module ASEPalette
44
75
  when COLOR_MODEL_LAB
45
76
  block_length += 4 * 3
46
77
  end
47
- elsif block_type == BLOCK_TYPE_GROUP_START
48
- block_length += 4
49
78
  end
50
79
  block_length
51
80
  }
81
+
52
82
  choice :block_data, selection: -> { block_type } do
53
83
  class BlockGroupStart < BinData::Record
54
84
  endian :big
55
- uint16 :name_length, value: -> { name.length / 2 + 1 }
56
- string :name, read_length: -> { (name_length - 1) * 2 }
57
- uint16 :null_padding, value: 0
85
+ String16Null :name
58
86
  end
59
87
  class BlockGroupEnd < BinData::Record
60
88
  end
61
89
  class BlockColor < BinData::Record
62
90
  endian :big
63
- uint16 :name_length, value: -> { name.length / 2 + 1 }
64
- string :name, read_length: -> { (name_length - 1) * 2 }
65
- uint16 :null_padding, value: 0
91
+
92
+ class ColorDataRGB < BinData::Record
93
+ endian :big
94
+ float :red, initial_value: 0
95
+ float :green, initial_value: 0
96
+ float :blue, initial_value: 0
97
+ end
98
+ class ColorDataCMYK < BinData::Record
99
+ endian :big
100
+ float :cyan, initial_value: 0
101
+ float :magenta, initial_value: 0
102
+ float :yellow, initial_value: 0
103
+ float :black, initial_value: 0
104
+ end
105
+ class ColorDataLAB < BinData::Record
106
+ endian :big
107
+ float :lightness, initial_value: 0
108
+ float :a, initial_value: 0
109
+ float :b, initial_value: 0
110
+ end
111
+
112
+ String16Null :name
66
113
  string :color_model, read_length: 4
67
114
  choice :color_data, selection: -> { color_model } do
68
- class ColorDataRGB < BinData::Record
69
- endian :big
70
- float :red, initial_value: 0
71
- float :green, initial_value: 0
72
- float :blue, initial_value: 0
73
- end
74
- class ColorDataCMYK < BinData::Record
75
- endian :big
76
- float :cyan, initial_value: 0
77
- float :magenta, initial_value: 0
78
- float :yellow, initial_value: 0
79
- float :black, initial_value: 0
80
- end
81
- class ColorDataLAB < BinData::Record
82
- endian :big
83
- float :lightness, initial_value: 0
84
- float :a, initial_value: 0
85
- float :b, initial_value: 0
86
- end
87
-
88
115
  ColorDataRGB COLOR_MODEL_RGB
89
116
  ColorDataCMYK COLOR_MODEL_CMYK
90
117
  ColorDataLAB COLOR_MODEL_LAB
91
- # Grayscale data is stored in a CMYK structure
92
- ColorDataCMYK COLOR_MODEL_GRAY
118
+ ColorDataCMYK COLOR_MODEL_GRAY # Grayscale data stored in CMYK structure
93
119
  end
94
120
  uint16 :color_type, initial_value: COLOR_TYPE_DEFAULT
95
121
  end
@@ -190,7 +216,7 @@ module ASEPalette
190
216
  palette.blocks.push({
191
217
  block_type: BLOCK_TYPE_COLOR,
192
218
  block_data: {
193
- name: name.encode(Encoding::UTF_16BE),
219
+ name: name,
194
220
  color_model: color_model,
195
221
  color_data: color_data,
196
222
  color_type: color_type,
@@ -202,7 +228,7 @@ module ASEPalette
202
228
  palette.blocks.push({
203
229
  block_type: BLOCK_TYPE_GROUP_START,
204
230
  block_data: {
205
- name: name.encode(Encoding::UTF_16BE),
231
+ name: name
206
232
  }
207
233
  })
208
234
  end
@@ -226,7 +252,7 @@ module ASEPalette
226
252
  block_type = block[:block_type]
227
253
  block_data = block[:block_data]
228
254
  if block_type == BLOCK_TYPE_COLOR || block_type == BLOCK_TYPE_GROUP_START
229
- block_name = block_data[:name].force_encoding(Encoding::UTF_16BE).encode(Encoding::UTF_8)
255
+ block_name = block_data[:name]
230
256
  end
231
257
  if block_type == BLOCK_TYPE_COLOR
232
258
  color = { name: block_name }
@@ -1,3 +1,3 @@
1
1
  module ASEPalette
2
- VERSION = "0.9.1"
2
+ VERSION = "0.9.2"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ase-palette
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.1
4
+ version: 0.9.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sam Becker
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-03-15 00:00:00.000000000 Z
11
+ date: 2022-01-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 2.4.4
19
+ version: 2.4.10
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 2.4.4
26
+ version: 2.4.10
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: hex_string
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -58,28 +58,28 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '11.2'
61
+ version: '13.0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '11.2'
68
+ version: '13.0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: rspec
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '3.8'
75
+ version: '3.10'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '3.8'
82
+ version: '3.10'
83
83
  description: Read and write Adobe Swatch Exchange files.
84
84
  email:
85
85
  - sam@sambecker.com
@@ -113,7 +113,7 @@ metadata:
113
113
  homepage_uri: https://github.com/sambecker/ase-palette
114
114
  source_code_uri: https://github.com/sambecker/ase-palette
115
115
  changelog_uri: https://github.com/sambecker/ase-palette/blob/master/CHANGELOG.md
116
- post_install_message:
116
+ post_install_message:
117
117
  rdoc_options: []
118
118
  require_paths:
119
119
  - lib
@@ -128,8 +128,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
128
128
  - !ruby/object:Gem::Version
129
129
  version: '0'
130
130
  requirements: []
131
- rubygems_version: 3.0.3
132
- signing_key:
131
+ rubygems_version: 3.3.5
132
+ signing_key:
133
133
  specification_version: 4
134
134
  summary: Create and manage Adobe ASE palettes.
135
135
  test_files: []