slim 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +3 -1
- data/CHANGES +6 -0
- data/Gemfile +1 -3
- data/README.md +504 -207
- data/Rakefile +28 -12
- data/benchmarks/profile-render.rb +3 -3
- data/benchmarks/run-benchmarks.rb +104 -62
- data/benchmarks/run-diffbench.rb +21 -0
- data/bin/slimrb +1 -2
- data/lib/slim.rb +0 -2
- data/lib/slim/command.rb +12 -5
- data/lib/slim/compiler.rb +10 -15
- data/lib/slim/embedded_engine.rb +34 -16
- data/lib/slim/engine.rb +4 -51
- data/lib/slim/filter.rb +5 -5
- data/lib/slim/grammar.rb +1 -1
- data/lib/slim/interpolation.rb +1 -3
- data/lib/slim/logic_less.rb +6 -0
- data/lib/slim/{sections.rb → logic_less/filter.rb} +16 -16
- data/lib/slim/logic_less/wrapper.rb +64 -0
- data/lib/slim/parser.rb +9 -11
- data/lib/slim/translator.rb +117 -0
- data/lib/slim/version.rb +1 -1
- data/slim.gemspec +1 -1
- data/test/slim/helper.rb +0 -5
- data/test/slim/{test_sections.rb → logic_less/test_logic_less.rb} +16 -15
- data/test/slim/{test_wrapper.rb → logic_less/test_wrapper.rb} +4 -12
- data/test/slim/test_encoding.rb +6 -0
- data/test/slim/test_slim_template.rb +4 -0
- data/test/slim/translator/test_translator.rb +64 -0
- metadata +69 -24
- data/lib/slim/wrapper.rb +0 -57
data/lib/slim/wrapper.rb
DELETED
@@ -1,57 +0,0 @@
|
|
1
|
-
module Slim
|
2
|
-
# For logic-less mode, objects can be encased in the Wrapper class.
|
3
|
-
# @api private
|
4
|
-
class Wrapper
|
5
|
-
attr_reader :value, :parent
|
6
|
-
|
7
|
-
def initialize(value, parent = nil)
|
8
|
-
@value, @parent = value, parent
|
9
|
-
end
|
10
|
-
|
11
|
-
# To find the reference, first check for standard method
|
12
|
-
# access by using respond_to?.
|
13
|
-
#
|
14
|
-
# If not found, check to see if the value is a hash and if the
|
15
|
-
# the name is a key on the hash.
|
16
|
-
#
|
17
|
-
# Not a hash, or not a key on the hash, then check to see if there
|
18
|
-
# is an instance variable with the name.
|
19
|
-
#
|
20
|
-
# If the instance variable doesn't exist and there is a parent object,
|
21
|
-
# go through the same steps on the parent object. This is useful when
|
22
|
-
# you are iterating over objects.
|
23
|
-
def [](name)
|
24
|
-
return wrap(value.send(name)) if value.respond_to?(name)
|
25
|
-
if value.respond_to?(:has_key?)
|
26
|
-
return wrap(value[name.to_sym]) if value.has_key?(name.to_sym)
|
27
|
-
return wrap(value[name.to_s]) if value.has_key?(name.to_s)
|
28
|
-
end
|
29
|
-
return wrap(value.instance_variable_get("@#{name}")) if value.instance_variable_defined?("@#{name}")
|
30
|
-
parent[name] if parent
|
31
|
-
end
|
32
|
-
|
33
|
-
# Empty objects must appear empty for inverted sections
|
34
|
-
def empty?
|
35
|
-
value.respond_to?(:empty) && value.empty?
|
36
|
-
end
|
37
|
-
|
38
|
-
# Used for output
|
39
|
-
def to_s
|
40
|
-
value.to_s
|
41
|
-
end
|
42
|
-
|
43
|
-
private
|
44
|
-
|
45
|
-
def wrap(response)
|
46
|
-
# Primitives are not wrapped
|
47
|
-
if [String, Numeric, TrueClass, FalseClass, NilClass].any? {|primitive| primitive === response }
|
48
|
-
response
|
49
|
-
# Enumerables are mapped with wrapped values (except Hash-like objects)
|
50
|
-
elsif !response.respond_to?(:has_key?) && response.respond_to?(:map)
|
51
|
-
response.map {|v| wrap(v) }
|
52
|
-
else
|
53
|
-
Wrapper.new(response, self)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
end
|
57
|
-
end
|