File: pretty_spec.rb

package info (click to toggle)
ruby-temple 0.10.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 476 kB
  • sloc: ruby: 3,347; makefile: 6
file content (55 lines) | stat: -rw-r--r-- 2,034 bytes parent folder | download | duplicates (2)
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
require 'spec_helper'

describe Temple::HTML::Pretty do
  before do
    @html = Temple::HTML::Pretty.new
  end

  it 'should indent nested tags' do
    expect(@html.call([:html, :tag, 'div', [:multi],
      [:html, :tag, 'p', [:multi], [:multi, [:static, 'text'], [:dynamic, 'code']]]
    ])).to eq [:multi,
                     [:code, "_temple_html_pretty1 = /<code|<pre|<textarea/"],
                     [:multi,
                      [:static, "<div"],
                      [:multi],
                      [:static, ">"],
                      [:multi,
                       [:static, "\n  <p"],
                       [:multi],
                       [:static, ">"],
                       [:multi,
                        [:static, "\n    text"],
                        [:dynamic, "::Temple::Utils.indent_dynamic((code), false, \"\\n    \", _temple_html_pretty1)"]],
                       [:static, "\n  </p>"]],
                      [:static, "\n</div>"]]]
  end

  it 'should not indent preformatted tags' do
    expect(@html.call([:html, :tag, 'pre', [:multi],
      [:html, :tag, 'p', [:multi], [:static, 'text']]
    ])).to eq [:multi,
                     [:code, "_temple_html_pretty1 = /<code|<pre|<textarea/"],
                     [:multi,
                      [:static, "<pre"],
                      [:multi],
                      [:static, ">"],
                      [:multi,
                       [:static, "<p"],
                       [:multi],
                       [:static, ">"],
                       [:static, "text"],
                       [:static, "</p>"]],
                      [:static, "</pre>"]]]
  end

  it 'should not escape html_safe strings' do
    with_html_safe do
      expect(@html.call(
        [:dynamic, '"text<".html_safe']
      )).to eq [:multi,
                      [:code, "_temple_html_pretty1 = /<code|<pre|<textarea/"],
                      [:dynamic, "::Temple::Utils.indent_dynamic((\"text<\".html_safe), nil, \"\\n\", _temple_html_pretty1)"]]
    end
  end
end