Class: Knitkit::OnlineDocumentSectionsController

Inherits:
BaseController
  • Object
show all
Includes:
ActionView::Helpers::SanitizeHelper
Defined in:
app/controllers/knitkit/online_document_sections_controller.rb

Instance Method Summary collapse

Methods inherited from BaseController

#view_current_publication, #website

Instance Method Details

#build_treeObject



29
30
31
# File 'app/controllers/knitkit/online_document_sections_controller.rb', line 29

def build_tree
  render :json => @document_sections.collect { |document| build_document_hash(document) }
end

#get_contentObject



33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'app/controllers/knitkit/online_document_sections_controller.rb', line 33

def get_content
  document_section = OnlineDocumentSection.where(:internal_identifier => params[:document_section_id]).first
  content = document_section.documented_item_published_content(@active_publication) unless @active_publication.nil?
  content = document_section.documented_item.content if @active_publication.nil? or content.nil?

  if document_section.use_markdown and content
    html = Kramdown::Document.new(content.body_html).to_html
  else
    html = content ? content.body_html : ''
  end

  render :json => {:success => true, :html => html}
end

#indexObject



10
11
12
13
# File 'app/controllers/knitkit/online_document_sections_controller.rb', line 10

def index
  @online_document = OnlineDocumentSection.find(params[:section_id])
  @online_document = nil if @online_document.id == find_root.id
end

#searchObject



15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'app/controllers/knitkit/online_document_sections_controller.rb', line 15

def search
  html = ''
  results = DocumentedContent.search({:query => params[:query].strip,
                                      :content_type => 'OnlineDocumentSection',
                                      :parent_id => params[:section_id],
                                      :website_id => @website.id})

  DocumentedContent.build_search_results(results).each do |result|
    html << "<p><a href=\"javascript:findShowAndExpandNode('#{result[:internal_identifier]}');\">#{result[:title]}</a><p style='border:solid 2px #CCC;padding:2px;'>#{strip_tags(result[:content].body_html[0..500])}...</p></p>"
  end

  render :json => {:success => true, :html => html}
end