trifle-docs 0.2.0 → 0.3.0

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: f67c8c3989c233312fc4ded291bbe1b0b0c0370e7fe3239e24579f7808c8ea0d
4
- data.tar.gz: 37d6d3f3b9de085f32c44aff933103fb08b94b811c3512837839d716ab3a141a
3
+ metadata.gz: 539c91d9c90586bfa38c2b7d89bbdf4dbbfde706c8f1ac306eb57aea550d3794
4
+ data.tar.gz: 784e68bf02e62481f5269bd6e6ed10f2c2bfc41857346466d6a117ee5f9a0f09
5
5
  SHA512:
6
- metadata.gz: '058e6e525500b64e34b2e2104be4fd10a0ad7d75b4533b093b5df9e16f33c526e5110b819ae910d6d0bd5dd477d998ecf4ffa8274d2bd788c33ac2bfb3ee8a85'
7
- data.tar.gz: 1afb6462f932882db707f1d0b22ea909b9ca34ffe3f9e913d38cc5f41cf3e6dd72fb08d46b3be460d346361da69c7bd7087623c0d01a40bc18d8abbd1a320536
6
+ metadata.gz: e2f827a9b25d6ef96a89c6e1cb73c7e20da8e3ab7d318be7ea3c89f78a4116ac90650b3628c268957fd4042f824418d3f53f150b1c886c851afab35b538b9461
7
+ data.tar.gz: ad2b341f5e35061ee9c7e78775135610a3bf4067594fcfa26ca9df604c77b27d093d0eef78d02208679b41810a26083562a43e88d73cd1145364c4b3a3cc31c4
data/.rubocop.yml CHANGED
@@ -10,6 +10,7 @@ AllCops:
10
10
  - 'spec/**/*'
11
11
  - 'Gemfile'
12
12
  - trifle-docs.gemspec
13
+ - website/**/*
13
14
 
14
15
  Style/Documentation:
15
16
  Enabled: false
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.2.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 (1.1.1)
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.3.1)
25
- rack-protection (2.2.0)
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 (3.29.0)
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.0)
60
- mustermann (~> 1.0)
59
+ sinatra (2.2.2)
60
+ mustermann (~> 2.0)
61
61
  rack (~> 2.2)
62
- rack-protection (= 2.2.0)
62
+ rack-protection (= 2.2.2)
63
63
  tilt (~> 2.0)
64
- tilt (2.0.10)
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).
@@ -13,6 +13,8 @@ module Trifle
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,19 +3,21 @@
3
3
  module Trifle
4
4
  module Docs
5
5
  class Configuration
6
- attr_accessor :path, :views, :layout, :namespace
6
+ attr_accessor :path, :views, :layout, :namespace, :cache
7
7
 
8
8
  def initialize
9
9
  @harvesters = []
10
10
  @path = nil
11
11
  @namespace = nil
12
+ @cache = true
12
13
  end
13
14
 
14
15
  def harvester
15
16
  @harvester ||= Trifle::Docs::Harvester::Walker.new(
16
17
  path: path,
17
18
  harvesters: @harvesters,
18
- namespace: namespace
19
+ namespace: namespace,
20
+ cache: cache
19
21
  )
20
22
  end
21
23
 
@@ -36,11 +36,16 @@ if Object.const_defined?('Rails')
36
36
  def show
37
37
  url = [params[:url], params[:format]].compact.join('.')
38
38
  meta = Trifle::Docs.meta(url: url, config: configuration)
39
+ render_not_found and return if meta.nil?
39
40
  render_file(meta: meta) and return if meta['type'] == 'file'
40
41
 
41
42
  render_content(url: url, meta: meta)
42
43
  end
43
44
 
45
+ def render_not_found
46
+ render text: 'Not Found', status: 404
47
+ end
48
+
44
49
  def render_file(meta:)
45
50
  send_file(meta['path'])
46
51
  end
@@ -22,7 +22,8 @@ module Trifle
22
22
  def meta
23
23
  {
24
24
  'path' => file,
25
- 'type' => 'file'
25
+ 'type' => 'file',
26
+ 'updated_at' => ::File.stat(file).mtime
26
27
  }
27
28
  end
28
29
  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
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,25 +4,28 @@ module Trifle
4
4
  module Docs
5
5
  module Harvester
6
6
  class Walker
7
- attr_reader :path, :router, :namespace
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
12
  @namespace = keywords.fetch(:namespace)
13
+ @cache = keywords.fetch(:cache)
13
14
  @router = {}
14
15
 
15
16
  gather
16
17
  end
17
18
 
18
- def gather
19
+ def gather # rubocop:disable Metrics/MethodLength
19
20
  Dir["#{path}/**/*.*"].each do |file|
20
21
  @harvesters.each do |harvester|
21
22
  sieve = harvester::Sieve.new(path: path, file: file)
22
- if sieve.match?
23
- @router[sieve.to_url] = harvester::Conveyor.new(file: file, url: sieve.to_url, namespace: namespace)
24
- break
25
- end
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
26
29
  end
27
30
  end
28
31
  true
@@ -45,11 +48,19 @@ module Trifle
45
48
  end
46
49
 
47
50
  def content_for(url:)
48
- @router[url].content
51
+ route_for(url: url)&.content
49
52
  end
50
53
 
51
54
  def meta_for(url:)
52
- @router[url].meta
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}"
53
64
  end
54
65
  end
55
66
 
@@ -71,15 +82,18 @@ module Trifle
71
82
  end
72
83
 
73
84
  class Conveyor
74
- attr_reader :file, :url, :namespace
85
+ attr_reader :file, :url, :namespace, :cache
75
86
 
76
- def initialize(file:, url:, namespace:)
87
+ def initialize(file:, url:, namespace:, cache:)
77
88
  @file = file
78
89
  @url = url
79
90
  @namespace = namespace
91
+ @cache = cache
80
92
  end
81
93
 
82
94
  def data
95
+ @data = nil unless cache
96
+
83
97
  @data ||= ::File.read(file)
84
98
  end
85
99
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Trifle
4
4
  module Docs
5
- VERSION = '0.2.0'
5
+ VERSION = '0.3.0'
6
6
  end
7
7
  end
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["changelog_uri"] = "https://github.com/trifle-io/trifle-docs/blob/main/CHANGELOG.md"
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.2.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-06-29 00:00:00.000000000 Z
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
- - CHANGELOG.md
168
+ - ".ruby-version"
169
+ - ".tool-versions"
169
170
  - CODE_OF_CONDUCT.md
170
171
  - Gemfile
171
172
  - Gemfile.lock
@@ -215,7 +216,7 @@ licenses:
215
216
  metadata:
216
217
  homepage_uri: https://trifle.io
217
218
  source_code_uri: https://github.com/trifle-io/trifle-docs
218
- changelog_uri: https://github.com/trifle-io/trifle-docs/blob/main/CHANGELOG.md
219
+ changelog_uri: https://trifle.io/trifle-docs/changelog
219
220
  post_install_message:
220
221
  rdoc_options: []
221
222
  require_paths:
@@ -231,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
232
  - !ruby/object:Gem::Version
232
233
  version: '0'
233
234
  requirements: []
234
- rubygems_version: 3.2.3
235
+ rubygems_version: 3.3.3
235
236
  signing_key:
236
237
  specification_version: 4
237
238
  summary: Simple documentation for your markdown files.
data/CHANGELOG.md DELETED
@@ -1,5 +0,0 @@
1
- ## [Unreleased]
2
-
3
- ## [0.1.0] - 2022-06-20
4
-
5
- - Initial release