Skip to content

Commit

Permalink
Merge pull request #11 from amclain/feature/copyright-templating
Browse files Browse the repository at this point in the history
Add templatable copyright properties
  • Loading branch information
amclain committed May 11, 2020
2 parents 0d58aca + 8824ea6 commit eb4b838
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 14 deletions.
11 changes: 10 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ and information about your cameras.
# Example config.yml
---
artist: "Example User"
copyright: "2016 Example User"
copyright: "{{ year_captured }} {{ artist }}"
cameras:
- tag: "rz67"
make: "Mamiya"
Expand All @@ -63,6 +63,15 @@ cameras:
focal_length: 250
```

### Templating

Templated values are supported within the YAML files using the moustache
`{{` `}}` syntax.

- `artist` - Available within the `copyright` field to substitute the artist name.
- `year_captured` - Available within the `copyright` field to substitute the year
the image was captured.

## Tags

Tags are user-defined values that serve as a quick and simple way to reference
Expand Down
13 changes: 12 additions & 1 deletion lib/halation/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ def run

ExifToolImage.new(_image_files[i]).tap do |exif|
exif["Artist"] = @roll.artist || @config.artist
exif["Copyright"] = @roll.copyright || @config.copyright
exif["Copyright"] = template_copyright(@config, @roll, frame)
exif["DateTimeOriginal"] = frame.date_captured || @roll.date_captured
exif["CreateDate"] = frame.date_scanned || @roll.date_scanned
exif["Make"] = camera.make
Expand All @@ -84,5 +84,16 @@ def run
end
end

private

def template_copyright(config, roll, frame)
artist = roll.artist || config.artist
date_captured = frame.date_captured || roll.date_captured
year_captured = date_captured.strftime("%Y")

copyright = (roll.copyright || config.copyright).clone
copyright.gsub!(Regexp.new("{{\s*artist\s*}}"), artist)
copyright.gsub!(Regexp.new("{{\s*year_captured\s*}}"), year_captured)
end
end
end
2 changes: 1 addition & 1 deletion spec/config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
}

let(:artist) { "Test Artist" }
let(:copyright) { "2016 Test Artist" }
let(:copyright) { "{{ year_captured }} {{ artist }}" }

let(:cameras) {[
{
Expand Down
17 changes: 13 additions & 4 deletions spec/engine_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,16 +34,16 @@
let(:working_dir) { "spec/samples/under_test" }

let(:artist) { "Me" }
let(:copyright) { "2016 Me" }
let(:make) { "Mamiya" }
let(:model) { "Mamiya RZ67 Pro II" }
let(:iso) { 100 }

let(:exif_results) {[
{
# Frame 1
"DateTimeOriginal" => Time.parse("2016-02-03 01:02:03"),
"CreateDate" => Time.parse("2016-02-15 08:09:10"),
"Copyright" => "2017 Me",
"DateTimeOriginal" => Time.parse("2017-02-03 01:02:03"),
"CreateDate" => Time.parse("2017-02-15 08:09:10"),
"LensModel" => "Z180mm f/4.5W-N",
"ExposureTime" => 1.0/250,
"FNumber" => 8,
Expand All @@ -53,6 +53,7 @@
},
{
# Frame 2
"Copyright" => "2016 Me",
"DateTimeOriginal" => Time.parse("2016-01-02"),
"CreateDate" => Time.parse("2016-01-05"),
"LensModel" => "Z100-200mm f/5.2W",
Expand All @@ -64,6 +65,7 @@
},
{
# Frame 3
"Copyright" => "2016 Me",
"DateTimeOriginal" => Time.parse("2016-01-02"),
"CreateDate" => Time.parse("2016-01-05"),
"LensModel" => "Z110mm f/2.8W",
Expand All @@ -75,6 +77,7 @@
},
{
# Frame 4
"Copyright" => "2016 Me",
"DateTimeOriginal" => Time.parse("2016-01-02"),
"CreateDate" => Time.parse("2016-01-05"),
"LensModel" => "Z110mm f/2.8W",
Expand All @@ -86,6 +89,7 @@
},
{
# Frame 5
"Copyright" => "2016 Me",
"DateTimeOriginal" => Time.parse("2016-01-02"),
"CreateDate" => Time.parse("2016-01-05"),
"LensModel" => "Z110mm f/2.8W",
Expand All @@ -97,6 +101,7 @@
},
{
# Frame 6
"Copyright" => "2016 Me",
"DateTimeOriginal" => Time.parse("2016-01-02"),
"CreateDate" => Time.parse("2016-01-05"),
"LensModel" => "Z110mm f/2.8W",
Expand All @@ -108,6 +113,7 @@
},
{
# Frame 7
"Copyright" => "2016 Me",
"DateTimeOriginal" => Time.parse("2016-01-02"),
"CreateDate" => Time.parse("2016-01-05"),
"LensModel" => "Z110mm f/2.8W",
Expand All @@ -119,6 +125,7 @@
},
{
# Frame 8
"Copyright" => "2016 Me",
"DateTimeOriginal" => Time.parse("2016-01-02"),
"CreateDate" => Time.parse("2016-01-05"),
"LensModel" => "Z110mm f/2.8W",
Expand All @@ -130,6 +137,7 @@
},
{
# Frame 9
"Copyright" => "2016 Me",
"DateTimeOriginal" => Time.parse("2016-01-02"),
"CreateDate" => Time.parse("2016-01-05"),
"LensModel" => "Z110mm f/2.8W",
Expand All @@ -141,6 +149,7 @@
},
{
# Frame 10
"Copyright" => "2016 Me",
"DateTimeOriginal" => Time.parse("2016-01-02"),
"CreateDate" => Time.parse("2016-01-05"),
"LensModel" => "Z110mm f/2.8W",
Expand Down Expand Up @@ -172,7 +181,7 @@

MiniExiftool.new(image_file, numerical: true).tap do |exif|
exif["Artist"].should eq artist
exif["Copyright"].should eq copyright
exif["Copyright"].should eq exif_results[i]["Copyright"]
exif["DateTimeOriginal"].should eq exif_results[i]["DateTimeOriginal"]
exif["CreateDate"].should eq exif_results[i]["CreateDate"]
exif["Make"].should eq make
Expand Down
6 changes: 3 additions & 3 deletions spec/roll_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

it "has values" do
subject.artist.should eq "Me"
subject.copyright.should eq "2016 Me"
subject.copyright.should eq "{{ year_captured }} {{ artist }}"
subject.date_captured.should eq Time.parse("2016-01-02")
subject.date_scanned.should eq Time.parse("2016-01-05")
subject.camera.should eq "rz67"
Expand All @@ -41,8 +41,8 @@
case i
when 0
frame.number.should eq 1
frame.date_captured.should eq Time.parse("2016-02-03 01:02:03")
frame.date_scanned.should eq Time.parse("2016-02-15 08:09:10")
frame.date_captured.should eq Time.parse("2017-02-03 01:02:03")
frame.date_scanned.should eq Time.parse("2017-02-15 08:09:10")
frame.lens.should eq "180"
frame.focal_length.should be nil
frame.shutter.should eq "1/250"
Expand Down
2 changes: 1 addition & 1 deletion spec/samples/set_1/config.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
artist: "Test Artist"
copyright: "2016 Test Artist"
copyright: "{{ year_captured }} {{ artist }}"
cameras:
- tag: "rz67"
make: "Mamiya"
Expand Down
6 changes: 3 additions & 3 deletions spec/samples/set_1/roll.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
---
artist: "Me"
copyright: "2016 Me"
copyright: "{{ year_captured }} {{ artist }}"
date_captured: "2016-01-02" # default
date_scanned: "2016-01-05" # default
camera: "rz67"
lens: 110 # default
iso: 100
frames:
- number: 1
date_captured: "2016-02-03 01:02:03" # overridden
date_scanned: "2016-02-15 08:09:10" # overridden
date_captured: "2017-02-03 01:02:03" # overridden
date_scanned: "2017-02-15 08:09:10" # overridden
lens: 180 # overridden
shutter: "1/250"
aperture: 8
Expand Down

0 comments on commit eb4b838

Please sign in to comment.