Class: BulmaPhlex::Title

Inherits:
Base
  • Object
show all
Defined in:
lib/bulma_phlex/title.rb

Overview

Renders a [Bulma title element](bulma.io/documentation/elements/title/) with an optional subtitle.

Supports size (1–6) for both the title and subtitle, an optional subtitle string, and a spaced layout option to increase the gap between the title and subtitle.

## Example

render BulmaPhlex::Title.new("Hello World")
render BulmaPhlex::Title.new("Dr. Strangelove", size: 2, subtitle: "Or: How I Learned to Stop Worrying and
  Love the Bomb")

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, size: nil, subtitle: nil, subtitle_size: nil, spaced: false) ⇒ Title

Returns a new instance of Title.



25
26
27
28
29
30
31
# File 'lib/bulma_phlex/title.rb', line 25

def initialize(text, size: nil, subtitle: nil, subtitle_size: nil, spaced: false)
  @text = text
  @size = size
  @subtitle = subtitle
  @subtitle_size = subtitle_size
  @spaced = spaced
end

Class Method Details

.new(text, size: nil, subtitle: nil, subtitle_size: nil, spaced: false) ⇒ Object

Parameters

  • ‘text` — The main title text to display

  • ‘size` — An integer from 1 to 6 indicating the title size; corresponds to Bulma’s ‘is-<size>` classes

  • ‘subtitle` — The subtitle text to display below the main title

  • ‘subtitle_size` — An integer from 1 to 6 indicating the subtitle size; defaults to `size + 2` if `size` is set

  • ‘spaced` — If `true`, adds the `is-spaced` class to the title



21
22
23
# File 'lib/bulma_phlex/title.rb', line 21

def self.new(text, size: nil, subtitle: nil, subtitle_size: nil, spaced: false)
  super
end

Instance Method Details

#view_templateObject



33
34
35
36
# File 'lib/bulma_phlex/title.rb', line 33

def view_template
  h1(class: title_classes) { @text }
  h2(class: subtitle_classes) { @subtitle } if @subtitle
end