Class: JekyllBookshop::ComponentBrowserTag

Inherits:
Liquid::Tag
  • Object
show all
Defined in:
lib/jekyll-bookshop/tags/component-browser-tag.rb

Instance Method Summary collapse

Constructor Details

#initialize(tag_name, markup, tokens) ⇒ ComponentBrowserTag

Returns a new instance of ComponentBrowserTag.



5
6
7
8
# File 'lib/jekyll-bookshop/tags/component-browser-tag.rb', line 5

def initialize(tag_name, markup, tokens)
  super
  @port = markup.strip
end

Instance Method Details

#render(context) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/jekyll-bookshop/tags/component-browser-tag.rb', line 10

def render(context)
  local_port = 30775;

  if @port.length > 0
    is_int = Integer(@port) rescue false
    unless is_int
      STDERR.puts "bookshop_component_browser expected either no argument, or an integer for the local port number used when running @bookshop/browser."
      exit 1
    end
    local_port = @port
  end

  "<div data-bookshop-browser=\"\"></div>
<script src=\"http://localhost:#{ local_port }/bookshop.js\"></script>
<script>
  window.bookshopBrowser = new window.BookshopBrowser({globals: []});
  window.bookshopBrowser.render();
</script>"
end