shorui 0.1.2 → 0.2.0
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 +4 -4
- data/README.md +59 -13
- data/lib/shorui/generator.rb +48 -18
- data/lib/shorui/version.rb +1 -1
- data/lib/shorui.rb +8 -4
- data/lib/tasks/shorui.rake +8 -3
- metadata +30 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9f9102ca73aae7b5452034ed9d668f92c1b554185f8324a42f4674657129af7a
|
4
|
+
data.tar.gz: 628a0ec7d8e7c08b9d33df04ba98caefab6b4ca021da6c3a2759aacfcfcfc631
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6ff9d04b9906b7a439c8f631192b3a03184c00590f213e774cc52085e66798aae835a8df88f44b549751339a70ab42d9173a6998895497ae258150cc9e018d98
|
7
|
+
data.tar.gz: 47267c746dd62adddf119503d94d09c17deb2afe0ee3af1491469da8d39f18fca661040ae63dc2d030ad37cce224fdbbe8e380e6407e37162b69669a1343c11c
|
data/README.md
CHANGED
@@ -1,43 +1,89 @@
|
|
1
1
|
# Shorui
|
2
2
|
|
3
|
-
|
3
|
+
[](https://badge.fury.io/rb/shorui)
|
4
4
|
|
5
|
-
|
5
|
+
Shorui is a Ruby gem that automatically generates API documentation by analyzing your Rails routes. It creates a clean, organized README.md file with detailed endpoint information.
|
6
6
|
|
7
7
|
## Installation
|
8
8
|
|
9
|
-
|
9
|
+
Add this line to your application's Gemfile:
|
10
10
|
|
11
|
-
|
11
|
+
```ruby
|
12
|
+
gem 'shorui'
|
13
|
+
```
|
12
14
|
|
15
|
+
And then execute:
|
13
16
|
```bash
|
14
|
-
bundle
|
17
|
+
$ bundle install
|
15
18
|
```
|
16
19
|
|
17
|
-
|
18
|
-
|
20
|
+
Or install it yourself as:
|
19
21
|
```bash
|
20
|
-
gem install
|
22
|
+
$ gem install shorui
|
21
23
|
```
|
22
24
|
|
23
25
|
## Usage
|
24
26
|
|
25
|
-
|
27
|
+
Shorui provides two Rake tasks:
|
28
|
+
|
29
|
+
1. Generate full documentation including Rails routes:
|
30
|
+
```bash
|
31
|
+
rails shorui:generate
|
32
|
+
```
|
33
|
+
|
34
|
+
2. Generate documentation excluding Rails routes:
|
35
|
+
```bash
|
36
|
+
rails shorui:generate:no_rails_routes
|
37
|
+
```
|
38
|
+
|
39
|
+
The gem will automatically:
|
40
|
+
- Analyze your Rails routes
|
41
|
+
- Extract controller and action information
|
42
|
+
- Identify required and optional parameters
|
43
|
+
- Generate a formatted README.md in your project root
|
44
|
+
- Include HTTP verbs, paths, and parameter details
|
45
|
+
|
46
|
+
## Output Format
|
47
|
+
|
48
|
+
The generated README.md will follow this structure:
|
49
|
+
|
50
|
+
```markdown
|
51
|
+
# Your Project Name API Documentation
|
52
|
+
|
53
|
+
#### [HTTP_VERB] /path/to/endpoint
|
54
|
+
- **Controller#Action:** `controller_name#action_name`
|
55
|
+
- **Required Params:** `param1, param2` (if any)
|
56
|
+
- **Optional Params:** `param1, param2` (if any)
|
57
|
+
```
|
58
|
+
|
59
|
+
## Features
|
60
|
+
|
61
|
+
- Automatic route analysis
|
62
|
+
- Clean and consistent documentation format
|
63
|
+
- Support for all HTTP verbs
|
64
|
+
- Parameter identification (required and optional)
|
65
|
+
- Rails route filtering option
|
66
|
+
- Proper handling of namespaced routes
|
67
|
+
- Automatic project name formatting
|
26
68
|
|
27
69
|
## Development
|
28
70
|
|
29
71
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
30
72
|
|
31
|
-
To install this gem onto your local machine, run `bundle exec rake install`.
|
73
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
32
74
|
|
33
75
|
## Contributing
|
34
76
|
|
35
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/
|
77
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/thiagochirana/shorui. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](CODE_OF_CONDUCT.md).
|
36
78
|
|
37
79
|
## License
|
38
80
|
|
39
|
-
The gem is available as open source under the terms of the [MIT License](
|
81
|
+
The gem is available as open source under the terms of the [MIT License](LICENSE.txt).
|
40
82
|
|
41
83
|
## Code of Conduct
|
42
84
|
|
43
|
-
Everyone interacting in the Shorui project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](
|
85
|
+
Everyone interacting in the Shorui project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](CODE_OF_CONDUCT.md).
|
86
|
+
|
87
|
+
## Origins
|
88
|
+
|
89
|
+
"Shorui" (書類) means "document" in Japanese, reflecting the gem's purpose of automatic documentation generation.
|
data/lib/shorui/generator.rb
CHANGED
@@ -1,29 +1,59 @@
|
|
1
1
|
module Shorui
|
2
2
|
class Generator
|
3
|
-
def self.fetch_routes
|
3
|
+
def self.fetch_routes(ignore_rails_paths = false)
|
4
4
|
Rails.application.routes.routes.map do |route|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
path = route.path.spec.to_s.gsub("(.:format)", "")
|
6
|
+
|
7
|
+
if ignore_rails_paths && path.start_with?("/rails")
|
8
|
+
next
|
9
|
+
end
|
10
|
+
|
11
|
+
controller = route.defaults.dig(:controller)
|
12
|
+
action = route.defaults.dig(:action)
|
13
|
+
|
14
|
+
if controller && action
|
15
|
+
{
|
16
|
+
path: path,
|
17
|
+
verb: route.verb,
|
18
|
+
controller_action: { controller: controller, action: action },
|
19
|
+
required_params: route.path.required_names,
|
20
|
+
optional_params: route.defaults.keys - [:controller, :action]
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end.compact
|
24
|
+
end
|
12
25
|
|
13
|
-
def self.generate_readme
|
14
|
-
routes = fetch_routes
|
15
|
-
|
26
|
+
def self.generate_readme(ignore_rails_paths = false)
|
27
|
+
routes = fetch_routes(ignore_rails_paths)
|
28
|
+
dir_name = File.basename(Dir.pwd)
|
29
|
+
formatted_name = dir_name.gsub(/[-_\/|\\.]/, ' ').split.map(&:capitalize).join(' ')
|
30
|
+
content = "# #{formatted_name} API Documentation\n\n"
|
16
31
|
|
17
32
|
routes.each do |route|
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
33
|
+
if route.nil?
|
34
|
+
next
|
35
|
+
end
|
36
|
+
|
37
|
+
if ignore_rails_paths
|
38
|
+
next if route[:verb].start_with?("/rails")
|
39
|
+
end
|
24
40
|
|
41
|
+
controller = route.dig(:controller_action, :controller)
|
42
|
+
action = route.dig(:controller_action, :action)
|
43
|
+
|
44
|
+
if controller && action
|
45
|
+
required_params = route[:required_params].any? ? route[:required_params].join(', ') : nil
|
46
|
+
optional_params = route[:optional_params].any? ? route[:optional_params].join(', ') : nil
|
47
|
+
|
48
|
+
content << "#### [#{route[:verb]}] #{route[:path]}\n"
|
49
|
+
content << "- **Controller#Action:** `#{controller}##{action}`\n"
|
50
|
+
content << "- **Required Params:** `#{required_params}`\n" if required_params
|
51
|
+
content << "- **Optional Params:** `#{optional_params}`\n\n" if optional_params
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
25
55
|
File.write('README.md', content)
|
26
56
|
puts "README.md successfully generated in #{Dir.pwd}!"
|
27
|
-
end
|
57
|
+
end
|
28
58
|
end
|
29
59
|
end
|
data/lib/shorui/version.rb
CHANGED
data/lib/shorui.rb
CHANGED
@@ -1,9 +1,13 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
require_relative "shorui/version"
|
4
2
|
require_relative "shorui/generator"
|
3
|
+
require 'rails'
|
5
4
|
|
6
5
|
module Shorui
|
7
6
|
class Error < StandardError; end
|
8
|
-
|
9
|
-
|
7
|
+
|
8
|
+
class Railtie < Rails::Railtie
|
9
|
+
rake_tasks do
|
10
|
+
load File.expand_path('../tasks/shorui.rake', __FILE__)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
data/lib/tasks/shorui.rake
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
namespace :shorui do
|
2
2
|
desc "Generate README.md from routes"
|
3
|
-
task generate
|
4
|
-
Shorui::Generator.generate_readme
|
3
|
+
task :generate => :environment do
|
4
|
+
Shorui::Generator.generate_readme(false)
|
5
5
|
end
|
6
|
-
|
6
|
+
|
7
|
+
desc "Generate README.md excluding Rails routes"
|
8
|
+
task :'generate:no_rails_routes' => :environment do
|
9
|
+
Shorui::Generator.generate_readme(true)
|
10
|
+
end
|
11
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: shorui
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- DevCurumin
|
@@ -9,7 +9,35 @@ autorequire:
|
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
11
|
date: 2025-01-20 00:00:00.000000000 Z
|
12
|
-
dependencies:
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rake
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rails
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '7.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '7.0'
|
13
41
|
description: A gem that helps you generate README.md from routes.rb
|
14
42
|
email:
|
15
43
|
- thiago.chirana@gmail.com
|