Class: JekyllGooglePhotos::Tag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-google-photos/tag.rb

Instance Method Summary collapse

Constructor Details

#initialize(tagName, args, tokens) ⇒ Tag

Returns a new instance of Tag.



10
11
12
13
14
15
# File 'lib/jekyll-google-photos/tag.rb', line 10

def initialize(tagName, args, tokens)
  super
  args = args.split(" ")
  @albumUrls = args[0]
  @albumSettings = args[1]
end

Instance Method Details

#addImages(albumSettings) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
# File 'lib/jekyll-google-photos/tag.rb', line 63

def addImages(albumSettings)
  sp = %Q{<div class="pa-gallery-player-widget" style="width:#{albumSettings["frame_width"]}; height:#{albumSettings["frame_height"]}; display:none;"
      data-title="#{albumSettings["title"]}"
      data-delay="#{albumSettings["delay"]}">
  }
  for x in @imgLinks
    sp += %Q{<object data="#{x}=w#{albumSettings["image_width"]}-h#{albumSettings["image_height"]}"></object>}
  end
  sp += %Q{</div>}
  return sp
end

#createDOM(albumSettings) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/jekyll-google-photos/tag.rb', line 43

def createDOM(albumSettings)
  sp = "<script>"
  sp += "googlePhotos = {};"
  sp += URLsInJSON()
  sp += "</script>"
  #puts albumSettings
  ##if(albumSettings != "none")
    ##sp += JekyllGooglePhotos::PublicalbumJS()
    ##sp += addImages(albumSettings)
  ##end
  return sp
end

#flexbinCSSObject



30
31
32
33
# File 'lib/jekyll-google-photos/tag.rb', line 30

def flexbinCSS()
  elem = JekyllGooglePhotos::FlexbinCSS()
  return elem
end


17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll-google-photos/tag.rb', line 17

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) ⇒ Object



56
57
58
59
60
61
# File 'lib/jekyll-google-photos/tag.rb', line 56

def imageObject(url)
  sp = %Q{
    <object data="#{url}=w#{@maxWidth}"></object>
  }
  return sp
end

#render(context) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/jekyll-google-photos/tag.rb', line 75

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)
      #puts imageLinks[0]
      for link in imageLinks
        @imgLinks.push(link)
      end
  end 
  if @albumSettings != "none"
    albumSettings = context[@albumSettings.strip]
  end
  createDOM(albumSettings)
end

#URLsInJSONObject



35
36
37
38
39
40
41
# File 'lib/jekyll-google-photos/tag.rb', line 35

def URLsInJSON()
  sp = 'googlePhotos.urls = ["'
  newImgLinks = @imgLinks.uniq.join('", "')
  sp += "#{newImgLinks}"
  sp += '"];'
  return sp
end