Sha256: 0111cac7192fe1096d16d013c20d88f1f82e69425811992fd5e46b8e59e89d28
Contents?: true
Size: 1.63 KB
Versions: 1
Compression:
Stored size: 1.63 KB
Contents
# frozen_string_literal: true if Object.const_defined?('Rails') module Trifle module Docs class Engine < ::Rails::Engine isolate_namespace Trifle::Docs def self.mount(router, namespace:) configuration = Configuration.new configuration.namespace = namespace yield(configuration) router.mount self => "/#{namespace}", as: namespace, configuration: configuration end def self.draw Trifle::Docs::Engine.routes.draw do root to: 'page#show' get '*url', to: 'page#show' end end end class PageController < ActionController::Base layout :docs_layout def configuration params[:configuration] || Trifle::Docs.default end def docs_layout "layouts/trifle/docs/#{configuration.layout}" end def show url = [params[:url], params[:format]].compact.join('.') meta = Trifle::Docs.meta(url: url, config: configuration) render_file(meta: meta) and return if meta['type'] == 'file' render_content(url: url, meta: meta) end def render_file(meta:) send_file(meta['path']) end 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 end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
trifle-docs-0.2.0 | lib/trifle/docs/engine.rb |