mysh 0.2.7 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,46 +0,0 @@
1
- # coding: utf-8
2
-
3
- #* user_input/handlebars.rb -- Handlebar embedded ruby support.
4
- class Object
5
-
6
- #Show a file with embedded ruby handlebars.
7
- #<br>Note:
8
- #The message receiver is the evaluation host for the handlebar code.
9
- def show_handlebar_file(name)
10
- puts eval_handlebar_file(name)
11
- rescue Interrupt, StandardError, ScriptError => err
12
- puts "Error in file: #{name}\n#{err.class}: #{err}"
13
- end
14
-
15
- #Expand a file with embedded ruby handlebars.
16
- #<br>Note:
17
- #The message receiver is the evaluation host for the handlebar code.
18
- def eval_handlebar_file(name)
19
- eval_handlebars(IO.read(name))
20
- end
21
-
22
- #Process a string with backslash quotes and code embedded in handlebars.
23
- #<br>Note:
24
- #The message receiver is the evaluation host for the handlebar code.
25
- def eval_handlebars(str)
26
- do_process_handlebars(str).gsub(/\\[\{\}]/) {|found| found[1]}
27
- end
28
-
29
- private
30
-
31
- #Process a string with code embedded in handlebars.
32
- #<br>Note:
33
- #The message receiver is the evaluation host for the handlebar code.
34
- def do_process_handlebars(str)
35
- str.gsub(/{{.*?}}/m) do |match|
36
- code = match[2...-2]
37
- silent = code.end_with?("#")
38
- result = mysh_eval(code)
39
-
40
- (result unless silent).to_s
41
- end
42
- end
43
-
44
- end
45
-
46
-