File: bootstrap_helper.rb

package info (click to toggle)
ruby-bootstrap-form 4.2.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 848 kB
  • sloc: ruby: 1,482; makefile: 4
file content (27 lines) | stat: -rw-r--r-- 600 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
module BootstrapHelper
  def form_with_source(&block)
    form_html = capture(&block)

    content_tag(:div, class: "example") do
      concat(form_html)
      concat(toggle)
      concat(codemirror)
    end
  end

  private

  def codemirror(form_html)
    content_tag(:div, class: "code", style: "display: none") do
      content_tag(:textarea, class: "codemirror") do
        HtmlBeautifier.beautify(form_html.strip.gsub(">", ">\n").gsub("<", "\n<"))
      end
    end
  end

  def toggle
    content_tag(:button, class: "toggle btn btn-sm btn-info") do
      "Show Source Code"
    end
  end
end