flott 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,5 @@
1
+ .*.sw[pon]
2
+ .AppleDouble
3
+ .rvmrc
4
+ Gemfile.lock
5
+ pkg
data/.travis.yml ADDED
@@ -0,0 +1,16 @@
1
+ # Passes arguments to bundle install (http://gembundler.com/man/bundle-install.1.html)
2
+ bundler_args: --binstubs
3
+
4
+ # Specify which ruby versions you wish to run your tests on, each version will be used
5
+ rvm:
6
+ - 1.8.7
7
+ - 1.9.2
8
+ - 1.9.3
9
+ - rbx-18mode
10
+ - rbx-19mode
11
+ - ree
12
+ - jruby-18mode
13
+ - jruby-19mode
14
+ - ruby-head
15
+
16
+ script: "bundle exec rake"
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ # vim: set filetype=ruby et sw=2 ts=2:
2
+
3
+ source :rubygems
4
+
5
+ gemspec
6
+
7
+ group :test do
8
+ gem 'simplecov', '0.6.2', :platform => :mri_19
9
+ end
data/README.rdoc ADDED
@@ -0,0 +1,76 @@
1
+ == Usage
2
+
3
+ If you want to play with the parser it's best to use the Flott method:
4
+
5
+ Flott('1 + 1 = [=1 + 1]') # => "1 + 1 = 2"
6
+
7
+
8
+ However if you want to take advantage of the directory tree walking and inclusion
9
+ features, you have to use actual files:
10
+
11
+ If two template files are stored in the current directory.
12
+ One file "header":
13
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
14
+ "http://www.w3.org/TR/html4/strict.dtd">
15
+ <html>
16
+ <head>
17
+ <title>Hello [=@name]!</title>
18
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15">
19
+ </head>
20
+ <body>
21
+ And one file "template":
22
+ [^header-]
23
+ <h1>Hello [=@name]!</h1>
24
+ [for i in 1..6
25
+ if i % 2 == 0-]
26
+ <b>Hello [=@name]!</b>
27
+ [else-]
28
+ <i>Hello [=@name]!</i>
29
+ [end
30
+ end-]
31
+ </body>
32
+ </html>
33
+
34
+ The parser can be used like this
35
+ fp = Flott::Parser.from_filename('template')
36
+ env = Flott::Environment.new
37
+ env[:name] = "Florian"
38
+ fp.evaluate(env)
39
+
40
+ Or this:
41
+ puts Flott.string_from_file(filename, :name => "Florian")
42
+
43
+ You should also take a look at the other convenience methods in the Flott
44
+ module.
45
+
46
+ The output is created by including "header" into "template" with the
47
+ <tt>[^filename]</tt> syntax. <tt>[!@name]</tt> is a shortcut for
48
+ <tt>[print @name]</tt> while <tt>[=@name]</tt> first calls
49
+ Flott::Parser.escape on @name. It's also possible to just print or puts
50
+ strings.
51
+
52
+ Note the use of the assignment to the instance variable @name before
53
+ executing the template. The state passed to Parser#evaluate as
54
+ an environment and can be referenced in the template itself with
55
+ <tt>[=@name]</tt>.
56
+
57
+ After execution the output is:
58
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
59
+ "http://www.w3.org/TR/html4/strict.dtd">
60
+ <html>
61
+ <head>
62
+ <title>Hello Florian!</title>
63
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15">
64
+ </head>
65
+ <body>
66
+
67
+ <h1>Hello Florian!</h1>
68
+ <i>Hello Florian!</i>
69
+ <b>Hello Florian!</b>
70
+ <i>Hello Florian!</i>
71
+ <b>Hello Florian!</b>
72
+ <i>Hello Florian!</i>
73
+ <b>Hello Florian!</b>
74
+ </body>
75
+ </html>
76
+
data/Rakefile ADDED
@@ -0,0 +1,25 @@
1
+ # vim: set filetype=ruby et sw=2 ts=2:
2
+
3
+ require 'gem_hadar'
4
+
5
+ GemHadar do
6
+ name 'flott'
7
+ author 'Florian Frank'
8
+ email 'flori@ping.de'
9
+ homepage "http://github.com/flori/#{name}"
10
+ summary 'Ruby as a templating language'
11
+ description summary
12
+ test_dir 'tests'
13
+ ignore '.*.sw[pon]', 'pkg', 'Gemfile.lock', '.rvmrc', '.AppleDouble'
14
+ readme 'README.rdoc'
15
+ clobber Dir['benchmarks/data/*.{dat,log}'], 'coverage'
16
+
17
+ dependency 'bullshit', '~>0.1.3'
18
+ dependency 'rake', '0.9.2.2'
19
+ dependency 'tins', '~>0.4.2'
20
+ end
21
+
22
+ desc "Benchmarking library"
23
+ task :benchmark do
24
+ ruby '-Ilib benchmarks/runner.rb'
25
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
File without changes
@@ -0,0 +1,165 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bullshit'
4
+ require 'tins/xt'
5
+
6
+ class FlottBenchmark < Bullshit::RepeatCase
7
+ warmup true
8
+
9
+ truncate_data do
10
+ window_size 50
11
+ end
12
+
13
+ autocorrelation do
14
+ alpha_level 0.05
15
+ max_lags 50
16
+ file yes
17
+ end
18
+
19
+ iterations 1000
20
+
21
+ output_dir File.join(File.dirname(__FILE__), 'data')
22
+ data_file yes
23
+
24
+ require 'erb'
25
+
26
+ require 'flott'
27
+ include Flott
28
+
29
+ require_maybe 'kashmir'
30
+ require_maybe 'eruby'
31
+ require_maybe "amrita2" and include Amrita2
32
+ require_maybe "tenjin"
33
+
34
+ LENGTH = 500
35
+
36
+ def setup
37
+ @output = String.new
38
+ @target = %'AAAAA9.865881AAAAA\n' * LENGTH
39
+ end
40
+
41
+ def common_output_reset
42
+ @output != @target and
43
+ raise "output incorrect: #{@output.inspect} != #{@target.inspect}"
44
+ @output.replace ''
45
+ end
46
+
47
+ def setup_flott
48
+ @env = Environment.new(@output)
49
+ par = Parser.new( %'AAAAA[!3.141 ** 2]AAAAA\n' * LENGTH)
50
+ @flott = par.compile
51
+ end
52
+
53
+ def benchmark_flott
54
+ @flott.evaluate(@env)
55
+ end
56
+
57
+ alias after_flott common_output_reset
58
+
59
+ def setup_flott_escaped
60
+ @env = Environment.new(@output)
61
+ @flott = Parser.new( %'AAAAA[=3.141 ** 2]AAAAA\n' * LENGTH).compile
62
+ end
63
+
64
+ def benchmark_flott_escaped
65
+ @flott.evaluate(@env)
66
+ end
67
+
68
+ alias after_flott_escaped common_output_reset
69
+
70
+ def setup_erb
71
+ @erb = ERB.new( %'AAAAA<%=3.141 ** 2%>AAAAA\n' * LENGTH, 0, '-')
72
+ end
73
+
74
+ def benchmark_erb
75
+ @output = @erb.result
76
+ end
77
+
78
+ alias after_erb common_output_reset
79
+
80
+ if defined? Kashmir
81
+ def setup_kashmir
82
+ @kashmir = Kashmir.new(%'AAAAA^(3.141 ** 2)AAAAA\n' * LENGTH)
83
+ end
84
+
85
+ def benchmark_kashmir
86
+ @output = @kashmir.expand(Object.new)
87
+ end
88
+
89
+ alias after_kashmir common_output_reset
90
+
91
+ def setup_kashmir_escaped
92
+ @kashmir = Kashmir.for_XML(%'AAAAA^(3.141 ** 2)AAAAA\n' * LENGTH)
93
+ end
94
+
95
+ def benchmark_kashmir_escaped
96
+ @output = @kashmir.expand(Object.new)
97
+ end
98
+
99
+ alias after_kashmir_escaped common_output_reset
100
+ end
101
+
102
+ if defined? ERuby
103
+ def setup_eruby
104
+ require 'stringio'
105
+ ec = ERuby::Compiler.new
106
+ @eruby = ec.compile_string(%'AAAAA<%=3.141 ** 2%>AAAAA\n' * LENGTH)
107
+ $stdout = StringIO.new(@output)
108
+ end
109
+
110
+ def benchmark_eruby
111
+ eval(@eruby)
112
+ end
113
+
114
+ def after_eruby
115
+ common_output_reset
116
+ $stdout.rewind
117
+ end
118
+ end
119
+
120
+ if defined? Amrita2
121
+ def setup_amrita
122
+ @amrita = Template.new(%'AAAAA<span am:src="test"></span>AAAAA\n' * LENGTH)
123
+ end
124
+
125
+ def benchmark_amrita
126
+ @output = @amrita.render_with(:test => 3.141 ** 2).dup
127
+ end
128
+
129
+ alias after_amrita common_output_reset
130
+ end
131
+
132
+ if defined? Tenjin
133
+ require 'tempfile'
134
+
135
+ def setup_tenjin
136
+ template = %'AAAAA\#{3.141 ** 2}AAAAA\n' * LENGTH
137
+ tempfile = Tempfile.new 'temp'
138
+ tempfile.write template
139
+ tempfile.fsync
140
+ @template_name = tempfile.path
141
+ @tenjin = Tenjin::Engine.new
142
+ end
143
+
144
+ def benchmark_tenjin
145
+ @output = @tenjin.render(@template_name)
146
+ end
147
+
148
+ alias after_tenjin common_output_reset
149
+
150
+ def setup_tenjin_escaped
151
+ template = %'AAAAA${3.141 ** 2}AAAAA\n' * LENGTH
152
+ tempfile = Tempfile.new 'temp'
153
+ tempfile.write template
154
+ tempfile.fsync
155
+ @template_name = tempfile.path
156
+ @tenjin = Tenjin::Engine.new
157
+ end
158
+
159
+ def benchmark_tenjin_escaped
160
+ @output = @tenjin.render(@template_name)
161
+ end
162
+
163
+ alias after_tenjin_escaped common_output_reset
164
+ end
165
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'bullshit'
4
+ include Bullshit
5
+ $:.unshift File.dirname(__FILE__)
6
+ require 'flott_benchmark.rb'
data/doc-main.txt ADDED
@@ -0,0 +1,76 @@
1
+ == Usage
2
+
3
+ If you want to play with the parser it's best to use the Flott method:
4
+
5
+ Flott('1 + 1 = [=1 + 1]') # => "1 + 1 = 2"
6
+
7
+
8
+ However if you want to take advantage of the directory tree walking and inclusion
9
+ features, you have to use methods.
10
+
11
+ If two template files are stored in the current directory.
12
+ One file "header":
13
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
14
+ "http://www.w3.org/TR/html4/strict.dtd">
15
+ <html>
16
+ <head>
17
+ <title>Hello [=@name]!</title>
18
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15">
19
+ </head>
20
+ <body>
21
+ And one file "template":
22
+ [^header-]
23
+ <h1>Hello [=@name]!</h1>
24
+ [for i in 1..6
25
+ if i % 2 == 0-]
26
+ <b>Hello [=@name]!</b>
27
+ [else-]
28
+ <i>Hello [=@name]!</i>
29
+ [end
30
+ end-]
31
+ </body>
32
+ </html>
33
+
34
+ The parser can be used like this
35
+ fp = Flott::Parser.from_filename('template')
36
+ env = Flott::Environment.new
37
+ env[:name] = "Florian"
38
+ fp.evaluate(env)
39
+
40
+ Or this:
41
+ puts Flott.string_from_file(filename, :name => "Florian")
42
+
43
+ You should also take a look at the other convenience methods in the Flott
44
+ module.
45
+
46
+ The output is created by including "header" into "template" with the
47
+ <tt>[^filename]</tt> syntax. <tt>[!@name]</tt> is a shortcut for
48
+ <tt>[print @name]</tt> while <tt>[=@name]</tt> first calls
49
+ Flott::Parser.escape on @name. It's also possible to just print or puts
50
+ strings.
51
+
52
+ Note the use of the assignment to the instance variable @name before
53
+ executing the template. The state passed to Parser#evaluate as
54
+ an environment and can be referenced in the template itself with
55
+ <tt>[=@name]</tt>.
56
+
57
+ After execution the output is:
58
+ <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
59
+ "http://www.w3.org/TR/html4/strict.dtd">
60
+ <html>
61
+ <head>
62
+ <title>Hello Florian!</title>
63
+ <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-15">
64
+ </head>
65
+ <body>
66
+
67
+ <h1>Hello Florian!</h1>
68
+ <i>Hello Florian!</i>
69
+ <b>Hello Florian!</b>
70
+ <i>Hello Florian!</i>
71
+ <b>Hello Florian!</b>
72
+ <i>Hello Florian!</i>
73
+ <b>Hello Florian!</b>
74
+ </body>
75
+ </html>
76
+
data/flott.gemspec ADDED
@@ -0,0 +1,41 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = "flott"
5
+ s.version = "1.0.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["Florian Frank"]
9
+ s.date = "2012-05-11"
10
+ s.description = "Ruby as a templating language"
11
+ s.email = "flori@ping.de"
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/flott.rb", "lib/flott/version.rb", "lib/flott/cache.rb"]
13
+ s.files = [".gitignore", ".travis.yml", "Gemfile", "README.rdoc", "Rakefile", "VERSION", "benchmarks/data/.keep", "benchmarks/flott_benchmark.rb", "benchmarks/runner.rb", "doc-main.txt", "flott.gemspec", "install.rb", "lib/flott.rb", "lib/flott/cache.rb", "lib/flott/version.rb", "make_doc.rb", "tests/templates/header", "tests/templates/subdir/deeptemplate", "tests/templates/subdir/included", "tests/templates/subdir/subdir2/deepincluded2", "tests/templates/subdir/subdir2/included2", "tests/templates/subdir/subdir3/included3", "tests/templates/template", "tests/templates/template2", "tests/templates/toplevel", "tests/templates/toplevel2", "tests/test_cache.rb", "tests/test_flott.rb", "tests/test_flott_file.rb", "tests/test_helper.rb"]
14
+ s.homepage = "http://github.com/flori/flott"
15
+ s.rdoc_options = ["--title", "Flott - Ruby as a templating language", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubygems_version = "1.8.24"
18
+ s.summary = "Ruby as a templating language"
19
+ s.test_files = ["tests/test_flott_file.rb", "tests/test_flott.rb", "tests/test_cache.rb", "tests/test_helper.rb"]
20
+
21
+ if s.respond_to? :specification_version then
22
+ s.specification_version = 3
23
+
24
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
25
+ s.add_development_dependency(%q<gem_hadar>, ["~> 0.1.8"])
26
+ s.add_runtime_dependency(%q<bullshit>, ["~> 0.1.3"])
27
+ s.add_runtime_dependency(%q<rake>, ["= 0.9.2.2"])
28
+ s.add_runtime_dependency(%q<tins>, ["~> 0.4.2"])
29
+ else
30
+ s.add_dependency(%q<gem_hadar>, ["~> 0.1.8"])
31
+ s.add_dependency(%q<bullshit>, ["~> 0.1.3"])
32
+ s.add_dependency(%q<rake>, ["= 0.9.2.2"])
33
+ s.add_dependency(%q<tins>, ["~> 0.4.2"])
34
+ end
35
+ else
36
+ s.add_dependency(%q<gem_hadar>, ["~> 0.1.8"])
37
+ s.add_dependency(%q<bullshit>, ["~> 0.1.3"])
38
+ s.add_dependency(%q<rake>, ["= 0.9.2.2"])
39
+ s.add_dependency(%q<tins>, ["~> 0.4.2"])
40
+ end
41
+ end
data/install.rb ADDED
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'rbconfig'
4
+ require 'fileutils'
5
+ include FileUtils::Verbose
6
+ include Config
7
+
8
+ dest = CONFIG["sitelibdir"]
9
+ mkdir_p(dest)
10
+ file = 'lib/flott.rb'
11
+ install(file, dest)
12
+
13
+ dest = File.join(dest, 'flott')
14
+ mkdir_p dest
15
+ file = 'lib/flott/cache.rb'
16
+ install(file, dest)