erb_asterisk 0.0.3 → 0.0.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +0 -3
- data/exe/erb_asterisk +3 -72
- data/lib/erb_asterisk/version.rb +1 -1
- data/lib/erb_asterisk.rb +90 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 15ea8de9a10deb06ada33cf27449a1dfc4fb8f12
|
4
|
+
data.tar.gz: be3349ce24ee0bec0a5ee6b0c779050a9868a611
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 07a37285ebe39767f5f60c71a601fd25a2cc3e24c056104c9daf51bd5df91cda7ab2a82a2940e90bea08b19543d4383bb10fe55739640c2184b9918019ab87c9
|
7
|
+
data.tar.gz: f677c3333572b3544387933e50b71e883af643d2eea6283cbbe02efd95ea3a4c25352838356741f4b39ceadb5b86cce0a22d9ff7cf2af9ca413c2cb2e1eb1389
|
data/Gemfile
CHANGED
data/exe/erb_asterisk
CHANGED
@@ -1,75 +1,6 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require '
|
4
|
-
require 'find'
|
5
|
-
require 'pathname'
|
3
|
+
require 'erb_asterisk'
|
6
4
|
|
7
|
-
|
8
|
-
|
9
|
-
require PROJECT_FILE
|
10
|
-
end
|
11
|
-
|
12
|
-
$exports = {}
|
13
|
-
$templates = ''
|
14
|
-
|
15
|
-
# Render template
|
16
|
-
def render(template, vars = {})
|
17
|
-
tpl = File.read("#{$templates}/#{template}.erb")
|
18
|
-
e = ERB.new(tpl)
|
19
|
-
|
20
|
-
b = TOPLEVEL_BINDING
|
21
|
-
vars.each do |name, value|
|
22
|
-
b.local_variable_set(name, value)
|
23
|
-
end
|
24
|
-
|
25
|
-
e.result
|
26
|
-
end
|
27
|
-
|
28
|
-
# Declare current config file inclusion to file_name
|
29
|
-
def include_to(file_name)
|
30
|
-
return unless TOPLEVEL_BINDING.local_variable_defined?(:current_conf_file)
|
31
|
-
$exports[file_name] = [] if $exports[file_name].nil?
|
32
|
-
arr = $exports[file_name]
|
33
|
-
|
34
|
-
current_conf_file = TOPLEVEL_BINDING.local_variable_get(:current_conf_file)
|
35
|
-
if arr.include?(current_conf_file)
|
36
|
-
puts "Skip #{current_conf_file} duplicate inclusion to #{file_name}"
|
37
|
-
return
|
38
|
-
end
|
39
|
-
|
40
|
-
arr << current_conf_file
|
41
|
-
"; Included to \"#{file_name}\""
|
42
|
-
end
|
43
|
-
|
44
|
-
def asterisk_root
|
45
|
-
return './' if File.exist?('asterisk.conf')
|
46
|
-
return 'asterisk/' if Dir.exist?('asterisk/')
|
47
|
-
raise 'Asterisk configuration not found'
|
48
|
-
end
|
49
|
-
|
50
|
-
root = asterisk_root
|
51
|
-
$templates = "#{root}templates".freeze
|
52
|
-
|
53
|
-
# Render ERB files
|
54
|
-
Find.find(root) do |f|
|
55
|
-
next if File.directory?(f)
|
56
|
-
next if f.start_with?($templates)
|
57
|
-
next unless f.end_with?('.erb')
|
58
|
-
|
59
|
-
output_config = f.chomp('.erb')
|
60
|
-
|
61
|
-
TOPLEVEL_BINDING.local_variable_set(:current_conf_file,
|
62
|
-
output_config.sub(root, ''))
|
63
|
-
|
64
|
-
File.write(output_config, ERB.new(File.read(f)).result)
|
65
|
-
end
|
66
|
-
|
67
|
-
# Save includes
|
68
|
-
$exports.each do |include_file, content|
|
69
|
-
s = ''
|
70
|
-
content.each do |file|
|
71
|
-
s << "#include \"#{file}\"\n"
|
72
|
-
end
|
73
|
-
|
74
|
-
File.write("#{root}#{include_file}", s)
|
75
|
-
end
|
5
|
+
include ErbAsterisk
|
6
|
+
execute
|
data/lib/erb_asterisk/version.rb
CHANGED
data/lib/erb_asterisk.rb
CHANGED
@@ -1,2 +1,92 @@
|
|
1
|
+
require 'erb'
|
2
|
+
require 'find'
|
3
|
+
require 'pathname'
|
4
|
+
|
1
5
|
module ErbAsterisk
|
6
|
+
# Render template
|
7
|
+
def render(template, vars = {})
|
8
|
+
tpl = File.read("#{@templates}/#{template}.erb")
|
9
|
+
e = ERB.new(tpl)
|
10
|
+
|
11
|
+
b = TOPLEVEL_BINDING
|
12
|
+
vars.each do |name, value|
|
13
|
+
b.local_variable_set(name, value)
|
14
|
+
end
|
15
|
+
|
16
|
+
e.result
|
17
|
+
end
|
18
|
+
|
19
|
+
# Declare current config file inclusion to file_name
|
20
|
+
def include_to(file_name)
|
21
|
+
return unless TOPLEVEL_BINDING.local_variable_defined?(:current_conf_file)
|
22
|
+
@exports[file_name] = [] if @exports[file_name].nil?
|
23
|
+
arr = @exports[file_name]
|
24
|
+
|
25
|
+
current_conf_file = TOPLEVEL_BINDING.local_variable_get(:current_conf_file)
|
26
|
+
if arr.include?(current_conf_file)
|
27
|
+
puts "Skip #{current_conf_file} duplicate inclusion to #{file_name}"
|
28
|
+
return
|
29
|
+
end
|
30
|
+
|
31
|
+
arr << current_conf_file
|
32
|
+
"; Included to \"#{file_name}\""
|
33
|
+
end
|
34
|
+
|
35
|
+
def execute
|
36
|
+
init_instance
|
37
|
+
load_project_file
|
38
|
+
|
39
|
+
root = asterisk_root
|
40
|
+
@templates = "#{root}templates".freeze
|
41
|
+
|
42
|
+
render_files(root)
|
43
|
+
export_includes(root)
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
ERB_PROJECT_FILE = './erb_asterisk_project.rb'.freeze
|
49
|
+
ERB_ASTERISK_CONF = 'asterisk.conf'.freeze
|
50
|
+
ERB_ASTERISK_DIR = 'asterisk/'.freeze
|
51
|
+
|
52
|
+
def init_instance
|
53
|
+
@exports = {}
|
54
|
+
@templates = ''
|
55
|
+
end
|
56
|
+
|
57
|
+
def asterisk_root
|
58
|
+
return './' if File.exist?(ERB_ASTERISK_CONF)
|
59
|
+
return ERB_ASTERISK_DIR if Dir.exist?(ERB_ASTERISK_DIR)
|
60
|
+
raise 'Asterisk configuration not found'
|
61
|
+
end
|
62
|
+
|
63
|
+
def load_project_file
|
64
|
+
require ERB_PROJECT_FILE if File.exist?(ERB_PROJECT_FILE)
|
65
|
+
end
|
66
|
+
|
67
|
+
def render_files(root)
|
68
|
+
Find.find(root) do |f|
|
69
|
+
next if File.directory?(f)
|
70
|
+
next if f.start_with?(@templates)
|
71
|
+
next unless f.end_with?('.erb')
|
72
|
+
|
73
|
+
output_config = f.chomp('.erb')
|
74
|
+
|
75
|
+
TOPLEVEL_BINDING.local_variable_set(:current_conf_file,
|
76
|
+
output_config.sub(root, ''))
|
77
|
+
|
78
|
+
File.write(output_config, ERB.new(File.read(f)).result)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
def export_includes(root)
|
83
|
+
@exports.each do |include_file, content|
|
84
|
+
s = ''
|
85
|
+
content.each do |file|
|
86
|
+
s << "#include \"#{file}\"\n"
|
87
|
+
end
|
88
|
+
|
89
|
+
File.write("#{root}#{include_file}", s)
|
90
|
+
end
|
91
|
+
end
|
2
92
|
end
|