vitepress-rails 0.1.0 → 0.1.2

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: e3630ebac35f9a3cf3c2ebf4d5c027a7557385efd79a92337a8761bc1494a4bf
4
- data.tar.gz: 53358818d780b7aa1131a42ca94fe5c3983405eee9467c2c0fa126cc999bf2c7
3
+ metadata.gz: d64f48a9f8abd212ee36a355e82e1d7c5ef3597686cf113717a8d8a547bdd2a0
4
+ data.tar.gz: 96a030364f74346b7d236c6aa83ca97b9ee8289526e514ea155b25e0900f8d46
5
5
  SHA512:
6
- metadata.gz: 1cc7c0194939b5320f35b037602a0b56f259d0931f2031af775b903e0647941ed03a4c62847c39cd4a6c2a8af9c3c431ef27f6da419afc31674861b37df1866f
7
- data.tar.gz: 861167cb94ba5e10704221df08a36feacf44d01881b26e031c615f67a09fbc2c678c19017a4026d4c501a5f09ce5e913cb084a524b1dfbb7556209bd0064a281
6
+ metadata.gz: 7fe415c7cd6a3fad89df4b595b5ecc6fcbc2f936b4bd90478bfed3e528a13225b76334663fbb32983a11167e303ebf0225e478b309c3d5ed1e7c75923128a7b7
7
+ data.tar.gz: 5586b99a9a74563f2d69a8c41a72a638c40c24b59d66123fe7b658584cd61693df4a105781b477cadc653fb6e16e49ab1f93c7522278e9be3dfe8ca90425bb17
data/Gemfile ADDED
@@ -0,0 +1,14 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # Specify your gem's dependencies in vitepress-rails.gemspec
6
+ gemspec
7
+
8
+ gem "rake", "~> 13.0"
9
+
10
+ gem "rspec", "~> 3.0"
11
+
12
+ gem "rubocop", "~> 1.21"
13
+
14
+ gem "switchcop"
data/README.md ADDED
@@ -0,0 +1,62 @@
1
+ # Vitepress::Rails
2
+
3
+ Integrate [Vitepress](https://vitepress.vuejs.org/) into your Rails application.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'vitepress-rails'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle install
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install vitepress-rails
20
+
21
+ 1. Run `rails vitepress:install` to add Vitepress to your Rails application and install the necessary dependencies.
22
+
23
+ This command creates docs folder that contains the Vitepress default application.
24
+
25
+ 2. Adds the following line to your `config/routes.rb` file:
26
+
27
+ ```ruby
28
+ mount Vitepress::Engine, at: "/"
29
+ ```
30
+ ***Only works with / path for now***
31
+
32
+ ## Usage
33
+
34
+ 1. Write your `.md` doc inside the `docs` folder.
35
+ 2. Run `rails assets:precompile`.
36
+ 3. Your page can be accessed at `/docs/<your-page-name>`
37
+
38
+ Your `/` path always will be `docs/index.md`
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can
43
+ also run `bin/console` for an interactive prompt that will allow you to experiment.
44
+
45
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the
46
+ version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version,
47
+ push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
48
+
49
+ ## Contributing
50
+
51
+ Bug reports and pull requests are welcome on GitHub at https://github.com/Switchdreams/vitepress-rails. This project is
52
+ intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to
53
+ the [code of conduct](https://github.com/SwitchDreams/vitepress-rails/blob/master/CODE_OF_CONDUCT.md).
54
+
55
+ ## License
56
+
57
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
58
+
59
+ ## Code of Conduct
60
+
61
+ Everyone interacting in the Vitepress::Rails project's codebases, issue trackers, chat rooms and mailing lists is
62
+ expected to follow the [code of conduct](https://github.com/SwitchDreams/vitepress-rails/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+ require "vitepress/rails"
6
+
7
+ RSpec::Core::RakeTask.new(:spec)
8
+
9
+ require "rubocop/rake_task"
10
+
11
+ RuboCop::RakeTask.new
12
+
13
+ task default: [:spec, :rubocop]
14
+
15
+ load "rails/tasks/engine.rake"
16
+
17
+ load "rails/tasks/statistics.rake"
18
+
19
+ path = File.expand_path(__dir__)
20
+ Dir.glob("#{path}/tasks/**/*.rake").each { |f| import f }
@@ -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
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "vitepress/rails"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ IRB.start(__FILE__)
data/bin/rails ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails gems
3
+ # installed from the root of your application.
4
+ #
5
+ ENGINE_ROOT = File.expand_path("..", __dir__)
6
+ ENGINE_PATH = File.expand_path("../lib/vitepress/engine", __dir__)
7
+ APP_PATH = File.expand_path("../test/dummy/config/application", __dir__)
8
+
9
+ # Set up gems listed in the Gemfile.
10
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__)
11
+ require "bundler/setup" if File.exist?(ENV["BUNDLE_GEMFILE"])
12
+
13
+ require "rails/all"
14
+ require "rails/engine/commands"
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -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
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.0"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
@@ -0,0 +1,37 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :vitepress do
4
+ desc "Build your docs"
5
+ task build: :environment do
6
+ Dir.chdir("./docs") do
7
+ unless system "yarn install && yarn docs:build"
8
+ raise "vitepress: docs:build failed"
9
+ end
10
+
11
+ # Move html files to pages folder
12
+ Dir.glob(".vitepress/dist/**/*.html").each do |file|
13
+ dir = File.dirname(file)
14
+ filename = File.basename(file)
15
+
16
+ dest = File.join("../app/views/pages", dir.remove(".vitepress/dist"))
17
+ FileUtils.mkdir_p(dest)
18
+
19
+ FileUtils.copy_file(file, File.join(dest, filename))
20
+ end
21
+
22
+ # Move assets files to public
23
+ if Dir.exist?(".vitepress/dist/assets")
24
+ FileUtils.copy_entry(".vitepress/dist/assets", "../public/assets")
25
+ end
26
+
27
+ # Copy public files
28
+ if Dir.exist?("public")
29
+ FileUtils.copy_entry("public", "../public")
30
+ end
31
+ end
32
+ end
33
+ end
34
+
35
+ if Rake::Task.task_defined?("assets:precompile")
36
+ Rake::Task["assets:precompile"].enhance(["vitepress:build"])
37
+ end
@@ -0,0 +1,4 @@
1
+ export default {
2
+ title: 'VitePress Rails',
3
+ description: 'Docs with vitepress-rails',
4
+ }
@@ -0,0 +1,25 @@
1
+ ---
2
+ # https://vitepress.dev/reference/default-theme-home-page
3
+ layout: home
4
+
5
+ hero:
6
+ name: "VitePress Rails"
7
+ text: "Docs with vitepress-rails"
8
+ tagline: My great project tagline
9
+ actions:
10
+ - theme: brand
11
+ text: Markdown Examples
12
+ link: /markdown-examples
13
+ - theme: alt
14
+ text: API Examples
15
+ link: /api-examples
16
+
17
+ features:
18
+ - title: Feature A
19
+ details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
20
+ - title: Feature B
21
+ details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
22
+ - title: Feature C
23
+ details: Lorem ipsum dolor sit amet, consectetur adipiscing elit
24
+ ---
25
+
@@ -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?
@@ -0,0 +1,4 @@
1
+ {
2
+ "name": "app",
3
+ "private": "true"
4
+ }
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ namespace :vitepress do
4
+ desc "Install vitepress"
5
+ task install: :environment do
6
+ system "#{RbConfig.ruby} ./bin/rails app:template LOCATION=#{File.expand_path("./init/install.rb", __dir__)}"
7
+ end
8
+ end
@@ -0,0 +1,6 @@
1
+ module Vitepress
2
+ module Rails
3
+ VERSION: String
4
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
5
+ end
6
+ end
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.0
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - PedroAugustoRamalhoDuarte
@@ -45,12 +45,29 @@ executables: []
45
45
  extensions: []
46
46
  extra_rdoc_files: []
47
47
  files:
48
+ - Gemfile
49
+ - README.md
50
+ - Rakefile
51
+ - app/controllers/concerns/vitepress/page.rb
52
+ - app/controllers/vitepress/application_controller.rb
53
+ - app/controllers/vitepress/pages_controller.rb
54
+ - bin/console
55
+ - bin/rails
56
+ - bin/setup
57
+ - config/initializers/high_voltage.rb
58
+ - config/routes.rb
48
59
  - lib/vitepress/engine.rb
49
60
  - lib/vitepress/rails.rb
50
61
  - lib/vitepress/rails/finder.rb
51
62
  - lib/vitepress/rails/version.rb
52
63
  - lib/vitepress/railtie.rb
64
+ - lib/vitepress/tasks/vitepress/build.rake
65
+ - lib/vitepress/tasks/vitepress/init/config.js
66
+ - lib/vitepress/tasks/vitepress/init/index.md
53
67
  - lib/vitepress/tasks/vitepress/init/install.rb
68
+ - lib/vitepress/tasks/vitepress/init/package.json
69
+ - lib/vitepress/tasks/vitepress/install.rake
70
+ - sig/vitepress/rails.rbs
54
71
  homepage: https://github.com/SwitchDreams/rest-api-generator
55
72
  licenses:
56
73
  - MIT