class JekyllGooglePhotos::Tag
Public Class Methods
new(tagName, args, tokens)
click to toggle source
Calls superclass method
# File lib/jekyll-google-photos/tag.rb, line 8 def initialize(tagName, args, tokens) super args = args.split(" ") @albumUrls = args[0] @albumSettings = args[1] end
Public Instance Methods
URLsInJSON()
click to toggle source
# File lib/jekyll-google-photos/tag.rb, line 28 def URLsInJSON() sp = 'googlePhotos.urls = ["' newImgLinks = @imgLinks.uniq.join('", "') sp += "#{newImgLinks}" sp += '"];' return sp end
createDOM(albumSettings)
click to toggle source
# File lib/jekyll-google-photos/tag.rb, line 36 def createDOM(albumSettings) sp = "<script>" sp += "googlePhotos = {};" sp += URLsInJSON() sp += "</script>" return sp end
getImageLinks(url)
click to toggle source
# File lib/jekyll-google-photos/tag.rb, line 15 def getImageLinks(url) doc = Nokogiri::HTML(open(url.strip).read) scripts = doc.xpath("//script") jsonString = "" for x in scripts do if x.inner_html.match(/initDataCallback\(/) jsonString = x.inner_html jsonString = jsonString.scan(/\[\"(http.*googleusercontent.com\/[^((?!\/a\/).)*$].*)\"/) end end return jsonString end
imageObject(url)
click to toggle source
# File lib/jekyll-google-photos/tag.rb, line 44 def imageObject(url) sp = %Q{ <object data="#{url}=w#{@maxWidth}"></object> } return sp end
render(context)
click to toggle source
# File lib/jekyll-google-photos/tag.rb, line 51 def render(context) @imgLinks = [] if @albumUrls[/https?:\/\/[\S]+/] albumUrls = [].push(@albumUrls) else albumUrls = context[@albumUrls.strip] if not albumUrls.instance_of? Array albumUrls = [].push(context[@albumUrls.strip]) end end for albumUrl in albumUrls imageLinks = getImageLinks(albumUrl) for link in imageLinks @imgLinks.push(link) end end if @albumSettings != "none" albumSettings = context[@albumSettings.strip] end createDOM(albumSettings) end