template_refi 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/template_refi.rb +51 -0
- metadata +78 -0
@@ -0,0 +1,51 @@
|
|
1
|
+
# encoding: UTF-8
|
2
|
+
|
3
|
+
require 'polyglot'
|
4
|
+
require 'treetop'
|
5
|
+
require 'minival_refi'
|
6
|
+
|
7
|
+
module Refi
|
8
|
+
|
9
|
+
grammar_path = File.join(File.dirname(__FILE__),'/template_refi/template_grammar.treetop')
|
10
|
+
Treetop.load(grammar_path)
|
11
|
+
|
12
|
+
class Template
|
13
|
+
|
14
|
+
@@parser = TemplateGrammarParser.new
|
15
|
+
|
16
|
+
def initialize(template_str)
|
17
|
+
@str = template_str
|
18
|
+
@parse_result = @@parser.parse(template_str)
|
19
|
+
unless is_valid
|
20
|
+
# TODO
|
21
|
+
puts "template string not valid:"
|
22
|
+
pp @str
|
23
|
+
puts "errors:"
|
24
|
+
Template.simple_report_errors
|
25
|
+
puts "invalid template string"
|
26
|
+
#dperr(1004,"invalid template string")
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def is_valid
|
31
|
+
if @parse_result
|
32
|
+
return true
|
33
|
+
else
|
34
|
+
return false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.simple_report_errors
|
39
|
+
puts @@parser.failure_reason
|
40
|
+
puts @@parser.failure_line
|
41
|
+
puts @@parser.failure_column
|
42
|
+
end
|
43
|
+
|
44
|
+
def get_chunks
|
45
|
+
@val = @parse_result.content
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end # Module Refi
|
metadata
ADDED
@@ -0,0 +1,78 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: template_refi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Robert Fey
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-07-24 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: minival_refi
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - "="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 1
|
31
|
+
- 0
|
32
|
+
version: 0.1.0
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: "it does not allow the execution of arbitrary code\n templates may contain functions calls of the form \\\\-function_name(coma,seperated,list,of,minival,values)\n \"minival\" is a variable parser (see gem \"minival_refi\")\n (last time I checked one argument was mandatory (suggestion: \"\\\\-fun_without_args(nil)\" ))\n \n usage:\n include Refi\n template = Template.new(template_string)\n chunks = template.get_chunks()\n \n \"chunks\" is an array containing the text of the template as strings and the function calls as hashes {fun_name => [list,of,arguments]}\n "
|
36
|
+
email: feyrob@gmail.com
|
37
|
+
executables: []
|
38
|
+
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
extra_rdoc_files: []
|
42
|
+
|
43
|
+
files:
|
44
|
+
- lib/template_refi.rb
|
45
|
+
has_rdoc: true
|
46
|
+
homepage: http://rubygems.org/gems/template_refi
|
47
|
+
licenses: []
|
48
|
+
|
49
|
+
post_install_message:
|
50
|
+
rdoc_options: []
|
51
|
+
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
none: false
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
segments:
|
60
|
+
- 0
|
61
|
+
version: "0"
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
segments:
|
68
|
+
- 0
|
69
|
+
version: "0"
|
70
|
+
requirements: []
|
71
|
+
|
72
|
+
rubyforge_project: nowarning
|
73
|
+
rubygems_version: 1.3.7
|
74
|
+
signing_key:
|
75
|
+
specification_version: 3
|
76
|
+
summary: a very rudimentary text substitution system (in some way like php, rails and erubis)
|
77
|
+
test_files: []
|
78
|
+
|