temple 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
metadata CHANGED
@@ -1,7 +1,12 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temple
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
5
10
  platform: ruby
6
11
  authors:
7
12
  - Magnus Holm
@@ -9,7 +14,7 @@ autorequire:
9
14
  bindir: bin
10
15
  cert_chain: []
11
16
 
12
- date: 2009-12-15 00:00:00 +01:00
17
+ date: 2010-01-23 00:00:00 +01:00
13
18
  default_executable:
14
19
  dependencies: []
15
20
 
@@ -19,59 +24,62 @@ executables: []
19
24
 
20
25
  extensions: []
21
26
 
22
- extra_rdoc_files:
23
- - README
27
+ extra_rdoc_files: []
28
+
24
29
  files:
25
- - README
30
+ - .yardopts
31
+ - LICENSE
32
+ - README.md
26
33
  - Rakefile
27
- - VERSION
28
34
  - lib/temple.rb
29
35
  - lib/temple/core.rb
30
36
  - lib/temple/engine.rb
37
+ - lib/temple/engines/erb.rb
31
38
  - lib/temple/filters/dynamic_inliner.rb
32
39
  - lib/temple/filters/escapable.rb
33
- - lib/temple/filters/mustache.rb
40
+ - lib/temple/filters/multi_flattener.rb
34
41
  - lib/temple/filters/static_merger.rb
35
42
  - lib/temple/generator.rb
36
43
  - lib/temple/parsers/erb.rb
37
- - lib/temple/parsers/mustache.rb
38
- - spec/dynamic_inliner_spec.rb
39
- - spec/escapable_spec.rb
40
- - spec/spec_helper.rb
41
- - spec/static_merger_spec.rb
42
- - spec/temple_spec.rb
44
+ - lib/temple/utils.rb
43
45
  - temple.gemspec
46
+ - test/engines/hello.erb
47
+ - test/engines/test_erb.rb
48
+ - test/engines/test_erb_m17n.rb
49
+ - test/filters/test_dynamic_inliner.rb
50
+ - test/filters/test_escapable.rb
51
+ - test/filters/test_static_merger.rb
52
+ - test/helper.rb
53
+ - test/test_generator.rb
44
54
  has_rdoc: true
45
55
  homepage: http://github.com/judofyr/temple
46
56
  licenses: []
47
57
 
48
58
  post_install_message:
49
- rdoc_options:
50
- - --charset=UTF-8
59
+ rdoc_options: []
60
+
51
61
  require_paths:
52
62
  - lib
53
63
  required_ruby_version: !ruby/object:Gem::Requirement
54
64
  requirements:
55
65
  - - ">="
56
66
  - !ruby/object:Gem::Version
67
+ segments:
68
+ - 0
57
69
  version: "0"
58
- version:
59
70
  required_rubygems_version: !ruby/object:Gem::Requirement
60
71
  requirements:
61
72
  - - ">="
62
73
  - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
63
76
  version: "0"
64
- version:
65
77
  requirements: []
66
78
 
67
79
  rubyforge_project:
68
- rubygems_version: 1.3.5
80
+ rubygems_version: 1.3.6
69
81
  signing_key:
70
82
  specification_version: 3
71
- summary: Template compilation framework in Ruby
72
- test_files:
73
- - spec/spec_helper.rb
74
- - spec/static_merger_spec.rb
75
- - spec/escapable_spec.rb
76
- - spec/dynamic_inliner_spec.rb
77
- - spec/temple_spec.rb
83
+ summary: Template compilation framework in RUby
84
+ test_files: []
85
+
data/README DELETED
@@ -1,7 +0,0 @@
1
- = Temple, a template compilation framework for Ruby
2
-
3
- I just wrote a 7521px long blog post about Temple, and I'm way too tired to
4
- write anything sensible here.
5
-
6
- * Read http://judofyr.net/posts/temple.html
7
- * Join http://groups.google.com/group/guardians-of-the-temple
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.0.1
@@ -1,70 +0,0 @@
1
- module Temple
2
- module Filters
3
- # A Mustache filter which compiles Mustache-nodes into Core and Escapable.
4
- # It's currently built for the Interpolation generator, but works with the
5
- # others too.
6
- class Mustache
7
- def initialize
8
- @tmpid = 0
9
- end
10
-
11
- def tmpid
12
- @tmpid += 1
13
- end
14
-
15
- def compile(exp)
16
- case exp.first
17
- when :mustache
18
- send("on_#{exp[1]}", *exp[2..-1])
19
- when :multi
20
- [:multi, *exp[1..-1].map { |e| compile(e) }]
21
- else
22
- exp
23
- end
24
- end
25
-
26
- def on_evar(name)
27
- exp = on_var(name)
28
- exp[1] = [:escape, exp[1]]
29
- exp
30
- end
31
-
32
- def on_var(name)
33
- [:dynamic, "ctx[#{name.inspect}]"]
34
- end
35
-
36
- def on_section(name, content)
37
- res = [:multi]
38
- code = compile(content)
39
- ctxtmp = "ctx#{tmpid}"
40
-
41
- block = <<-EOF
42
- if v = ctx[#{name.inspect}]
43
- v = [v] if v.is_a?(Hash) # shortcut when passed a single hash
44
- if v.respond_to?(:each)
45
- #{ctxtmp} = ctx.dup
46
- begin
47
- r = v.map { |h| ctx.update(h); CODE }.join
48
- rescue TypeError => e
49
- raise TypeError,
50
- "All elements in {{#{name.to_s}}} are not hashes!"
51
- end
52
- ctx.replace(#{ctxtmp})
53
- r
54
- else
55
- CODE
56
- end
57
- end
58
- EOF
59
-
60
- block.split("CODE").each do |str|
61
- res << [:block, str]
62
- res << code
63
- end
64
-
65
- res.pop
66
- res
67
- end
68
- end
69
- end
70
- end
@@ -1,68 +0,0 @@
1
- module Temple
2
- module Parsers
3
- # A Mustache parser which compiles into Mustache-nodes:
4
- #
5
- # {{ name }} # => [:mustache, :evar, :name]
6
- # {{{ name }}} # => [:mustache, :var, :name]
7
- # {{#name}} code {{/name}} # => [:mustache, :section, :name, code]
8
- # {{> simple }} # => [:mustache, :partial, :simple]
9
- class Mustache
10
- attr_accessor :otag, :ctag
11
-
12
- def compile(src)
13
- res = [:multi]
14
- while src =~ /#{otag}\#([^\}]*)#{ctag}\s*(.+?)#{otag}\/\1#{ctag}\s*/m
15
- # $` = The string to the left of the last successful match
16
- res << compile_tags($`)
17
- name = $1.strip.to_sym
18
- code = compile($2)
19
- res << [:mustache, :section, name, code]
20
- # $' = The string to the right of the last successful match
21
- src = $'
22
- end
23
- res << compile_tags(src)
24
- end
25
-
26
- def compile_tags(src)
27
- res = [:multi]
28
- while src =~ /#{otag}(#|=|!|<|>|\{)?(.+?)\1?#{ctag}+/
29
- res << [:static, $`]
30
- case $1
31
- when '#'
32
- raise "Unclosed section"
33
- when '!'
34
- # ignore comments
35
- when '='
36
- self.otag, self.ctag = $2.strip.split(' ', 2)
37
- when '>', '<'
38
- res << [:mustache, :partial, $2.strip.to_sym]
39
- when '{'
40
- res << [:mustache, :var, $2.strip.to_sym]
41
- else
42
- res << [:mustache, :evar, $2.strip.to_sym]
43
- end
44
- src = $'
45
- end
46
- res << [:static, src]
47
- end
48
-
49
- # {{ - opening tag delimiter
50
- def otag
51
- @otag ||= Regexp.escape('{{')
52
- end
53
-
54
- def otag=(tag)
55
- @otag = Regexp.escape(tag)
56
- end
57
-
58
- # }} - closing tag delimiter
59
- def ctag
60
- @ctag ||= Regexp.escape('}}')
61
- end
62
-
63
- def ctag=(tag)
64
- @ctag = Regexp.escape(tag)
65
- end
66
- end
67
- end
68
- end
@@ -1,79 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- describe_filter :DynamicInliner do
4
- it "should merge several statics into dynamic" do
5
- @filter.compile([:multi,
6
- [:static, "Hello "],
7
- [:static, "World\n "],
8
- [:static, "Have a nice day"]
9
- ]).should == [:multi,
10
- [:dynamic, '"Hello World\n Have a nice day"']
11
- ]
12
- end
13
-
14
- it "should merge several dynamics into a single dynamic" do
15
- @filter.compile([:multi,
16
- [:dynamic, "@hello"],
17
- [:dynamic, "@world"],
18
- [:dynamic, "@yeah"]
19
- ]).should == [:multi,
20
- [:dynamic, '"#{@hello}#{@world}#{@yeah}"']
21
- ]
22
- end
23
-
24
- it "should merge static+dynamic into dynamic" do
25
- @filter.compile([:multi,
26
- [:static, "Hello"],
27
- [:dynamic, "@world"],
28
- [:dynamic, "@yeah"],
29
- [:static, "Nice"]
30
- ]).should == [:multi,
31
- [:dynamic, '"Hello#{@world}#{@yeah}Nice"']
32
- ]
33
- end
34
-
35
- it "should merge static+dynamic around blocks" do
36
- @filter.compile([:multi,
37
- [:static, "Hello "],
38
- [:dynamic, "@world"],
39
- [:block, "Oh yeah"],
40
- [:dynamic, "@yeah"],
41
- [:static, "Once more"]
42
- ]).should == [:multi,
43
- [:dynamic, '"Hello #{@world}"'],
44
- [:block, "Oh yeah"],
45
- [:dynamic, '"#{@yeah}Once more"']
46
- ]
47
- end
48
-
49
- it "should keep blocks intact" do
50
- exp = [:multi, [:block, 'foo']]
51
- @filter.compile(exp).should == exp
52
- end
53
-
54
- it "should keep single static intact" do
55
- exp = [:multi, [:static, 'foo']]
56
- @filter.compile(exp).should == exp
57
- end
58
-
59
- it "should keep single dynamic intact" do
60
- exp = [:multi, [:dynamic, 'foo']]
61
- @filter.compile(exp).should == exp
62
- end
63
-
64
- it "should inline inside multi" do
65
- @filter.compile([:multi,
66
- [:static, "Hello "],
67
- [:dynamic, "@world"],
68
- [:multi,
69
- [:static, "Hello "],
70
- [:dynamic, "@world"]],
71
- [:static, "Hello "],
72
- [:dynamic, "@world"]
73
- ]).should == [:multi,
74
- [:dynamic, '"Hello #{@world}"'],
75
- [:multi, [:dynamic, '"Hello #{@world}"']],
76
- [:dynamic, '"Hello #{@world}"']
77
- ]
78
- end
79
- end
@@ -1,24 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
- require 'cgi'
3
-
4
- describe_filter :Escapable do
5
- it "should escape everywhere" do
6
- @filter.compile([:multi,
7
- [:dynamic, [:escape, "@hello"]],
8
- [:block, [:escape, "@world"]]
9
- ]).should == [:multi,
10
- [:dynamic, "CGI.escapeHTML(@hello.to_s)"],
11
- [:block, "CGI.escapeHTML(@world.to_s)"]
12
- ]
13
- end
14
-
15
- it "should automatically escape static content" do
16
- @filter.compile([:multi,
17
- [:static, [:escape, "<hello>"]],
18
- [:block, [:escape, "@world"]]
19
- ]).should == [:multi,
20
- [:static, "&lt;hello&gt;"],
21
- [:block, "CGI.escapeHTML(@world.to_s)"]
22
- ]
23
- end
24
- end
data/spec/spec_helper.rb DELETED
@@ -1,15 +0,0 @@
1
- $LOAD_PATH.unshift File.dirname(__FILE__) + '/../lib'
2
-
3
- require 'rubygems'
4
- require 'temple'
5
-
6
- def describe_filter(name, &blk)
7
- klass = Temple::Filters.const_get(name)
8
- describe(klass) do
9
- before do
10
- @filter = klass.new
11
- end
12
-
13
- instance_eval(&blk)
14
- end
15
- end
@@ -1,27 +0,0 @@
1
- require File.dirname(__FILE__) + '/spec_helper.rb'
2
-
3
- describe_filter :StaticMerger do
4
- it "should merge several statics" do
5
- @filter.compile([:multi,
6
- [:static, "Hello "],
7
- [:static, "World, "],
8
- [:static, "Good night"]
9
- ]).should == [:multi,
10
- [:static, "Hello World, Good night"]
11
- ]
12
- end
13
-
14
- it "should merge several statics around block" do
15
- @filter.compile([:multi,
16
- [:static, "Hello "],
17
- [:static, "World!"],
18
- [:block, "123"],
19
- [:static, "Good night, "],
20
- [:static, "everybody"]
21
- ]).should == [:multi,
22
- [:static, "Hello World!"],
23
- [:block, "123"],
24
- [:static, "Good night, everybody"]
25
- ]
26
- end
27
- end
data/spec/temple_spec.rb DELETED
@@ -1,5 +0,0 @@
1
- describe Temple do
2
- it "has a VERSION" do
3
- Temple::VERSION.join('.').should =~ /^\d+\.\d+\.\d+$/
4
- end
5
- end