erb_asterisk 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10921588da08da44d6bea41147209c7116366db2
4
- data.tar.gz: b48c7ea95a4ce48c57324fb720021fcf96a55767
3
+ metadata.gz: bbf38bf4e673c087ae0196dc27ecb1e34c94d1df
4
+ data.tar.gz: 8da193f97e93ea16c87a9ec70fc294c6dfd39c0c
5
5
  SHA512:
6
- metadata.gz: 0eb250cd67eb98cff1653e9b54a30b9e797724b4d87d7b7364cb73392acda5272a6136bc202c606867cb95726d5f5cda1d44552f0788714f85dcd7e247b50c85
7
- data.tar.gz: 7868a18253dfec254c82188027f9820aac8b990d863e9e440bdb8bee34984334d08d63b8a79f1ca8b5330c383e280a28a8ab96ed1c0ea09984540ee9eed41837
6
+ metadata.gz: d715f98ac45b62b52a2431418c152e09940bb572f6b470def263604952a117e1fb33e02be6290cd11b488d5e833b9ae5b27e321227d201dfbcd3c157b336342c
7
+ data.tar.gz: ced26955e954ee6fdbbc08f33cabb429c21fbfae13b5956cec00705a532230ff731cba22e88c54cb66633bdc517fac53370318c90b670d791c9a5acc8ee5919a
data/erb_asterisk.gemspec CHANGED
@@ -24,6 +24,8 @@ Gem::Specification.new do |spec|
24
24
  spec.executables = 'erb_asterisk'
25
25
  spec.require_paths = ['lib']
26
26
 
27
+ spec.add_runtime_dependency 'slop', '~> 4.5'
28
+
27
29
  spec.add_development_dependency 'bundler', '~> 1.15'
28
30
  spec.add_development_dependency 'rake', '~> 10.0'
29
31
  spec.add_development_dependency 'minitest', '~> 5.10', '>= 5.10.3'
data/exe/erb_asterisk CHANGED
@@ -1,10 +1,14 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
+ require 'optparse'
3
4
  require 'pathname'
4
5
  $LOAD_PATH.unshift(
5
6
  File.expand_path('../../lib', Pathname.new(__FILE__).realpath))
6
7
 
7
8
  require 'erb_asterisk'
9
+ require 'erb_asterisk/arg_parser'
10
+
11
+ arg_parser = ErbAsterisk::ArgParser.new
8
12
 
9
13
  include ErbAsterisk
10
- execute
14
+ execute(arg_parser.execute)
data/lib/erb_asterisk.rb CHANGED
@@ -4,9 +4,8 @@ require 'pathname'
4
4
 
5
5
  module ErbAsterisk
6
6
  # Render template
7
- # TODO: render user defined templates
8
7
  def render(template, vars = {})
9
- tpl = File.read("#{@templates_path}/#{template}.erb")
8
+ tpl = read_template(template)
10
9
  e = ERB.new(tpl)
11
10
 
12
11
  b = TOPLEVEL_BINDING
@@ -56,8 +55,8 @@ module ErbAsterisk
56
55
  @yields[tag]
57
56
  end
58
57
 
59
- def execute
60
- init_instance
58
+ def execute(opts)
59
+ init_instance(opts)
61
60
  load_project_file
62
61
 
63
62
  root = asterisk_root
@@ -73,10 +72,13 @@ module ErbAsterisk
73
72
  ERB_ASTERISK_CONF = 'asterisk.conf'.freeze
74
73
  ERB_ASTERISK_DIR = 'asterisk/'.freeze
75
74
 
76
- def init_instance
75
+ def init_instance(opts)
77
76
  @exports = {}
78
77
  @templates_path = ''
79
78
  @yields = {}
79
+
80
+ user_path = opts[:templates].nil? ? '~/.erb_asterisk' : opts[:templates]
81
+ @user_templates = File.expand_path("#{user_path}/templates")
80
82
  end
81
83
 
82
84
  def asterisk_root
@@ -141,4 +143,15 @@ module ErbAsterisk
141
143
  File.write("#{root}#{include_file}", result)
142
144
  end
143
145
  end
146
+
147
+ def read_template(template)
148
+ file_name = "#{template}.erb"
149
+ project_template = "#{@templates_path}/#{file_name}"
150
+ return File.read(project_template) if File.exist?(project_template)
151
+
152
+ user_template = "#{@user_templates}/#{file_name}"
153
+ return File.read(user_template) if File.exist?(user_template)
154
+
155
+ raise "Template not found: #{template}"
156
+ end
144
157
  end
@@ -0,0 +1,23 @@
1
+ require 'slop'
2
+ require 'erb_asterisk/version'
3
+
4
+ module ErbAsterisk
5
+ class ArgParser
6
+ def execute
7
+ Slop.parse do |o|
8
+ o.string '-t', '--templates',
9
+ 'set templates path (e.g.: ~/.erb_asterisk)'
10
+
11
+ o.on '-v', '--version', 'print the version' do
12
+ puts "#{VERSION}"
13
+ exit
14
+ end
15
+
16
+ o.on '-h', '--help', 'print this help' do
17
+ puts o
18
+ exit
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -1,3 +1,3 @@
1
1
  module ErbAsterisk
2
- VERSION = '0.0.7'.freeze
2
+ VERSION = '0.0.8'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: erb_asterisk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Artem Baikuzin
@@ -10,6 +10,20 @@ bindir: exe
10
10
  cert_chain: []
11
11
  date: 2017-08-04 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: slop
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.5'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.5'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -98,6 +112,7 @@ files:
98
112
  - erb_asterisk.gemspec
99
113
  - exe/erb_asterisk
100
114
  - lib/erb_asterisk.rb
115
+ - lib/erb_asterisk/arg_parser.rb
101
116
  - lib/erb_asterisk/version.rb
102
117
  homepage: https://github.com/ybinzu/erb_asterisk
103
118
  licenses: