Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 12 additions & 4 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@ Rake::TestTask.new(:engine_test) do |t|
t.test_files = FileList["test/test_engine/**/*_test.rb"]
end

Rake::TestTask.new(:docs_test) do |t|
t.libs << "test"
t.libs << "lib"
t.test_files = FileList["test/docs/*_test.rb"]
end

begin
require "rspec/core/rake_task"
RSpec::Core::RakeTask.new(:spec)
Expand Down Expand Up @@ -100,7 +106,7 @@ namespace :docs do

error_keys = registry.keys.select { |key| key.to_s.include?("Error::MESSAGE") }.map(&:to_s)

docs = ActionController::Base.new.render_to_string(
docs = ActionController::Base.renderer.render(
ViewComponent::DocsBuilderComponent.new(
sections: [
ViewComponent::DocsBuilderComponent::Section.new(
Expand Down Expand Up @@ -128,10 +134,12 @@ namespace :docs do
)
).chomp

File.open("docs/api.md", "w") do |f|
f.puts(docs)
if ENV["RAILS_ENV"] != "test"
File.open("docs/api.md", "w") do |f|
f.puts(docs)
end
end
end
end

task default: [:test, :engine_test, :spec]
task default: [:docs_test, :test, :engine_test, :spec]
4 changes: 4 additions & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ nav_order: 6

## main

* Fix generation of ViewComponent documentation that was broken due to HTML safety issues.

*Simon Fish*

* Add documentation on how ViewComponent works.

*Joel Hawksley*
Expand Down
4 changes: 2 additions & 2 deletions lib/view_component/docs_builder_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ nav_order: 3
## <%= section.heading %>

<% section.methods.each do |method| %>
### <%== render ViewComponent::DocsBuilderComponent::MethodDoc.new(method, section.show_types) %>
### <%= render ViewComponent::DocsBuilderComponent::MethodDoc.new(method, section.show_types) %>

<% end %>
<% section.error_klasses.each do |error_klass| %>
### <%== render ViewComponent::DocsBuilderComponent::ErrorKlassDoc.new(error_klass, section.show_types) %>
### <%= render ViewComponent::DocsBuilderComponent::ErrorKlassDoc.new(error_klass, section.show_types) %>

<% end %>
<% end %>
6 changes: 3 additions & 3 deletions lib/view_component/docs_builder_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def error_message
end

def call
<<~DOCS.chomp
<<~DOCS.chomp.html_safe
`#{klass_name}`

#{error_message}
Expand Down Expand Up @@ -67,15 +67,15 @@ def deprecation_text
end

def docstring_and_deprecation_text
<<~DOCS.strip
<<~DOCS.strip.html_safe
#{docstring}

#{"_#{deprecation_text}_" if deprecated?}
DOCS
end

def call
<<~DOCS.chomp
<<~DOCS.chomp.html_safe
`#{separator}#{signature_or_name}`#{types}#{suffix}

#{docstring_and_deprecation_text}
Expand Down
15 changes: 15 additions & 0 deletions test/docs/docs_rake_task_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# frozen_string_literal: true

require "test_helper"

class DocsRakeTaskTest < ActiveSupport::TestCase
def test_rake_task
load "Rakefile"

assert_nothing_raised do
Rake::Task["docs:build"].invoke
end

Rake::Task.clear
end
end
Loading