Skip to content

Commit

Permalink
Split up code blocks for multi-file examples [ci-skip]
Browse files Browse the repository at this point in the history
RDoc treats consecutive indented lines as a single code block.  For code
examples that span multiple files / languages, this confuses the syntax
highlighter and makes the examples harder to read.  Unfortunately, RDoc
doesn't provide syntax to prevent this, and it ignores multiple
consecutive blank lines.  However, by inserting an empty tag such as
`<code></code>`, we can force RDoc to recognize separate code blocks.

(cherry picked from commit d1411b2)
  • Loading branch information
jonathanhefner committed Jan 7, 2024
1 parent bc77495 commit a8b302c
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 4 deletions.
4 changes: 4 additions & 0 deletions actionview/lib/action_view/helpers/form_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,8 @@ def fields(scope = nil, model: nil, **options, &block)
# post:
# cost: "Total cost"
#
# <code></code>
#
# label(:post, :cost)
# # => <label for="post_cost">Total cost</label>
#
Expand Down Expand Up @@ -2358,6 +2360,8 @@ def fields(scope = nil, model: nil, **options, &block)
# post:
# cost: "Total cost"
#
# <code></code>
#
# label(:cost)
# # => <label for="post_cost">Total cost</label>
#
Expand Down
4 changes: 4 additions & 0 deletions actionview/lib/action_view/helpers/sanitize_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ module SanitizeHelper
# end
# end
#
# <code></code>
#
# <%= sanitize @comment.body, scrubber: CommentScrubber.new %>
#
# See {Rails HTML Sanitizer}[https://github.com/rails/rails-html-sanitizer] for
Expand All @@ -71,6 +73,8 @@ module SanitizeHelper
# node.remove if node.name == 'script'
# end
#
# <code></code>
#
# <%= sanitize @comment.body, scrubber: scrubber %>
#
# See {Loofah's documentation}[https://github.com/flavorjones/loofah] for more
Expand Down
16 changes: 16 additions & 0 deletions activerecord/lib/active_record/fixtures.rb
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,8 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError # :nodoc:
# name: Reginald the Pirate
# monkey_id: 1
#
# <code></code>
#
# ### in monkeys.yml
#
# george:
Expand All @@ -285,6 +287,8 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError # :nodoc:
# name: Reginald the Pirate
# monkey: george
#
# <code></code>
#
# ### in monkeys.yml
#
# george:
Expand All @@ -306,6 +310,8 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError # :nodoc:
#
# belongs_to :eater, polymorphic: true
#
# <code></code>
#
# ### in fruits.yml
#
# apple:
Expand All @@ -331,6 +337,8 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError # :nodoc:
# id: 1
# name: George the Monkey
#
# <code></code>
#
# ### in fruits.yml
#
# apple:
Expand All @@ -345,6 +353,8 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError # :nodoc:
# id: 3
# name: grape
#
# <code></code>
#
# ### in fruits_monkeys.yml
#
# apple_george:
Expand All @@ -368,6 +378,8 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError # :nodoc:
# name: George the Monkey
# fruits: apple, orange, grape
#
# <code></code>
#
# ### in fruits.yml
#
# apple:
Expand Down Expand Up @@ -467,6 +479,8 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError # :nodoc:
# belongs_to :author
# end
#
# <code></code>
#
# # books.yml
# alices_adventure_in_wonderland:
# author_id: <%= ActiveRecord::FixtureSet.identify(:lewis_carroll) %>
Expand All @@ -482,6 +496,8 @@ class FixtureClassNotFound < ActiveRecord::ActiveRecordError # :nodoc:
# belongs_to :book, query_constraints: [:author_id, :book_id]
# end
#
# <code></code>
#
# # book_orders.yml
# alices_adventure_in_wonderland_in_books:
# author: lewis_carroll
Expand Down
4 changes: 4 additions & 0 deletions activestorage/lib/active_storage/fixture_set.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ module ActiveStorage
# has_one_attached :thumbnail
# end
#
# <code></code>
#
# # fixtures/active_storage/blobs.yml
# first_thumbnail_blob: <%= ActiveStorage::FixtureSet.blob filename: "first.png" %>
#
# <code></code>
#
# # fixtures/active_storage/attachments.yml
# first_thumbnail_attachment:
# name: thumbnail
Expand Down
11 changes: 7 additions & 4 deletions railties/lib/rails/application.rb
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,7 @@ def deprecators
end

# Convenience for loading config/foo.yml for the current \Rails env.
#
# Examples:
# Example:
#
# # config/exception_notification.yml:
# production:
Expand All @@ -246,13 +245,15 @@ def deprecators
# url: http://localhost:3001
# namespace: my_app_development
#
# <code></code>
#
# # config/environments/production.rb
# Rails.application.configure do
# config.middleware.use ExceptionNotifier, config_for(:exception_notification)
# end
#
# # You can also store configurations in a shared section which will be
# # merged with the environment configuration
# You can also store configurations in a shared section which will be merged
# with the environment configuration
#
# # config/example.yml
# shared:
Expand All @@ -265,6 +266,8 @@ def deprecators
# bar:
# qux: 2
#
# <code></code>
#
# # development environment
# Rails.application.config_for(:example)[:foo][:bar]
# # => { baz: 1, qux: 2 }
Expand Down

0 comments on commit a8b302c

Please sign in to comment.