Class: Bootstrap5RailsExtensions::CardHelper::CardBuilder
- Inherits:
-
Object
- Object
- Bootstrap5RailsExtensions::CardHelper::CardBuilder
- Defined in:
- app/helpers/bootstrap5_rails_extensions/card_helper.rb
Instance Method Summary collapse
- #body(content = nil, **options, &block) ⇒ Object
- #footer(content = nil, **options, &block) ⇒ Object
- #header(content = nil, **options, &block) ⇒ Object
-
#initialize(view_context) ⇒ CardBuilder
constructor
A new instance of CardBuilder.
- #render ⇒ Object
Constructor Details
#initialize(view_context) ⇒ CardBuilder
Returns a new instance of CardBuilder.
41 42 43 44 45 46 47 48 49 |
# File 'app/helpers/bootstrap5_rails_extensions/card_helper.rb', line 41 def initialize(view_context) @view = view_context @header_html = nil = {} @body_fragments = [] = {} = nil = {} end |
Instance Method Details
#body(content = nil, **options, &block) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'app/helpers/bootstrap5_rails_extensions/card_helper.rb', line 60 def body(content = nil, **, &block) html = extract_content(content, &block) raise ArgumentError, "カード本文が空です" if blank_html?(html) @body_fragments << html css_class = extract_css_class!() if css_class.present? if [:class].present? && [:class] != css_class raise ArgumentError, "カード本文のクラス指定は一度だけ行ってください" end [:class] = css_class end self end |
#footer(content = nil, **options, &block) ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'app/helpers/bootstrap5_rails_extensions/card_helper.rb', line 75 def (content = nil, **, &block) raise ArgumentError, "カードフッターは一度だけ定義できます" if html = extract_content(content, &block) = html unless blank_html?(html) css_class = extract_css_class!() [:class] = css_class if css_class.present? self end |
#header(content = nil, **options, &block) ⇒ Object
51 52 53 54 55 56 57 58 |
# File 'app/helpers/bootstrap5_rails_extensions/card_helper.rb', line 51 def header(content = nil, **, &block) raise ArgumentError, "カードヘッダーは一度だけ定義できます" if @header_html @header_html = extract_content(content, &block) css_class = extract_css_class!() [:class] = css_class if css_class.present? self end |
#render ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'app/helpers/bootstrap5_rails_extensions/card_helper.rb', line 85 def render raise ArgumentError, "カード本文を定義してください" if @body_fragments.empty? fragments = [] fragments << wrap_section(@header_html, default_header_class, [:class]) if @header_html fragments << wrap_section(@view.safe_join(@body_fragments), default_body_class, [:class]) fragments << wrap_section(, , [:class]) if @view.safe_join(fragments.compact) end |