diff --git a/Gemfile b/Gemfile index 32e1f6f0a..9f26113fe 100644 --- a/Gemfile +++ b/Gemfile @@ -59,6 +59,7 @@ gem "translator-text", "~> 0.1.0" gem "turbolinks", "~> 5.2.1" gem "turnout", "~> 2.5.0" gem "uglifier", "~> 4.2.0" +gem "view_component", "~> 2.19.1", require: "view_component/engine" gem "whenever", "~> 1.0.0", require: false gem "wicked_pdf", "~> 2.1.0" gem "wkhtmltopdf-binary", "~> 0.12.4" diff --git a/Gemfile.lock b/Gemfile.lock index 89922ea49..e44bb04ed 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -608,6 +608,8 @@ GEM uniform_notifier (1.13.0) user_agent_parser (2.6.0) uuidtools (2.1.5) + view_component (2.19.1) + activesupport (>= 5.0.0, < 7.0) warden (1.2.9) rack (>= 2.0.9) wasabi (3.5.0) @@ -728,6 +730,7 @@ DEPENDENCIES turbolinks (~> 5.2.1) turnout (~> 2.5.0) uglifier (~> 4.2.0) + view_component (~> 2.19.1) web-console (~> 3.7.0) webdrivers (~> 4.4.1) whenever (~> 1.0.0) diff --git a/app/components/application_component.rb b/app/components/application_component.rb new file mode 100644 index 000000000..3db4d0451 --- /dev/null +++ b/app/components/application_component.rb @@ -0,0 +1,2 @@ +class ApplicationComponent < ViewComponent::Base +end diff --git a/config/application.rb b/config/application.rb index 819918788..935dffa93 100644 --- a/config/application.rb +++ b/config/application.rb @@ -112,6 +112,7 @@ module Consul # * English: https://github.com/consul/consul/blob/master/CUSTOMIZE_EN.md # * Spanish: https://github.com/consul/consul/blob/master/CUSTOMIZE_ES.md # + config.autoload_paths << "#{Rails.root}/app/components/custom" config.autoload_paths << "#{Rails.root}/app/controllers/custom" config.autoload_paths << "#{Rails.root}/app/models/custom" config.paths["app/views"].unshift(Rails.root.join("app", "views", "custom")) diff --git a/config/initializers/wicked_pdf.rb b/config/initializers/wicked_pdf.rb index 824095dc3..37820d285 100644 --- a/config/initializers/wicked_pdf.rb +++ b/config/initializers/wicked_pdf.rb @@ -1,3 +1,27 @@ +class WickedPdf + # Wicked Pdf magic breaks ViewComponent + # https://github.com/mileszs/wicked_pdf/pull/925 + module PdfHelper + def render(*args) + options = args.first + if options.is_a?(Hash) && options.key?(:pdf) + render_with_wicked_pdf(options) + else + super + end + end + + def render_to_string(*args) + options = args.first + if options.is_a?(Hash) && options.key?(:pdf) + render_to_string_with_wicked_pdf(options) + else + super + end + end + end +end + # WickedPDF Global Configuration # # Use this to set up shared configuration options for your entire application. diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index c4756dd02..717007659 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -11,6 +11,11 @@ require "spec_helper" require "capybara/rails" require "capybara/rspec" require "selenium/webdriver" +require "view_component/test_helpers" + +RSpec.configure do |config| + config.include ViewComponent::TestHelpers, type: :component +end Rails.application.load_tasks if Rake::Task.tasks.empty?