diff --git a/Gemfile b/Gemfile index 52ad3538..a94359cb 100644 --- a/Gemfile +++ b/Gemfile @@ -2,7 +2,7 @@ source "https://rubygems.org" ruby file: ".ruby-version" -gem "rails", github: "rails/rails" +gem "rails", github: "rails/rails", ref: "f32d09e2e8228c720a49c368de578559e37d7731" # Drivers gem "sqlite3", "~> 2.5" diff --git a/Gemfile.lock b/Gemfile.lock index a0cae4e8..fd6e412f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -6,31 +6,32 @@ GIT GIT remote: https://github.com/rails/rails.git - revision: 13d5f87208921cc5139cd53b280c42f23c334826 + revision: f32d09e2e8228c720a49c368de578559e37d7731 + ref: f32d09e2e8228c720a49c368de578559e37d7731 specs: - actioncable (8.0.0.beta1) - actionpack (= 8.0.0.beta1) - activesupport (= 8.0.0.beta1) + actioncable (8.1.0.alpha) + actionpack (= 8.1.0.alpha) + activesupport (= 8.1.0.alpha) nio4r (~> 2.0) websocket-driver (>= 0.6.1) zeitwerk (~> 2.6) - actionmailbox (8.0.0.beta1) - actionpack (= 8.0.0.beta1) - activejob (= 8.0.0.beta1) - activerecord (= 8.0.0.beta1) - activestorage (= 8.0.0.beta1) - activesupport (= 8.0.0.beta1) + actionmailbox (8.1.0.alpha) + actionpack (= 8.1.0.alpha) + activejob (= 8.1.0.alpha) + activerecord (= 8.1.0.alpha) + activestorage (= 8.1.0.alpha) + activesupport (= 8.1.0.alpha) mail (>= 2.8.0) - actionmailer (8.0.0.beta1) - actionpack (= 8.0.0.beta1) - actionview (= 8.0.0.beta1) - activejob (= 8.0.0.beta1) - activesupport (= 8.0.0.beta1) + actionmailer (8.1.0.alpha) + actionpack (= 8.1.0.alpha) + actionview (= 8.1.0.alpha) + activejob (= 8.1.0.alpha) + activesupport (= 8.1.0.alpha) mail (>= 2.8.0) rails-dom-testing (~> 2.2) - actionpack (8.0.0.beta1) - actionview (= 8.0.0.beta1) - activesupport (= 8.0.0.beta1) + actionpack (8.1.0.alpha) + actionview (= 8.1.0.alpha) + activesupport (= 8.1.0.alpha) nokogiri (>= 1.8.5) rack (>= 2.2.4) rack-session (>= 1.0.1) @@ -38,35 +39,36 @@ GIT rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) useragent (~> 0.16) - actiontext (8.0.0.beta1) - actionpack (= 8.0.0.beta1) - activerecord (= 8.0.0.beta1) - activestorage (= 8.0.0.beta1) - activesupport (= 8.0.0.beta1) + actiontext (8.1.0.alpha) + action_text-trix (~> 2.1.15) + actionpack (= 8.1.0.alpha) + activerecord (= 8.1.0.alpha) + activestorage (= 8.1.0.alpha) + activesupport (= 8.1.0.alpha) globalid (>= 0.6.0) nokogiri (>= 1.8.5) - actionview (8.0.0.beta1) - activesupport (= 8.0.0.beta1) + actionview (8.1.0.alpha) + activesupport (= 8.1.0.alpha) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activejob (8.0.0.beta1) - activesupport (= 8.0.0.beta1) + activejob (8.1.0.alpha) + activesupport (= 8.1.0.alpha) globalid (>= 0.3.6) - activemodel (8.0.0.beta1) - activesupport (= 8.0.0.beta1) - activerecord (8.0.0.beta1) - activemodel (= 8.0.0.beta1) - activesupport (= 8.0.0.beta1) + activemodel (8.1.0.alpha) + activesupport (= 8.1.0.alpha) + activerecord (8.1.0.alpha) + activemodel (= 8.1.0.alpha) + activesupport (= 8.1.0.alpha) timeout (>= 0.4.0) - activestorage (8.0.0.beta1) - actionpack (= 8.0.0.beta1) - activejob (= 8.0.0.beta1) - activerecord (= 8.0.0.beta1) - activesupport (= 8.0.0.beta1) + activestorage (8.1.0.alpha) + actionpack (= 8.1.0.alpha) + activejob (= 8.1.0.alpha) + activerecord (= 8.1.0.alpha) + activesupport (= 8.1.0.alpha) marcel (~> 1.0) - activesupport (8.0.0.beta1) + activesupport (8.1.0.alpha) base64 benchmark (>= 0.3) bigdecimal @@ -79,41 +81,44 @@ GIT securerandom (>= 0.3) tzinfo (~> 2.0, >= 2.0.5) uri (>= 0.13.1) - rails (8.0.0.beta1) - actioncable (= 8.0.0.beta1) - actionmailbox (= 8.0.0.beta1) - actionmailer (= 8.0.0.beta1) - actionpack (= 8.0.0.beta1) - actiontext (= 8.0.0.beta1) - actionview (= 8.0.0.beta1) - activejob (= 8.0.0.beta1) - activemodel (= 8.0.0.beta1) - activerecord (= 8.0.0.beta1) - activestorage (= 8.0.0.beta1) - activesupport (= 8.0.0.beta1) + rails (8.1.0.alpha) + actioncable (= 8.1.0.alpha) + actionmailbox (= 8.1.0.alpha) + actionmailer (= 8.1.0.alpha) + actionpack (= 8.1.0.alpha) + actiontext (= 8.1.0.alpha) + actionview (= 8.1.0.alpha) + activejob (= 8.1.0.alpha) + activemodel (= 8.1.0.alpha) + activerecord (= 8.1.0.alpha) + activestorage (= 8.1.0.alpha) + activesupport (= 8.1.0.alpha) bundler (>= 1.15.0) - railties (= 8.0.0.beta1) - railties (8.0.0.beta1) - actionpack (= 8.0.0.beta1) - activesupport (= 8.0.0.beta1) + railties (= 8.1.0.alpha) + railties (8.1.0.alpha) + actionpack (= 8.1.0.alpha) + activesupport (= 8.1.0.alpha) irb (~> 1.13) rackup (>= 1.0.0) rake (>= 12.2) thor (~> 1.0, >= 1.2.2) + tsort (>= 0.2) zeitwerk (~> 2.6) GEM remote: https://rubygems.org/ specs: - addressable (2.8.6) - public_suffix (>= 2.0.2, < 6.0) - ast (2.4.2) - base64 (0.2.0) + action_text-trix (2.1.15) + railties + addressable (2.8.7) + public_suffix (>= 2.0.2, < 7.0) + ast (2.4.3) + base64 (0.3.0) bcrypt (3.1.20) - benchmark (0.3.0) - bigdecimal (3.1.8) + benchmark (0.4.1) + bigdecimal (3.2.2) bindex (0.8.1) - brakeman (7.0.2) + brakeman (7.1.0) racc builder (3.3.0) capybara (3.40.0) @@ -126,47 +131,49 @@ GEM regexp_parser (>= 1.5, < 3.0) xpath (~> 3.2) chunky_png (1.4.0) - concurrent-ruby (1.3.4) - connection_pool (2.4.1) + concurrent-ruby (1.3.5) + connection_pool (2.5.3) crass (1.0.6) date (3.4.1) - debug (1.10.0) + debug (1.11.0) irb (~> 1.10) reline (>= 0.3.8) - drb (2.2.1) - erubi (1.13.0) - faker (3.5.1) + drb (2.2.3) + erb (5.0.2) + erubi (1.13.1) + faker (3.5.2) i18n (>= 1.8.11, < 2) - ffi (1.17.0-aarch64-linux-gnu) - ffi (1.17.0-arm-linux-gnu) - ffi (1.17.0-arm64-darwin) - ffi (1.17.0-x86-linux-gnu) - ffi (1.17.0-x86_64-darwin) - ffi (1.17.0-x86_64-linux-gnu) + ffi (1.17.2-aarch64-linux-gnu) + ffi (1.17.2-arm-linux-gnu) + ffi (1.17.2-arm64-darwin) + ffi (1.17.2-x86-linux-gnu) + ffi (1.17.2-x86_64-darwin) + ffi (1.17.2-x86_64-linux-gnu) front_matter_parser (1.0.1) globalid (1.2.1) activesupport (>= 6.1) - i18n (1.14.6) + i18n (1.14.7) concurrent-ruby (~> 1.0) - image_processing (1.13.0) - mini_magick (>= 4.9.5, < 5) + image_processing (1.14.0) + mini_magick (>= 4.9.5, < 6) ruby-vips (>= 2.0.17, < 3) - importmap-rails (2.0.1) + importmap-rails (2.2.2) actionpack (>= 6.0.0) activesupport (>= 6.0.0) railties (>= 6.0.0) - io-console (0.8.0) - irb (1.15.1) + io-console (0.8.1) + irb (1.15.2) pp (>= 0.6.0) rdoc (>= 4.0.0) reline (>= 0.4.2) - jbuilder (2.13.0) - actionview (>= 5.0.0) - activesupport (>= 5.0.0) - json (2.7.2) - language_server-protocol (3.17.0.3) - logger (1.6.5) - loofah (2.23.1) + jbuilder (2.14.1) + actionview (>= 7.0.0) + activesupport (>= 7.0.0) + json (2.13.2) + language_server-protocol (3.17.0.5) + lint_roller (1.1.0) + logger (1.7.0) + loofah (2.24.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) mail (2.8.1) @@ -175,89 +182,91 @@ GEM net-pop net-smtp marcel (1.0.4) - matrix (0.4.2) - mini_magick (4.13.2) + matrix (0.4.3) + mini_magick (5.3.0) + logger mini_mime (1.1.5) - mini_portile2 (2.8.8) - minitest (5.25.1) + mini_portile2 (2.8.9) + minitest (5.25.5) mono_logger (1.1.2) - multi_json (1.15.0) - mustermann (3.0.3) + multi_json (1.17.0) + mustermann (3.0.4) ruby2_keywords (~> 0.0.1) - net-imap (0.4.19) + net-imap (0.5.9) date net-protocol net-pop (0.1.2) net-protocol net-protocol (0.2.2) timeout - net-smtp (0.5.0) + net-smtp (0.5.1) net-protocol nio4r (2.7.4) - nokogiri (1.18.8) + nokogiri (1.18.9) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.18.8-aarch64-linux-gnu) + nokogiri (1.18.9-aarch64-linux-gnu) racc (~> 1.4) - nokogiri (1.18.8-arm-linux-gnu) + nokogiri (1.18.9-arm-linux-gnu) racc (~> 1.4) - nokogiri (1.18.8-arm64-darwin) + nokogiri (1.18.9-arm64-darwin) racc (~> 1.4) - nokogiri (1.18.8-x86_64-darwin) + nokogiri (1.18.9-x86_64-darwin) racc (~> 1.4) - nokogiri (1.18.8-x86_64-linux-gnu) + nokogiri (1.18.9-x86_64-linux-gnu) racc (~> 1.4) - parallel (1.25.1) - parser (3.3.3.0) + parallel (1.27.0) + parser (3.3.9.0) ast (~> 2.4.1) racc pp (0.6.2) prettyprint prettyprint (0.2.0) - propshaft (1.0.0) + prism (1.4.0) + propshaft (1.2.1) actionpack (>= 7.0.0) activesupport (>= 7.0.0) rack - railties (>= 7.0.0) - psych (5.2.3) + psych (5.2.6) date stringio - public_suffix (5.0.5) - puma (6.6.0) + public_suffix (6.0.2) + puma (6.6.1) nio4r (~> 2.0) racc (1.8.1) - rack (3.1.11) - rack-protection (4.1.0) + rack (3.2.0) + rack-protection (4.1.1) base64 (>= 0.1.0) logger (>= 1.6.0) rack (>= 3.0.0, < 4) - rack-session (2.0.0) + rack-session (2.1.1) + base64 (>= 0.1.0) rack (>= 3.0.0) - rack-test (2.1.0) + rack-test (2.2.0) rack (>= 1.3) - rackup (2.1.0) + rackup (2.2.1) rack (>= 3) - webrick (~> 1.8) - rails-dom-testing (2.2.0) + rails-dom-testing (2.3.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.6.1) + rails-html-sanitizer (1.6.2) loofah (~> 2.21) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) rainbow (3.1.1) - rake (13.2.1) - rdoc (6.11.0) + rake (13.3.0) + rdoc (6.14.2) + erb psych (>= 4.0.0) - redcarpet (3.6.0) - redis (5.3.0) + redcarpet (3.6.1) + redis (5.4.1) redis-client (>= 0.22.0) - redis-client (0.22.2) + redis-client (0.25.2) connection_pool redis-namespace (1.11.0) redis (>= 4) - regexp_parser (2.9.2) - reline (0.6.0) + regexp_parser (2.11.2) + reline (0.6.2) io-console (~> 0.5) resque (2.6.0) mono_logger (~> 1.0) @@ -267,98 +276,100 @@ GEM resque-pool (0.7.1) rake (>= 10.0, < 14.0) resque (>= 1.22, < 3) - rexml (3.4.0) - rouge (4.5.1) - rqrcode (2.2.0) + rexml (3.4.1) + rouge (4.6.0) + rqrcode (3.1.0) chunky_png (~> 1.0) - rqrcode_core (~> 1.0) - rqrcode_core (1.2.0) - rubocop (1.64.1) + rqrcode_core (~> 2.0) + rqrcode_core (2.0.0) + rubocop (1.79.2) json (~> 2.3) - language_server-protocol (>= 3.17.0) + language_server-protocol (~> 3.17.0.2) + lint_roller (~> 1.1.0) parallel (~> 1.10) parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) - regexp_parser (>= 1.8, < 3.0) - rexml (>= 3.2.5, < 4.0) - rubocop-ast (>= 1.31.1, < 2.0) + regexp_parser (>= 2.9.3, < 3.0) + rubocop-ast (>= 1.46.0, < 2.0) ruby-progressbar (~> 1.7) - unicode-display_width (>= 2.4.0, < 3.0) - rubocop-ast (1.31.3) - parser (>= 3.3.1.0) - rubocop-minitest (0.35.0) - rubocop (>= 1.61, < 2.0) - rubocop-ast (>= 1.31.1, < 2.0) - rubocop-performance (1.21.0) - rubocop (>= 1.48.1, < 2.0) - rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails (2.25.0) + unicode-display_width (>= 2.4.0, < 4.0) + rubocop-ast (1.46.0) + parser (>= 3.3.7.2) + prism (~> 1.4) + rubocop-performance (1.25.0) + lint_roller (~> 1.1) + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.38.0, < 2.0) + rubocop-rails (2.33.3) activesupport (>= 4.2.0) + lint_roller (~> 1.1) rack (>= 1.1) - rubocop (>= 1.33.0, < 2.0) - rubocop-ast (>= 1.31.1, < 2.0) - rubocop-rails-omakase (1.0.0) - rubocop - rubocop-minitest - rubocop-performance - rubocop-rails + rubocop (>= 1.75.0, < 2.0) + rubocop-ast (>= 1.44.0, < 2.0) + rubocop-rails-omakase (1.1.0) + rubocop (>= 1.72) + rubocop-performance (>= 1.24) + rubocop-rails (>= 2.30) ruby-progressbar (1.13.0) - ruby-vips (2.2.2) + ruby-vips (2.2.4) ffi (~> 1.12) logger ruby2_keywords (0.0.5) - rubyzip (2.4.1) - securerandom (0.3.1) - selenium-webdriver (4.28.0) + rubyzip (3.0.1) + securerandom (0.4.1) + selenium-webdriver (4.35.0) base64 (~> 0.2) logger (~> 1.4) rexml (~> 3.2, >= 3.2.5) - rubyzip (>= 1.2.2, < 3.0) + rubyzip (>= 1.2.2, < 4.0) websocket (~> 1.0) - sinatra (4.1.0) + sinatra (4.1.1) logger (>= 1.6.0) mustermann (~> 3.0) rack (>= 3.0.0, < 4) - rack-protection (= 4.1.0) + rack-protection (= 4.1.1) rack-session (>= 2.0.0, < 3) tilt (~> 2.0) - sqlite3 (2.5.0-aarch64-linux-gnu) - sqlite3 (2.5.0-arm-linux-gnu) - sqlite3 (2.5.0-arm64-darwin) - sqlite3 (2.5.0-x86-linux-gnu) - sqlite3 (2.5.0-x86_64-darwin) - sqlite3 (2.5.0-x86_64-linux-gnu) + sqlite3 (2.7.3-aarch64-linux-gnu) + sqlite3 (2.7.3-arm-linux-gnu) + sqlite3 (2.7.3-arm64-darwin) + sqlite3 (2.7.3-x86-linux-gnu) + sqlite3 (2.7.3-x86_64-darwin) + sqlite3 (2.7.3-x86_64-linux-gnu) stimulus-rails (1.3.4) railties (>= 6.0.0) - stringio (3.1.2) - thor (1.3.2) - thruster (0.1.9) - thruster (0.1.9-aarch64-linux) - thruster (0.1.9-arm64-darwin) - thruster (0.1.9-x86_64-darwin) - thruster (0.1.9-x86_64-linux) - tilt (2.4.0) + stringio (3.1.7) + thor (1.4.0) + thruster (0.1.15) + thruster (0.1.15-aarch64-linux) + thruster (0.1.15-arm64-darwin) + thruster (0.1.15-x86_64-darwin) + thruster (0.1.15-x86_64-linux) + tilt (2.6.1) timeout (0.4.3) - turbo-rails (2.0.11) - actionpack (>= 6.0.0) - railties (>= 6.0.0) + tsort (0.2.0) + turbo-rails (2.0.16) + actionpack (>= 7.1.0) + railties (>= 7.1.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (2.5.0) - uri (0.13.2) + unicode-display_width (3.1.5) + unicode-emoji (~> 4.0, >= 4.0.4) + unicode-emoji (4.0.4) + uri (1.0.3) web-console (4.2.1) actionview (>= 6.0.0) activemodel (>= 6.0.0) bindex (>= 0.4.0) railties (>= 6.0.0) - webrick (1.8.2) websocket (1.2.11) - websocket-driver (0.7.6) + websocket-driver (0.8.0) + base64 websocket-extensions (>= 0.1.0) websocket-extensions (0.1.5) xpath (3.2.0) nokogiri (~> 1.8) - zeitwerk (2.7.1) + zeitwerk (2.7.3) PLATFORMS aarch64-linux diff --git a/app/controllers/leafables_controller.rb b/app/controllers/leafables_controller.rb index bf472599..c2a300a4 100644 --- a/app/controllers/leafables_controller.rb +++ b/app/controllers/leafables_controller.rb @@ -16,6 +16,10 @@ def create end def show + respond_to do |format| + format.html + format.md { render markdown: @leaf.leafable } + end end def edit diff --git a/app/models/book.rb b/app/models/book.rb index 93de9985..234461d3 100644 --- a/app/models/book.rb +++ b/app/models/book.rb @@ -12,4 +12,10 @@ class Book < ApplicationRecord def press(leafable, leaf_params) leaves.create! leaf_params.merge(leafable: leafable) end + + def to_markdown + leaves.active.with_leafables.positioned \ + .collect { |leaf| leaf.leafable.to_markdown } + .join("\n\n") + end end diff --git a/app/models/leafable.rb b/app/models/leafable.rb index 6d90efd5..0e6185dc 100644 --- a/app/models/leafable.rb +++ b/app/models/leafable.rb @@ -11,7 +11,9 @@ module Leafable end def searchable_content - nil + end + + def to_markdown end class_methods do diff --git a/app/models/page.rb b/app/models/page.rb index 5b4adba8..3585bdeb 100644 --- a/app/models/page.rb +++ b/app/models/page.rb @@ -16,6 +16,10 @@ def html_preview rendered_html(markdown_source.first(1024)) end + def to_markdown + body.content + end + private def plain_text html_body = rendered_html(markdown_source) diff --git a/app/models/picture.rb b/app/models/picture.rb index 1a2acde7..043b9afe 100644 --- a/app/models/picture.rb +++ b/app/models/picture.rb @@ -4,4 +4,8 @@ class Picture < ApplicationRecord has_one_attached :image do |attachable| attachable.variant :large, resize_to_limit: [ 1500, 1500 ] end + + def to_markdown + "#{caption.presence || image&.attachment&.slug || "Image"}" + end end diff --git a/app/models/section.rb b/app/models/section.rb index f86f7046..a6fe574b 100644 --- a/app/models/section.rb +++ b/app/models/section.rb @@ -4,4 +4,8 @@ class Section < ApplicationRecord def searchable_content body end + + def to_markdown + "# #{body}" + end end diff --git a/test/controllers/leafables_controller_test.rb b/test/controllers/leafables_controller_test.rb index 9fa0c8ff..24d8d14f 100644 --- a/test/controllers/leafables_controller_test.rb +++ b/test/controllers/leafables_controller_test.rb @@ -12,6 +12,13 @@ class LeafablesControllerTest < ActionDispatch::IntegrationTest assert_select "p", "This is such a great handbook." end + test "show markdown" do + get leafable_slug_path(leaves(:welcome_page), format: "md") + + assert_response :success + assert_equal "This is _such_ a great handbook.", @response.body + end + test "show with public access to a published book" do sign_out books(:handbook).update!(published: true)