trifle-docs 0.1.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +1 -0
- data/.ruby-version +1 -0
- data/.tool-versions +1 -0
- data/Gemfile.lock +10 -9
- data/README.md +7 -34
- data/lib/trifle/docs/app.rb +3 -1
- data/lib/trifle/docs/configuration.rb +6 -2
- data/lib/trifle/docs/engine.rb +65 -0
- data/lib/trifle/docs/harvester/file.rb +2 -1
- data/lib/trifle/docs/harvester/markdown.rb +9 -2
- data/lib/trifle/docs/harvester.rb +26 -10
- data/lib/trifle/docs/version.rb +1 -1
- data/lib/trifle/docs.rb +3 -1
- data/trifle-docs.gemspec +1 -1
- metadata +7 -5
- data/CHANGELOG.md +0 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 539c91d9c90586bfa38c2b7d89bbdf4dbbfde706c8f1ac306eb57aea550d3794
|
4
|
+
data.tar.gz: 784e68bf02e62481f5269bd6e6ed10f2c2bfc41857346466d6a117ee5f9a0f09
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e2f827a9b25d6ef96a89c6e1cb73c7e20da8e3ab7d318be7ea3c89f78a4116ac90650b3628c268957fd4042f824418d3f53f150b1c886c851afab35b538b9461
|
7
|
+
data.tar.gz: ad2b341f5e35061ee9c7e78775135610a3bf4067594fcfa26ca9df604c77b27d093d0eef78d02208679b41810a26083562a43e88d73cd1145364c4b3a3cc31c4
|
data/.rubocop.yml
CHANGED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-3.1.0
|
data/.tool-versions
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby 3.1.0
|
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
trifle-docs (0.
|
4
|
+
trifle-docs (0.3.0)
|
5
5
|
redcarpet
|
6
6
|
rouge
|
7
7
|
sinatra
|
@@ -13,7 +13,7 @@ GEM
|
|
13
13
|
ast (2.4.2)
|
14
14
|
byebug (11.1.3)
|
15
15
|
diff-lcs (1.5.0)
|
16
|
-
mustermann (
|
16
|
+
mustermann (2.0.2)
|
17
17
|
ruby2_keywords (~> 0.0.1)
|
18
18
|
nio4r (2.5.8)
|
19
19
|
parallel (1.22.1)
|
@@ -21,15 +21,15 @@ GEM
|
|
21
21
|
ast (~> 2.4.1)
|
22
22
|
puma (5.6.4)
|
23
23
|
nio4r (~> 2.0)
|
24
|
-
rack (2.2.
|
25
|
-
rack-protection (2.2.
|
24
|
+
rack (2.2.4)
|
25
|
+
rack-protection (2.2.2)
|
26
26
|
rack
|
27
27
|
rainbow (3.1.1)
|
28
28
|
rake (13.0.6)
|
29
29
|
redcarpet (3.5.1)
|
30
30
|
regexp_parser (2.5.0)
|
31
31
|
rexml (3.2.5)
|
32
|
-
rouge (
|
32
|
+
rouge (4.0.0)
|
33
33
|
rspec (3.11.0)
|
34
34
|
rspec-core (~> 3.11.0)
|
35
35
|
rspec-expectations (~> 3.11.0)
|
@@ -56,16 +56,17 @@ GEM
|
|
56
56
|
parser (>= 3.1.1.0)
|
57
57
|
ruby-progressbar (1.11.0)
|
58
58
|
ruby2_keywords (0.0.5)
|
59
|
-
sinatra (2.2.
|
60
|
-
mustermann (~>
|
59
|
+
sinatra (2.2.2)
|
60
|
+
mustermann (~> 2.0)
|
61
61
|
rack (~> 2.2)
|
62
|
-
rack-protection (= 2.2.
|
62
|
+
rack-protection (= 2.2.2)
|
63
63
|
tilt (~> 2.0)
|
64
|
-
tilt (2.0.
|
64
|
+
tilt (2.0.11)
|
65
65
|
unicode-display_width (2.1.0)
|
66
66
|
yaml (0.2.0)
|
67
67
|
|
68
68
|
PLATFORMS
|
69
|
+
arm64-darwin-21
|
69
70
|
x86_64-linux
|
70
71
|
|
71
72
|
DEPENDENCIES
|
data/README.md
CHANGED
@@ -10,6 +10,11 @@ Integrate your documentation or blog into your existing Rails application. `Trif
|
|
10
10
|
|
11
11
|
![Demo App](demo.gif)
|
12
12
|
|
13
|
+
|
14
|
+
## Documentation
|
15
|
+
|
16
|
+
You can find guides and documentation at https://trifle.io/trifle-docs
|
17
|
+
|
13
18
|
## Installation
|
14
19
|
|
15
20
|
Install the gem and add to the application's Gemfile by executing:
|
@@ -26,9 +31,7 @@ $ gem install trifle-docs
|
|
26
31
|
|
27
32
|
## Usage
|
28
33
|
|
29
|
-
You can use this as a build-in Sinatra app or mount it in your Rails app.
|
30
|
-
|
31
|
-
Sinatra configuration requires simple integration in your ruby file.
|
34
|
+
You can use this as a build-in Sinatra app or mount it in your Rails app. For each usecse, refere to documentation. Below is sample Sinatra integration.
|
32
35
|
|
33
36
|
```ruby
|
34
37
|
# app.rb
|
@@ -44,37 +47,6 @@ end
|
|
44
47
|
Trifle::Docs.App.run!
|
45
48
|
```
|
46
49
|
|
47
|
-
Rails configuration requires initializer and routes configuration.
|
48
|
-
|
49
|
-
```ruby
|
50
|
-
# config/initializers/trifle.rb
|
51
|
-
Trifle::Docs.configure do |config|
|
52
|
-
config.path = File.join(Rails.root, 'docs')
|
53
|
-
config.templates = File.join(Rails.root, 'app', 'views', 'trifle', 'docs')
|
54
|
-
config.register_harvester(Trifle::Docs::Harvester::Markdown)
|
55
|
-
config.register_harvester(Trifle::Docs::Harvester::File)
|
56
|
-
end
|
57
|
-
|
58
|
-
# config/routes.rb
|
59
|
-
MyRailsApp::Application.routes.draw do
|
60
|
-
# ...
|
61
|
-
mount Trifle::Docs::App.new => '/docs'
|
62
|
-
# ...
|
63
|
-
end
|
64
|
-
```
|
65
|
-
|
66
|
-
Or use individual configuration per mount.
|
67
|
-
|
68
|
-
```ruby
|
69
|
-
# config/routes.rb
|
70
|
-
MyRailsApp::Application.routes.draw do
|
71
|
-
# ...
|
72
|
-
mount Trifle::Docs::App.new => '/docs'
|
73
|
-
mount Trifle::Docs::App.new => '/blog'
|
74
|
-
# ...
|
75
|
-
end
|
76
|
-
```
|
77
|
-
|
78
50
|
### Templates
|
79
51
|
|
80
52
|
Please create two files in folder you provided the configuration.
|
@@ -96,6 +68,7 @@ Please create two files in folder you provided the configuration.
|
|
96
68
|
```
|
97
69
|
|
98
70
|
### Template variables
|
71
|
+
|
99
72
|
There are several variables available in your template file (except `layout.erb`).
|
100
73
|
- `sitemap` - complete sitemap tree of the folder.
|
101
74
|
- `collection` - current subtree of the folder (useful for rendering child content, aka collection).
|
data/lib/trifle/docs/app.rb
CHANGED
@@ -7,12 +7,14 @@ module Trifle
|
|
7
7
|
class App < Sinatra::Base
|
8
8
|
configure do
|
9
9
|
set :bind, '0.0.0.0'
|
10
|
-
set :views, proc { Trifle::Docs.default.
|
10
|
+
set :views, proc { Trifle::Docs.default.views }
|
11
11
|
end
|
12
12
|
|
13
13
|
get '/*' do
|
14
14
|
url = params['splat'].first.chomp('/')
|
15
15
|
meta = Trifle::Docs.meta(url: url)
|
16
|
+
halt(404, 'Not Found') if meta.nil?
|
17
|
+
|
16
18
|
if meta['type'] == 'file'
|
17
19
|
send_file meta['path']
|
18
20
|
else
|
@@ -3,17 +3,21 @@
|
|
3
3
|
module Trifle
|
4
4
|
module Docs
|
5
5
|
class Configuration
|
6
|
-
attr_accessor :path, :
|
6
|
+
attr_accessor :path, :views, :layout, :namespace, :cache
|
7
7
|
|
8
8
|
def initialize
|
9
9
|
@harvesters = []
|
10
10
|
@path = nil
|
11
|
+
@namespace = nil
|
12
|
+
@cache = true
|
11
13
|
end
|
12
14
|
|
13
15
|
def harvester
|
14
16
|
@harvester ||= Trifle::Docs::Harvester::Walker.new(
|
15
17
|
path: path,
|
16
|
-
harvesters: @harvesters
|
18
|
+
harvesters: @harvesters,
|
19
|
+
namespace: namespace,
|
20
|
+
cache: cache
|
17
21
|
)
|
18
22
|
end
|
19
23
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
if Object.const_defined?('Rails')
|
4
|
+
module Trifle
|
5
|
+
module Docs
|
6
|
+
class Engine < ::Rails::Engine
|
7
|
+
isolate_namespace Trifle::Docs
|
8
|
+
|
9
|
+
def self.mount(router, namespace:)
|
10
|
+
configuration = Configuration.new
|
11
|
+
configuration.namespace = namespace
|
12
|
+
yield(configuration)
|
13
|
+
|
14
|
+
router.mount self => "/#{namespace}", as: namespace, configuration: configuration
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.draw
|
18
|
+
Trifle::Docs::Engine.routes.draw do
|
19
|
+
root to: 'page#show'
|
20
|
+
get '*url', to: 'page#show'
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class PageController < ActionController::Base
|
26
|
+
layout :docs_layout
|
27
|
+
|
28
|
+
def configuration
|
29
|
+
params[:configuration] || Trifle::Docs.default
|
30
|
+
end
|
31
|
+
|
32
|
+
def docs_layout
|
33
|
+
"layouts/trifle/docs/#{configuration.layout}"
|
34
|
+
end
|
35
|
+
|
36
|
+
def show
|
37
|
+
url = [params[:url], params[:format]].compact.join('.')
|
38
|
+
meta = Trifle::Docs.meta(url: url, config: configuration)
|
39
|
+
render_not_found and return if meta.nil?
|
40
|
+
render_file(meta: meta) and return if meta['type'] == 'file'
|
41
|
+
|
42
|
+
render_content(url: url, meta: meta)
|
43
|
+
end
|
44
|
+
|
45
|
+
def render_not_found
|
46
|
+
render text: 'Not Found', status: 404
|
47
|
+
end
|
48
|
+
|
49
|
+
def render_file(meta:)
|
50
|
+
send_file(meta['path'])
|
51
|
+
end
|
52
|
+
|
53
|
+
def render_content(url:, meta:)
|
54
|
+
render (meta['template'] || 'page'), locals: {
|
55
|
+
sitemap: Trifle::Docs.sitemap(config: configuration),
|
56
|
+
collection: Trifle::Docs.collection(url: url, config: configuration),
|
57
|
+
content: Trifle::Docs.content(url: url, config: configuration),
|
58
|
+
meta: meta,
|
59
|
+
url: url
|
60
|
+
}
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -27,6 +27,8 @@ module Trifle
|
|
27
27
|
|
28
28
|
class Conveyor < Harvester::Conveyor
|
29
29
|
def content
|
30
|
+
@content = nil unless cache
|
31
|
+
|
30
32
|
@content ||= Redcarpet::Markdown.new(
|
31
33
|
Render.new(with_toc_data: true),
|
32
34
|
fenced_code_blocks: true,
|
@@ -36,14 +38,19 @@ module Trifle
|
|
36
38
|
end
|
37
39
|
|
38
40
|
def meta
|
41
|
+
@meta = nil unless cache
|
42
|
+
|
39
43
|
@meta ||= (YAML.safe_load(data[/^---(.*?)---(\s*)/m].to_s) || {}).merge(
|
40
|
-
'url' => "/#{url}",
|
44
|
+
'url' => "/#{[namespace, url].compact.join('/')}",
|
41
45
|
'breadcrumbs' => url.split('/'),
|
42
|
-
'toc' => toc
|
46
|
+
'toc' => toc,
|
47
|
+
'updated_at' => ::File.stat(file).mtime
|
43
48
|
)
|
44
49
|
end
|
45
50
|
|
46
51
|
def toc
|
52
|
+
@toc = nil unless cache
|
53
|
+
|
47
54
|
@toc ||= Redcarpet::Markdown.new(
|
48
55
|
Redcarpet::Render::HTML_TOC
|
49
56
|
).render(data.sub(/^---(.*?)---(\s*)/m, ''))
|
@@ -4,24 +4,28 @@ module Trifle
|
|
4
4
|
module Docs
|
5
5
|
module Harvester
|
6
6
|
class Walker
|
7
|
-
attr_reader :path, :router
|
7
|
+
attr_reader :path, :router, :namespace, :cache
|
8
8
|
|
9
9
|
def initialize(**keywords)
|
10
10
|
@path = keywords.fetch(:path)
|
11
11
|
@harvesters = keywords.fetch(:harvesters)
|
12
|
+
@namespace = keywords.fetch(:namespace)
|
13
|
+
@cache = keywords.fetch(:cache)
|
12
14
|
@router = {}
|
13
15
|
|
14
16
|
gather
|
15
17
|
end
|
16
18
|
|
17
|
-
def gather
|
19
|
+
def gather # rubocop:disable Metrics/MethodLength
|
18
20
|
Dir["#{path}/**/*.*"].each do |file|
|
19
21
|
@harvesters.each do |harvester|
|
20
22
|
sieve = harvester::Sieve.new(path: path, file: file)
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
next unless sieve.match?
|
24
|
+
|
25
|
+
@router[sieve.to_url] = harvester::Conveyor.new(
|
26
|
+
file: file, url: sieve.to_url, namespace: namespace, cache: cache
|
27
|
+
)
|
28
|
+
break
|
25
29
|
end
|
26
30
|
end
|
27
31
|
true
|
@@ -44,11 +48,19 @@ module Trifle
|
|
44
48
|
end
|
45
49
|
|
46
50
|
def content_for(url:)
|
47
|
-
|
51
|
+
route_for(url: url)&.content
|
48
52
|
end
|
49
53
|
|
50
54
|
def meta_for(url:)
|
51
|
-
|
55
|
+
route_for(url: url)&.meta
|
56
|
+
end
|
57
|
+
|
58
|
+
def route_for(url:)
|
59
|
+
@router[url] || not_found(url: url)
|
60
|
+
end
|
61
|
+
|
62
|
+
def not_found(url:)
|
63
|
+
puts "No route found for url: #{url}"
|
52
64
|
end
|
53
65
|
end
|
54
66
|
|
@@ -70,14 +82,18 @@ module Trifle
|
|
70
82
|
end
|
71
83
|
|
72
84
|
class Conveyor
|
73
|
-
attr_reader :file, :url
|
85
|
+
attr_reader :file, :url, :namespace, :cache
|
74
86
|
|
75
|
-
def initialize(file:, url:)
|
87
|
+
def initialize(file:, url:, namespace:, cache:)
|
76
88
|
@file = file
|
77
89
|
@url = url
|
90
|
+
@namespace = namespace
|
91
|
+
@cache = cache
|
78
92
|
end
|
79
93
|
|
80
94
|
def data
|
95
|
+
@data = nil unless cache
|
96
|
+
|
81
97
|
@data ||= ::File.read(file)
|
82
98
|
end
|
83
99
|
end
|
data/lib/trifle/docs/version.rb
CHANGED
data/lib/trifle/docs.rb
CHANGED
@@ -10,7 +10,9 @@ require_relative 'docs/operations/collection'
|
|
10
10
|
require_relative 'docs/operations/meta'
|
11
11
|
require_relative 'docs/operations/sitemap'
|
12
12
|
require_relative 'docs/version'
|
13
|
-
|
13
|
+
# NOTE: Load app and engine last
|
14
|
+
require_relative 'docs/app'
|
15
|
+
require_relative 'docs/engine'
|
14
16
|
|
15
17
|
module Trifle
|
16
18
|
module Docs
|
data/trifle-docs.gemspec
CHANGED
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
|
|
19
19
|
|
20
20
|
spec.metadata['homepage_uri'] = spec.homepage
|
21
21
|
spec.metadata['source_code_uri'] = 'https://github.com/trifle-io/trifle-docs'
|
22
|
-
spec.metadata[
|
22
|
+
spec.metadata['changelog_uri'] = 'https://trifle.io/trifle-docs/changelog'
|
23
23
|
|
24
24
|
# Specify which files should be added to the gem when it is released.
|
25
25
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: trifle-docs
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jozef Vaclavik
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-09-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -165,7 +165,8 @@ files:
|
|
165
165
|
- ".devops/docker/codespaces/docker-compose.yml"
|
166
166
|
- ".rspec"
|
167
167
|
- ".rubocop.yml"
|
168
|
-
-
|
168
|
+
- ".ruby-version"
|
169
|
+
- ".tool-versions"
|
169
170
|
- CODE_OF_CONDUCT.md
|
170
171
|
- Gemfile
|
171
172
|
- Gemfile.lock
|
@@ -195,6 +196,7 @@ files:
|
|
195
196
|
- lib/trifle/docs.rb
|
196
197
|
- lib/trifle/docs/app.rb
|
197
198
|
- lib/trifle/docs/configuration.rb
|
199
|
+
- lib/trifle/docs/engine.rb
|
198
200
|
- lib/trifle/docs/harvester.rb
|
199
201
|
- lib/trifle/docs/harvester/file.rb
|
200
202
|
- lib/trifle/docs/harvester/markdown.rb
|
@@ -214,7 +216,7 @@ licenses:
|
|
214
216
|
metadata:
|
215
217
|
homepage_uri: https://trifle.io
|
216
218
|
source_code_uri: https://github.com/trifle-io/trifle-docs
|
217
|
-
changelog_uri: https://
|
219
|
+
changelog_uri: https://trifle.io/trifle-docs/changelog
|
218
220
|
post_install_message:
|
219
221
|
rdoc_options: []
|
220
222
|
require_paths:
|
@@ -230,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
230
232
|
- !ruby/object:Gem::Version
|
231
233
|
version: '0'
|
232
234
|
requirements: []
|
233
|
-
rubygems_version: 3.
|
235
|
+
rubygems_version: 3.3.3
|
234
236
|
signing_key:
|
235
237
|
specification_version: 4
|
236
238
|
summary: Simple documentation for your markdown files.
|