Module: MarkdownRecord::ViewHelpers
- Defined in:
- app/helpers/markdown_record/view_helpers.rb
Instance Method Summary collapse
- #link_to_download_markdown_record_html(model, name = nil, html_options = nil, &block) ⇒ Object
- #link_to_download_markdown_record_json(model, name = nil, html_options = nil, &block) ⇒ Object
- #link_to_markdown_record(model, name = nil, html_options = nil, &block) ⇒ Object
- #link_to_markdown_record_html(model, name = nil, html_options = nil, &block) ⇒ Object
- #link_to_markdown_record_json(model, name = nil, html_options = nil, &block) ⇒ Object
- #path_to_markdown_record(model, ext, download = false) ⇒ Object
- #path_to_markdown_record_html(model, download = false) ⇒ Object
- #path_to_markdown_record_json(model, download = false) ⇒ Object
- #render_fragment(fragment_or_model) ⇒ Object
- #url_for_markdown_record_html(model, download = false) ⇒ Object
- #url_for_markdown_record_json(model, download = false) ⇒ Object
Instance Method Details
#link_to_download_markdown_record_html(model, name = nil, html_options = nil, &block) ⇒ Object
21 22 23 24 25 26 27 28 |
# File 'app/helpers/markdown_record/view_helpers.rb', line 21 def link_to_download_markdown_record_html(model, name = nil, = nil, &block) return nil if model.nil? path = path_to_markdown_record_html(model, true) name ||= model.name if model.respond_to?(:name) block_given? ? link_to("/#{path}", , nil, &block) : link_to(name, path, , &block) end |
#link_to_download_markdown_record_json(model, name = nil, html_options = nil, &block) ⇒ Object
49 50 51 52 53 54 55 56 |
# File 'app/helpers/markdown_record/view_helpers.rb', line 49 def link_to_download_markdown_record_json(model, name = nil, = nil, &block) return nil if model.nil? path = path_to_markdown_record_json(model, true) name ||= model.name if model.respond_to?(:name) block_given? ? link_to("/#{path}", , nil, &block) : link_to(name, path, , &block) end |
#link_to_markdown_record(model, name = nil, html_options = nil, &block) ⇒ Object
3 4 5 6 7 8 9 10 |
# File 'app/helpers/markdown_record/view_helpers.rb', line 3 def link_to_markdown_record(model, name = nil, = nil, &block) return nil if model.nil? path = path_to_markdown_record(model, "") name ||= model.name if model.respond_to?(:name) block_given? ? link_to(path, , nil, &block) : link_to(name, path, , &block) end |
#link_to_markdown_record_html(model, name = nil, html_options = nil, &block) ⇒ Object
12 13 14 15 16 17 18 19 |
# File 'app/helpers/markdown_record/view_helpers.rb', line 12 def link_to_markdown_record_html(model, name = nil, = nil, &block) return nil if model.nil? path = path_to_markdown_record_html(model) name ||= model.name if model.respond_to?(:name) block_given? ? link_to(path, , nil, &block) : link_to(name, path, , &block) end |
#link_to_markdown_record_json(model, name = nil, html_options = nil, &block) ⇒ Object
40 41 42 43 44 45 46 47 |
# File 'app/helpers/markdown_record/view_helpers.rb', line 40 def link_to_markdown_record_json(model, name = nil, = nil, &block) return nil if model.nil? path = path_to_markdown_record_json(model) name ||= model.name if model.respond_to?(:name) block_given? ? link_to(path, , nil, &block) : link_to(name, path, , &block) end |
#path_to_markdown_record(model, ext, download = false) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 |
# File 'app/helpers/markdown_record/view_helpers.rb', line 68 def path_to_markdown_record(model, ext, download = false) raise ArgumentError.new("A MarkdownRecord model must be provided.") unless model&.is_a?(::MarkdownRecord::Base) subdirectory = model.fragment_id path = Pathname.new(MarkdownRecord.config.mount_path).join(ext) path = path.join("download") if download path = path.join(subdirectory).to_s "/#{path}" end |
#path_to_markdown_record_html(model, download = false) ⇒ Object
30 31 32 |
# File 'app/helpers/markdown_record/view_helpers.rb', line 30 def path_to_markdown_record_html(model, download = false) path_to_markdown_record(model, "html", download) end |
#path_to_markdown_record_json(model, download = false) ⇒ Object
58 59 60 |
# File 'app/helpers/markdown_record/view_helpers.rb', line 58 def path_to_markdown_record_json(model, download = false) path_to_markdown_record(model, "json", download) end |
#render_fragment(fragment_or_model) ⇒ Object
80 81 82 83 84 85 86 87 88 |
# File 'app/helpers/markdown_record/view_helpers.rb', line 80 def render_fragment(fragment_or_model) unless fragment_or_model.is_a?(MarkdownRecord::ContentFragment) fragment = fragment_or_model.fragment end fragment ||= fragment_or_model raw(fragment.read_html) end |
#url_for_markdown_record_html(model, download = false) ⇒ Object
34 35 36 37 38 |
# File 'app/helpers/markdown_record/view_helpers.rb', line 34 def url_for_markdown_record_html(model, download = false) path = path_to_markdown_record_html(model, download) "#{root_url}/#{path}" end |
#url_for_markdown_record_json(model, download = false) ⇒ Object
62 63 64 65 66 |
# File 'app/helpers/markdown_record/view_helpers.rb', line 62 def url_for_markdown_record_json(model, download = false) path = path_to_markdown_record_json(model, download) "#{root_url}/#{path}" end |