module Documentation::ViewHelpers
Public Instance Methods
documentation_content_for(page)
click to toggle source
Return appropriate content for a given page
# File lib/documentation/view_helpers.rb, line 96 def documentation_content_for(page) # Get the content content = page.compiled_content.to_s # Insert navigation content.gsub!("<p class=''>{{nav}}</p>") do children = page.children children = children.select { |c| documentation_authorizer.can_view_page?(c) } items = children.map { |c| "<li><a href='#{documentation_doc_root}/#{c.full_permalink}'>#{c.title}</a></li>" }.join "<ul class='pages'>#{items}</ul>" end # Set the document root as appropriate content.gsub!("{{docRoot}}", documentation_doc_root) # Return HTML safe content content.html_safe end
documentation_doc_root()
click to toggle source
Return the documentation document root
# File lib/documentation/view_helpers.rb, line 118 def documentation_doc_root @documentation_doc_root ||= begin if controller.is_a?(Documentation::ApplicationController) ::Documentation::Engine.mounted_path.to_s.sub(/\/$/, '') else ::Documentation.config.preview_path_prefix.to_s.sub(/\/$/, '') end end end
documentation_edit_page_path(page)
click to toggle source
Path to edit a page in the manager UI
# File lib/documentation/view_helpers.rb, line 7 def documentation_edit_page_path(page) "#{::Documentation::Engine.mounted_path}/edit/#{page.full_permalink}" end
documentation_page_path(page)
click to toggle source
Path to view a page in the manager UI
# File lib/documentation/view_helpers.rb, line 14 def documentation_page_path(page) "#{::Documentation::Engine.mounted_path}/#{page.try(:full_permalink)}" end
documentation_search_pagination(result, options = {})
click to toggle source
Return search pagination links
# File lib/documentation/view_helpers.rb, line 167 def documentation_search_pagination(result, options = {}) String.new.tap do |s| unless result.first_page? querystring = {:query => result.query, :page => result.page - 1}.to_query s << link_to(t('documentation.helpers.documentation_search_pagination.previous'), "#{documentation_doc_root}/search?#{querystring}", :class => [options[:link_class], options[:previous_link_class]].compact.join(' ')) end unless result.last_page? querystring = {:query => result.query, :page => result.page + 1}.to_query s << link_to(t('documentation.helpers.documentation_search_pagination.next'), "#{documentation_doc_root}/search?#{querystring}", :class => [options[:link_class], options[:next_link_class]].compact.join(' ')) end end.html_safe end
documentation_search_results(result, options = {})
click to toggle source
Return the search results
# File lib/documentation/view_helpers.rb, line 145 def documentation_search_results(result, options = {}) options[:class] ||= 'searchResults' String.new.tap do |s| s << "<ul class='#{options[:class]}'>" result.results.each do |page| s << "<li>" s << "<h4><a href='#{documentation_doc_root}/#{page.full_permalink}'>#{page.title}</a></h4>" unless page.parents.empty? s << "<p class='in'>#{t('documentation.helpers.documentation_search_results.in')} " s << page.parents.map { |c| link_to(h(c.title), "#{documentation_doc_root}/#{c.full_permalink}")}.join(" ⇒ ").html_safe s << "</p>" end s << "<p class='excerpt'>#{result.excerpt_for(page)}</p>" s << "</li>" end s << "</ul>" end.html_safe end
documentation_search_summary(result)
click to toggle source
Return summary information for search results
# File lib/documentation/view_helpers.rb, line 138 def documentation_search_summary(result) t('documentation.helpers.documentation_search_summary.text', :total_results => result.total_results, :start_result => result.start_result_number, :end_result => result.end_result_number, :query => result.query) end