Module: CabbageDoc::WebHelper
- Defined in:
- lib/cabbage_doc/web_helper.rb
Instance Method Summary collapse
- #asset_path(path) ⇒ Object
- #auth ⇒ Object
- #collection ⇒ Object
- #config ⇒ Object
- #eval_with_erb(text) ⇒ Object
- #format_json_response(response) ⇒ Object
- #format_tag(tag) ⇒ Object
- #format_visibility(o) ⇒ Object
- #highlighter ⇒ Object
- #markdown ⇒ Object
- #post_request ⇒ Object
- #response_by_id(id) ⇒ Object
- #tag_visible?(tag) ⇒ Boolean
- #theme_path ⇒ Object
- #title ⇒ Object
- #visible?(o) ⇒ Boolean
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 |
#auth ⇒ Object
44 45 46 |
# File 'lib/cabbage_doc/web_helper.rb', line 44 def auth @_auth ||= Authentication.new(request) end |
#collection ⇒ Object
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 |
#config ⇒ Object
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 |
#highlighter ⇒ Object
28 29 30 |
# File 'lib/cabbage_doc/web_helper.rb', line 28 def highlighter @_highlighter ||= Highlighter.new end |
#markdown ⇒ Object
32 33 34 |
# File 'lib/cabbage_doc/web_helper.rb', line 32 def markdown @_markdown ||= Markdown.new end |
#post_request ⇒ Object
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
52 53 54 |
# File 'lib/cabbage_doc/web_helper.rb', line 52 def tag_visible?(tag) config..size <= 1 || auth.visibility.include?(tag) end |
#theme_path ⇒ Object
9 10 11 |
# File 'lib/cabbage_doc/web_helper.rb', line 9 def theme_path asset_path("css/highlight/#{config.theme}.css") end |
#title ⇒ Object
40 41 42 |
# File 'lib/cabbage_doc/web_helper.rb', line 40 def title @_title ||= config.title end |
#visible?(o) ⇒ Boolean
48 49 50 |
# File 'lib/cabbage_doc/web_helper.rb', line 48 def visible?(o) auth.visibility.include?(o.visibility) end |