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



35
36
37
# File 'app/controllers/knitkit/online_document_sections_controller.rb', line 35

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

#get_contentObject



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'app/controllers/knitkit/online_document_sections_controller.rb', line 39

def get_content
  document_section = OnlineDocumentSection.find(params[:document_section_id])
  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
# File 'app/controllers/knitkit/online_document_sections_controller.rb', line 10

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

#searchObject



21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'app/controllers/knitkit/online_document_sections_controller.rb', line 21

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

#showObject



14
15
16
17
18
19
# File 'app/controllers/knitkit/online_document_sections_controller.rb', line 14

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

  render :show, :layout => false
end