Class: Pulse::Layout

Inherits:
Component
  • Object
show all
Defined in:
app/components/pulse/layout.rb

Overview

Renders a two-column page layout

Defined Under Namespace

Classes: Main, Sidebar

Constant Summary collapse

FIRST_IN_SOURCE_DEFAULT =
:sidebar
FIRST_IN_SOURCE_OPTIONS =
[FIRST_IN_SOURCE_DEFAULT, :main].freeze
GUTTER_DEFAULT =
:default
GUTTER_MAPPINGS =
{
  # :none => "Layout--gutter-none",
  # :condensed => "Layout--gutter-condensed",
  # :spacious => "Layout--gutter-spacious",
  GUTTER_DEFAULT => ''
}.freeze
GUTTER_OPTIONS =
GUTTER_MAPPINGS.keys.freeze
:default
{
  SIDEBAR_WIDTH_DEFAULT => ''
  # :narrow => "Layout--sidebar-narrow",
  # :wide => "Layout--sidebar-wide"
}.freeze
SIDEBAR_WIDTH_MAPPINGS.keys.freeze

Instance Method Summary collapse

Constructor Details

#initialize(first_in_source: FIRST_IN_SOURCE_DEFAULT, gutter: :default, **system_arguments) ⇒ Layout

Returns a new instance of Layout.

Parameters:

  • first_in_source (Symbol) (defaults to: FIRST_IN_SOURCE_DEFAULT)

    Which element to render first in the HTML. This will change the keyboard navigation order. <%= one_of(Layout::FIRST_IN_SOURCE_OPTIONS) %>

  • gutter (Symbol) (defaults to: :default)

    The amount of space between the main section and the sidebar. <%= one_of(Layout::GUTTER_OPTIONS) %>

  • system_arguments (Hash)

    <%= link_to_system_arguments_docs %>



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'app/components/pulse/layout.rb', line 53

def initialize(first_in_source: FIRST_IN_SOURCE_DEFAULT, gutter: :default,
               **system_arguments)
  @first_in_source = fetch_or_fallback(
    FIRST_IN_SOURCE_OPTIONS,
    first_in_source,
    FIRST_IN_SOURCE_OPTIONS
  )

  @system_arguments = system_arguments
  @system_arguments[:tag] = :div
  @system_arguments[:classes] = merge_classes(
    'pulse-grid pulse-grid-flow-col',
    'pulse-grid-cols-[auto_0_minmax(0,calc(100%_-_var(--pulse-layout' \
    '-sidebar-width)_-_var(--pulse-layout-gutter)))]',
    'pulse-gap-[var(--pulse-layout-gutter)]',
    GUTTER_MAPPINGS[fetch_or_fallback(GUTTER_OPTIONS, gutter,
                                      GUTTER_DEFAULT)],
    system_arguments[:classes]
  )
end

Instance Method Details

#render?Boolean

Returns:

  • (Boolean)


74
75
76
# File 'app/components/pulse/layout.rb', line 74

def render?
  main? && sidebar?
end