Sha256: 2228e369186c2c10b10ceea1d1c6a95d18c5baff3da47d9e6d10b0172c1e3a76

Contents?: true

Size: 719 Bytes

Versions: 6

Compression:

Stored size: 719 Bytes

Contents

# frozen_string_literal: true

module Buoys
  class Renderer
    def initialize(context, key, *args)
      @context = context
      @key = key
      @args = args

      Buoys::Loader.load_buoys_files
    end

    def render
      return [] unless @key

      buoy = Buoys::Buoy.new(@context, @key, *@args)
      build_links(buoy)
    end

    private

    def build_links(buoy)
      links = buoy.links.dup

      links.unshift(*collect_previous_links(buoy))
      links.last.mark_as_current!

      links
    end

    def collect_previous_links(buoy)
      links = []

      buoy = buoy.previous
      while buoy
        links.unshift(*buoy.links)
        buoy = buoy.previous
      end

      links
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
buoys-2.1.0 lib/buoys/renderer.rb
buoys-2.0.2 lib/buoys/renderer.rb
buoys-2.0.1 lib/buoys/renderer.rb
buoys-2.0.0 lib/buoys/renderer.rb
buoys-1.1.0 lib/buoys/renderer.rb
buoys-1.0.0 lib/buoys/renderer.rb