jekyll-exiftag 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/jekyll-exiftag.rb +80 -0
  2. metadata +57 -0
@@ -0,0 +1,80 @@
1
+ # -*- coding: utf-8 -*-
2
+ # A LiquidTag to get Exif Tags using EXIFR
3
+ # by: Beni Buess
4
+ #
5
+ #
6
+ # Usage:
7
+ #
8
+ # {% exiftag tagname,[source],[file] %}
9
+ #
10
+ # Everything given as tagname is called on EXIFR::JPEG, so this could be model oder f_number.to_f (see https://github.com/remvee/exifr)
11
+ # If you give a source, this source is used build the fullpath for the given file (you can also configure them in _config.yml, see below)
12
+ # If the file is given, this is the file to get Exif Tags for, this can be alternatively defined in the YAML Front Matter as img: file
13
+ #
14
+ #
15
+ # Configuration:
16
+ #
17
+ # Put this in your _config.yml
18
+ #
19
+ # exiftag:
20
+ # sources:
21
+ # - photos
22
+ # - photos/other_source
23
+ #
24
+ # These paths are relative to your sites root. Don't add leading and trailing slashes.
25
+ #
26
+
27
+ require 'exifr'
28
+
29
+ module Jekyll
30
+ class ExifTag < Liquid::Tag
31
+ def initialize(tag_name, params, token)
32
+ super
33
+ @args = self.split_params(params)
34
+ end
35
+
36
+ def render(context)
37
+ #abort context.registers[:site].config['source'].inspect
38
+ sources = Array.new(context.registers[:site].config['exiftag']['sources'])
39
+ # first param is the exif tag
40
+ tag = @args[0]
41
+
42
+ # if a second parameter is passed, use it as a possible img source
43
+ if @args.count > 1
44
+ sources.unshift(@args[1])
45
+ end
46
+
47
+ # the image can be passed as the third parameter
48
+ if @args.count > 2
49
+ img = @args[2]
50
+ # or be defined in the YAML Front Matter like img: <file>
51
+ else
52
+ img = context.environments.first["page"]["img"]
53
+ end
54
+
55
+ # first check if the given img is already the path
56
+ if File.exist?(img)
57
+ file_name = img
58
+ else
59
+ # then start testing with the sources from _config.yml
60
+ begin
61
+ source = sources.shift
62
+ file_name = File.join(context.registers[:site].config['source'], source, img)
63
+ end until File.exist?(file_name) or sources.count == 0
64
+ end
65
+ # try it and return empty string on failure
66
+ begin
67
+ exif = EXIFR::JPEG::new(file_name)
68
+ "#{exif.instance_eval(tag)}"
69
+ rescue
70
+ ""
71
+ end
72
+ end
73
+
74
+ def split_params(params)
75
+ params.split(",").map(&:strip)
76
+ end
77
+ end
78
+ end
79
+
80
+ Liquid::Template.register_tag('exiftag', Jekyll::ExifTag)
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jekyll-exiftag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Beni Buess
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-04-12 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: exifr
16
+ requirement: &14157540 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *14157540
25
+ description: jekyll-exiftag is a LiquidTag Extension for Jekyll to get Exif data from
26
+ images
27
+ email: beni@benel.net
28
+ executables: []
29
+ extensions: []
30
+ extra_rdoc_files: []
31
+ files:
32
+ - lib/jekyll-exiftag.rb
33
+ homepage: http://github.com/benib/jekyll-exiftag
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project:
53
+ rubygems_version: 1.8.11
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: jekyll-exiftag provides exif data in jekyll sites
57
+ test_files: []