Module: CabbageDoc::WebHelper

Defined in:
lib/cabbage_doc/web_helper.rb

Instance Method Summary collapse

Instance Method Details

#asset_path(path) ⇒ Object



3
4
5
# File 'lib/cabbage_doc/web_helper.rb', line 3

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

#authObject



39
40
41
# File 'lib/cabbage_doc/web_helper.rb', line 39

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

#collectionObject



15
16
17
18
19
20
21
22
23
24
# File 'lib/cabbage_doc/web_helper.rb', line 15

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

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

#configObject



11
12
13
# File 'lib/cabbage_doc/web_helper.rb', line 11

def config
  Configuration.instance
end

#format_visibility(o) ⇒ Object



47
48
49
# File 'lib/cabbage_doc/web_helper.rb', line 47

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

#markdownObject



26
27
28
29
30
31
32
33
# File 'lib/cabbage_doc/web_helper.rb', line 26

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

#post_requestObject



51
52
53
# File 'lib/cabbage_doc/web_helper.rb', line 51

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

#response_by_id(id) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/cabbage_doc/web_helper.rb', line 55

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

#theme_pathObject



7
8
9
# File 'lib/cabbage_doc/web_helper.rb', line 7

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

#titleObject



35
36
37
# File 'lib/cabbage_doc/web_helper.rb', line 35

def title
  @_title ||= config.title
end

#visible?(o) ⇒ Boolean

Returns:

  • (Boolean)


43
44
45
# File 'lib/cabbage_doc/web_helper.rb', line 43

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