Components
Code block
Source snippets with copying, optional highlighting and collapsible long content.
Usage
After the one-time setup, call the helper directly from ERB. No component import is needed.
<%= lc_code_block "def hello(name)\n puts name\nend", id: "my-component-ruby", language: :ruby, label: "Ruby greeting", class: "w-full" %>
Examples
Plain source
def hello(name)
puts name
end
<%= lc_code_block "def hello(name)\n puts name\nend", id: "example-0-ruby", language: :ruby, label: "Ruby greeting", class: "w-full" %>
With a filename
app/helpers/greeting_helper.rb
def hello(name)
puts name
end
<%= lc_code_block "def hello(name)\n puts name\nend", id: "example-1-file", language: :ruby, title: "app/helpers/greeting_helper.rb", label: "Greeting helper", class: "w-full" %>
Collapsible source
puts 1
puts 2
puts 3
puts 4
puts 5
puts 6
puts 7
puts 8
puts 9
puts 10
puts 11
puts 12
puts 13
puts 14
puts 15
<%= lc_code_block (1..15).map { |number| "puts #{number}" }.join("\n"), id: "example-2-long", language: :ruby, label: "Long Ruby snippet", max_lines: 5, class: "w-full" %>
API reference
Helpers render semantic HTML and include their interaction wiring. Pass native attributes through class:, data:, aria: and the usual Rails options. Blocks use captured ERB content.
lc_code_block
lc_code_block(source, id:, language: nil, title: nil, label: nil, max_lines: 10, **attributes, &block)
| Input | Default | Values |
|---|---|---|
| source | Required | — |
| id | Required | — |
| language | nil | — |
| title | nil | — |
| label | nil | Accessible name, visible where applicable |
| max_lines | 10 | — |
| attributes | {} | Native HTML attributes; class:, data: and aria: merge with defaults |
| block | Captured block | Captured Rails ERB content |
Styling and extension
Use class: to merge utilities, native attributes for application behavior, and the theming guide for the shared palette. For custom markup, the advanced class helpers expose the same styles, including glass surfaces and class merging.