class MarkdownController
Public Instance Methods
api()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 35 def api redirect = Redirector.find(request) if redirect redirect_to redirect else render_not_found end end
show()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 8 def show if path_is_folder? @frontmatter, @content = content_from_folder else @document_path = document.path @frontmatter, @content = content_from_file set_canonical_url end @document_title = @frontmatter['meta_title'] || @frontmatter['title'] @sidenav = Sidenav.new( namespace: params[:namespace], locale: params[:locale], request_path: request.path, navigation: @navigation, code_language: params[:code_language], product: @product ) if !Rails.env.development? && @frontmatter['wip'] render 'wip', layout: 'documentation' else render layout: 'documentation' end end
Private Instance Methods
canonical_redirect()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 139 def canonical_redirect # TODO: change this to use the locale from the domain # once we add support for that. return if params[:namespace] return if params[:locale].nil? && session[:locale].nil? return if params[:locale] && params[:locale] != I18n.default_locale.to_s if params[:locale] redirect_to url_for( controller: :markdown, action: :show, only_path: true, locale: nil, document: params[:document], product: params[:product] ) elsif session[:locale] && session[:locale] != I18n.default_locale.to_s redirect_to "/#{session[:locale]}/#{params[:product]}/#{params[:document]}" end end
check_redirects()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 134 def check_redirects redirect = Redirector.find(request) return redirect_to redirect if redirect end
content_from_file()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 111 def content_from_file content = File.read(document.path) frontmatter = YAML.safe_load(content) raise Errno::ENOENT if frontmatter['redirect'] content = Nexmo::Markdown::Renderer.new({ code_language: @code_language, current_user: current_user, locale: params[:locale], }).call(content) [frontmatter, content] end
content_from_folder()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 92 def content_from_folder frontmatter = YAML.safe_load(File.read(folder_config_path)) path = folder_config_path.chomp('/.config.yml') content = Nexmo::Markdown::Renderer.new({ code_language: @code_language, current_user: current_user, }).call(<<~HEREDOC <h1>#{@document_title}</h1> ```tabbed_folder source: #{path} ``` HEREDOC ) [frontmatter, content] end
document()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 58 def document @document ||= Nexmo::Markdown::DocFinder.find( root: root_folder, document: params[:document], language: params[:locale], product: params[:product], code_language: params[:code_language] ) end
folder_config_path()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 82 def folder_config_path @folder_config_path ||= Nexmo::Markdown::DocFinder.find( root: root_folder, document: "#{params[:document]}/.config.yml", language: params[:locale], product: params[:product], code_language: params[:code_language] ).path end
path_is_folder?()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 76 def path_is_folder? folder_config_path rescue Nexmo::Markdown::DocFinder::MissingDoc false end
root_folder()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 68 def root_folder if params[:namespace].present? "app/views/#{params[:namespace]}" else "#{Rails.configuration.docs_base_path}/_documentation" end end
set_canonical_url()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 126 def set_canonical_url if params[:namespace] || !params[:locale] || document.available_languages.include?(params[:locale]) @canonical_url = canonical_url else @canonical_url = "#{canonical_base}#{canonical_path.sub("#{params[:locale]}/", '')}" end end
set_product()
click to toggle source
# File lib/nexmo_developer/app/controllers/markdown_controller.rb, line 50 def set_product @product = params[:product] end