handlebars 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/Gemfile +4 -0
- data/Rakefile +2 -0
- data/handlebars.gemspec +23 -0
- data/lib/handlebars.rb +30 -0
- data/lib/handlebars/compiler.rb +96 -0
- data/lib/handlebars/version.rb +3 -0
- data/spec/spec_helper.rb +17 -0
- data/spec/test_spec.rb +8 -0
- metadata +104 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
data/handlebars.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path("../lib/handlebars/version", __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |s|
|
5
|
+
s.name = "handlebars"
|
6
|
+
s.version = Handlebars::VERSION
|
7
|
+
s.platform = Gem::Platform::RUBY
|
8
|
+
s.authors = ['Martin Schuerrer']
|
9
|
+
s.email = ['martin@schuerrer.org']
|
10
|
+
s.homepage = "http://github.com/MSch/handlebars-ruby"
|
11
|
+
s.summary = "handlebars.js port to ruby"
|
12
|
+
s.description = "A straight port of handlebars.js to ruby. Currently unfinished, if you've got a complete version let me know so I'll release the name to you"
|
13
|
+
|
14
|
+
s.required_rubygems_version = ">= 1.3.6"
|
15
|
+
s.rubyforge_project = "handlebars"
|
16
|
+
|
17
|
+
s.add_development_dependency "bundler", ">= 1.0.0"
|
18
|
+
s.add_development_dependency "rspec", ">= 2.0.0"
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.executables = `git ls-files`.split("\n").map{|f| f =~ /^bin\/(.*)/ ? $1 : nil}.compact
|
22
|
+
s.require_path = 'lib'
|
23
|
+
end
|
data/lib/handlebars.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'handlebars/compiler'
|
2
|
+
|
3
|
+
class Handlebars
|
4
|
+
attr_accessor :compiled_partials
|
5
|
+
def compile(input)
|
6
|
+
end
|
7
|
+
|
8
|
+
def compile_to_string(input)
|
9
|
+
end
|
10
|
+
|
11
|
+
def compile_function_body(input)
|
12
|
+
end
|
13
|
+
|
14
|
+
def escape_text(input)
|
15
|
+
CGI.escapeHTML(input)
|
16
|
+
end
|
17
|
+
|
18
|
+
def escape_expression(input)
|
19
|
+
end
|
20
|
+
|
21
|
+
|
22
|
+
def compile_partials(input)
|
23
|
+
end
|
24
|
+
|
25
|
+
def parse_path(input)
|
26
|
+
end
|
27
|
+
|
28
|
+
def filter_output(input, escape=true)
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
3
|
+
class Handlebars
|
4
|
+
class Compiler
|
5
|
+
attr_accessor :input, :pointer, :mustache, :text, :fn, :newlines, :comment, :escaped, :partial, :inverted, :end_condition, :continue_inverted
|
6
|
+
def initialize(input)
|
7
|
+
@input = input
|
8
|
+
@pointer = -1
|
9
|
+
@mustache = false
|
10
|
+
@text = ''
|
11
|
+
@fn = 'out = ""; lookup = nil; '
|
12
|
+
@newlines = ''
|
13
|
+
@comment = false
|
14
|
+
@escaped = true
|
15
|
+
@partial = false
|
16
|
+
@inverted = false
|
17
|
+
@end_condition = nil
|
18
|
+
@continue_inverted = false
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_text
|
22
|
+
if not @text.empty?
|
23
|
+
@fn << 'out = out + \'' + CGI.escapeHTML(@text) + '\''
|
24
|
+
@fn << @newlines
|
25
|
+
@newlines = ''
|
26
|
+
@text = ''
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def parse_mustache
|
31
|
+
chr, part, mustache, param = nil
|
32
|
+
@s = StringScanner.new(input)
|
33
|
+
|
34
|
+
next_char = @s.peek
|
35
|
+
case next_char
|
36
|
+
when '!'
|
37
|
+
@comment = true
|
38
|
+
when '#'
|
39
|
+
@open_block = true
|
40
|
+
when '>'
|
41
|
+
@partial = true
|
42
|
+
when '^'
|
43
|
+
@inverted = true
|
44
|
+
@open_block = true
|
45
|
+
when '{'
|
46
|
+
@escaped = false
|
47
|
+
when '&'
|
48
|
+
@escaped = false
|
49
|
+
end
|
50
|
+
@s.getch
|
51
|
+
|
52
|
+
add_text
|
53
|
+
@mustache = ' '
|
54
|
+
|
55
|
+
while(chr = @s.getch)
|
56
|
+
if @mustache && chr == '}' && @s.peek == '}'
|
57
|
+
parts = @mustache.chomp.split(/\s+/)
|
58
|
+
mustache = parts[0]
|
59
|
+
param = lookup_for(parts[1])
|
60
|
+
|
61
|
+
@mustace = false
|
62
|
+
|
63
|
+
# finish reading off the close of the handlebars
|
64
|
+
@s.getch
|
65
|
+
|
66
|
+
# {{{expression}} is techically valid, but if we started with {{{ we'll try to read
|
67
|
+
# }}} off of the close of the handlebars
|
68
|
+
@s.getch if (!@escaped && @s.peek == '}')
|
69
|
+
|
70
|
+
if @comment
|
71
|
+
@comment = false
|
72
|
+
return
|
73
|
+
elsif @partial
|
74
|
+
add_partial(mustache, param)
|
75
|
+
return
|
76
|
+
elsif @inverted
|
77
|
+
add_inverted_section(mustache)
|
78
|
+
return
|
79
|
+
elsif @open_block
|
80
|
+
add_block(mustache, param, parts)
|
81
|
+
return
|
82
|
+
else
|
83
|
+
return this.add_expression(mustache, param)
|
84
|
+
end
|
85
|
+
|
86
|
+
@escaped = true
|
87
|
+
elsif @comment
|
88
|
+
;
|
89
|
+
else
|
90
|
+
@mustace << chr
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
end
|
96
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'rspec'
|
2
|
+
|
3
|
+
# Requires supporting files with custom matchers and macros, etc,
|
4
|
+
# in ./support/ and its subdirectories.
|
5
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
# == Mock Framework
|
9
|
+
#
|
10
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
11
|
+
#
|
12
|
+
# config.mock_with :mocha
|
13
|
+
# config.mock_with :flexmock
|
14
|
+
# config.mock_with :rr
|
15
|
+
config.mock_with :rspec
|
16
|
+
end
|
17
|
+
|
data/spec/test_spec.rb
ADDED
metadata
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: handlebars
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Martin Schuerrer
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-09-10 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bundler
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
- 0
|
32
|
+
version: 1.0.0
|
33
|
+
type: :development
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: rspec
|
37
|
+
prerelease: false
|
38
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ">="
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
segments:
|
44
|
+
- 2
|
45
|
+
- 0
|
46
|
+
- 0
|
47
|
+
version: 2.0.0
|
48
|
+
type: :development
|
49
|
+
version_requirements: *id002
|
50
|
+
description: A straight port of handlebars.js to ruby. Currently unfinished, if you've got a complete version let me know so I'll release the name to you
|
51
|
+
email:
|
52
|
+
- martin@schuerrer.org
|
53
|
+
executables: []
|
54
|
+
|
55
|
+
extensions: []
|
56
|
+
|
57
|
+
extra_rdoc_files: []
|
58
|
+
|
59
|
+
files:
|
60
|
+
- .gitignore
|
61
|
+
- Gemfile
|
62
|
+
- Rakefile
|
63
|
+
- handlebars.gemspec
|
64
|
+
- lib/handlebars.rb
|
65
|
+
- lib/handlebars/compiler.rb
|
66
|
+
- lib/handlebars/version.rb
|
67
|
+
- spec/spec_helper.rb
|
68
|
+
- spec/test_spec.rb
|
69
|
+
has_rdoc: true
|
70
|
+
homepage: http://github.com/MSch/handlebars-ruby
|
71
|
+
licenses: []
|
72
|
+
|
73
|
+
post_install_message:
|
74
|
+
rdoc_options: []
|
75
|
+
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
segments:
|
84
|
+
- 0
|
85
|
+
version: "0"
|
86
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
87
|
+
none: false
|
88
|
+
requirements:
|
89
|
+
- - ">="
|
90
|
+
- !ruby/object:Gem::Version
|
91
|
+
segments:
|
92
|
+
- 1
|
93
|
+
- 3
|
94
|
+
- 6
|
95
|
+
version: 1.3.6
|
96
|
+
requirements: []
|
97
|
+
|
98
|
+
rubyforge_project: handlebars
|
99
|
+
rubygems_version: 1.3.7
|
100
|
+
signing_key:
|
101
|
+
specification_version: 3
|
102
|
+
summary: handlebars.js port to ruby
|
103
|
+
test_files: []
|
104
|
+
|