Sha256: 7f9aec36db0b8e4e153cbaa623e4b1d29fd3398e918f6c3fab04fc3f18c11e17

Contents?: true

Size: 1.59 KB

Versions: 2

Compression:

Stored size: 1.59 KB

Contents

require 'erb'

module CabbageDoc
  module WebHelper
    def asset_path(path)
      [config.asset_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 && config.auto_generate
        Generator.perform(:all)
        @_collection = nil
      end

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

    def highlighter
      @_highlighter ||= Highlighter.new
    end

    def markdown
      @_markdown ||= Markdown.new
    end

    def eval_with_erb(text)
      ERB.new(text).result(binding)
    end

    def title
      @_title ||= config.title
    end

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

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

    def tag_visible?(tag)
      config.tags.size <= 1 || auth.visibility.include?(tag)
    end

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

    def format_tag(tag)
      tag.to_s.capitalize
    end

    def format_json_response(response)
      content_type :json
      response.to_json
    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)
        format_json_response(response)
      else
        status 503
        content_type :json
        { id: id }.to_json
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
cabbage_doc-0.1.4 lib/cabbage_doc/web_helper.rb
cabbage_doc-0.1.3 lib/cabbage_doc/web_helper.rb