class Jekyll::RenderLive2D

Public Class Methods

new(tag_name, text, tokens) click to toggle source
Calls superclass method
# File lib/live2d.rb, line 5
def initialize(tag_name, text, tokens)
  @config = Jekyll.configuration({})['live2d']
  if text.empty?
    if @config
      @width = @config['style']['width']
      @height = @config['style']['height']
      @position = @config['style']['position']
      @top = @config['style']['top']
      @bottom = @config['style']['bottom']
      @left = @config['style']['left']
      @right = @config['style']['right']
    else
      @width = '150'
      @height = '150'
      @position = 'fixed'
      @top = '100'
      @bottom = '0'
      @left = '100'
      @right = '0'
    end
  else
    @width = text.split(",").first.strip
    @height = text.split(",").last.strip
  end
  super
end

Public Instance Methods

render(context) click to toggle source
# File lib/live2d.rb, line 32
    def render(context)
      <<~HEREDOC
        <canvas
        id="glcanvas"
        style="
        width: #{@width}px;
        height: #{@height}px;
        position: fixed;
        top: #{@top};
        bottom: #{@bottom};
        left: #{@left};
        right: #{@right};
        "
        >
        </canvas>
        <script type="text/javascript" src="/assets/javascripts/live2d.min.js"></script>
        <script type="text/javascript" src="/assets/javascripts/Simple.js"></script>
        <script type="text/javascript">
          Simple();
        </script>
      HEREDOC
    end