Sha256: 6a8696367673662d5ff3aaf5b33f5736965b841bed04606149c2dd8d279bafd6

Contents?: true

Size: 1.31 KB

Versions: 69

Compression:

Stored size: 1.31 KB

Contents

class Sidenav
  attr_reader :request_path, :navigation, :product, :code_language, :locale

  # rubocop:disable Metrics/ParameterLists
  def initialize(request_path:, navigation:, product:, locale: nil, code_language: nil, namespace: nil)
    @request_path  = request_path
    @navigation    = navigation
    @product       = product
    @locale        = locale
    @code_language = code_language
    @namespace     = namespace

    after_initialize!
  end
  # rubocop:enable Metrics/ParameterLists

  def nav_items
    @nav_items ||= items.map do |item|
      SidenavItem.new(folder: item, sidenav: self)
    end
  end

  def namespace
    @namespace.presence || 'documentation'
  end

  def documentation?
    namespace == 'documentation'
  end

  private

  def after_initialize!
    if @namespace.present?
      @path = "app/views/#{@namespace}"
    else
      @path = "#{Rails.configuration.docs_base_path}/_documentation"
    end
  end

  def children
    @children ||= resolver.items
  end

  def items
    if @namespace.present?
      [{
        title: @namespace,
        path: @path.gsub('app/views', ''),
        children: children,
      }]
    else
      children
    end
  end

  def resolver
    @resolver ||= SidenavResolver.new(
      path: @path,
      namespace: @namespace,
      language: I18n.locale
    )
  end
end

Version data entries

69 entries across 69 versions & 1 rubygems

Version Path
station-0.4.1 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.4.0 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.3.2 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.3.1 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.3.0 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.2.6 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.2.5 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.2.4 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.2.3 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.2.2 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.2.1 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.2.0 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.1.8 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.1.7 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.1.6 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.1.5 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.1.4 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.1.3 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.1.2 lib/nexmo_developer/app/presenters/sidenav.rb
station-0.1.1 lib/nexmo_developer/app/presenters/sidenav.rb