Class: JekyllBookshop::BrowserTag
- Inherits:
-
Liquid::Tag
- Object
- Liquid::Tag
- JekyllBookshop::BrowserTag
- Defined in:
- lib/jekyll-bookshop/tags/browser-tag.rb
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(tag_name, markup, tokens) ⇒ BrowserTag
constructor
A new instance of BrowserTag.
- #render(context) ⇒ Object
Constructor Details
#initialize(tag_name, markup, tokens) ⇒ BrowserTag
Returns a new instance of BrowserTag.
5 6 7 8 |
# File 'lib/jekyll-bookshop/tags/browser-tag.rb', line 5 def initialize(tag_name, markup, tokens) super @host = markup.strip end |
Class Method Details
.transformHostString(host) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/jekyll-bookshop/tags/browser-tag.rb', line 10 def self.transformHostString(host) case when host =~ %r!^:\d+$! "http://localhost#{host}/bookshop.js" when host =~ %r!^\d+$! "http://localhost:#{host}/bookshop.js" when host =~ %r!^localhost:\d+$! "http://#{host}/bookshop.js" when host =~ %r!^/|https?://! host else "//#{host}" end end |
Instance Method Details
#render(context) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/jekyll-bookshop/tags/browser-tag.rb', line 25 def render(context) return unless @host host = BrowserTag.transformHostString(@host) site = context.registers[:site] page = context.registers[:page] site.data["_bookshop_data_pages"] ||= [] unless site.data["_bookshop_data_pages"].include?(page["url"]) site.data["_bookshop_data_pages"].push(page["url"]) end "<div data-bookshop-browser></div> <script>window.bookshop_browser_site_data = null;</script> <script src=\"#{host}\"></script> <script> window.bookshopBrowser = new window.BookshopBrowser({ globals: [window.bookshop_browser_site_data] }); window.bookshopBrowser.render(); </script>" end |