File: fast_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 (97 lines) | stat: -rw-r--r-- 3,926 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
require 'spec_helper'

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

  it 'should compile html doctype' do
    expect(@html.call([:multi, [:html, :doctype, '5']])).to eq([:multi, [:static, '<!DOCTYPE html>']])
    expect(@html.call([:multi, [:html, :doctype, 'html']])).to eq([:multi, [:static, '<!DOCTYPE html>']])
    expect(@html.call([:multi, [:html, :doctype, '1.1']])).to eq [:multi,
      [:static, '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">']]
  end

  it 'should compile xml encoding' do
    expect(@html.call([:html, :doctype, 'xml latin1'])).to eq([:static, "<?xml version=\"1.0\" encoding=\"latin1\" ?>"])
  end

  it 'should compile html comment' do
    expect(@html.call([:html, :comment, [:static, 'test']])).to eq([:multi, [:static, "<!--"], [:static, "test"], [:static, "-->"]])
  end

  it 'should compile js wrapped in comments' do
    expect(Temple::HTML::Fast.new(js_wrapper: nil).call([:html, :js, [:static, 'test']])).to eq([:static, "test"])
    expect(Temple::HTML::Fast.new(js_wrapper: :comment).call([:html, :js, [:static, 'test']])).to eq([:multi, [:static, "<!--\n"], [:static, "test"], [:static, "\n//-->"]])
    expect(Temple::HTML::Fast.new(js_wrapper: :cdata).call([:html, :js, [:static, 'test']])).to eq([:multi, [:static, "\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n"]])
    expect(Temple::HTML::Fast.new(js_wrapper: :both).call([:html, :js, [:static, 'test']])).to eq([:multi, [:static, "<!--\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n//-->"]])
  end

  it 'should guess default js comment' do
    expect(Temple::HTML::Fast.new(js_wrapper: :guess, format: :xhtml).call([:html, :js, [:static, 'test']])).to eq([:multi, [:static, "\n//<![CDATA[\n"], [:static, "test"], [:static, "\n//]]>\n"]])
    expect(Temple::HTML::Fast.new(js_wrapper: :guess, format: :html).call([:html, :js, [:static, 'test']])).to eq([:multi, [:static, "<!--\n"], [:static, "test"], [:static, "\n//-->"]])
  end

  it 'should compile autoclosed html tag' do
    expect(@html.call([:html, :tag,
      'img', [:attrs],
      [:multi, [:newline]]
    ])).to eq [:multi,
                     [:static, "<img"],
                     [:attrs],
                     [:static, " />"],
                     [:multi, [:newline]]]
  end

  it 'should compile explicitly closed html tag' do
    expect(@html.call([:html, :tag,
      'closed', [:attrs]
    ])).to eq [:multi,
                     [:static, "<closed"],
                     [:attrs],
                     [:static, " />"]]
  end

  it 'should compile html with content' do
    expect(@html.call([:html, :tag,
      'div', [:attrs], [:content]
    ])).to eq [:multi,
                     [:static, "<div"],
                     [:attrs],
                     [:static, ">"],
                     [:content],
                     [:static, "</div>"]]
  end

  it 'should compile html with attrs' do
    expect(@html.call([:html, :tag,
      'div',
      [:html, :attrs,
       [:html, :attr, 'id', [:static, 'test']],
       [:html, :attr, 'class', [:dynamic, 'block']]],
       [:content]
    ])).to eq [:multi,
                     [:static, "<div"],
                     [:multi,
                      [:multi, [:static, " id=\""], [:static, "test"], [:static, '"']],
                      [:multi, [:static, " class=\""], [:dynamic, "block"], [:static, '"']]],
                     [:static, ">"],
                     [:content],
                     [:static, "</div>"]]
  end

  it 'should keep codes intact' do
    exp = [:multi, [:code, 'foo']]
    expect(@html.call(exp)).to eq(exp)
  end

  it 'should keep statics intact' do
    exp = [:multi, [:static, '<']]
    expect(@html.call(exp)).to eq(exp)
  end

  it 'should keep dynamic intact' do
    exp = [:multi, [:dynamic, 'foo']]
    expect(@html.call(exp)).to eq(exp)
  end
end