Sha256: 31be173bfa4ebd23d78184a7871a83bb577162edd6e7dab407a9fcbe66e65e4e

Contents?: true

Size: 668 Bytes

Versions: 1

Compression:

Stored size: 668 Bytes

Contents

module Buoys
  class Renderer
    def initialize(context, key, *args)
      @context, @key, @args = context, key, *args
      Buoys::Loader.load_buoys_files if Buoys::Loader.buoys.keys.empty?
    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 = []

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

      links
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
buoys-0.1.0 lib/buoys/renderer.rb