trifle-docs 0.1.1 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6297e523736ee0f3ed2f9eb0f5df85d98e6499b05922f23d220b59b8f44e8b8b
4
- data.tar.gz: b5713c0bd7dc7713d0dc8c02f7fa090e1eeff12af37f7997281cd0e3258a374a
3
+ metadata.gz: f67c8c3989c233312fc4ded291bbe1b0b0c0370e7fe3239e24579f7808c8ea0d
4
+ data.tar.gz: 37d6d3f3b9de085f32c44aff933103fb08b94b811c3512837839d716ab3a141a
5
5
  SHA512:
6
- metadata.gz: 5e4e3a7e5bae382a7e765930cdfcaba26d3eb59bdbb47570403f9dae854072262e76fc40551862e503ccd7316fbdd7f92154e1e05512d7ff7b23951b8f43b934
7
- data.tar.gz: 394e69ad719ecb670ab63d845bd6774dc1912f59ee7f9fb914e77b85c62bd6535967ddab6a73eabad52450fbc1ea1b2b17757b21157191e6f4a218bff5463c1b
6
+ metadata.gz: '058e6e525500b64e34b2e2104be4fd10a0ad7d75b4533b093b5df9e16f33c526e5110b819ae910d6d0bd5dd477d998ecf4ffa8274d2bd788c33ac2bfb3ee8a85'
7
+ data.tar.gz: 1afb6462f932882db707f1d0b22ea909b9ca34ffe3f9e913d38cc5f41cf3e6dd72fb08d46b3be460d346361da69c7bd7087623c0d01a40bc18d8abbd1a320536
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- trifle-docs (0.1.1)
4
+ trifle-docs (0.2.0)
5
5
  redcarpet
6
6
  rouge
7
7
  sinatra
@@ -7,7 +7,7 @@ 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.templates }
10
+ set :views, proc { Trifle::Docs.default.views }
11
11
  end
12
12
 
13
13
  get '/*' do
@@ -3,17 +3,19 @@
3
3
  module Trifle
4
4
  module Docs
5
5
  class Configuration
6
- attr_accessor :path, :templates
6
+ attr_accessor :path, :views, :layout, :namespace
7
7
 
8
8
  def initialize
9
9
  @harvesters = []
10
10
  @path = nil
11
+ @namespace = nil
11
12
  end
12
13
 
13
14
  def harvester
14
15
  @harvester ||= Trifle::Docs::Harvester::Walker.new(
15
16
  path: path,
16
- harvesters: @harvesters
17
+ harvesters: @harvesters,
18
+ namespace: namespace
17
19
  )
18
20
  end
19
21
 
@@ -0,0 +1,60 @@
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_file(meta: meta) and return if meta['type'] == 'file'
40
+
41
+ render_content(url: url, meta: meta)
42
+ end
43
+
44
+ def render_file(meta:)
45
+ send_file(meta['path'])
46
+ end
47
+
48
+ def render_content(url:, meta:)
49
+ render (meta['template'] || 'page'), locals: {
50
+ sitemap: Trifle::Docs.sitemap(config: configuration),
51
+ collection: Trifle::Docs.collection(url: url, config: configuration),
52
+ content: Trifle::Docs.content(url: url, config: configuration),
53
+ meta: meta,
54
+ url: url
55
+ }
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -37,7 +37,7 @@ module Trifle
37
37
 
38
38
  def meta
39
39
  @meta ||= (YAML.safe_load(data[/^---(.*?)---(\s*)/m].to_s) || {}).merge(
40
- 'url' => "/#{url}",
40
+ 'url' => "/#{[namespace, url].compact.join('/')}",
41
41
  'breadcrumbs' => url.split('/'),
42
42
  'toc' => toc
43
43
  )
@@ -4,11 +4,12 @@ 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
8
8
 
9
9
  def initialize(**keywords)
10
10
  @path = keywords.fetch(:path)
11
11
  @harvesters = keywords.fetch(:harvesters)
12
+ @namespace = keywords.fetch(:namespace)
12
13
  @router = {}
13
14
 
14
15
  gather
@@ -19,7 +20,7 @@ module Trifle
19
20
  @harvesters.each do |harvester|
20
21
  sieve = harvester::Sieve.new(path: path, file: file)
21
22
  if sieve.match?
22
- @router[sieve.to_url] = harvester::Conveyor.new(file: file, url: sieve.to_url)
23
+ @router[sieve.to_url] = harvester::Conveyor.new(file: file, url: sieve.to_url, namespace: namespace)
23
24
  break
24
25
  end
25
26
  end
@@ -70,11 +71,12 @@ module Trifle
70
71
  end
71
72
 
72
73
  class Conveyor
73
- attr_reader :file, :url
74
+ attr_reader :file, :url, :namespace
74
75
 
75
- def initialize(file:, url:)
76
+ def initialize(file:, url:, namespace:)
76
77
  @file = file
77
78
  @url = url
79
+ @namespace = namespace
78
80
  end
79
81
 
80
82
  def data
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Trifle
4
4
  module Docs
5
- VERSION = '0.1.1'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
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
- require_relative 'docs/app' # NOTE: Load app last
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
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.1.1
4
+ version: 0.2.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-28 00:00:00.000000000 Z
11
+ date: 2022-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -195,6 +195,7 @@ files:
195
195
  - lib/trifle/docs.rb
196
196
  - lib/trifle/docs/app.rb
197
197
  - lib/trifle/docs/configuration.rb
198
+ - lib/trifle/docs/engine.rb
198
199
  - lib/trifle/docs/harvester.rb
199
200
  - lib/trifle/docs/harvester/file.rb
200
201
  - lib/trifle/docs/harvester/markdown.rb