code_block(
source = nil, # or the block's text
language: :plaintext, # any Rouge lexer: :ruby, :erb, :javascript, :css, :json, :sql…
title: nil,
copy: true,
**html
)
Highlighting runs on the server with Rouge, so it works without JavaScript and supports 200+ languages (ruby, erb, javascript, html, css, json, yaml, sql, shell…). The colours are Trail UI's code-* tokens. Pass the source as the first argument or as the block's text; the title defaults to the language name.
class Quest < ApplicationRecord
belongs_to :project
has_many :missions, dependent: :destroy
scope :active, -> { where(completed_at: nil, abandoned_at: nil) }
def progress
missions.completed.count.fdiv(missions.count) # 0.0..1.0
end
end
{ "quest": "Lançar o canal", "missions": 13, "continuous": false }
bin/rails server -p 3000
<%= stack(gap: "12px") do %>
<%= code_block <<~RUBY, language: :ruby, title: "app/models/quest.rb" %>
class Quest < ApplicationRecord
belongs_to :project
has_many :missions, dependent: :destroy
scope :active, -> { where(completed_at: nil, abandoned_at: nil) }
def progress
missions.completed.count.fdiv(missions.count) # 0.0..1.0
end
end
RUBY
<%= code_block %({ "quest": "Lançar o canal", "missions": 13, "continuous": false }), language: :json %>
<%= code_block "bin/rails server -p 3000", language: :shell, copy: false %>
<% end %>
Options
| Option | What it does |
|---|---|
language | Rouge lexer name or alias; unknown names fall back to plain text |
title | Text on the bar above the code (a file name, for example) |
copy | Show the copy button (default true) |