Changesets can be listed by changeset number.
The Git repository is here.
- Revision:
- 193
- Log:
First stage commit of Typo 4.1, modified for the ROOL site.
Includes all local modifications but a final pass needs to be
made to delete any files left over from earlier Typo versions
that shouldn't be here anymore. See the 'tags' section of the
repository for a clean Typo 4.1 tree.Note that symlinks to shared files in the RISC OS Open theme
directory have been deliberately included this time around; I
decided that on balance it was better to leave them in as
placeholders, since unlike symlinks in app/views/shared, the
Typo theme structure is not a standard Rails concept.
- Author:
- rool
- Date:
- Wed Apr 04 18:51:02 +0100 2007
- Size:
- 3801 Bytes
1 | #!/usr/bin/env ruby |
2 | |
3 | require 'test/unit' |
4 | require 'rubygems' |
5 | require 'active_support' |
6 | require 'action_view' |
7 | |
8 | require File.dirname(__FILE__) + '/../lib/haml/template' |
9 | require File.dirname(__FILE__) + '/mocks/article' |
10 | |
11 | class TemplateTest < Test::Unit::TestCase |
12 | @@templates = %w{ very_basic standard helpers |
13 | whitespace_handling original_engine list helpful |
14 | silent_script tag_parsing just_stuff partials } |
15 | |
16 | def setup |
17 | ActionView::Base.register_template_handler("haml", Haml::Template) |
18 | @base = ActionView::Base.new(File.dirname(__FILE__) + "/../test/templates/") |
19 | @base.instance_variable_set("@article", Article.new) |
20 | @base.instance_variable_set("@foo", 'value one') |
21 | end |
22 | |
23 | def render(text) |
24 | Haml::Engine.new(text).to_html(@base) |
25 | end |
26 | |
27 | def load_result(name) |
28 | @result = '' |
29 | File.new(File.dirname(__FILE__) + "/results/#{name}.xhtml").each_line { |l| @result += l } |
30 | @result |
31 | end |
32 | |
33 | def assert_renders_correctly(name) |
34 | test = Proc.new do |rendered| |
35 | load_result(name).split("\n").zip(rendered.split("\n")).each_with_index do |pair, line| |
36 | message = "template: #{name}\nline: #{line}" |
37 | assert_equal(pair.first, pair.last, message) |
38 | end |
39 | end |
40 | test.call(@base.render(name)) |
41 | test.call(@base.render(:file => "partialize", :locals => { :name => name })) |
42 | end |
43 | |
44 | def test_empty_render_should_remain_empty |
45 | assert_equal('', render('')) |
46 | end |
47 | |
48 | def test_templates_should_render_correctly |
49 | @@templates.each do |template| |
50 | assert_renders_correctly template |
51 | end |
52 | end |
53 | |
54 | def test_action_view_templates_render_correctly |
55 | @base.instance_variable_set("@content_for_layout", 'Lorem ipsum dolor sit amet') |
56 | assert_renders_correctly 'content_for_layout' |
57 | end |
58 | |
59 | def test_instance_variables_should_work_inside_templates |
60 | @base.instance_variable_set("@content_for_layout", 'something') |
61 | assert_equal("<p>something</p>", render("%p= @content_for_layout").chomp) |
62 | |
63 | @base.instance_eval("@author = 'Hampton Catlin'") |
64 | assert_equal("<div class='author'>Hampton Catlin</div>", render(".author= @author").chomp) |
65 | |
66 | @base.instance_eval("@author = 'Hampton'") |
67 | assert_equal("Hampton", render("= @author").chomp) |
68 | |
69 | @base.instance_eval("@author = 'Catlin'") |
70 | assert_equal("Catlin", render("= @author").chomp) |
71 | end |
72 | |
73 | def test_instance_variables_should_work_inside_attributes |
74 | @base.instance_eval("@author = 'hcatlin'") |
75 | assert_equal("<p class='hcatlin'>foo</p>", render("%p{:class => @author} foo").chomp) |
76 | end |
77 | |
78 | def test_template_renders_should_eval |
79 | assert_equal("2\n", render("= 1+1")) |
80 | end |
81 | |
82 | def test_rhtml_still_renders |
83 | res = @base.render("../rhtml/standard") |
84 | assert !(res.nil? || res.empty?) |
85 | end |
86 | |
87 | def test_haml_options |
88 | Haml::Template.options = { :suppress_eval => true } |
89 | assert_equal({ :suppress_eval => true }, Haml::Template.options) |
90 | assert_renders_correctly("eval_suppressed") |
91 | Haml::Template.options = {} |
92 | end |
93 | |
94 | def test_exceptions_should_work_correctly |
95 | template = <<END |
96 | %p |
97 | %h1 Hello! |
98 | = "lots of lines" |
99 | - raise "Oh no!" |
100 | %p |
101 | this is after the exception |
102 | %strong yes it is! |
103 | ho ho ho. |
104 | END |
105 | @base.haml_filename = "(test)" |
106 | begin |
107 | render(template.chomp) |
108 | rescue Exception => e |
109 | assert_equal("(test).haml:4", e.backtrace[0]) |
110 | end |
111 | |
112 | @base.haml_filename = nil |
113 | begin |
114 | render(template.chomp) |
115 | rescue Exception => e |
116 | assert_equal("(haml):4", e.backtrace[0]) |
117 | end |
118 | |
119 | template = <<END |
120 | %p |
121 | %h1 Hello! |
122 | = "lots of lines" |
123 | = "even more!" |
124 | - compile_error( |
125 | %p |
126 | this is after the exception |
127 | %strong yes it is! |
128 | ho ho ho. |
129 | END |
130 | |
131 | begin |
132 | render(template.chomp) |
133 | rescue Exception => e |
134 | assert_equal("(haml):5", e.backtrace[0]) |
135 | end |
136 | end |
137 | end |