Module: CabbageDoc::WebHelper

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



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

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

#eval_with_erb(text) ⇒ Object



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

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

#format_json_response(response) ⇒ Object



64
65
66
67
# File 'lib/cabbage_doc/web_helper.rb', line 64

def format_json_response(response)
  content_type :json
  response.to_json
end

#format_tag(tag) ⇒ Object



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

def format_tag(tag)
  tag.to_s.capitalize
end

#format_visibility(o) ⇒ Object



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

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

#highlighterObject



28
29
30
# File 'lib/cabbage_doc/web_helper.rb', line 28

def highlighter
  @_highlighter ||= Highlighter.new
end

#markdownObject



32
33
34
# File 'lib/cabbage_doc/web_helper.rb', line 32

def markdown
  @_markdown ||= Markdown.new
end

#post_requestObject



69
70
71
# File 'lib/cabbage_doc/web_helper.rb', line 69

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

#response_by_id(id) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
# File 'lib/cabbage_doc/web_helper.rb', line 73

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

#tag_visible?(tag) ⇒ Boolean

Returns:

  • (Boolean)


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

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



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

def title
  @_title ||= config.title
end

#visible?(o) ⇒ Boolean

Returns:

  • (Boolean)


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

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