sdoc_live 0.1.8 → 0.1.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 2c58eaf82f18b4feb7c431156e8ba8be018e22eb57b8b62d69e0e0c503e2085c
4
- data.tar.gz: 372965feda50bdc4bc08b196d3acbbc43af6fe2b7fb4461b622bbb4f80c0befa
3
+ metadata.gz: 01316e7563fe0c297ff8ee3304b86fcab074251063ab2c503369a8288362210c
4
+ data.tar.gz: d4d839d93250944f290f0157282213c8888daf1c4bfbb2872c17b0ff1034b0b7
5
5
  SHA512:
6
- metadata.gz: 224cc2e187603628bb1e76664ef87ff8f6c33640d34512d38e7f262b1e96490a3e05dc07ed2cc08f78e372adf8a016bae6c55199f2a9de3c57ebbcc1ea2e5bfb
7
- data.tar.gz: dc1222d122c5992e1e9505e752305a28b164b0d55dff3bbdc3f3b19aae4d630c76d6940be15fd45201426e1c548172bea7722b61cf6f3f95eb4ffec2ef02c2f2
6
+ metadata.gz: 0fed3626046989a0448f0368d0d3d65d3889e82ec71cb43775969e832824f156dc773f25b2c9a0e7c92c284f6d76227045fc46e8bbd4e6052f397f99c1cbbf15
7
+ data.tar.gz: 7b73e3fe0c6aecc0414120f1af80e4e92ecde9ddc314939ce3165ace61398c31d5a2f85238aec220395b2bd57ed78c4f3e949862eb0d5b85841fd163ead4af75
data/README.md CHANGED
@@ -26,15 +26,7 @@ Then run `bundle install`.
26
26
 
27
27
  ## Usage
28
28
 
29
- ### 1. Mount the Engine
30
-
31
- Add to your `config/routes.rb`:
32
-
33
- ```ruby
34
- mount SdocLive::Engine, at: "/doc"
35
- ```
36
-
37
- ### 2. Puma Plugin (Development Watch Mode)
29
+ ### 1. Puma Plugin (Development Watch Mode)
38
30
 
39
31
  Add to your `config/puma.rb`:
40
32
 
@@ -46,7 +38,7 @@ end
46
38
 
47
39
  This watches `app/` and `lib/` for `.rb` file changes and automatically regenerates SDoc documentation.
48
40
 
49
- ### 3. Rake Task (Manual / Deploy)
41
+ ### 2. Rake Task (Manual / Deploy)
50
42
 
51
43
  ```bash
52
44
  rake sdoc:build
@@ -77,6 +69,9 @@ SdocLive.configure do |config|
77
69
 
78
70
  # Additional RDoc options passed to the SDoc generator
79
71
  # config.rdoc_options = ["--all", "--hyperlink-all"]
72
+
73
+ # URL path where documentation is served (default: "/doc")
74
+ # config.mount_path = "/doc"
80
75
  end if defined?(SdocLive)
81
76
  ```
82
77
 
@@ -85,7 +80,7 @@ end if defined?(SdocLive)
85
80
  1. **Development**: Puma boots → forks a child process that runs `SdocLive::Generator#build_watch`
86
81
  2. The `listen` gem monitors `app/` and `lib/` for `.rb` file changes
87
82
  3. On change, SDoc regenerates documentation into `tmp/doc/`
88
- 4. Docs are served by the mounted engine (e.g. at `/doc`)
83
+ 4. Docs are served via middleware at the configured `mount_path` (default: `/doc`)
89
84
  5. Clean subprocess management with bidirectional lifecycle monitoring (Puma ↔ SDoc)
90
85
 
91
86
  ## License
@@ -6,47 +6,55 @@ module SdocLive
6
6
  load File.expand_path("../tasks/sdoc_live.rake", __dir__)
7
7
  end
8
8
 
9
- initializer "sdoc_live.static" do |app|
10
- doc_root = (SdocLive.configuration.output_dir || app.root.join("tmp", "doc")).to_s
11
-
12
- SdocLive::Engine.routes.draw do
13
- doc_app = ::Rack::Static.new(
14
- ->(_) { [404, { "content-type" => "text/plain" }, ["Not Found"]] },
15
- urls: ["/"],
16
- root: doc_root,
17
- index: "index.html"
18
- )
19
-
20
- mount doc_app, at: "/"
21
- end
9
+ initializer "sdoc_live.static" do
10
+ config = SdocLive.configuration
11
+ doc_root = (config.output_dir || Rails.root.join("tmp", "doc")).to_s
12
+ mount_path = config.mount_path
13
+
14
+ app.middleware.use(SdocLive::StaticFiles, doc_root, mount_path)
15
+ end
16
+
17
+ end
18
+
19
+ class StaticFiles
20
+
21
+ def initialize(app, doc_root, mount_path)
22
+ @app = app
23
+ @doc_root = doc_root
24
+ @mount_path = mount_path.chomp("/")
22
25
  end
23
26
 
24
- initializer "sdoc_live.trailing_slash", after: :add_routing_paths do |app|
25
- mount_path = nil
27
+ def call(env)
28
+ path_info = env["PATH_INFO"]
26
29
 
27
- app.routes.routes.each do |route|
28
- if route.app.respond_to?(:app) && route.app.app == SdocLive::Engine
29
- mount_path = route.path.spec.to_s.gsub("(.:format)", "").chomp("/")
30
- break
31
- end
30
+ if path_info == @mount_path
31
+ query = env["QUERY_STRING"].to_s.empty? ? "" : "?#{ env['QUERY_STRING'] }"
32
+ return [301, { "location" => "#{ @mount_path }/#{ query }" }, []]
32
33
  end
33
34
 
34
- if mount_path && !mount_path.empty?
35
- app.middleware.use(Class.new do
36
- define_method(:initialize) { |a| @app = a }
37
-
38
- define_method(:call) do |env|
39
- if env["PATH_INFO"] == mount_path && !env["PATH_INFO"].end_with?("/")
40
- query = env["QUERY_STRING"].to_s.empty? ? "" : "?#{ env['QUERY_STRING'] }"
41
- [301, { "location" => "#{ mount_path }/#{ query }", "content-type" => "text/html" }, ["Redirecting..."]]
42
- else
43
- @app.call(env)
44
- end
45
- end
46
- end)
35
+ return @app.call(env) unless path_info.start_with?("#{ @mount_path }/")
36
+
37
+ relative_path = path_info.delete_prefix(@mount_path)
38
+ relative_path = "/index.html" if relative_path == "/"
39
+
40
+ file_path = File.join(@doc_root, relative_path)
41
+ file_path = File.join(file_path, "index.html") if File.directory?(file_path)
42
+
43
+ if File.file?(file_path)
44
+ serve_file(file_path)
45
+ else
46
+ @app.call(env)
47
47
  end
48
48
  end
49
49
 
50
+ private
51
+
52
+ def serve_file(path)
53
+ content_type = Rack::Mime.mime_type(File.extname(path), "application/octet-stream")
54
+ body = File.read(path, mode: "rb")
55
+ [200, { "content-type" => content_type, "content-length" => body.bytesize.to_s }, [body]]
56
+ end
57
+
50
58
  end
51
59
 
52
60
  end
@@ -1,5 +1,5 @@
1
1
  module SdocLive
2
2
 
3
- VERSION = "0.1.8"
3
+ VERSION = "0.1.10"
4
4
 
5
5
  end
data/lib/sdoc_live.rb CHANGED
@@ -19,13 +19,14 @@ module SdocLive
19
19
  class Configuration
20
20
 
21
21
  attr_accessor :output_dir, :title, :main_file, :source_dirs, :watch_dirs,
22
- :watch_file_type_regex, :rdoc_options
22
+ :watch_file_type_regex, :rdoc_options, :mount_path
23
23
 
24
24
  def initialize
25
25
  @source_dirs = ["app", "lib"]
26
26
  @watch_file_type_regex = /\.rb$/
27
27
  @title = "Documentation"
28
28
  @main_file = "README.md"
29
+ @mount_path = "/doc"
29
30
  end
30
31
 
31
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sdoc_live
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - 16554289+optimuspwnius@users.noreply.github.com