File: app_markup.rb

package info (click to toggle)
camping 3.2.6-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,312 kB
  • sloc: ruby: 5,032; javascript: 2,362; makefile: 29
file content (90 lines) | stat: -rw-r--r-- 1,382 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
require 'test_helper'
require 'camping'

Camping.goes :Markup

module Markup::Controllers
  class Index
    def get
      render :index
    end
  end

  class NoLayout
    def get
      render :index, :layout => false
    end
  end

  class AutoPrepend
    def get
      mab do
        img :src => '/hello.png'
      end
    end
  end

  class Compat < R '/compat/(.*?)'
    def get(type)
      mab do
        send(type) do
          body { h1 'Nice' }
        end
      end
    end
  end

  class CompatHelpers
    def get
      mab do
        helpers.R CompatHelpers
      end
    end
  end
end

module Markup::Views
  def index
    h1 "Welcome!"
  end

  def layout
    self << '<!DOCTYPE html>'
    html do
      head do
        title "Web Page"
      end

      body { yield }
    end
  end
end

class Markup::Test < TestCase
  def test_render
    get '/'
    assert_body %r{\A<!DOCTYPE html>}
    assert_body %r{<h1>Welcome!</h1>}
    assert_body %r{<title>Web Page</title>}
  end

  def test_no_layout
    get '/no/layout'
    assert_body %r{<h1>Welcome!</h1>}

    assert_reverse do
      assert_body %r{<title>Web Page</title>}
    end
  end

  def test_auto_prepend
    get '/auto/prepend', {}, 'SCRIPT_NAME' => '/mount'
    assert_body '<img src="/mount/hello.png">'
  end

  def test_compat_helpers
    get '/compat/helpers'
    assert_body '/compat/helpers'
  end
end