signature_generator 0.1.1 → 0.1.2
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/README.md +5 -2
- data/exe/sg +8 -3
- data/lib/signature_generator/processor.rb +4 -2
- data/lib/signature_generator/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c8de23633f2e0983ed395fe8b16d78a0ec1bdd8
|
4
|
+
data.tar.gz: 48f34f59ea6369118415fc4a009791c5a7b76e75
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0a0230c4e62a5d992df66f5c00866aa3a0535cc39d0de29c838d0bec9809463aeece7d39b4321dc77a03f22eb023010398b986c81ca520ae67e9cced52b025a1
|
7
|
+
data.tar.gz: c07e76de765c3cbb43b02df6bf85ed22f12ae96e090ce4a4ce32e93e595d7ea09b2eae97bd01aac50f01e285978de4cfb743cd051f98b06e56c1fb847d860f77
|
data/README.md
CHANGED
@@ -3,9 +3,12 @@
|
|
3
3
|
[](https://travis-ci.org/lbriais/signature_generator)
|
4
4
|
[](http://badge.fury.io/rb/signature_generator)
|
5
5
|
|
6
|
+
The goal of this Ruby Gem is to provide a simple script to manage company email staff signatures consistently
|
7
|
+
by providing a simple ERB-based templating mechanism to generate actual employee signature.
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
+
|
10
|
+
This gem provides the `sg` executable to generate signature file from template.
|
11
|
+
Any undefined variable used in the ERB template has to be provided at run-time either by:
|
9
12
|
|
10
13
|
* Providing values on command line
|
11
14
|
* Providing values in config file
|
data/exe/sg
CHANGED
@@ -34,6 +34,9 @@ module SignatureGenerator
|
|
34
34
|
slop.on :f, :'template-file', 'Specify the signature template file. Default is STDIN.', argument: true, as: String
|
35
35
|
slop.on :o, :'output-file', 'Specify the output file for the signature. Default is STDOUT.', argument: true, as: String
|
36
36
|
slop.on :force, 'Force overwriting output file.', argument: false
|
37
|
+
slop.on :'max-retry',
|
38
|
+
"Number of times retrying is allowed when prompted for values. Default is #{SignatureGenerator::Processor::MAX_RETRY}.",
|
39
|
+
argument: true, as: Integer
|
37
40
|
slop.on :var=, 'Define variables in the form name=value', argument: true, as: Array
|
38
41
|
slop.on :n, :'no-minify', 'Will not minify the resulting html signature. By default will do', argument: false
|
39
42
|
end
|
@@ -43,7 +46,7 @@ module SignatureGenerator
|
|
43
46
|
# Your code here.
|
44
47
|
content = template_io.read
|
45
48
|
logger.debug content
|
46
|
-
processor = SignatureGenerator::Processor.new context
|
49
|
+
processor = SignatureGenerator::Processor.new context: context, max_retry: config['max-retry']
|
47
50
|
signature = processor.transform content
|
48
51
|
logger.debug signature
|
49
52
|
unless config[:'no-minify']
|
@@ -61,17 +64,18 @@ module SignatureGenerator
|
|
61
64
|
def check_config
|
62
65
|
# Check the config and raise an exception if incorrect.
|
63
66
|
config[:var] ||=[]
|
67
|
+
# Context setup
|
64
68
|
@context = {}
|
65
69
|
config[:var].each do |definition|
|
66
70
|
valid = false
|
67
|
-
definition.match(/^\s*(?<var_name>[a-z][a-z0-9_]*)\s*=\s*(?<var_value>.+)\s*$/) do |md|
|
71
|
+
definition.match(/^\s*(?<var_name>[a-z][a-z0-9_]*[!\?]?)\s*=\s*(?<var_value>.+)\s*$/) do |md|
|
68
72
|
logger.warning "Overwriting existing variable '#{md['var_name']}' !" if context[md['var_name']]
|
69
73
|
context[md['var_name'].to_sym] = md['var_value']
|
70
74
|
valid = true
|
71
75
|
end
|
72
76
|
raise SignatureGenerator::Error, 'Invalid property specified !' unless valid
|
73
77
|
end
|
74
|
-
|
78
|
+
# Input definition
|
75
79
|
@template_io = case config[:'template-file']
|
76
80
|
when NilClass
|
77
81
|
logger.debug 'Template from STDIN'
|
@@ -83,6 +87,7 @@ module SignatureGenerator
|
|
83
87
|
logger.debug "Template from file '#{file}'"
|
84
88
|
io
|
85
89
|
end
|
90
|
+
# Output definition
|
86
91
|
@output_io = case config[:'output-file']
|
87
92
|
when NilClass
|
88
93
|
logger.debug 'Signature to STDOUT'
|
@@ -9,9 +9,11 @@ module SignatureGenerator
|
|
9
9
|
MAX_RETRY = 3
|
10
10
|
|
11
11
|
attr_reader :results, :context
|
12
|
+
attr_accessor :max_retry
|
12
13
|
|
13
|
-
def initialize(context
|
14
|
+
def initialize(context: {}, max_retry: MAX_RETRY)
|
14
15
|
self.context = context
|
16
|
+
self.max_retry = max_retry
|
15
17
|
end
|
16
18
|
|
17
19
|
def transform(template, context = self.context)
|
@@ -24,7 +26,7 @@ module SignatureGenerator
|
|
24
26
|
counters[missing_var] += 1
|
25
27
|
debug_msg = "Variable not provided: #{missing_var} (attempt ##{counters[missing_var]})"
|
26
28
|
logger.debug debug_msg
|
27
|
-
if counters[missing_var] >
|
29
|
+
if counters[missing_var] > max_retry
|
28
30
|
logger.error 'Maximum retry number exceeded. Aborting !'
|
29
31
|
raise e
|
30
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: signature_generator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Laurent B.
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|