Sha256: 565464cc6b58fa8a2e4ed05d06236e0c1341af983fbe66f98f66fabb7fb125f7

Contents?: true

Size: 878 Bytes

Versions: 12

Compression:

Stored size: 878 Bytes

Contents

module Lookbook
  class PageSection < Page
    attr_accessor :parent

    def initialize(file_path)
      @file_path = Pathname(file_path)
      @parent = nil
      super
    end

    def name
      Utils.name(name_parts[:name])
    end

    def lookup_path
      directory = if relative_directory_path.present? && !relative_directory_path.to_s.start_with?(".")
        relative_directory_path
      end

      path = PathUtils.to_path(directory, name_parts[:parent_name])
      PathUtils.to_lookup_path(path)
    end

    def landing?
      false
    end

    def url_path
      nil
    end

    alias_method :page, :parent

    protected

    def name_parts
      return @_name_parts if @_name_parts

      matches = file_name(true).match(/(?<parent_name>.*)\[(?<name>.*)\]/)
      @_name_parts ||= {name: matches[:name], parent_name: matches[:parent_name]}
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
lookbook-1.5.5 lib/lookbook/entities/page_section.rb
lookbook-1.5.4 lib/lookbook/entities/page_section.rb
lookbook-1.5.3 lib/lookbook/entities/page_section.rb
lookbook-1.5.2 lib/lookbook/entities/page_section.rb
lookbook-1.5.1 lib/lookbook/entities/page_section.rb
lookbook-1.5.0 lib/lookbook/entities/page_section.rb
lookbook-1.4.5 lib/lookbook/entities/page_section.rb
lookbook-1.4.4 lib/lookbook/entities/page_section.rb
lookbook-1.4.3 lib/lookbook/entities/page_section.rb
lookbook-1.4.2 lib/lookbook/entities/page_section.rb
lookbook-1.4.1 lib/lookbook/entities/page_section.rb
lookbook-1.4.0 lib/lookbook/entities/page_section.rb