From 7b9a0ba5a8ab9ec1ca31bec4d445621647a97bf0 Mon Sep 17 00:00:00 2001 From: Diego Toral Date: Wed, 7 Feb 2024 11:23:20 -0800 Subject: [PATCH] Add support for content as first argument for SubtitleComponent --- app/components/bulma/subtitle_component.rb | 6 +++++- spec/components/bulma/subtitle_component_spec.rb | 6 ++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/app/components/bulma/subtitle_component.rb b/app/components/bulma/subtitle_component.rb index 0b97961..37bb6f3 100644 --- a/app/components/bulma/subtitle_component.rb +++ b/app/components/bulma/subtitle_component.rb @@ -2,8 +2,12 @@ module Bulma class SubtitleComponent < Component + def initialize(text = nil) + @text = text + end + def call - content_tag :p, nil, class: "subtitle" + content_tag :p, @text, class: "subtitle" end end end diff --git a/spec/components/bulma/subtitle_component_spec.rb b/spec/components/bulma/subtitle_component_spec.rb index 0186af0..db189a4 100644 --- a/spec/components/bulma/subtitle_component_spec.rb +++ b/spec/components/bulma/subtitle_component_spec.rb @@ -6,4 +6,10 @@ expect(page).to have_css "p.subtitle" end + + it "renders content provided as first argument" do + render_inline(described_class.new("Subtitle")) + + expect(page).to have_content "Subtitle" + end end