Class: JekyllGooglePhotos::Tag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- JekyllGooglePhotos::Tag
- Defined in:
- lib/jekyll-google-photos/tag.rb
Instance Method Summary collapse
- #addImages ⇒ Object
- #createDOM ⇒ Object
- #flexbinCSS ⇒ Object
- #getImageLinks(url) ⇒ Object
-
#initialize(tagName, args, tokens) ⇒ Tag
constructor
A new instance of Tag.
- #render(context) ⇒ Object
- #URLsInJSON ⇒ Object
Constructor Details
#initialize(tagName, args, tokens) ⇒ Tag
Returns a new instance of Tag.
9 10 11 12 13 14 |
# File 'lib/jekyll-google-photos/tag.rb', line 9 def initialize(tagName, args, tokens) super args = args.split(" ") @albumUrls = args[0] @maxWidth = args[1] end |
Instance Method Details
#addImages ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/jekyll-google-photos/tag.rb', line 58 def addImages() sp = %Q{<div class="flexbin">} idx = 0 for x in @imgLinks link = x + "=w#{@maxWidth}" sp += %Q{ <div onclick="showSlides(#{idx});" class="slideImgs"> <img src="#{link}" /> </div> } idx += 1 end sp += %Q{</div>} return sp end |
#createDOM ⇒ Object
44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/jekyll-google-photos/tag.rb', line 44 def createDOM() sp = "<script>" sp += "googlePhotos = {};" sp += URLsInJSON() sp += "</script>" if(@maxWidth != "none") sp += %Q{<style>} sp += flexbinCSS() sp += %Q{</style>} sp += addImages() end return sp end |
#flexbinCSS ⇒ Object
30 31 32 33 |
# File 'lib/jekyll-google-photos/tag.rb', line 30 def flexbinCSS() elem = JekyllGooglePhotos::FlexbinCSS() return elem end |
#getImageLinks(url) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/jekyll-google-photos/tag.rb', line 16 def getImageLinks(url) doc = Nokogiri::HTML(open(url.strip).read) scripts = doc.xpath("//script") for x in scripts do if x.inner_html.match(/initDataCallback\(/) jsonString = x.inner_html jsonString = jsonString.sub(/.*function\(\)\{return /,"") jsonString["\n}});"] = "" end end json = JSON.parse(jsonString) return json[1] end |
#render(context) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/jekyll-google-photos/tag.rb', line 74 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[1][0]) end end createDOM() end |
#URLsInJSON ⇒ Object
35 36 37 38 39 40 41 42 |
# File 'lib/jekyll-google-photos/tag.rb', line 35 def URLsInJSON() sp = "googlePhotos.urls = [" for x in @imgLinks sp += "\"#{x}\"," end sp += "];" return sp end |