slim 0.7.3 → 0.7.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/extra/slim.vim DELETED
@@ -1,60 +0,0 @@
1
- " Vim syntax file
2
- " Language: Slim
3
- " Maintainer: Andrew Stone <andy@stonean.com>
4
- " Version: 1
5
- " Last Change: 2010 Sep 25
6
- " TODO: Feedback is welcomed.
7
-
8
- " Quit when a syntax file is already loaded.
9
- if exists("b:current_syntax")
10
- finish
11
- endif
12
-
13
- if !exists("main_syntax")
14
- let main_syntax = 'slim'
15
- endif
16
-
17
- " Allows a per line syntax evaluation.
18
- let b:ruby_no_expensive = 1
19
-
20
- " Include Ruby syntax highlighting
21
- syn include @slimRuby syntax/ruby.vim
22
- unlet! b:current_syntax
23
- " Include Haml syntax highlighting
24
- syn include @slimHaml syntax/haml.vim
25
- unlet! b:current_syntax
26
- " Include Erb syntax highlighting
27
- syn include @slimErb syntax/eruby.vim
28
- unlet! b:current_syntax
29
-
30
- " Include HTML
31
- runtime! syntax/html.vim
32
- unlet! b:current_syntax
33
-
34
- setlocal iskeyword+=:
35
-
36
-
37
- syn region slimHtml start="^\s*[^-=]\w" end="$" contains=htmlTagName,htmlArg,htmlString
38
- syn region slimControl start="-" end="$" contains=@slimRuby keepend
39
-
40
- syn match slimFilter /\s*\w\+:\s*/ contained
41
-
42
- syn match slimCode /^\s*[-=#.].*/ contained
43
- syn match slimComment /^\(\s\+\)[/].*\(\n\1\s.*\)*/
44
- syn match slimText /^\(\s\+\)[`|'].*\(\n\1\s.*\)*/
45
-
46
- syn match slimJs /^\(\s\+\)\<javascript:\>.*\(\n\1\s.*\)*/ contains=@htmlJavaScript,slimFilter
47
- syn match slimHaml /^\(\s\+\)\<haml:\>.*\(\n\1\s.*\)*/ contains=@slimHaml,slimFilter
48
- syn match slimHaml /^\(\s\+\)\<erb:\>.*\(\n\1\s.*\)*/ contains=@slimErb,slimFilter
49
-
50
-
51
- "syn match slimFilter /\s*\<javascript:\>\s*/
52
-
53
-
54
- "contained containedin=slimJs
55
-
56
- hi def link slimText String
57
- hi def link slimComment Comment
58
- hi def link slimFilter Special
59
-
60
- let b:current_syntax = "slim"
data/extra/test.slim DELETED
@@ -1,48 +0,0 @@
1
- ! doctype html
2
- html
3
- head
4
- title Slim Test
5
- meta name="keywords" content="slim, syntax"
6
-
7
- javascript:
8
- $(function() {
9
- alert('Hello World');
10
- });
11
-
12
- haml:
13
- #someid.someclass{:this => 'test'} Content in haml
14
-
15
- erb:
16
- <%= some_method(@request) %>
17
-
18
- body
19
- / comment block
20
- with multiple lines
21
- This is another line
22
- h1 = @page_title
23
- p#notice.message
24
- | Welcome to the the syntax test.
25
- This file is to exercise the various markup.
26
- This is another line
27
- - unless @users.empty?
28
- table
29
- - for user in users do
30
- tr
31
- td.user id=user.name = user.name
32
- - else
33
- p There are no users.
34
-
35
- / Single comment line
36
- #content Hello #{@user.name}! Welcome to the test page!
37
- Try out Slim!
38
-
39
- = function_with_many_parameters(:a, \
40
- variable, :option => 1)
41
-
42
- p.text
43
- ' Another text block
44
- with multiple lines
45
-
46
- .text#footer
47
- ` Footer text block
48
- with multiple lines
data/slim.gemspec DELETED
@@ -1,34 +0,0 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.dirname(__FILE__) + "/lib/slim/version"
3
- require "date"
4
-
5
- Gem::Specification.new do |s|
6
- s.name = "slim"
7
- s.version = Slim::VERSION
8
- s.date = Date.today.to_s
9
- s.authors = ["Andrew Stone", "Fred Wu", "Daniel Mendler"]
10
- s.email = ["andy@stonean.com", "ifredwu@gmail.com", "mail@daniel-mendler.de"]
11
- s.summary = %q{Slim is a template language.}
12
- s.description = %q{Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.}
13
- s.homepage = %q{http://github.com/stonean/slim}
14
- s.extra_rdoc_files = ["README.md"]
15
- s.rdoc_options = ["--charset=UTF-8"]
16
- s.require_paths = ["lib"]
17
- s.rubyforge_project = s.name
18
-
19
- s.files = `git ls-files`.split("\n")
20
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
- s.require_paths = ["lib"]
23
-
24
- s.add_runtime_dependency(%q<temple>, ["~> 0.1.5"])
25
- s.add_runtime_dependency(%q<tilt>, ["~> 1.1"])
26
- s.add_development_dependency(%q<rake>, [">= 0.8.7"])
27
- s.add_development_dependency(%q<haml>, [">= 0"])
28
- s.add_development_dependency(%q<erubis>, [">= 0"])
29
- s.add_development_dependency(%q<minitest>, [">= 0"])
30
- s.add_development_dependency(%q<rcov>, [">= 0"])
31
- s.add_development_dependency(%q<rdiscount>, [">= 0"])
32
- s.add_development_dependency(%q<liquid>, [">= 0"])
33
- s.add_development_dependency(%q<yard>, [">= 0"])
34
- end
data/test/helper.rb DELETED
@@ -1,114 +0,0 @@
1
- # encoding: utf-8
2
-
3
- require 'rubygems'
4
- require 'minitest/unit'
5
- require 'slim'
6
-
7
- MiniTest::Unit.autorun
8
-
9
- class TestSlim < MiniTest::Unit::TestCase
10
- def setup
11
- @env = Env.new
12
- # Slim::Filter::DEFAULT_OPTIONS[:debug] = true
13
- end
14
-
15
- def teardown
16
- String.send(:undef_method, :html_safe?) if String.method_defined?(:html_safe?)
17
- String.send(:undef_method, :html_safe) if String.method_defined?(:html_safe)
18
- Object.send(:undef_method, :html_safe?) if Object.method_defined?(:html_safe?)
19
- Temple::Filters::EscapeHTML.default_options.delete(:use_html_safe)
20
- end
21
-
22
- def render(source, options = {}, &block)
23
- Slim::Template.new(options[:file], options) { source }.render(options[:scope] || @env, &block)
24
- end
25
-
26
- def assert_html(expected, source, options = {}, &block)
27
- assert_equal expected, render(source, options, &block)
28
- end
29
-
30
- def assert_syntax_error(message, source, options = {})
31
- render(source, options)
32
- raise 'Syntax error expected'
33
- rescue Slim::Parser::SyntaxError => ex
34
- assert_equal message, ex.message
35
- end
36
-
37
- def assert_ruby_error(error, from, source, options = {})
38
- render(source, options)
39
- raise 'Ruby error expected'
40
- rescue error => ex
41
- ex.backtrace[0] =~ /^(.*?:\d+):/
42
- assert_equal from, $1
43
- end
44
-
45
- def assert_ruby_syntax_error(from, source, options = {})
46
- render(source, options)
47
- raise 'Ruby syntax error expected'
48
- rescue SyntaxError => ex
49
- ex.message =~ /^(.*?:\d+):/
50
- assert_equal from, $1
51
- end
52
-
53
- def assert_runtime_error(message, source, options = {})
54
- render(source, options)
55
- raise Exception, 'Runtime error expected'
56
- rescue RuntimeError => ex
57
- assert_equal message, ex.message
58
- end
59
- end
60
-
61
- class Env
62
- attr_reader :var
63
-
64
- def initialize
65
- @var = 'instance'
66
- end
67
-
68
- def id_helper
69
- "notice"
70
- end
71
-
72
- def hash
73
- {:a => 'The letter a', :b => 'The letter b'}
74
- end
75
-
76
- def show_first?(show = false)
77
- show
78
- end
79
-
80
- def define_macro(name, &block)
81
- @macro ||= {}
82
- @macro[name.to_s] = block
83
- ''
84
- end
85
-
86
- def call_macro(name, *args)
87
- @macro[name.to_s].call(*args)
88
- end
89
-
90
- def hello_world(text = "Hello World from @env", opts = {})
91
- text << opts.to_a * " " if opts.any?
92
- if block_given?
93
- "#{text} #{yield} #{text}"
94
- else
95
- text
96
- end
97
- end
98
-
99
- def action_path(*args)
100
- "/action-#{args.join('-')}"
101
- end
102
-
103
- def in_keyword
104
- "starts with keyword"
105
- end
106
-
107
- def evil_method
108
- "<script>do_something_evil();</script>"
109
- end
110
-
111
- def output_number
112
- 1337
113
- end
114
- end
@@ -1,68 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSlimCodeBlocks < TestSlim
4
- def test_render_with_output_code_block
5
- source = %q{
6
- p
7
- = hello_world "Hello Ruby!" do
8
- | Hello from within a block!
9
- }
10
-
11
- assert_html '<p>Hello Ruby! Hello from within a block! Hello Ruby!</p>', source
12
- end
13
-
14
- def test_render_with_output_code_within_block
15
- source = %q{
16
- p
17
- = hello_world "Hello Ruby!" do
18
- = hello_world "Hello from within a block!"
19
- }
20
-
21
- assert_html '<p>Hello Ruby! Hello from within a block! Hello Ruby!</p>', source
22
- end
23
-
24
- def test_render_with_output_code_within_block_2
25
- source = %q{
26
- p
27
- = hello_world "Hello Ruby!" do
28
- = hello_world "Hello from within a block!" do
29
- = hello_world "And another one!"
30
- }
31
-
32
- assert_html '<p>Hello Ruby! Hello from within a block! And another one! Hello from within a block! Hello Ruby!</p>', source
33
- end
34
-
35
- def test_output_block_with_arguments
36
- source = %q{
37
- p
38
- = define_macro :person do |first_name, last_name|
39
- .first_name = first_name
40
- .last_name = last_name
41
- == call_macro :person, 'John', 'Doe'
42
- == call_macro :person, 'Max', 'Mustermann'
43
- }
44
-
45
- assert_html '<p><div class="first_name">John</div><div class="last_name">Doe</div><div class="first_name">Max</div><div class="last_name">Mustermann</div></p>', source
46
- end
47
-
48
-
49
- def test_render_with_control_code_loop
50
- source = %q{
51
- p
52
- - 3.times do
53
- | Hey!
54
- }
55
-
56
- assert_html '<p>Hey!Hey!Hey!</p>', source
57
- end
58
-
59
- def test_captured_code_block_with_conditional
60
- source = %q{
61
- = hello_world "Hello Ruby!" do
62
- - if true
63
- | Hello from within a block!
64
- }
65
-
66
- assert_html 'Hello Ruby! Hello from within a block! Hello Ruby!', source
67
- end
68
- end
@@ -1,69 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSlimCodeEscaping < TestSlim
4
- def test_escaping_evil_method
5
- source = %q{
6
- p = evil_method
7
- }
8
-
9
- assert_html '<p>&lt;script&gt;do_something_evil();&lt;&#47;script&gt;</p>', source
10
- end
11
-
12
- def test_escape_interpolation
13
- source = %q{
14
- p \\#{hello_world}
15
- }
16
-
17
- assert_html '<p>#{hello_world}</p>', source
18
- end
19
-
20
- def test_render_without_html_safe
21
- source = %q{
22
- p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
23
- }
24
-
25
- assert_html "<p>&lt;strong&gt;Hello World\n, meet \&quot;Slim\&quot;&lt;&#47;strong&gt;.</p>", source
26
- end
27
-
28
- def test_render_with_html_safe_false
29
- String.send(:define_method, :html_safe?) { false }
30
-
31
- source = %q{
32
- p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
33
- }
34
-
35
- assert_html "<p>&lt;strong&gt;Hello World\n, meet \&quot;Slim\&quot;&lt;&#47;strong&gt;.</p>", source, :use_html_safe => true
36
- end
37
-
38
- def test_render_with_html_safe_true
39
- String.send(:define_method, :html_safe?) { true }
40
-
41
- source = %q{
42
- p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
43
- }
44
-
45
- assert_html "<p><strong>Hello World\n, meet \"Slim\"</strong>.</p>", source, :use_html_safe => true
46
- end
47
-
48
- def test_render_with_global_html_safe_false
49
- String.send(:define_method, :html_safe?) { false }
50
- Temple::Filters::EscapeHTML.default_options[:use_html_safe] = false
51
-
52
- source = %q{
53
- p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
54
- }
55
-
56
- assert_html "<p>&lt;strong&gt;Hello World\n, meet \&quot;Slim\&quot;&lt;&#47;strong&gt;.</p>", source
57
- end
58
-
59
- def test_render_with_global_html_safe_true
60
- String.send(:define_method, :html_safe?) { true }
61
- Temple::Filters::EscapeHTML.default_options[:use_html_safe] = true
62
-
63
- source = %q{
64
- p = "<strong>Hello World\\n, meet \\"Slim\\"</strong>."
65
- }
66
-
67
- assert_html "<p><strong>Hello World\n, meet \"Slim\"</strong>.</p>", source
68
- end
69
- end
@@ -1,221 +0,0 @@
1
- require 'helper'
2
-
3
- class TestSlimCodeEvaluation < TestSlim
4
- def test_render_with_call_to_set_attributes
5
- source = %q{
6
- p id="#{id_helper}" class="hello world" = hello_world
7
- }
8
-
9
- assert_html '<p class="hello world" id="notice">Hello World from @env</p>', source
10
- end
11
-
12
- def test_render_with_call_to_set_custom_attributes
13
- source = %q{
14
- p data-id="#{id_helper}" data-class="hello world"
15
- = hello_world
16
- }
17
-
18
- assert_html '<p data-class="hello world" data-id="notice">Hello World from @env</p>', source
19
- end
20
-
21
- def test_render_with_call_to_set_attributes_and_call_to_set_content
22
- source = %q{
23
- p id="#{id_helper}" class="hello world" = hello_world
24
- }
25
-
26
- assert_html '<p class="hello world" id="notice">Hello World from @env</p>', source
27
- end
28
-
29
- def test_render_with_parameterized_call_to_set_attributes_and_call_to_set_content
30
- source = %q{
31
- p id="#{id_helper}" class="hello world" = hello_world("Hello Ruby!")
32
- }
33
-
34
- assert_html '<p class="hello world" id="notice">Hello Ruby!</p>', source
35
- end
36
-
37
- def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content
38
- source = %q{
39
- p id="#{id_helper}" class="hello world" = hello_world "Hello Ruby!"
40
- }
41
-
42
- assert_html '<p class="hello world" id="notice">Hello Ruby!</p>', source
43
- end
44
-
45
- def test_render_with_spaced_parameterized_call_to_set_attributes_and_call_to_set_content_2
46
- source = %q{
47
- p id="#{id_helper}" class="hello world" = hello_world "Hello Ruby!", :dummy => "value"
48
- }
49
-
50
- assert_html '<p class="hello world" id="notice">Hello Ruby!dummy value</p>', source
51
- end
52
-
53
- def test_hash_call_in_attribute
54
- source = %q{
55
- p id="#{hash[:a]}" Test it
56
- }
57
-
58
- assert_html '<p id="The letter a">Test it</p>', source
59
- end
60
-
61
- def test_instance_variable_in_attribute_without_quotes
62
- source = %q{
63
- p id=@var
64
- }
65
-
66
- assert_html '<p id="instance"></p>', source
67
- end
68
-
69
- def test_method_call_in_attribute_without_quotes
70
- source = %q{
71
- form action=action_path(:page, :save) method='post'
72
- }
73
-
74
- assert_html '<form action="&#47;action-page-save" method="post"></form>', source
75
- end
76
-
77
- def test_method_call_in_delimited_attribute_without_quotes
78
- source = %q{
79
- form(action=action_path(:page, :save) method='post')
80
- }
81
-
82
- assert_html '<form action="&#47;action-page-save" method="post"></form>', source
83
- end
84
-
85
- def test_method_call_in_delimited_attribute_without_quotes2
86
- source = %q{
87
- form(method='post' action=action_path(:page, :save))
88
- }
89
-
90
- assert_html '<form action="&#47;action-page-save" method="post"></form>', source
91
- end
92
-
93
- def test_hash_call_in_attribute_without_quotes
94
- source = %q{
95
- p id=hash[:a] Test it
96
- }
97
-
98
- assert_html '<p id="The letter a">Test it</p>', source
99
- end
100
-
101
- def test_hash_call_in_delimited_attribute
102
- source = %q{
103
- p(id=hash[:a]) Test it
104
- }
105
-
106
- assert_html '<p id="The letter a">Test it</p>', source
107
- end
108
-
109
- def test_hash_call_in_attribute_with_ruby_evaluation
110
- source = %q{
111
- p id={hash[:a] + hash[:a]} Test it
112
- }
113
-
114
- assert_html '<p id="The letter aThe letter a">Test it</p>', source
115
- end
116
-
117
- def test_hash_call_in_delimited_attribute_with_ruby_evaluation
118
- source = %q{
119
- p(id=(hash[:a] + hash[:a])) Test it
120
- }
121
-
122
- assert_html '<p id="The letter aThe letter a">Test it</p>', source
123
- end
124
-
125
- def test_hash_call_in_delimited_attribute_with_ruby_evaluation_2
126
- source = %q{
127
- p[id=(hash[:a] + hash[:a])] Test it
128
- }
129
-
130
- assert_html '<p id="The letter aThe letter a">Test it</p>', source
131
- end
132
-
133
- def test_hash_call_in_delimited_attribute_with_ruby_evaluation_3
134
- source = %q{
135
- p(id=[hash[:a] + hash[:a]]) Test it
136
- }
137
-
138
- assert_html '<p id="The letter aThe letter a">Test it</p>', source
139
- end
140
-
141
- def test_hash_call_in_delimited_attribute_with_ruby_evaluation_4
142
- source = %q{
143
- p(id=[hash[:a] + hash[:a]] class=[hash[:a]]) Test it
144
- }
145
-
146
- assert_html '<p class="The letter a" id="The letter aThe letter a">Test it</p>', source
147
- end
148
-
149
- def test_hash_call_in_delimited_attribute_with_ruby_evaluation_5
150
- source = %q{
151
- p(id=hash[:a] class=[hash[:a]]) Test it
152
- }
153
-
154
- assert_html '<p class="The letter a" id="The letter a">Test it</p>', source
155
- end
156
-
157
- def test_computation_in_attribute
158
- source = %q{
159
- p id=(1 + 1)*5 Test it
160
- }
161
-
162
- assert_html '<p id="10">Test it</p>', source
163
- end
164
-
165
- def test_interpolation_in_text
166
- source = %q{
167
- p
168
- | #{hello_world} with "quotes"
169
- p
170
- |
171
- A message from the compiler: #{hello_world}
172
- }
173
-
174
- assert_html '<p>Hello World from @env with "quotes"</p><p>A message from the compiler: Hello World from @env</p>', source
175
- end
176
-
177
- def test_interpolation_in_tag
178
- source = %q{
179
- p #{hello_world}
180
- }
181
-
182
- assert_html '<p>Hello World from @env</p>', source
183
- end
184
-
185
- def test_number_type_interpolation
186
- source = %q{
187
- p = output_number
188
- }
189
-
190
- assert_html '<p>1337</p>', source
191
- end
192
-
193
- def test_ternary_operation_in_attribute
194
- source = %q{
195
- p id="#{(false ? 'notshown' : 'shown')}" = output_number
196
- }
197
-
198
- assert_html '<p id="shown">1337</p>', source
199
- end
200
-
201
- def test_class_attribute_merging
202
- source = %{
203
- .alpha class="beta" Test it
204
- }
205
- assert_html '<div class="alpha beta">Test it</div>', source
206
- end
207
-
208
- def test_id_attribute_merging
209
- source = %{
210
- #alpha id="beta" Test it
211
- }
212
- assert_html '<div id="alpha_beta">Test it</div>', source, :id_delimiter => '_'
213
- end
214
-
215
- def test_id_attribute_merging2
216
- source = %{
217
- #alpha id="beta" Test it
218
- }
219
- assert_html '<div id="alpha-beta">Test it</div>', source, :id_delimiter => '-'
220
- end
221
- end