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_tag(tag) ⇒ Object
- #format_visibility(o) ⇒ 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
6 7 8 |
# File 'lib/cabbage_doc/web_helper.rb', line 6 def asset_path(path) [config.asset_path || request.path, path].join('/').gsub(/\/\/+/, '/') end |
#auth ⇒ Object
46 47 48 |
# File 'lib/cabbage_doc/web_helper.rb', line 46 def auth @_auth ||= Authentication.new(request) end |
#collection ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/cabbage_doc/web_helper.rb', line 18 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
14 15 16 |
# File 'lib/cabbage_doc/web_helper.rb', line 14 def config Configuration.instance end |
#eval_with_erb(text) ⇒ Object
38 39 40 |
# File 'lib/cabbage_doc/web_helper.rb', line 38 def eval_with_erb(text) ERB.new(text).result(binding) end |
#format_tag(tag) ⇒ Object
62 63 64 |
# File 'lib/cabbage_doc/web_helper.rb', line 62 def format_tag(tag) tag.to_s.capitalize end |
#format_visibility(o) ⇒ Object
58 59 60 |
# File 'lib/cabbage_doc/web_helper.rb', line 58 def format_visibility(o) o.visibility.to_s.capitalize if o.visibility != VISIBILITY.first end |
#markdown ⇒ Object
29 30 31 32 33 34 35 36 |
# File 'lib/cabbage_doc/web_helper.rb', line 29 def markdown @_markdown ||= Redcarpet::Markdown.new( Redcarpet::Render::HTML.new, tables: true, fenced_code_blocks: true, autolink: true ) end |
#post_request ⇒ Object
66 67 68 |
# File 'lib/cabbage_doc/web_helper.rb', line 66 def post_request @_post_request ||= Request.new(request, collection) end |
#response_by_id(id) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/cabbage_doc/web_helper.rb', line 70 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
54 55 56 |
# File 'lib/cabbage_doc/web_helper.rb', line 54 def tag_visible?(tag) config..size <= 1 || auth.visibility.include?(tag) end |
#theme_path ⇒ Object
10 11 12 |
# File 'lib/cabbage_doc/web_helper.rb', line 10 def theme_path asset_path("css/highlight/#{config.theme}.css") end |
#title ⇒ Object
42 43 44 |
# File 'lib/cabbage_doc/web_helper.rb', line 42 def title @_title ||= config.title end |
#visible?(o) ⇒ Boolean
50 51 52 |
# File 'lib/cabbage_doc/web_helper.rb', line 50 def visible?(o) auth.visibility.include?(o.visibility) end |