Class: Jekyll::ExifTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- Jekyll::ExifTag
- Defined in:
- lib/jekyll-exiftag.rb
Instance Method Summary collapse
-
#initialize(tag_name, params, token) ⇒ ExifTag
constructor
A new instance of ExifTag.
- #render(context) ⇒ Object
- #split_params(params) ⇒ Object
Constructor Details
#initialize(tag_name, params, token) ⇒ ExifTag
Returns a new instance of ExifTag.
31 32 33 34 |
# File 'lib/jekyll-exiftag.rb', line 31 def initialize(tag_name, params, token) super @args = self.split_params(params) end |
Instance Method Details
#render(context) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jekyll-exiftag.rb', line 36 def render(context) #abort context.registers[:site].config['source'].inspect sources = Array.new(context.registers[:site].config['exiftag']['sources']) # first param is the exif tag tag = @args[0] # if a second parameter is passed, use it as a possible img source if @args.count > 1 sources.unshift(@args[1]) end # the image can be passed as the third parameter if @args.count > 2 img = @args[2] # or be defined in the YAML Front Matter like img: <file> else img = context.environments.first["page"]["img"] end # first check if the given img is already the path if File.exist?(img) file_name = img else # then start testing with the sources from _config.yml begin source = sources.shift file_name = File.join(context.registers[:site].config['source'], source, img) end until File.exist?(file_name) or sources.count == 0 end # try it and return empty string on failure begin exif = EXIFR::JPEG::new(file_name) return tag.split('.').inject(exif){|o,m| o.send(m)} rescue "" end end |
#split_params(params) ⇒ Object
74 75 76 |
# File 'lib/jekyll-exiftag.rb', line 74 def split_params(params) params.split(",").map(&:strip) end |