slim 1.3.3 → 1.3.4

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGES CHANGED
@@ -1,3 +1,8 @@
1
+ 1.3.4
2
+
3
+ * Fixed #314
4
+ * Logic-less test cases added
5
+
1
6
  1.3.3
2
7
 
3
8
  * Attribute handling made consistent:
data/README.md CHANGED
@@ -408,6 +408,24 @@ renders as
408
408
 
409
409
  div class="first second third"
410
410
 
411
+ #### Dynamic tags `*`
412
+
413
+ You can create completely dynamic tags using the splat attributes. Just create a method which returns a hash
414
+ with the :tag key.
415
+
416
+ ruby:
417
+ def a_unless_current
418
+ @page_current ? {:tag => 'span'} : {:tag => 'a', :href => 'http://slim-lang.com/'}
419
+ end
420
+ - @page_current = true
421
+ *a_unless_current Link
422
+ - @page_current = false
423
+ *a_unless_current Link
424
+
425
+ renders as
426
+
427
+ <span>Link</span><a href="http://slim-lang.com/">Link</a>
428
+
411
429
  #### ID shortcut `#` and class shortcut `.`
412
430
 
413
431
  Similarly to Haml, you can specify the `id` and `class` attributes in the following shortcut form
data/Rakefile CHANGED
@@ -20,6 +20,7 @@ namespace 'test' do
20
20
  t.libs << 'lib' << 'test/core'
21
21
  t.test_files = FileList['test/core/test_*.rb']
22
22
  t.verbose = true
23
+ #t.ruby_opts << '-w' << '-v'
23
24
  end
24
25
 
25
26
  Rake::TestTask.new('literate') do |t|
data/lib/slim/filter.rb CHANGED
@@ -26,10 +26,5 @@ module Slim
26
26
  def on_slim_output(code, escape, content)
27
27
  [:slim, :output, code, escape, compile(content)]
28
28
  end
29
-
30
- # Pass-through handler
31
- def on_slim_attrs(*attrs)
32
- [:slim, :attrs, *attrs.map {|a| compile(a) }]
33
- end
34
29
  end
35
30
  end
@@ -41,8 +41,8 @@ module Slim
41
41
  [:slim, :output, escape, access(name), content]
42
42
  end
43
43
 
44
- def on_slim_attr(name, escape, value)
45
- [:slim, :attr, name, escape, access(value)]
44
+ def on_slim_attrvalue(escape, value)
45
+ [:slim, :attrvalue, escape, access(value)]
46
46
  end
47
47
 
48
48
  def on_slim_splat(code)
data/lib/slim/version.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Slim
2
2
  # Slim version string
3
3
  # @api public
4
- VERSION = '1.3.3'
4
+ VERSION = '1.3.4'
5
5
  end
@@ -77,7 +77,7 @@ h1#title This is my title
77
77
  }
78
78
 
79
79
  assert_html '<section class="hello world" id="notice">Hello World from @env</section>', source, :default_tag => 'section'
80
- end
80
+ end
81
81
 
82
82
  def test_render_with_custom_shortcut
83
83
  source = %q{
@@ -225,7 +225,7 @@ p class='underscored_class_name' = output_number
225
225
  }
226
226
 
227
227
  assert_html '<p class="underscored_class_name">1337</p>', source
228
- end
228
+ end
229
229
 
230
230
  def test_nonstandard_attributes
231
231
  source = %q{
@@ -4,9 +4,6 @@ class ::MockError < NameError
4
4
  end
5
5
 
6
6
  class TestSlimTemplate < TestSlim
7
- class Scope
8
- end
9
-
10
7
  def test_default_mime_type
11
8
  assert_equal 'text/html', Slim::Template.default_mime_type
12
9
  end
@@ -20,11 +17,6 @@ class TestSlimTemplate < TestSlim
20
17
  assert_equal "<p>Hello World!</p>", template.render
21
18
  end
22
19
 
23
- def test_passing_locals
24
- template = Slim::Template.new { "p = 'Hey ' + name + '!'\n" }
25
- assert_equal "<p>Hey Joe!</p>", template.render(Object.new, :name => 'Joe')
26
- end
27
-
28
20
  def test_evaluating_in_an_object_scope
29
21
  template = Slim::Template.new { "p = 'Hey ' + @name + '!'\n" }
30
22
  scope = Object.new
@@ -58,57 +50,20 @@ class TestSlimTemplate < TestSlim
58
50
  res = template.render(Object.new, :name => 'Joe', :foo => 'bar')
59
51
  rescue => ex
60
52
  assert_kind_of MockError, ex
61
- assert_backtrace(ex, 'test.slim:4')
53
+ assert_backtrace(ex, 'test.slim:5')
62
54
  end
63
55
  end
64
56
 
65
57
  def test_compiling_template_source_to_a_method
66
58
  template = Slim::Template.new { |t| "Hello World!" }
67
- template.render(Scope.new)
59
+ template.render
68
60
  method = template.send(:compiled_method, [])
69
61
  assert_kind_of UnboundMethod, method
70
62
  end
71
63
 
72
64
  def test_passing_locals
73
65
  template = Slim::Template.new { "p = 'Hey ' + name + '!'\n" }
74
- assert_equal "<p>Hey Joe!</p>", template.render(Scope.new, :name => 'Joe')
75
- end
76
-
77
- def test_evaluating_in_an_object_scope
78
- template = Slim::Template.new { "p = 'Hey ' + @name + '!'\n" }
79
- scope = Scope.new
80
- scope.instance_variable_set :@name, 'Joe'
81
- assert_equal "<p>Hey Joe!</p>", template.render(scope)
82
- end
83
-
84
- def test_passing_a_block_for_yield
85
- template = Slim::Template.new { "p = 'Hey ' + yield + '!'\n" }
86
- assert_equal "<p>Hey Joe!</p>", template.render(Scope.new) { 'Joe' }
87
- end
88
-
89
- def test_backtrace_file_and_line_reporting_without_locals
90
- data = File.read(__FILE__).split("\n__END__\n").last
91
- fail unless data[0] == ?h
92
- template = Slim::Template.new('test.slim', 10) { data }
93
- begin
94
- template.render(Scope.new)
95
- fail 'should have raised an exception'
96
- rescue => ex
97
- assert_kind_of NameError, ex
98
- assert_backtrace(ex, 'test.slim:12')
99
- end
100
- end
101
-
102
- def test_backtrace_file_and_line_reporting_with_locals
103
- data = File.read(__FILE__).split("\n__END__\n").last
104
- fail unless data[0] == ?h
105
- template = Slim::Template.new('test.slim') { data }
106
- begin
107
- res = template.render(Scope.new, :name => 'Joe', :foo => 'bar')
108
- rescue => ex
109
- assert_kind_of MockError, ex
110
- assert_backtrace(ex, 'test.slim:5')
111
- end
66
+ assert_equal "<p>Hey Joe!</p>", template.render(Object.new, :name => 'Joe')
112
67
  end
113
68
  end
114
69
 
@@ -782,6 +782,29 @@ renders as
782
782
 
783
783
  #### Splat attributes `*`
784
784
 
785
+
786
+ #### Dynamic tags `*`
787
+
788
+ You can create completely dynamic tags using the splat attributes. Just create a method which returns a hash
789
+ with the :tag key.
790
+
791
+ ~~~ slim
792
+ ruby:
793
+ def a_unless_current
794
+ @page_current ? {:tag => 'span'} : {:tag => 'a', :href => 'http://slim-lang.com/'}
795
+ end
796
+ - @page_current = true
797
+ *a_unless_current Link
798
+ - @page_current = false
799
+ *a_unless_current Link
800
+ ~~~
801
+
802
+ renders as
803
+
804
+ ~~~ html
805
+ <span>Link</span><a href="http://slim-lang.com/">Link</a>
806
+ ~~~
807
+
785
808
  #### ID shortcut and class shortcut `.`
786
809
 
787
810
  #### Attribute shortcuts
@@ -8,7 +8,7 @@ Slim::Engine.after Slim::Parser, Temple::Filters::Validator, :grammar => Slim::
8
8
  Slim::Engine.before :Pretty, Temple::Filters::Validator
9
9
  Slim::Engine.set_default_options :tr => false, :logic_less => false
10
10
 
11
- module Helper
11
+ class MiniTest::Spec
12
12
  def render(source, options = {}, &block)
13
13
  Slim::Template.new(options) { source }.render(self, &block)
14
14
  end
data/test/literate/run.rb CHANGED
@@ -34,20 +34,16 @@ class LiterateTest < Temple::Engine
34
34
 
35
35
  class Compiler < Temple::Filter
36
36
  def call(exp)
37
- @opts, @in_testcase, @level = {}, false, 0
38
- "require 'helper'\n\n" << compile(exp)
37
+ @opts, @in_testcase = {}, false
38
+ "require 'helper'\n\n#{compile(exp)}"
39
39
  end
40
40
 
41
41
  def on_section(title, body)
42
42
  old_opts = @opts.dup
43
- @level += 1
44
43
  raise Temple::FilterError, 'New section between slim and html block' if @in_testcase
45
- result = "describe #{title.inspect} do\n "
46
- result << "include Helper\n " if @level == 1
47
- result << compile(body).gsub("\n", "\n ") << "\nend\n"
44
+ "describe #{title.inspect} do\n #{compile(body).gsub("\n", "\n ")}\nend\n"
48
45
  ensure
49
46
  @opts = old_opts
50
- @level -= 1
51
47
  end
52
48
 
53
49
  def on_multi(*exps)
@@ -6,8 +6,8 @@ class TestSlimLogicLess < TestSlim
6
6
  def initialize
7
7
  @hash = {
8
8
  :person => [
9
- { :name => 'Joe', },
10
- { :name => 'Jack', }
9
+ { :name => 'Joe', :age => 1, :selected => true },
10
+ { :name => 'Jack', :age => 2 }
11
11
  ]
12
12
  }
13
13
  end
@@ -109,4 +109,27 @@ p text with \#{123} test
109
109
 
110
110
  assert_html '<p>text with #{123} test</p>', source
111
111
  end
112
+
113
+ def test_ruby_attributes
114
+ source = %q{
115
+ p
116
+ - person
117
+ b name=name Person
118
+ a id=name = age
119
+ span class=name
120
+ Person
121
+ }
122
+
123
+ assert_html '<p><b name="Joe">Person</b><a id="Joe">1</a><span class="Joe"><Person></Person></span><b name="Jack">Person</b><a id="Jack">2</a><span class="Jack"><Person></Person></span></p>', source, :scope => Scope.new, :dictionary => '@hash', :dictionary_access => :symbol
124
+ end
125
+
126
+ def test_boolean_attributes
127
+ source = %q{
128
+ p
129
+ - person
130
+ input checked=selected = name
131
+ }
132
+
133
+ assert_html '<p><input checked="checked">Joe</input><input>Jack</input></p>', source, :scope => Scope.new, :dictionary => '@hash', :dictionary_access => :symbol
134
+ end
112
135
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: slim
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.3
4
+ version: 1.3.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -11,11 +11,11 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2012-10-16 00:00:00.000000000 Z
14
+ date: 2012-11-15 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: temple
18
- requirement: !ruby/object:Gem::Requirement
18
+ requirement: &6992320 !ruby/object:Gem::Requirement
19
19
  none: false
20
20
  requirements:
21
21
  - - ~>
@@ -23,15 +23,10 @@ dependencies:
23
23
  version: 0.5.5
24
24
  type: :runtime
25
25
  prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- none: false
28
- requirements:
29
- - - ~>
30
- - !ruby/object:Gem::Version
31
- version: 0.5.5
26
+ version_requirements: *6992320
32
27
  - !ruby/object:Gem::Dependency
33
28
  name: tilt
34
- requirement: !ruby/object:Gem::Requirement
29
+ requirement: &6991480 !ruby/object:Gem::Requirement
35
30
  none: false
36
31
  requirements:
37
32
  - - ~>
@@ -39,15 +34,10 @@ dependencies:
39
34
  version: 1.3.3
40
35
  type: :runtime
41
36
  prerelease: false
42
- version_requirements: !ruby/object:Gem::Requirement
43
- none: false
44
- requirements:
45
- - - ~>
46
- - !ruby/object:Gem::Version
47
- version: 1.3.3
37
+ version_requirements: *6991480
48
38
  - !ruby/object:Gem::Dependency
49
39
  name: rake
50
- requirement: !ruby/object:Gem::Requirement
40
+ requirement: &7050740 !ruby/object:Gem::Requirement
51
41
  none: false
52
42
  requirements:
53
43
  - - ! '>='
@@ -55,15 +45,10 @@ dependencies:
55
45
  version: 0.8.7
56
46
  type: :development
57
47
  prerelease: false
58
- version_requirements: !ruby/object:Gem::Requirement
59
- none: false
60
- requirements:
61
- - - ! '>='
62
- - !ruby/object:Gem::Version
63
- version: 0.8.7
48
+ version_requirements: *7050740
64
49
  - !ruby/object:Gem::Dependency
65
50
  name: sass
66
- requirement: !ruby/object:Gem::Requirement
51
+ requirement: &7050220 !ruby/object:Gem::Requirement
67
52
  none: false
68
53
  requirements:
69
54
  - - ! '>='
@@ -71,15 +56,10 @@ dependencies:
71
56
  version: 3.1.0
72
57
  type: :development
73
58
  prerelease: false
74
- version_requirements: !ruby/object:Gem::Requirement
75
- none: false
76
- requirements:
77
- - - ! '>='
78
- - !ruby/object:Gem::Version
79
- version: 3.1.0
59
+ version_requirements: *7050220
80
60
  - !ruby/object:Gem::Dependency
81
61
  name: minitest
82
- requirement: !ruby/object:Gem::Requirement
62
+ requirement: &7049700 !ruby/object:Gem::Requirement
83
63
  none: false
84
64
  requirements:
85
65
  - - ! '>='
@@ -87,15 +67,10 @@ dependencies:
87
67
  version: '0'
88
68
  type: :development
89
69
  prerelease: false
90
- version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
- requirements:
93
- - - ! '>='
94
- - !ruby/object:Gem::Version
95
- version: '0'
70
+ version_requirements: *7049700
96
71
  - !ruby/object:Gem::Dependency
97
72
  name: kramdown
98
- requirement: !ruby/object:Gem::Requirement
73
+ requirement: &7049220 !ruby/object:Gem::Requirement
99
74
  none: false
100
75
  requirements:
101
76
  - - ! '>='
@@ -103,15 +78,10 @@ dependencies:
103
78
  version: '0'
104
79
  type: :development
105
80
  prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
- requirements:
109
- - - ! '>='
110
- - !ruby/object:Gem::Version
111
- version: '0'
81
+ version_requirements: *7049220
112
82
  - !ruby/object:Gem::Dependency
113
83
  name: creole
114
- requirement: !ruby/object:Gem::Requirement
84
+ requirement: &7048720 !ruby/object:Gem::Requirement
115
85
  none: false
116
86
  requirements:
117
87
  - - ! '>='
@@ -119,15 +89,10 @@ dependencies:
119
89
  version: '0'
120
90
  type: :development
121
91
  prerelease: false
122
- version_requirements: !ruby/object:Gem::Requirement
123
- none: false
124
- requirements:
125
- - - ! '>='
126
- - !ruby/object:Gem::Version
127
- version: '0'
92
+ version_requirements: *7048720
128
93
  - !ruby/object:Gem::Dependency
129
94
  name: builder
130
- requirement: !ruby/object:Gem::Requirement
95
+ requirement: &7048140 !ruby/object:Gem::Requirement
131
96
  none: false
132
97
  requirements:
133
98
  - - ! '>='
@@ -135,12 +100,7 @@ dependencies:
135
100
  version: '0'
136
101
  type: :development
137
102
  prerelease: false
138
- version_requirements: !ruby/object:Gem::Requirement
139
- none: false
140
- requirements:
141
- - - ! '>='
142
- - !ruby/object:Gem::Version
143
- version: '0'
103
+ version_requirements: *7048140
144
104
  description: Slim is a template language whose goal is reduce the syntax to the essential
145
105
  parts without becoming cryptic.
146
106
  email:
@@ -272,8 +232,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
272
232
  version: '0'
273
233
  requirements: []
274
234
  rubyforge_project: slim
275
- rubygems_version: 1.8.24
235
+ rubygems_version: 1.8.15
276
236
  signing_key:
277
237
  specification_version: 3
278
238
  summary: Slim is a template language.
279
239
  test_files: []
240
+ has_rdoc: