vitepress-rails 0.1.1 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dedbe372715777b6f811161f40652f9197aa0b8d5ac324af5111d2cadcec35ec
4
- data.tar.gz: 800e17e91840b8e41ea08de8894c4269ae98c720deeddecc10ff1df8ce52b1ca
3
+ metadata.gz: 13c5b41037eb03ea1741a3c22c26852bb30c55fe06d9fd462e1bfd9b36df3753
4
+ data.tar.gz: 619b3b0f6f5fce0f5307911951802f8c3ad919daf783d177ffc261c841e0d5a3
5
5
  SHA512:
6
- metadata.gz: 6410d722b48436dc70f8d4477f7c2e8172b183cb174e31f712c52ff778aa05d1b6570fbe735661e35d7e3570cda294b40d79bce28b0790b2fed923ce0c689a11
7
- data.tar.gz: 45de6006269917000307314012f1500eaed470a304f4c5b2a955d0b9ac47232adee98d3bbef156f3967cd34311ae4f63513d632d969a6d69896acc0bd054fa27
6
+ metadata.gz: 278a577f49d1227a645636c0064c92e508dcec77f9e9311c9d87c227bab55945402f9d606631aae80d7b3c152c0dab5eccff2980fca7b2995757fc88760a399e
7
+ data.tar.gz: 95142f46e97aeec20ec8ef2852bbbe13b30fa29e55fec443738808bf25f48e359ab1ba7c7bc6deb410dbacafa77650c5e2622ad635a09e9b8ce3b37b61fd8606
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Inspired from https://github.com/thoughtbot/high_voltage/blob/main/app/controllers/concerns/high_voltage/static_page.rb
4
+ require "vitepress/rails/finder"
5
+
6
+ module Vitepress::Page
7
+ extend ActiveSupport::Concern
8
+
9
+ included do
10
+ layout ->(_) { HighVoltage.layout }
11
+
12
+ rescue_from ActionView::MissingTemplate do |exception|
13
+ if /Missing template #{page_finder.content_path}/.match?(exception.message)
14
+ invalid_page
15
+ else
16
+ raise exception
17
+ end
18
+ end
19
+
20
+ rescue_from HighVoltage::InvalidPageIdError, with: :invalid_page
21
+ end
22
+
23
+ def show
24
+ render(
25
+ template: current_page,
26
+ locals: { current_page: current_page },
27
+ )
28
+ end
29
+
30
+ def invalid_page
31
+ raise ActionController::RoutingError, "No such page: #{params[:id]}"
32
+ end
33
+
34
+ private
35
+
36
+ def current_page
37
+ page_finder.find
38
+ end
39
+
40
+ def page_finder
41
+ page_finder_factory.new(params[:id])
42
+ end
43
+
44
+ def page_finder_factory
45
+ Vitepress::Rails::Finder
46
+ end
47
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Vitepress
4
+ class ApplicationController < ActionController::Base
5
+ end
6
+ end
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Vitepress::PagesController < ActionController::Base
4
+ include Vitepress::Page
5
+
6
+ layout false
7
+
8
+ def index
9
+ render(
10
+ template: "pages/index",
11
+ locals: { current_page: "pages/index" },
12
+ )
13
+ end
14
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "high_voltage"
4
+
5
+ HighVoltage.configure do |config|
6
+ config.route_drawer = HighVoltage::RouteDrawers::Default
7
+ config.parent_engine = Vitepress::Engine
8
+ config.routes = false
9
+ end
data/config/routes.rb ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ Vitepress::Engine.routes.draw do
4
+ get "/*id", to: "pages#show", as: :page, format: false
5
+ root to: "pages#index"
6
+ end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Vitepress
4
4
  module Rails
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.3"
6
6
  end
7
7
  end
@@ -4,7 +4,9 @@ if Rails.root.join(".gitignore").exist?
4
4
  # High voltage genereated files
5
5
  append_to_file(".gitignore", %(\n/app/views/pages/*\n!app/views/pages/.keep\n))
6
6
  # Vitepress generated files
7
- append_to_file(".gitignore", %(\n.vitepress/dist\n.vitepress/cache\n))
7
+ append_to_file(".gitignore", %(\ndocs/.vitepress/dist\ndocs/.vitepress/cache\n))
8
+ # Public assets for rails
9
+ append_to_file(".gitignore", %(\npublic/assets\n))
8
10
  end
9
11
 
10
12
  unless Rails.root.join("package.json").exist?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vitepress-rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - PedroAugustoRamalhoDuarte
@@ -48,9 +48,14 @@ files:
48
48
  - Gemfile
49
49
  - README.md
50
50
  - Rakefile
51
+ - app/controllers/concerns/vitepress/page.rb
52
+ - app/controllers/vitepress/application_controller.rb
53
+ - app/controllers/vitepress/pages_controller.rb
51
54
  - bin/console
52
55
  - bin/rails
53
56
  - bin/setup
57
+ - config/initializers/high_voltage.rb
58
+ - config/routes.rb
54
59
  - lib/vitepress/engine.rb
55
60
  - lib/vitepress/rails.rb
56
61
  - lib/vitepress/rails/finder.rb