slim 0.7.0 → 0.7.1
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/Gemfile.lock +3 -6
- data/README.md +32 -56
- data/Rakefile +2 -2
- data/benchmarks/run.rb +49 -16
- data/lib/slim.rb +0 -8
- data/lib/slim/compiler.rb +17 -26
- data/lib/slim/embedded_engine.rb +18 -11
- data/lib/slim/end_inserter.rb +10 -11
- data/lib/slim/engine.rb +8 -3
- data/lib/slim/filter.rb +8 -37
- data/lib/slim/parser.rb +27 -25
- data/lib/slim/template.rb +2 -31
- data/lib/slim/version.rb +1 -1
- data/slim.gemspec +1 -2
- data/test/helper.rb +35 -8
- data/test/slim/test_code_blocks.rb +37 -2
- data/test/slim/test_code_escaping.rb +2 -2
- data/test/slim/test_code_evaluation.rb +31 -9
- data/test/slim/test_code_output.rb +9 -1
- data/test/slim/test_code_structure.rb +23 -13
- data/test/slim/test_html_structure.rb +32 -8
- data/test/slim/test_parser_errors.rb +2 -2
- data/test/slim/test_ruby_errors.rb +28 -0
- metadata +25 -42
- data/lib/slim/helpers.rb +0 -81
- data/test/slim/test_code_helpers.rb +0 -30
data/lib/slim/helpers.rb
DELETED
@@ -1,81 +0,0 @@
|
|
1
|
-
module Slim
|
2
|
-
# Slim helper functions
|
3
|
-
#
|
4
|
-
# @api public
|
5
|
-
module Helpers
|
6
|
-
# Iterate over `Enumerable` object
|
7
|
-
# yielding each element to a Slim block
|
8
|
-
# and putting the result into `<li>` elements.
|
9
|
-
# For example:
|
10
|
-
#
|
11
|
-
# = list_of([1,2]) do |i|
|
12
|
-
# = i
|
13
|
-
#
|
14
|
-
# Produces:
|
15
|
-
#
|
16
|
-
# <li>1</li>
|
17
|
-
# <li>2</li>
|
18
|
-
#
|
19
|
-
# @param enum [Enumerable] The enumerable objects to iterate over
|
20
|
-
# @yield [item] A block which contains Slim code that goes within list items
|
21
|
-
# @yieldparam item An element of `enum`
|
22
|
-
# @api public
|
23
|
-
def list_of(enum, &block)
|
24
|
-
list = enum.map do |i|
|
25
|
-
"<li>#{yield(i)}</li>"
|
26
|
-
end.join("\n")
|
27
|
-
list.respond_to?(:html_safe) ? list.html_safe : list
|
28
|
-
end
|
29
|
-
|
30
|
-
# Returns an escaped copy of `html`.
|
31
|
-
# Strings which are declared as html_safe are not escaped.
|
32
|
-
#
|
33
|
-
# @param html [String] The string to escape
|
34
|
-
# @return [String] The escaped string
|
35
|
-
# @api public
|
36
|
-
def escape_html_safe(html)
|
37
|
-
html.html_safe? ? html : escape_html(html)
|
38
|
-
end
|
39
|
-
|
40
|
-
if defined?(EscapeUtils)
|
41
|
-
# Returns an escaped copy of `html`.
|
42
|
-
#
|
43
|
-
# @param html [String] The string to escape
|
44
|
-
# @return [String] The escaped string
|
45
|
-
# @api public
|
46
|
-
def escape_html(html)
|
47
|
-
EscapeUtils.escape_html(html.to_s)
|
48
|
-
end
|
49
|
-
elsif RUBY_VERSION > '1.9'
|
50
|
-
# Used by escape_html
|
51
|
-
# @api private
|
52
|
-
ESCAPE_HTML = {
|
53
|
-
'&' => '&',
|
54
|
-
'"' => '"',
|
55
|
-
'<' => '<',
|
56
|
-
'>' => '>',
|
57
|
-
'/' => '/',
|
58
|
-
}.freeze
|
59
|
-
|
60
|
-
# Returns an escaped copy of `html`.
|
61
|
-
#
|
62
|
-
# @param html [String] The string to escape
|
63
|
-
# @return [String] The escaped string
|
64
|
-
# @api public
|
65
|
-
def escape_html(html)
|
66
|
-
html.to_s.gsub(/[&\"<>\/]/, ESCAPE_HTML)
|
67
|
-
end
|
68
|
-
else
|
69
|
-
# Returns an escaped copy of `html`.
|
70
|
-
#
|
71
|
-
# @param html [String] The string to escape
|
72
|
-
# @return [String] The escaped string
|
73
|
-
# @api public
|
74
|
-
def escape_html(html)
|
75
|
-
html.to_s.gsub(/&/n, '&').gsub(/\"/n, '"').gsub(/>/n, '>').gsub(/</n, '<').gsub(/\//, '/')
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
module_function :escape_html, :escape_html_safe
|
80
|
-
end
|
81
|
-
end
|
@@ -1,30 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
class TestSlimHelpers < TestSlim
|
4
|
-
class HtmlSafeString < String
|
5
|
-
def html_safe?
|
6
|
-
true
|
7
|
-
end
|
8
|
-
end
|
9
|
-
|
10
|
-
def test_list_of
|
11
|
-
source = %q{
|
12
|
-
== list_of([1, 2, 3]) do |i|
|
13
|
-
= i
|
14
|
-
}
|
15
|
-
|
16
|
-
assert_html "<li>1</li>\n<li>2</li>\n<li>3</li>", source, :helpers => true
|
17
|
-
end
|
18
|
-
|
19
|
-
def test_list_of_with_html_safe
|
20
|
-
Object.send(:define_method, :html_safe?) { false }
|
21
|
-
String.send(:define_method, :html_safe) { HtmlSafeString.new(self) }
|
22
|
-
|
23
|
-
source = %q{
|
24
|
-
= list_of([1, 2, 3]) do |i|
|
25
|
-
= i
|
26
|
-
}
|
27
|
-
|
28
|
-
html = Slim::Template.new(:helpers => true, :use_html_safe => true) { source }.render(@env)
|
29
|
-
end
|
30
|
-
end
|