Class: Trifle::Docs::PageController

Inherits:
ActionController::Base
  • Object
show all
Defined in:
lib/trifle/docs/engine.rb

Instance Method Summary collapse

Instance Method Details

#configurationObject



28
29
30
# File 'lib/trifle/docs/engine.rb', line 28

def configuration
  params[:configuration] || Trifle::Docs.default
end

#docs_layoutObject



32
33
34
# File 'lib/trifle/docs/engine.rb', line 32

def docs_layout
  "layouts/trifle/docs/#{configuration.layout}"
end

#render_content(url:, meta:) ⇒ Object



53
54
55
56
57
58
59
60
61
# File 'lib/trifle/docs/engine.rb', line 53

def render_content(url:, meta:)
  render (meta['template'] || 'page'), locals: {
    sitemap: Trifle::Docs.sitemap(config: configuration),
    collection: Trifle::Docs.collection(url: url, config: configuration),
    content: Trifle::Docs.content(url: url, config: configuration),
    meta: meta,
    url: url
  }
end

#render_file(meta:) ⇒ Object



49
50
51
# File 'lib/trifle/docs/engine.rb', line 49

def render_file(meta:)
  send_file(meta['path'])
end

#render_not_foundObject



45
46
47
# File 'lib/trifle/docs/engine.rb', line 45

def render_not_found
  render text: 'Not Found', status: 404
end

#showObject



36
37
38
39
40
41
42
43
# File 'lib/trifle/docs/engine.rb', line 36

def show
  url = [params[:url], params[:format]].compact.join('.')
  meta = Trifle::Docs.meta(url: url, config: configuration)
  render_not_found and return if meta.nil?
  render_file(meta: meta) and return if meta['type'] == 'file'

  render_content(url: url, meta: meta)
end