sal 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/sal.rb CHANGED
@@ -4,7 +4,6 @@ require 'temple'
4
4
  require 'sal/u'
5
5
  require 'sal/wrapper'
6
6
  require 'sal/parser'
7
- require 'sal/filter'
8
7
  require 'sal/compiler'
9
8
  require 'sal/engine'
10
9
  require 'sal/template'
data/lib/sal/compiler.rb CHANGED
@@ -1,10 +1,15 @@
1
1
  module Sal
2
2
  # Compiles HTML into Temple::HTML expressions
3
3
  # @api private
4
- class Compiler < Filter
4
+ class Compiler < Temple::Filter
5
+ def call(exp)
6
+ [:multi,
7
+ [:code, "_saldict = Sal::Wrapper.new(self)"],
8
+ super]
9
+ end
5
10
 
6
11
  def on_sal_tag(tag, attrs, content)
7
- [:html, :tag, tag, format_attrs(attrs), false, compile(content)]
12
+ [:html, :tag, tag, format_attrs(attrs), compile(content)]
8
13
  end
9
14
 
10
15
  def on_sal_text(incode, text)
@@ -16,31 +21,25 @@ module Sal
16
21
  end
17
22
 
18
23
  def on_sal_code(code, tag, attrs, content)
19
- tmp1, tmp2 = tmp_var(:sal), tmp_var(:sal)
24
+ tmp1, tmp2 = unique_name, unique_name
20
25
  content = compile(content)
21
- [:multi,
22
- [:block, "if (#{tmp1} = _saldict['#{code}'])"],
23
- [:block, "#{tmp2} = _saldict"],
24
- [:block, "_saldict = #{tmp1}"],
25
- [:block, "case (#{tmp1})"],
26
- [:block, "when Array"],
27
- [:block, "#{tmp1}.each do |_saldict|"],
28
- [:html, :tag, tag, ada(attrs), false, content],
29
- [:block, 'end'],
30
- [:block, "else"],
31
- [:html, :tag, tag, ada(attrs), false, content],
32
- [:block, 'end'],
33
- [:block, "_saldict = #{tmp2}"],
34
- [:block, 'end'],
35
- ]
26
+ [:if, "(#{tmp1} = _saldict['#{code}'])",
27
+ [:multi,
28
+ [:code, "#{tmp2} = _saldict"],
29
+ [:code, "_saldict = #{tmp1}"],
30
+ [:case, tmp1,
31
+ ['Array',
32
+ [:block, "#{tmp1}.each do |_saldict|",
33
+ [:html, :tag, tag, ada(attrs), content]]],
34
+ [:else,
35
+ [:html, :tag, tag, ada(attrs), content]]],
36
+ [:code, "_saldict = #{tmp2}"]]]
36
37
  end
37
38
 
38
39
  private
39
40
 
40
41
  def format_attrs(attrs)
41
- a = []
42
- attrs.each{ |k,v| a << [k, [:static, v]] }
43
- [:multi, [:html, :staticattrs] + a]
42
+ attrs.inject([:html, :attrs]) {|a, (k,v)| a << [:html, :attr, k, [:static, v]] }
44
43
  end
45
44
 
46
45
  def ada(attrs)
data/lib/sal/engine.rb CHANGED
@@ -3,10 +3,11 @@ module Sal
3
3
  set_default_options :format => :html,
4
4
  :generator => Temple::Generators::ArrayBuffer
5
5
 
6
- use Sal::Parser, :file, :tabsize, :encoding
6
+ use Sal::Parser, :file, :encoding
7
7
  use Sal::Compiler
8
8
  use Temple::HTML::Fast
9
9
 
10
+ filter :ControlFlow
10
11
  filter :MultiFlattener # Collapse nested multis into single multi
11
12
  filter :StaticMerger # Merge several statics into a single static
12
13
  filter :DynamicInliner # Merge several static/dynamic into single dynamic
data/lib/sal/parser.rb CHANGED
@@ -4,13 +4,7 @@ module Sal
4
4
  class Parser
5
5
  include Temple::Mixins::Options
6
6
 
7
- set_default_options :tabsize => 4,
8
- :encoding => 'utf-8'
9
-
10
- def initialize(options = {})
11
- super
12
- @tab = ' ' * @options[:tabsize]
13
- end
7
+ set_default_options :encoding => 'utf-8'
14
8
 
15
9
  # Compile the string to a Temple expression
16
10
  #
@@ -25,13 +19,8 @@ module Sal
25
19
  str.force_encoding(old_enc) unless str.valid_encoding?
26
20
  end
27
21
 
28
- result = [:multi,
29
- [:block, "_saldict = Sal::Wrapper.new(self)"]]
30
-
31
- doc = Nokogiri::XML(str)
32
-
33
- parse_nodeset([result], doc)
34
-
22
+ result = [:multi]
23
+ parse_nodeset([result], Nokogiri::XML(str))
35
24
  result
36
25
  end
37
26
 
data/lib/sal/template.rb CHANGED
@@ -4,10 +4,10 @@ module Sal
4
4
  Template = Temple::Templates::Tilt(Sal::Engine, :register_as => :sal)
5
5
 
6
6
  if Object.const_defined?(:Rails)
7
- RailsTemplate = Temple::Templates::Rails(Sal::Engine, :register_as => :sal)
8
-
9
- RailsTemplate.set_default_options :generator => Temple::Generators::RailsOutputBuffer,
10
- :disable_capture => true
7
+ RailsTemplate = Temple::Templates::Rails(Sal::Engine,
8
+ :register_as => :sal,
9
+ :generator => Temple::Generators::RailsOutputBuffer,
10
+ :disable_capture => true)
11
11
  end
12
12
  end
13
13
 
data/lib/sal/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Sal
2
- VERSION = '0.2.1'
2
+ VERSION = '0.2.2'
3
3
  end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: sal
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.2.1
5
+ version: 0.2.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Andrew Stone
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-04-27 00:00:00 -04:00
13
+ date: 2011-05-15 00:00:00 -04:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -32,7 +32,7 @@ dependencies:
32
32
  requirements:
33
33
  - - ~>
34
34
  - !ruby/object:Gem::Version
35
- version: "0.2"
35
+ version: "0.3"
36
36
  type: :runtime
37
37
  version_requirements: *id002
38
38
  - !ruby/object:Gem::Dependency
@@ -60,7 +60,6 @@ files:
60
60
  - lib/sal.rb
61
61
  - lib/sal/compiler.rb
62
62
  - lib/sal/engine.rb
63
- - lib/sal/filter.rb
64
63
  - lib/sal/parser.rb
65
64
  - lib/sal/template.rb
66
65
  - lib/sal/u.rb
@@ -90,7 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
90
89
  requirements: []
91
90
 
92
91
  rubyforge_project: sal
93
- rubygems_version: 1.6.1
92
+ rubygems_version: 1.6.2
94
93
  signing_key:
95
94
  specification_version: 3
96
95
  summary: sal is a template language.
data/lib/sal/filter.rb DELETED
@@ -1,5 +0,0 @@
1
- module Sal
2
- class Filter < Temple::Filter
3
- temple_dispatch :sal
4
- end
5
- end