class BananaDocs::Helpers
encoding: utf-8
Constants
- FIXED_COLUMNS
Public Class Methods
new()
click to toggle source
# File lib/banana_docs/helpers.rb, line 10 def initialize @navigations = [] end
Public Instance Methods
action(title, options)
click to toggle source
# File lib/banana_docs/helpers.rb, line 28 def action(title, options) content_tag(:h5, encode(title)) + content_tag(:code, "#{options[:method]} #{options[:url]}") + content_tag(:br) end
build_span(text, clazz)
click to toggle source
# File lib/banana_docs/helpers.rb, line 59 def build_span(text, clazz) content_tag(:span, encode(text), class: clazz) end
code() { || ... }
click to toggle source
# File lib/banana_docs/helpers.rb, line 94 def code(&block) content_tag(:code, yield.html_safe).html_safe end
empty()
click to toggle source
# File lib/banana_docs/helpers.rb, line 107 def empty "[]" end
encode(string)
click to toggle source
# File lib/banana_docs/helpers.rb, line 119 def encode(string) @coder ||= HTMLEntities.new @coder.encode(string, :named).html_safe end
include_assets()
click to toggle source
# File lib/banana_docs/helpers.rb, line 115 def include_assets render 'assets' end
key_value(key, value, show_keys = true)
click to toggle source
# File lib/banana_docs/helpers.rb, line 98 def key_value(key, value, show_keys = true) value = value.starts_with?('[') ? encode(value) : "\"#{encode value}\"" (show_keys ? "{ \"#{encode key}\":#{encode value} }" : "\"#{encode key}\": #{encode value}, ").html_safe end
key_with_block(key, &block)
click to toggle source
# File lib/banana_docs/helpers.rb, line 103 def key_with_block(key, &block) "{ \"#{encode key}\": { #{yield} } }".html_safe end
more()
click to toggle source
# File lib/banana_docs/helpers.rb, line 111 def more "..." end
note(text)
click to toggle source
# File lib/banana_docs/helpers.rb, line 63 def note(text) content_tag(:blockquote) do content_tag(:p, encode(text), style: 'font-size: 14px') end end
param(name, description, type, format, options = {})
click to toggle source
# File lib/banana_docs/helpers.rb, line 45 def param(name, description, type, format, options = {}) obs = options[:obs].nil? ? '-' : options[:obs] required, clazz = options[:required] ? ['Sim', 'badge badge-important'] : ['Não', 'badge badge-info'] content_tag(:tr) do content_tag(:td, build_span(name, 'label label-inverse')) + content_tag(:td, encode(description)) + content_tag(:td, encode(type)) + content_tag(:td, encode(format)) + content_tag(:td, encode(obs)) + content_tag(:td, build_span(required, clazz)) #options... end end
params() { || ... }
click to toggle source
# File lib/banana_docs/helpers.rb, line 34 def params(&block) content_tag(:table, class: 'table table-striped') do content_tag(:thead) do content_tag(:tr) do FIXED_COLUMNS.map{ |th| content_tag(:th, encode(th)) }.reduce(:+) end end + content_tag(:tbody, yield.html_safe) end end
render(view)
click to toggle source
# File lib/banana_docs/helpers.rb, line 14 def render(view) view = view.sub(/(\.slim|)$/, '.slim') banana_views_dir = File.join Gem::Specification.find_by_name('banana_docs').gem_dir, 'views' view = File.join(banana_views_dir, view) unless File.exists?(view) Slim::Template.new(view).render(self).html_safe end
response() { || ... }
click to toggle source
# File lib/banana_docs/helpers.rb, line 80 def response(&block) content_tag(:div) do content_tag(:span, content_tag(:i, "", class: 'icon-chevron-right').html_safe + 'Exemplos de respostas', class: 'response') + content_tag(:br) + yield.html_safe end end
section(title, options = {})
click to toggle source
# File lib/banana_docs/helpers.rb, line 21 def section(title, options = {}) anchor = title.parameterize add_nav_item(title, anchor) title = content_tag :h3, encode(title) link_to(title, '#', name: anchor) end
status_code(status)
click to toggle source
# File lib/banana_docs/helpers.rb, line 88 def status_code(status) status_codes = { '200' => 'success', '400' => 'important', '404' => 'important' } status = content_tag(:span, status, class: "label label-#{status_codes[status]}") "Status HTTP: #{status} #{content_tag(:br)}".html_safe end