erb_asterisk 0.0.1
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 +7 -0
- data/.gitignore +13 -0
- data/.ruby-version +1 -0
- data/Gemfile +6 -0
- data/LICENSE.txt +21 -0
- data/README.md +110 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/erb_asterisk.gemspec +31 -0
- data/exe/erb_asterisk +70 -0
- data/lib/erb_asterisk.rb +2 -0
- data/lib/erb_asterisk/version.rb +3 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 445f8fc5661ccdf30f20638c842fbb04481ea5df
|
4
|
+
data.tar.gz: c7ec702d5e284480a4fbf0d71cd0f34f8bbfc48b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 99c89f2bd6fb8fe3bc720388b919f9d0a59a54dde92065aa0ef2ed23d9d8a5f8c79695c684634d99b80bd1f513fd41f85daa48cdab13e107076da1afad8b99ee
|
7
|
+
data.tar.gz: fcccdd78ccaa196e2cf51b2e606d5161e68d6ef18460729a03e2057f217f45054afb4c3055f9190f796677a15ac1b6684b018bf6eef68204c0692568aeeaee20
|
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.4.1
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2017 Artem Baikuzin
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
# erb_asterisk
|
2
|
+
|
3
|
+
This gem is add ability to declare asterisk configuration with ERB files.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
$ gem install erb_asterisk
|
8
|
+
|
9
|
+
## Usage
|
10
|
+
|
11
|
+
### Create ERB configuration files and templates
|
12
|
+
```
|
13
|
+
├── asterisk
|
14
|
+
...
|
15
|
+
│ ├── entities
|
16
|
+
│ │ ├── office
|
17
|
+
│ │ │ ├── pjsip_endpoints.conf
|
18
|
+
│ │ │ └── pjsip_endpoints.conf.erb
|
19
|
+
│ │ ├── taxi
|
20
|
+
│ │ │ ├── pjsip_endpoints.conf
|
21
|
+
│ │ │ ├── pjsip_endpoints.conf.erb
|
22
|
+
│ │ │ ├── queues.conf
|
23
|
+
│ │ │ └── queues.conf.erb
|
24
|
+
...
|
25
|
+
│ ├── pjsip_endpoints.conf
|
26
|
+
│ ├── pjsip_endpoints.conf.includes
|
27
|
+
...
|
28
|
+
│ ├── queues.conf
|
29
|
+
│ ├── queues.conf.includes
|
30
|
+
...
|
31
|
+
│ ├── templates
|
32
|
+
│ │ ├── pjsip_operators.erb
|
33
|
+
│ │ └── queues.erb
|
34
|
+
```
|
35
|
+
|
36
|
+
### Templates
|
37
|
+
|
38
|
+
Templates can be defined only in `asterisk/templates` directory.
|
39
|
+
|
40
|
+
pjsip_operators.erb:
|
41
|
+
```
|
42
|
+
[<%= op %>](operator)
|
43
|
+
auth=<%= op %>
|
44
|
+
aors=<%= op %>
|
45
|
+
set_var=GROUP()=operator<%= op %>
|
46
|
+
[<%= op %>](operator-auth)
|
47
|
+
username=<%= op %>
|
48
|
+
[<%= op %>](aor-single-reg)
|
49
|
+
<% end %>
|
50
|
+
```
|
51
|
+
|
52
|
+
queues.erb:
|
53
|
+
```
|
54
|
+
[operators-<%= name %>]
|
55
|
+
strategy = rrmemory
|
56
|
+
joinempty = yes
|
57
|
+
musicclass = queue
|
58
|
+
<% members.times.each do |i| %>
|
59
|
+
<% op = offset + i %>
|
60
|
+
<% group = 100 + i %>
|
61
|
+
member => Local/<%= "#{group}#{op}" %>@queue-dial-control,0,,SIP/<%= op %>
|
62
|
+
<% end %>
|
63
|
+
ringinuse = no
|
64
|
+
announce-frequency = 30
|
65
|
+
announce-holdtime = no
|
66
|
+
retry = 0
|
67
|
+
```
|
68
|
+
|
69
|
+
### ERB configuration
|
70
|
+
|
71
|
+
Rendering template:
|
72
|
+
```
|
73
|
+
<%= render 'template_file_name_without_ext', variable_name: variable_value %>
|
74
|
+
```
|
75
|
+
|
76
|
+
Define inclusion (asterisk `#include` command) to external configuration file:
|
77
|
+
```
|
78
|
+
<%= include_to 'pjsip_endpoints.conf.includes' %>
|
79
|
+
```
|
80
|
+
This will create (overwrite) file pjsip_endpoints.conf.includes with `#include` command of current processed erb file. For example:
|
81
|
+
|
82
|
+
pjsip_endpoints.conf.includes:
|
83
|
+
```
|
84
|
+
#include "entities/office/pjsip_endpoints.conf"
|
85
|
+
#include "entities/taxi/pjsip_endpoints.conf"
|
86
|
+
...
|
87
|
+
```
|
88
|
+
|
89
|
+
You can include this file to your actual pjsip_endpoints.conf.
|
90
|
+
|
91
|
+
entities/office/pjsip_endpoints.conf.erb:
|
92
|
+
```
|
93
|
+
<%= include_to 'pjsip_endpoints.conf.includes' %>
|
94
|
+
<%= 15.times.each do |i| %>
|
95
|
+
<%= render 'pjsip_operators', op: 100 + i %>
|
96
|
+
<% end %>
|
97
|
+
```
|
98
|
+
|
99
|
+
entities/taxi/pjsip_endpoints.conf.erb:
|
100
|
+
```
|
101
|
+
<%= include_to 'pjsip_endpoints.conf.includes' %>
|
102
|
+
<%= 5.times.each do |i| %>
|
103
|
+
<%= render 'pjsip_operators', op: 200 + i %>
|
104
|
+
<% end %>
|
105
|
+
```
|
106
|
+
|
107
|
+
### Run erb_asterisk
|
108
|
+
|
109
|
+
$ cd /etc/asterisk
|
110
|
+
$ erb_asterisk
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'erb_asterisk'
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require 'irb'
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
lib = File.expand_path('../lib', __FILE__)
|
4
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
5
|
+
require 'erb_asterisk/version'
|
6
|
+
|
7
|
+
Gem::Specification.new do |spec|
|
8
|
+
spec.name = 'erb_asterisk'
|
9
|
+
spec.version = ErbAsterisk::VERSION
|
10
|
+
spec.authors = ['Artem Baikuzin']
|
11
|
+
spec.email = ['ybinzu@gmail.com']
|
12
|
+
|
13
|
+
spec.summary = 'Asterisk configuration with ERB'
|
14
|
+
spec.description = 'Converts all .erb files to .conf files inside ' \
|
15
|
+
'asterisk configuration directory'
|
16
|
+
spec.homepage = 'https://github.com/ybinzu/erb_asterisk'
|
17
|
+
spec.license = 'MIT'
|
18
|
+
|
19
|
+
spec.files = `git ls-files -z`.split("\x0").reject do |f|
|
20
|
+
f.match(%r{^(test|spec|features)/})
|
21
|
+
end
|
22
|
+
|
23
|
+
spec.bindir = 'exe'
|
24
|
+
spec.executables = 'erb_asterisk'
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
|
27
|
+
spec.add_development_dependency 'bundler', '~> 1.15'
|
28
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
29
|
+
spec.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.3'
|
30
|
+
spec.add_development_dependency 'minitest-reporters', '~> 1.1', '>= 1.1.14'
|
31
|
+
end
|
data/exe/erb_asterisk
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'erb'
|
4
|
+
require 'find'
|
5
|
+
require 'pathname'
|
6
|
+
|
7
|
+
$exports = {}
|
8
|
+
$templates = ''
|
9
|
+
|
10
|
+
# Render template
|
11
|
+
def render(template, vars)
|
12
|
+
tpl = File.read("#{$templates}/#{template}.erb")
|
13
|
+
e = ERB.new(tpl)
|
14
|
+
|
15
|
+
b = TOPLEVEL_BINDING
|
16
|
+
vars.each do |name, value|
|
17
|
+
b.local_variable_set(name, value)
|
18
|
+
end
|
19
|
+
|
20
|
+
e.result
|
21
|
+
end
|
22
|
+
|
23
|
+
# Declare current config file inclusion to file_name
|
24
|
+
def include_to(file_name)
|
25
|
+
return unless TOPLEVEL_BINDING.local_variable_defined?(:current_conf_file)
|
26
|
+
$exports[file_name] = [] if $exports[file_name].nil?
|
27
|
+
arr = $exports[file_name]
|
28
|
+
|
29
|
+
current_conf_file = TOPLEVEL_BINDING.local_variable_get(:current_conf_file)
|
30
|
+
if arr.include?(current_conf_file)
|
31
|
+
puts "Skip #{current_conf_file} duplicate inclusion to #{file_name}"
|
32
|
+
return
|
33
|
+
end
|
34
|
+
|
35
|
+
arr << current_conf_file
|
36
|
+
"; Included to \"#{file_name}\""
|
37
|
+
end
|
38
|
+
|
39
|
+
def asterisk_root
|
40
|
+
return './' if File.exist?('asterisk.conf')
|
41
|
+
return 'asterisk/' if Dir.exist?('asterisk/')
|
42
|
+
raise 'Asterisk configuration not found'
|
43
|
+
end
|
44
|
+
|
45
|
+
root = asterisk_root
|
46
|
+
$templates = "#{root}templates".freeze
|
47
|
+
|
48
|
+
# Render ERB files
|
49
|
+
Find.find(root) do |f|
|
50
|
+
next if File.directory?(f)
|
51
|
+
next if f.start_with?($templates)
|
52
|
+
next unless f.end_with?('.erb')
|
53
|
+
|
54
|
+
output_config = f.chomp('.erb')
|
55
|
+
|
56
|
+
TOPLEVEL_BINDING.local_variable_set(:current_conf_file,
|
57
|
+
output_config.sub(root, ''))
|
58
|
+
|
59
|
+
File.write(output_config, ERB.new(File.read(f)).result)
|
60
|
+
end
|
61
|
+
|
62
|
+
# Save includes
|
63
|
+
$exports.each do |include_file, content|
|
64
|
+
s = ''
|
65
|
+
content.each do |file|
|
66
|
+
s << "#include \"#{file}\"\n"
|
67
|
+
end
|
68
|
+
|
69
|
+
File.write("#{root}#{include_file}", s)
|
70
|
+
end
|
data/lib/erb_asterisk.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: erb_asterisk
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Artem Baikuzin
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-01 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.15'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.15'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '10.0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '10.0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '5.10'
|
48
|
+
- - ">="
|
49
|
+
- !ruby/object:Gem::Version
|
50
|
+
version: 5.10.3
|
51
|
+
type: :development
|
52
|
+
prerelease: false
|
53
|
+
version_requirements: !ruby/object:Gem::Requirement
|
54
|
+
requirements:
|
55
|
+
- - "~>"
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
version: '5.10'
|
58
|
+
- - ">="
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: 5.10.3
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: minitest-reporters
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '1.1'
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 1.1.14
|
71
|
+
type: :development
|
72
|
+
prerelease: false
|
73
|
+
version_requirements: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - "~>"
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '1.1'
|
78
|
+
- - ">="
|
79
|
+
- !ruby/object:Gem::Version
|
80
|
+
version: 1.1.14
|
81
|
+
description: Converts all .erb files to .conf files inside asterisk configuration
|
82
|
+
directory
|
83
|
+
email:
|
84
|
+
- ybinzu@gmail.com
|
85
|
+
executables:
|
86
|
+
- erb_asterisk
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- ".gitignore"
|
91
|
+
- ".ruby-version"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/console
|
97
|
+
- bin/setup
|
98
|
+
- erb_asterisk.gemspec
|
99
|
+
- exe/erb_asterisk
|
100
|
+
- lib/erb_asterisk.rb
|
101
|
+
- lib/erb_asterisk/version.rb
|
102
|
+
homepage: https://github.com/ybinzu/erb_asterisk
|
103
|
+
licenses:
|
104
|
+
- MIT
|
105
|
+
metadata: {}
|
106
|
+
post_install_message:
|
107
|
+
rdoc_options: []
|
108
|
+
require_paths:
|
109
|
+
- lib
|
110
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
111
|
+
requirements:
|
112
|
+
- - ">="
|
113
|
+
- !ruby/object:Gem::Version
|
114
|
+
version: '0'
|
115
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
|
+
requirements:
|
117
|
+
- - ">="
|
118
|
+
- !ruby/object:Gem::Version
|
119
|
+
version: '0'
|
120
|
+
requirements: []
|
121
|
+
rubyforge_project:
|
122
|
+
rubygems_version: 2.6.11
|
123
|
+
signing_key:
|
124
|
+
specification_version: 4
|
125
|
+
summary: Asterisk configuration with ERB
|
126
|
+
test_files: []
|