acv2lrtemplate 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d91651b23a20caa9698c0c5b20b0ce018a2372b
4
+ data.tar.gz: e83f1ae7984611c854c7097619d290ad2b336fe1
5
+ SHA512:
6
+ metadata.gz: 5879de31c8fe979e2a05bb1293721cfcb1d54b3c5be1b8f918f0d5f4322aea99a3583166e96053fb65e1052f9cd111230e916362ed0635a1fa610885c68281f9
7
+ data.tar.gz: c7906c6647808b67f13eca13a0532935509d651a5bb7f5211923631f42f3ec2f53f3e6843cc51d18953254a58f8d1228c7f7d774503bf90a72b82b55f900d5c7
data/LICENSE.md ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2017 []().
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,46 @@
1
+ [![Gem Version](https://badge.fury.io/rb/acv2lightroom.svg)](https://badge.fury.io/rb/permitted_attributes)
2
+ [![Build Status](https://travis-ci.org/laurentzziu/acv2lightroom.svg?branch=master)](https://travis-ci.org/laurentzziu/acv2lightroom)
3
+
4
+ # ACV2Lightroom
5
+
6
+ Easily convert `.acv` (Photoshop Curves) to `.lrtemplate` (Adobe Lightroom Preset) files.
7
+
8
+ ## Description
9
+
10
+ Converts Adobe Photoshop Curves (`.acv` files) to Adobe Lightroom Presets (`.lrtemplate` files).
11
+
12
+ ## Installation
13
+
14
+ Add this line to your application's Gemfile:
15
+
16
+ ```ruby
17
+ gem 'acv2lightroom'
18
+ ```
19
+
20
+ And then execute:
21
+
22
+ $ bundle
23
+
24
+ Or install it yourself as:
25
+
26
+ $ gem install acv2lightroom
27
+
28
+ ## Usage
29
+
30
+ ## Development
31
+
32
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
33
+
34
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at [https://github.com/laurentzziu/acv2lightroom](https://github.com/laurentzziu/acv2lightroom). This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
39
+
40
+ ## License
41
+
42
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
43
+
44
+ ## Code of Conduct
45
+
46
+ Everyone interacting in the PermittedAttributes project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/laurentzziu/acv2lightroom/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ %w(object string).each do |file|
4
+ require "core_ext/#{file}"
5
+ end
6
+
7
+ %w(identity parser validator errors json2lrtemplate exporter).each do |file|
8
+ require "acv2lrtemplate/#{file}"
9
+ end
10
+
11
+ module Acv2lrtemplate
12
+ def self.convert!(filename, export_name = nil)
13
+ @parsed = Acv2lrtemplate::Parser.new(filename)
14
+ Acv2lrtemplate::Exporter.new(@parsed.curves, @parsed.acv_file, export_name).export!
15
+ end
16
+
17
+ def self.root
18
+ File.dirname __dir__
19
+ end
20
+
21
+ def self.lib
22
+ File.join(root, 'lib')
23
+ end
24
+
25
+ def self.spec
26
+ File.join(root, 'spec')
27
+ end
28
+ end
@@ -0,0 +1,9 @@
1
+ require_relative "errors/base"
2
+
3
+ %w(invalid_file_extension no_present_file no_file_provided).each do |file|
4
+ require_relative "errors/validator/#{file}"
5
+ end
6
+
7
+ %w(curves_data_invalid no_filename_provided).each do |file|
8
+ require_relative "errors/exporter/#{file}"
9
+ end
@@ -0,0 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acv2lrtemplate
4
+ module Errors
5
+ class Base < StandardError
6
+ def self.default_message
7
+ "There was an error."
8
+ end
9
+
10
+ def initialize(message = nil)
11
+ super(message || self.class.default_message)
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acv2lrtemplate
4
+ module Errors
5
+ module Exporter
6
+ class CurvesDataInvalid < Acv2lrtemplate::Errors::Base
7
+ def self.default_message
8
+ "The provided curves data is invalid. " \
9
+ "Make sure to run the Exporter after the Parser."
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acv2lrtemplate
4
+ module Errors
5
+ module Validator
6
+ class NoFileProvided < Acv2lrtemplate::Errors::Base
7
+ def self.default_message
8
+ "No file was provided. " \
9
+ "Please provide a file."
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acv2lrtemplate
4
+ module Errors
5
+ module Validator
6
+ class InvalidFileExtension < Acv2lrtemplate::Errors::Base
7
+ def self.default_message
8
+ "A file with invalid extension was provided. " \
9
+ "The accepted file extension is .acv."
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acv2lrtemplate
4
+ module Errors
5
+ module Validator
6
+ class NoFileProvided < Acv2lrtemplate::Errors::Base
7
+ def self.default_message
8
+ "No file was provided. " \
9
+ "Please provide a file."
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acv2lrtemplate
4
+ module Errors
5
+ module Validator
6
+ class NoPresentFile < Acv2lrtemplate::Errors::Base
7
+ def self.default_message
8
+ "No file was found at the provided path. " \
9
+ "Please check the path."
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,88 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'securerandom'
4
+ require 'json'
5
+
6
+ COPYRIGHT = "This file was generated automatically by the Acv2lrtemplate Ruby gem." \
7
+ "Copyright at Florinel Gorgan. https://floringorgan.com"
8
+
9
+ # parsed = Acv2lrtemplate::Parser.new(File.join(Acv2lrtemplate.spec, 'support', 'files', 's_line.acv'))
10
+ # Acv2lrtemplate::Exporter.new(parsed.curves, parsed.acv_file, "S Line").export!
11
+
12
+ module Acv2lrtemplate
13
+ class Exporter
14
+ TITLES = %i(ToneCurvePV2012 ToneCurvePV2012Blue
15
+ ToneCurvePV2012Green ToneCurvePV2012Red).freeze
16
+
17
+ attr_reader :curves, :file_name, :name, :exported_file
18
+
19
+ # TODO: add option to export to memory, not to a file
20
+ def initialize(curves, file_name, name = nil)
21
+ raise Acv2lrtemplate::Errors::Exporter::CurvesDataInvalid unless !curves.blank? && curves.kind_of?(Array)
22
+ @curves = curves
23
+ raise Acv2lrtemplate::Errors::Exporter::NoFileProvided if file_name.blank?
24
+ @file_name = file_name
25
+ @name = name || sanitize_filename.titleize
26
+ @exported_file = nil
27
+ end
28
+
29
+ def export!
30
+ structure = generate_structure.to_json
31
+ string = Acv2lrtemplate::JSON2lrtemplate.new(structure).convert!
32
+
33
+ File.open(new_file_name, 'w') do |file|
34
+ file.puts("--#{COPYRIGHT}")
35
+ file.puts(string)
36
+ end
37
+
38
+ @exported_file = new_file_name
39
+
40
+ new_file_name
41
+ end
42
+
43
+ private
44
+
45
+ def generate_structure
46
+ {
47
+ s: {
48
+ id: SecureRandom.uuid.upcase,
49
+ internal_name: @name,
50
+ title: @name,
51
+ type: 'Develop',
52
+ value: {
53
+ uuid: SecureRandom.uuid.upcase,
54
+ settings: generate_settings
55
+ },
56
+ version: 0
57
+ }
58
+ }
59
+ end
60
+
61
+ def export_curves
62
+ hash = {}
63
+ @curves.map.with_index do |channel, index|
64
+ hash[TITLES[index]] = channel.flatten
65
+ end
66
+ hash
67
+ end
68
+
69
+ def generate_settings
70
+ export_curves.merge(ToneCurveName2012: @name)
71
+ end
72
+
73
+ def new_file_name
74
+ File.join(file_path, sanitize_filename) + '.lrtemplate'
75
+ end
76
+
77
+ def sanitize_filename
78
+ File.basename(@name || @file_name, '.*').downcase
79
+ .tr('\/:*?"<>|!@#$%^&±~[]{}=+ ', '_')
80
+ .gsub(/_+/, '_')
81
+ .sub(/\A_/, '').sub(/_\z/, '')
82
+ end
83
+
84
+ def file_path
85
+ File.dirname(@file_name)
86
+ end
87
+ end
88
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acv2lrtemplate
4
+ # Gem identity information.
5
+ module Identity
6
+ def self.name
7
+ "acv2lrtemplate"
8
+ end
9
+
10
+ def self.label
11
+ "Acv2lrtemplate"
12
+ end
13
+
14
+ def self.version
15
+ "0.1.0"
16
+ end
17
+
18
+ def self.version_label
19
+ "#{label} #{version}"
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acv2lrtemplate
4
+ class JSON2lrtemplate
5
+ attr_reader :json_string
6
+
7
+ def initialize(json_string)
8
+ @json_string = json_string
9
+ end
10
+
11
+ # Transform "keys" to keys
12
+ # Transform [] to {} - works for values on the same line?
13
+ # Transform : to =
14
+ # Remove leading and ending {}
15
+ # , before closing }
16
+
17
+ def convert!
18
+ @json_string.gsub(/"(\w+)"(?=:)/) { |_| $1.camelize(false) }
19
+ .gsub(/(\[[.\S\s^"]*?\])/) { |_| $1.tr('[]', '{}') }
20
+ .gsub(':', ' = ')
21
+ .sub(/\A{/, '').sub(/}\Z/, '')
22
+ .gsub(/(?<=.)(}){1}(?=.)?/) { |_| ",#{$1}" }
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'curver'
4
+
5
+ module Acv2lrtemplate
6
+ class Parser
7
+ attr_reader :acv_file, :curver
8
+ attr_accessor :curves
9
+
10
+ def initialize(filename)
11
+ raise Acv2lrtemplate::Errors::Validator::NoFileProvided if filename.blank?
12
+ @acv_file = filename
13
+ validate
14
+ parse
15
+ end
16
+
17
+ def parse
18
+ @curver = Curver.new(@acv_file)
19
+ @curves = parse_channels
20
+ end
21
+
22
+ private
23
+
24
+ def validate
25
+ Acv2lrtemplate::Validator.new(@acv_file).validate
26
+ end
27
+
28
+ def parse_channels
29
+ # channels: RGB, R(ed), G(reen), B(lue)
30
+ @curves = @curver.curves.map do |channel|
31
+ channel.points.map do |point|
32
+ point_convertor(point)
33
+ end
34
+ end
35
+ end
36
+
37
+ # The 'curver' gem parses the Adobe Photoshop Curves file as
38
+ # points with x and y coordinates between 0.0 and 1.0
39
+ # Adobe Lightroom uses points with coordinates between
40
+ # 0 and 255, so a conversion is needed
41
+ def point_convertor(point)
42
+ point.map do |coordonate|
43
+ (coordonate * 255).to_i
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Acv2lrtemplate
4
+ class Validator
5
+ attr_reader :filename
6
+
7
+ def initialize(filename)
8
+ @filename = filename
9
+ end
10
+
11
+ def valid?
12
+ validate
13
+ end
14
+
15
+ def invalid?
16
+ !valid?
17
+ end
18
+
19
+ def validate
20
+ validate_presence
21
+ validate_extension
22
+ end
23
+
24
+ private
25
+
26
+ ACCEPTED_FORMATS = %w[.acv .ACV].freeze
27
+
28
+ def validate_extension
29
+ unless ACCEPTED_FORMATS.include?(File.extname(@filename))
30
+ raise Acv2lrtemplate::Errors::Validator::InvalidFileExtension
31
+ end
32
+ end
33
+
34
+ def validate_presence
35
+ unless File.exist?(@filename)
36
+ raise Acv2lrtemplate::Errors::Validator::NoPresentFile
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,6 @@
1
+ class Object
2
+ # http://api.rubyonrails.org/v4.2/classes/Object.html#method-i-blank-3F
3
+ def blank?
4
+ respond_to?(:empty?) ? !!empty? : !self
5
+ end
6
+ end
@@ -0,0 +1,17 @@
1
+ class String
2
+ # https://apidock.com/rails/String/camelize
3
+ def camelize(uppercase_first_letter = true)
4
+ string = self
5
+ if uppercase_first_letter
6
+ string = string.sub(/^[a-z\d]*/) { $&.capitalize }
7
+ else
8
+ string = string.sub(/^(?:(?=\b|[A-Z_])|\w)/) { $&.downcase }
9
+ end
10
+ string.gsub(/(?:_|(\/))([a-z\d]*)/) { "#{$1}#{$2.capitalize}" }.gsub('/', '::')
11
+ end
12
+
13
+ # https://stackoverflow.com/a/27737214
14
+ def titleize
15
+ self.split(" ").map{ |word| word.capitalize }.join(" ")
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,190 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: acv2lrtemplate
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Florinel Gorgan
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-30 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '12.0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '12.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: gemsmith
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: pry
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '0.10'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '0.10'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry-byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry-state
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.1'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.1'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '3.6'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '3.6'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard-rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '4.7'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '4.7'
111
+ - !ruby/object:Gem::Dependency
112
+ name: rubocop
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.49'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.49'
125
+ - !ruby/object:Gem::Dependency
126
+ name: curver
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.0.2
132
+ type: :runtime
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.0.2
139
+ description:
140
+ email:
141
+ - florin@floringorgan.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files:
145
+ - README.md
146
+ - LICENSE.md
147
+ files:
148
+ - LICENSE.md
149
+ - README.md
150
+ - lib/acv2lrtemplate.rb
151
+ - lib/acv2lrtemplate/errors.rb
152
+ - lib/acv2lrtemplate/errors/base.rb
153
+ - lib/acv2lrtemplate/errors/exporter/curves_data_invalid.rb
154
+ - lib/acv2lrtemplate/errors/exporter/no_filename_provided.rb
155
+ - lib/acv2lrtemplate/errors/validator/invalid_file_extension.rb
156
+ - lib/acv2lrtemplate/errors/validator/no_file_provided.rb
157
+ - lib/acv2lrtemplate/errors/validator/no_present_file.rb
158
+ - lib/acv2lrtemplate/exporter.rb
159
+ - lib/acv2lrtemplate/identity.rb
160
+ - lib/acv2lrtemplate/json2lrtemplate.rb
161
+ - lib/acv2lrtemplate/parser.rb
162
+ - lib/acv2lrtemplate/validator.rb
163
+ - lib/core_ext/object.rb
164
+ - lib/core_ext/string.rb
165
+ homepage: https://github.com/laurentzziu/permitted_attributes
166
+ licenses:
167
+ - MIT
168
+ metadata: {}
169
+ post_install_message:
170
+ rdoc_options: []
171
+ require_paths:
172
+ - lib
173
+ required_ruby_version: !ruby/object:Gem::Requirement
174
+ requirements:
175
+ - - "~>"
176
+ - !ruby/object:Gem::Version
177
+ version: '2.4'
178
+ required_rubygems_version: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ requirements: []
184
+ rubyforge_project:
185
+ rubygems_version: 2.6.14
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Easily convert .acv (Photoshop Curves) to .lrtemplate (Adobe Lightroom Preset)
189
+ files.
190
+ test_files: []