Sha256: a2a457199a69dda533d0e97e557069363ed80574d576b61ee76e20fa180c8b84

Contents?: true

Size: 1.3 KB

Versions: 4

Compression:

Stored size: 1.3 KB

Contents

module CabbageDoc
  module WebHelper
    def asset_path(path)
      [request.path, path].join('/').gsub(/\/\/+/, '/')
    end

    def theme_path
      asset_path("css/highlight/#{config.theme}.css")
    end

    def config
      Configuration.instance
    end

    def collection
      if config.dev
        Processor.perform(:documentation)
        @_collection = nil
      end

      @_collection ||= Collection.instance.tap do |collection|
        collection.load!
      end
    end

    def markdown
      @_markdown ||= Redcarpet::Markdown.new(
        Redcarpet::Render::HTML.new,
        tables: true,
        fenced_code_blocks: true,
        autolink: true
      )
    end

    def title
      @_title ||= config.title
    end

    def auth
      @_auth ||= Authentication.new(request)
    end

    def visible?(o)
      auth.visibility.include?(o.visibility)
    end

    def format_visibility(o)
      o.visibility.to_s.capitalize if o.visibility != VISIBILITY.first
    end

    def post_request
      @_post_request ||= Request.new(request, collection)
    end

    def response_by_id(id)
      response = Worker.get(id)

      if response.is_a?(Response)
        content_type :json
        response.to_json
      else
        status 503
        content_type :json
        { id: id }.to_json
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
cabbage_doc-0.0.7 lib/cabbage_doc/web_helper.rb
cabbage_doc-0.0.6 lib/cabbage_doc/web_helper.rb
cabbage_doc-0.0.5 lib/cabbage_doc/web_helper.rb
cabbage_doc-0.0.4 lib/cabbage_doc/web_helper.rb