class SidenavResolver
Constants
- IGNORED_PATHS
Public Class Methods
new(path:, language:, namespace: nil)
click to toggle source
# File lib/nexmo_developer/app/presenters/sidenav_resolver.rb, line 4 def initialize(path:, language:, namespace: nil) @path = path @language = language @namespace = namespace end
Public Instance Methods
directories(path, name = nil)
click to toggle source
# File lib/nexmo_developer/app/presenters/sidenav_resolver.rb, line 18 def directories(path, name = nil) data = { title: (name || path), path: path } data[:children] = [] # Find all markdown files on disk that are children Dir.foreach(path) do |entry| next if entry.start_with?('.') next if IGNORED_PATHS.include? entry full_path = File.join(path, entry) next if documentation_index?(full_path) if File.directory?(full_path) config = if tabbed_folder?(full_path) YAML.safe_load(File.read("#{full_path}/.config.yml")) end if config && config['tabbed'] data[:children] << { title: config['title'], path: full_path, is_tabbed?: true } else data[:children] << directories(full_path, entry) end else doc_path = Nexmo::Markdown::DocFinder.find(root: @path, document: full_path, language: @language, strip_root_and_language: true).path data[:children] << { title: entry, path: doc_path, is_file?: true } end end # Do we have tasks for this product? product = path.sub(%r{#{Rails.configuration.docs_base_path}/\w+/\w+/}, '') if DocumentationConstraint.products_for_routes.include? product tasks = TutorialList.by_product(product) # If we have use cases and tutorials, output them if tasks['tutorials'].any? data[:children] << { title: 'tutorials', path: "/#{product}/tutorials", children: tasks['tutorials'].map(&:as_json) } end if tasks['use_cases'].any? # Otherwise show use_case as the top level data[:children] << { title: 'use-cases', path: "/#{product}/use-cases", children: tasks['use_cases'] } end end sort_navigation(data) end
document_meta(item)
click to toggle source
# File lib/nexmo_developer/app/presenters/sidenav_resolver.rb, line 114 def document_meta(item) doc = Nexmo::Markdown::DocFinder.find(root: item[:root] || @path, document: item[:path], language: @language, strip_root_and_language: true).path YAML.load_file(doc) end
items()
click to toggle source
# File lib/nexmo_developer/app/presenters/sidenav_resolver.rb, line 10 def items if @path.starts_with?('app/views') directories(@path)[:children] else directories("#{@path}/#{I18n.default_locale}")[:children] end end
path_to_url(path)
click to toggle source
# File lib/nexmo_developer/app/presenters/sidenav_resolver.rb, line 99 def path_to_url(path) strip_namespace(path).gsub('.md', '') end
strip_namespace(path)
click to toggle source
# File lib/nexmo_developer/app/presenters/sidenav_resolver.rb, line 92 def strip_namespace(path) path = path.gsub('.yml', '').sub("#{Rails.configuration.docs_base_path}/_use_cases/", 'use-cases/') path = path.gsub('.yml', '').sub('config/tutorials/', '/tutorials/') path = path.gsub('.yml', '').sub("#{Rails.configuration.docs_base_path}/", '') path.sub(%r{\w+/\w+/}, '') end
url_to_configuration_identifier(url)
click to toggle source
# File lib/nexmo_developer/app/presenters/sidenav_resolver.rb, line 88 def url_to_configuration_identifier(url) url.tr('/', '.') end
Private Instance Methods
documentation_index?(path)
click to toggle source
# File lib/nexmo_developer/app/presenters/sidenav_resolver.rb, line 121 def documentation_index?(path) path == "#{Rails.configuration.docs_base_path}/_documentation/#{I18n.default_locale}/index.md" end
tabbed_folder?(full_path)
click to toggle source
# File lib/nexmo_developer/app/presenters/sidenav_resolver.rb, line 125 def tabbed_folder?(full_path) File.exist?("#{full_path}/.config.yml") end