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/README.md CHANGED
@@ -29,7 +29,7 @@ Install Slim as a gem:
29
29
 
30
30
  Include Slim in your Gemfile:
31
31
 
32
- gem 'slim', require: 'slim/rails'
32
+ gem 'slim', :require => 'slim/rails'
33
33
 
34
34
  That's it! Now, just use the .slim extension and you're good to go.
35
35
 
@@ -76,7 +76,7 @@ Here's a quick example to demonstrate what a Slim template looks like:
76
76
  #footer
77
77
  | Copyright © 2010 Andrew Stone
78
78
 
79
- = render partial: 'tracking_code'
79
+ = render 'tracking_code'
80
80
 
81
81
  script
82
82
  | $(content).do_something();
@@ -90,9 +90,9 @@ Here's a quick example to demonstrate what a Slim template looks like:
90
90
 
91
91
  > The pipe tells Slim to just copy the line. It essentially escapes any processing.
92
92
 
93
- #### `` ` `` or `'`
93
+ #### `'`
94
94
 
95
- > _Same as the pipe (`|`)._
95
+ > The single quote tells Slim to copy the line (similar to |), but makes sure that a single trailing space is appended.
96
96
 
97
97
  #### `-`
98
98
 
@@ -120,7 +120,7 @@ Here's a quick example to demonstrate what a Slim template looks like:
120
120
  `end` is forbidden behind `-`. Blocks are defined only by indentation.
121
121
 
122
122
  #### Can put content on same line or nest it.
123
- If you nest content (e.g. put it on the next line), start the line with a pipe (`|`) or a backtick (`` ` ``).
123
+ If you nest content (e.g. put it on the next line), start the line with a pipe (`|`) or a single quote (`` ' ``).
124
124
 
125
125
  #### Indentation matters, but it's not as strict as Haml.
126
126
  If you want to first indent 2 spaces, then 5 spaces, it's your choice. To nest markup you only need to indent by one space, the rest is gravy.
@@ -226,7 +226,7 @@ Here's a quick example to demonstrate what a Slim template looks like:
226
226
 
227
227
  ### Treat multiple lines of code as text that should bypass parsing
228
228
 
229
- Use a pipe (`|`) or backtick (`` ` ``) to start the escape.
229
+ Use a pipe (`|`) or single quote (`` ' ``) to start the escape.
230
230
  Each following line that is indented greater than
231
231
  the backtick is copied over.
232
232
 
@@ -297,7 +297,7 @@ Here's a quick example to demonstrate what a Slim template looks like:
297
297
  [Google Group](http://groups.google.com/group/slim-template)
298
298
 
299
299
  ## Slim related projects
300
-
300
+
301
301
  * [Textmate bundle](http://github.com/fredwu/ruby-slim-textmate-bundle)
302
302
  * [Rails 3 Generators](http://github.com/leogalmeida/slim-rails)
303
303
  * [Slim for Clojure](http://github.com/chaslemley/slim.clj)
data/lib/slim.rb CHANGED
@@ -12,8 +12,3 @@ require 'slim/engine'
12
12
  require 'slim/template'
13
13
  require 'slim/version'
14
14
 
15
- module Slim
16
- def self.version
17
- VERSION
18
- end
19
- end
data/lib/slim/command.rb CHANGED
@@ -54,7 +54,7 @@ module Slim
54
54
  end
55
55
 
56
56
  opts.on_tail('-v', '--version', 'Print version') do
57
- puts "Slim #{Slim.version}"
57
+ puts "Slim #{Slim::VERSION}"
58
58
  exit
59
59
  end
60
60
  end
data/lib/slim/compiler.rb CHANGED
@@ -49,9 +49,6 @@ module Slim
49
49
  [:capture, tmp2,
50
50
  compile!(content)],
51
51
 
52
- # Make sure that `yield` returns the output.
53
- [:block, tmp2],
54
-
55
52
  # Close the block.
56
53
  [:block, 'end'],
57
54
 
@@ -14,17 +14,16 @@ module Slim
14
14
  engine.dup
15
15
  end
16
16
 
17
- def on_slim_embedded(engine, *body)
18
- EmbeddedEngine[engine].on_slim_embedded(engine, *body)
17
+ def on_slim_embedded(name, *body)
18
+ engine = EmbeddedEngine[name]
19
+ raise "Embedded engine #{name} is disabled" if (options[:enable_engines] && !options[:enable_engines].include?(name)) ||
20
+ (options[:disable_engines] && options[:disable_engines].include?(name))
21
+ engine.on_slim_embedded(name, *body)
19
22
  end
20
23
 
21
24
  def collect_text(body)
22
25
  body.inject('') do |text, exp|
23
- if exp[0] == :slim && exp[1] == :text
24
- text << exp[2]
25
- elsif exp[0] == :newline
26
- text << "\n"
27
- end
26
+ text << exp[2] if exp[0] == :slim && exp[1] == :text
28
27
  text
29
28
  end
30
29
  end
data/lib/slim/engine.rb CHANGED
@@ -10,10 +10,11 @@ module Slim
10
10
  set_default_options :pretty => false,
11
11
  :attr_wrapper => '"',
12
12
  :format => :html5,
13
- :id_delimiter => nil
13
+ :id_delimiter => nil,
14
+ :generator => Temple::Generators::ArrayBuffer
14
15
 
15
- use Slim::Parser, :file
16
- use Slim::EmbeddedEngine
16
+ use Slim::Parser, :file, :tabsize
17
+ use Slim::EmbeddedEngine, :enable_engines, :disable_engines
17
18
  use Slim::Interpolation
18
19
  use Slim::Sections, :sections, :dictionary, :dictionary_access
19
20
  use Slim::EndInserter
@@ -23,6 +24,6 @@ module Slim
23
24
  filter :MultiFlattener
24
25
  filter :StaticMerger
25
26
  filter :DynamicInliner
26
- generator :ArrayBuffer
27
+ chain << proc {|options| options[:generator].new }
27
28
  end
28
29
  end
data/lib/slim/parser.rb CHANGED
@@ -109,6 +109,7 @@ module Slim
109
109
 
110
110
  if !in_comment
111
111
  # The indentation of first line of the text block determines the text base indentation.
112
+ newline = text_indent ? "\n" : ''
112
113
  text_indent ||= indent
113
114
 
114
115
  # The text block lines must be at least indented as deep as the first line.
@@ -116,8 +117,7 @@ module Slim
116
117
  syntax_error! 'Unexpected text indentation', line, lineno if offset < 0
117
118
 
118
119
  # Generate the additional spaces in front.
119
- i = ' ' * offset
120
- stacks.last << [:slim, :text, i + line]
120
+ stacks.last << [:slim, :text, newline + (' ' * offset) + line]
121
121
  end
122
122
 
123
123
  stacks.last << [:newline]
@@ -163,13 +163,13 @@ module Slim
163
163
  end
164
164
 
165
165
  case line[0]
166
- when ?|, ?', ?`, ?/
166
+ when ?|, ?', ?/
167
167
  # Found a block.
168
168
 
169
169
  # We're now expecting the next line to be indented, so we'll need
170
170
  # to push a block to the stack.
171
171
  block = [:multi]
172
- stacks.last << block
172
+ stacks.last << (line[0] == ?' ? [:multi, block, [:slim, :text, ' ']] : block)
173
173
  stacks << block
174
174
  block_indent = indent
175
175
 
@@ -187,7 +187,7 @@ module Slim
187
187
  stacks.last << [:slim, :control, broken_line, block]
188
188
  stacks << block
189
189
  when ?=
190
- # Found a output bloc
190
+ # Found an output block.
191
191
  # We expect the line to be broken or the next line to be indented.
192
192
  block = [:multi]
193
193
  escape = line[1] != ?=
data/lib/slim/rails.rb CHANGED
@@ -1,5 +1,7 @@
1
1
  require 'slim'
2
2
 
3
+ Slim::Engine.default_options[:generator] = Temple::Generators::RailsOutputBuffer
4
+
3
5
  module ActionView
4
6
  module TemplateHandlers
5
7
  raise "Slim supports only Rails 3.x and greater, your Rails version is #{Rails::VERSION::STRING}" if Rails::VERSION::MAJOR < 3
@@ -16,7 +18,7 @@ module ActionView
16
18
  else
17
19
  # Slim handler for Rails 3.1 and greater
18
20
  class SlimHandler
19
- def call(template)
21
+ def self.call(template)
20
22
  Slim::Engine.new.compile(template.source)
21
23
  end
22
24
  end
data/lib/slim/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Slim
2
- VERSION = "0.7.3"
2
+ VERSION = '0.7.4'
3
3
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 7
8
- - 3
9
- version: 0.7.3
8
+ - 4
9
+ version: 0.7.4
10
10
  platform: ruby
11
11
  authors:
12
12
  - Andrew Stone
@@ -16,7 +16,7 @@ autorequire:
16
16
  bindir: bin
17
17
  cert_chain: []
18
18
 
19
- date: 2010-11-16 00:00:00 -05:00
19
+ date: 2010-11-22 00:00:00 -05:00
20
20
  default_executable:
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
@@ -30,8 +30,8 @@ dependencies:
30
30
  segments:
31
31
  - 0
32
32
  - 1
33
- - 5
34
- version: 0.1.5
33
+ - 6
34
+ version: 0.1.6
35
35
  type: :runtime
36
36
  version_requirements: *id001
37
37
  - !ruby/object:Gem::Dependency
@@ -77,7 +77,7 @@ dependencies:
77
77
  type: :development
78
78
  version_requirements: *id004
79
79
  - !ruby/object:Gem::Dependency
80
- name: erubis
80
+ name: minitest
81
81
  prerelease: false
82
82
  requirement: &id005 !ruby/object:Gem::Requirement
83
83
  none: false
@@ -90,7 +90,7 @@ dependencies:
90
90
  type: :development
91
91
  version_requirements: *id005
92
92
  - !ruby/object:Gem::Dependency
93
- name: minitest
93
+ name: rcov
94
94
  prerelease: false
95
95
  requirement: &id006 !ruby/object:Gem::Requirement
96
96
  none: false
@@ -103,7 +103,7 @@ dependencies:
103
103
  type: :development
104
104
  version_requirements: *id006
105
105
  - !ruby/object:Gem::Dependency
106
- name: rcov
106
+ name: rdiscount
107
107
  prerelease: false
108
108
  requirement: &id007 !ruby/object:Gem::Requirement
109
109
  none: false
@@ -116,7 +116,7 @@ dependencies:
116
116
  type: :development
117
117
  version_requirements: *id007
118
118
  - !ruby/object:Gem::Dependency
119
- name: rdiscount
119
+ name: liquid
120
120
  prerelease: false
121
121
  requirement: &id008 !ruby/object:Gem::Requirement
122
122
  none: false
@@ -129,7 +129,7 @@ dependencies:
129
129
  type: :development
130
130
  version_requirements: *id008
131
131
  - !ruby/object:Gem::Dependency
132
- name: liquid
132
+ name: yard
133
133
  prerelease: false
134
134
  requirement: &id009 !ruby/object:Gem::Requirement
135
135
  none: false
@@ -141,19 +141,6 @@ dependencies:
141
141
  version: "0"
142
142
  type: :development
143
143
  version_requirements: *id009
144
- - !ruby/object:Gem::Dependency
145
- name: yard
146
- prerelease: false
147
- requirement: &id010 !ruby/object:Gem::Requirement
148
- none: false
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- segments:
153
- - 0
154
- version: "0"
155
- type: :development
156
- version_requirements: *id010
157
144
  description: Slim is a template language whose goal is reduce the syntax to the essential parts without becoming cryptic.
158
145
  email:
159
146
  - andy@stonean.com
@@ -166,20 +153,8 @@ extensions: []
166
153
  extra_rdoc_files:
167
154
  - README.md
168
155
  files:
169
- - .gitignore
170
- - Gemfile
171
- - Gemfile.lock
172
156
  - README.md
173
- - Rakefile
174
- - benchmarks/run.rb
175
- - benchmarks/src/complex.erb
176
- - benchmarks/src/complex.haml
177
- - benchmarks/src/complex.slim
178
- - benchmarks/src/complex_view.rb
179
157
  - bin/slim
180
- - extra/slim-mode.el
181
- - extra/slim.vim
182
- - extra/test.slim
183
158
  - lib/slim.rb
184
159
  - lib/slim/command.rb
185
160
  - lib/slim/compiler.rb
@@ -193,21 +168,6 @@ files:
193
168
  - lib/slim/sections.rb
194
169
  - lib/slim/template.rb
195
170
  - lib/slim/version.rb
196
- - slim.gemspec
197
- - test/helper.rb
198
- - test/slim/test_code_blocks.rb
199
- - test/slim/test_code_escaping.rb
200
- - test/slim/test_code_evaluation.rb
201
- - test/slim/test_code_output.rb
202
- - test/slim/test_code_structure.rb
203
- - test/slim/test_embedded_engines.rb
204
- - test/slim/test_html_escaping.rb
205
- - test/slim/test_html_structure.rb
206
- - test/slim/test_parser_errors.rb
207
- - test/slim/test_rails.rb
208
- - test/slim/test_ruby_errors.rb
209
- - test/slim/test_sections.rb
210
- - test/slim/test_slim_template.rb
211
171
  has_rdoc: true
212
172
  homepage: http://github.com/stonean/slim
213
173
  licenses: []
data/.gitignore DELETED
@@ -1,8 +0,0 @@
1
- *.swp
2
- pkg/*
3
- *.gem
4
- .bundle
5
- readme.html
6
- .yardoc/
7
- doc/
8
- coverage/
data/Gemfile DELETED
@@ -1,3 +0,0 @@
1
- source :rubygems
2
-
3
- gemspec
data/Gemfile.lock DELETED
@@ -1,38 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- slim (0.7.2)
5
- temple (~> 0.1.5)
6
- tilt (~> 1.1)
7
-
8
- GEM
9
- remote: http://rubygems.org/
10
- specs:
11
- abstract (1.0.0)
12
- erubis (2.6.6)
13
- abstract (>= 1.0.0)
14
- haml (3.0.22)
15
- liquid (2.2.2)
16
- minitest (1.7.2)
17
- rake (0.8.7)
18
- rcov (0.9.9)
19
- rdiscount (1.6.5)
20
- temple (0.1.5)
21
- tilt (1.1)
22
- yard (0.6.1)
23
-
24
- PLATFORMS
25
- ruby
26
-
27
- DEPENDENCIES
28
- erubis
29
- haml
30
- liquid
31
- minitest
32
- rake (>= 0.8.7)
33
- rcov
34
- rdiscount
35
- slim!
36
- temple (~> 0.1.5)
37
- tilt (~> 1.1)
38
- yard
data/Rakefile DELETED
@@ -1,47 +0,0 @@
1
- begin
2
- require 'bundler'
3
- Bundler::GemHelper.install_tasks
4
- rescue Exception => e
5
- end
6
-
7
- require 'rake/testtask'
8
-
9
- desc 'Run Slim benchmarks! (Default :iterations is 1000)'
10
- task :bench, :iterations, :slow do |t, args|
11
- ruby("benchmarks/run.rb #{args[:slow]} #{args[:iterations]}")
12
- end
13
-
14
- Rake::TestTask.new(:test) do |t|
15
- t.libs << 'lib' << 'test'
16
- t.pattern = 'test/**/test_*.rb'
17
- t.verbose = true
18
- end
19
-
20
- begin
21
- require 'rcov/rcovtask'
22
- Rcov::RcovTask.new do |t|
23
- t.libs << 'lib' << 'test'
24
- t.pattern = 'test/**/test_*.rb'
25
- t.verbose = true
26
- end
27
- rescue LoadError
28
- task :rcov do
29
- abort "RCov is not available. In order to run rcov, you must: gem install rcov"
30
- end
31
- end
32
-
33
- begin
34
- require 'yard'
35
- YARD::Rake::YardocTask.new do |t|
36
- t.files = %w(lib/**/*.rb)
37
- end
38
- rescue LoadError
39
- task :yard do
40
- abort "YARD is not available. In order to run yard, you must: gem install yard"
41
- end
42
- end
43
-
44
- desc "Generate Documentation"
45
- task :doc => :yard
46
-
47
- task :default => 'test'
data/benchmarks/run.rb DELETED
@@ -1,96 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- $:.unshift(File.join(File.dirname(__FILE__), '..', 'lib'), File.join(File.dirname(__FILE__), 'src'))
4
-
5
- require 'slim'
6
- require 'complex_view'
7
-
8
- require 'benchmark'
9
- require 'ostruct'
10
- require 'erubis'
11
- require 'erb'
12
- require 'haml'
13
-
14
- class SlimBenchmarks
15
- def initialize(slow, iterations)
16
- @iterations = (iterations || 1000).to_i
17
- @benches = []
18
-
19
- tpl_erb = File.read(File.dirname(__FILE__) + '/src/complex.erb')
20
- tpl_haml = File.read(File.dirname(__FILE__) + '/src/complex.haml')
21
- tpl_slim = File.read(File.dirname(__FILE__) + '/src/complex.slim')
22
-
23
- view = ComplexView.new
24
- eview = OpenStruct.new(:header => view.header, :item => view.item).instance_eval{ binding }
25
-
26
- erb = ERB.new(tpl_erb)
27
- erubis = Erubis::Eruby.new(tpl_erb)
28
- fast_erubis = Erubis::FastEruby.new(tpl_erb)
29
- haml = Haml::Engine.new(tpl_haml, :format => :html5)
30
- haml_ugly = Haml::Engine.new(tpl_haml, :format => :html5, :ugly => true)
31
- slim = Slim::Template.new { tpl_slim }
32
-
33
- haml.def_method(view, :run_haml)
34
- haml_ugly.def_method(view, :run_haml_ugly)
35
- view.instance_eval %{
36
- def run_erb; #{erb.src}; end
37
- def run_erubis; #{erubis.src}; end
38
- def run_fast_erubis; #{fast_erubis.src}; end
39
- def run_slim; #{slim.precompiled_template}; end
40
- }
41
-
42
- if slow
43
- bench('erb (1)') { ERB.new(tpl_erb).result(eview) }
44
- bench('erubis (1)') { Erubis::Eruby.new(tpl_erb).result(eview) }
45
- bench('fast erubis (1)') { Erubis::Eruby.new(tpl_erb).result(eview) }
46
- bench('slim (1)') { Slim::Template.new { tpl_slim }.render(view) }
47
- bench('haml (1)') { Haml::Engine.new(tpl_haml, :format => :html5).render(view) }
48
- bench('haml ugly (1)') { Haml::Engine.new(tpl_haml, :format => :html5, :ugly => true).render(view) }
49
- end
50
-
51
- bench('erb (2)') { erb.result(eview) }
52
- bench('erubis (2)') { erubis.result(eview) }
53
- bench('fast (2)') { fast_erubis.result(eview) }
54
- bench('slim (2)') { slim.render(view) }
55
- bench('haml (2)') { haml.render(view) }
56
- bench('haml (2)') { haml_ugly.render(view) }
57
-
58
- bench('erb (3)') { view.run_erb }
59
- bench('erubis (3)') { view.run_erubis }
60
- bench('fast erubis (3)') { view.run_fast_erubis }
61
- bench('slim (3)') { view.run_slim }
62
- bench('haml (3)') { view.run_haml }
63
- bench('haml ugly (3)') { view.run_haml_ugly }
64
- end
65
-
66
- def run
67
- puts "#{@iterations} Iterations"
68
- Benchmark.bmbm do |x|
69
- @benches.each do |name, block|
70
- x.report name.to_s do
71
- @iterations.to_i.times { block.call }
72
- end
73
- end
74
- end
75
- puts "
76
- 1. Uncached benchmark. Template is parsed every time.
77
- Activate this benchmark with slow=1.
78
-
79
- 2. Cached benchmark. Template is parsed before the benchmark.
80
- The ruby code generated by the template engine might be evaluated every time.
81
- This benchmark uses the standard API of the template engine.
82
-
83
- 3. Compiled benchmark. Template is parsed before the benchmark and
84
- generated ruby code is compiled into a method.
85
- This is the fastest evaluation strategy because it benchmarks
86
- pure execution speed of the generated ruby code.
87
-
88
- "
89
- end
90
-
91
- def bench(name, &block)
92
- @benches.push([name, block])
93
- end
94
- end
95
-
96
- SlimBenchmarks.new(ARGV[0], ARGV[1]).run