Module: MarkdownRecord::ControllerHelpers

Included in:
ApplicationController
Defined in:
app/helpers/markdown_record/controller_helpers.rb

Instance Method Summary collapse

Instance Method Details

#content_fragment(content_path = params[:content_path]) ⇒ Object



35
36
37
# File 'app/helpers/markdown_record/controller_helpers.rb', line 35

def content_fragment(content_path = params[:content_path])
  @content_fragment ||= ::MarkdownRecord::ContentFragment.find(content_path)
end

#download_html(fragment = content_fragment, layout = MarkdownRecord.config.public_layout) ⇒ Object



19
20
21
22
23
24
25
# File 'app/helpers/markdown_record/controller_helpers.rb', line 19

def download_html(fragment = content_fragment, layout = MarkdownRecord.config.public_layout)
  if fragment.html_exists?
    send_file fragment.html_path, layout: layout
  else
    head :not_found
  end
end

#download_json(fragment = content_fragment) ⇒ Object



27
28
29
30
31
32
33
# File 'app/helpers/markdown_record/controller_helpers.rb', line 27

def download_json(fragment = content_fragment)
  if fragment.json_exists?
    send_file fragment.json_path, layout: nil
  else
    head :not_found
  end
end

#render_html(fragment = content_fragment, layout = MarkdownRecord.config.public_layout) ⇒ Object



3
4
5
6
7
8
9
# File 'app/helpers/markdown_record/controller_helpers.rb', line 3

def render_html(fragment = content_fragment, layout = MarkdownRecord.config.public_layout)
  if fragment.html_exists?
    render file: fragment.html_path, layout: layout
  else
    head :not_found
  end
end

#render_json(fragment = content_fragment) ⇒ Object



11
12
13
14
15
16
17
# File 'app/helpers/markdown_record/controller_helpers.rb', line 11

def render_json(fragment = content_fragment)
  if fragment.json_exists?
    render file: fragment.json_path, layout: nil
  else
    head :not_found
  end
end