Module: CabbageDoc::WebHelper

Included in:
Generators::Pages::Helper
Defined in:
lib/cabbage_doc/web_helper.rb

Instance Method Summary collapse

Instance Method Details

#asset_path(path) ⇒ Object



5
6
7
# File 'lib/cabbage_doc/web_helper.rb', line 5

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

#authObject



41
42
43
# File 'lib/cabbage_doc/web_helper.rb', line 41

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

#collectionObject



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

def collection
  if config.dev && config.auto_generate
    Generator.perform(:all)
    @_collection = nil
  end

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

#configObject



13
14
15
# File 'lib/cabbage_doc/web_helper.rb', line 13

def config
  Configuration.instance
end

#format_tag(tag) ⇒ Object



57
58
59
# File 'lib/cabbage_doc/web_helper.rb', line 57

def format_tag(tag)
  tag.to_s.capitalize
end

#format_visibility(o) ⇒ Object



53
54
55
# File 'lib/cabbage_doc/web_helper.rb', line 53

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

#markdownObject



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

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

#post_requestObject



61
62
63
# File 'lib/cabbage_doc/web_helper.rb', line 61

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

#response_by_id(id) ⇒ Object



65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/cabbage_doc/web_helper.rb', line 65

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

#tag_visible?(tag) ⇒ Boolean

Returns:

  • (Boolean)


49
50
51
# File 'lib/cabbage_doc/web_helper.rb', line 49

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

#theme_pathObject



9
10
11
# File 'lib/cabbage_doc/web_helper.rb', line 9

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

#titleObject



37
38
39
# File 'lib/cabbage_doc/web_helper.rb', line 37

def title
  @_title ||= config.title
end

#visible?(o) ⇒ Boolean

Returns:

  • (Boolean)


45
46
47
# File 'lib/cabbage_doc/web_helper.rb', line 45

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