signature_generator 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +182 -0
- data/.rspec +2 -0
- data/.travis.yml +6 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +78 -0
- data/Rakefile +4 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/sg +104 -0
- data/lib/signature_generator/context.rb +26 -0
- data/lib/signature_generator/error.rb +5 -0
- data/lib/signature_generator/processor.rb +57 -0
- data/lib/signature_generator/version.rb +3 -0
- data/lib/signature_generator.rb +10 -0
- data/signature_generator.gemspec +29 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8f7bf9f84d0258e6fc0eaac70bf19a65a1c3093f
|
4
|
+
data.tar.gz: 902bc3dab4a1809e7c090c9033058c40b63e52c7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 2290c0db425a9b29f1914d8dfc5a3ad86f9fc4c5b573372e173d06a3b8df55cfe91c1da50ff13069b9ce32e792d33feea40cfe0427d3d72944c35afbd5faa59a
|
7
|
+
data.tar.gz: 20f1e4f3bbf1067ae0438dc2ef8dc4424b58fefccd148920b234da2b2314ef1b6f5c80d08e6697a59a0d8eaf5daec2e0e86fcb5ba819da8c89e1dbf559e2d7fb
|
data/.gitignore
ADDED
@@ -0,0 +1,182 @@
|
|
1
|
+
/.bundle/
|
2
|
+
/.yardoc
|
3
|
+
/Gemfile.lock
|
4
|
+
/_yardoc/
|
5
|
+
/coverage/
|
6
|
+
/doc/
|
7
|
+
/pkg/
|
8
|
+
/spec/reports/
|
9
|
+
/tmp/
|
10
|
+
### Ruby template
|
11
|
+
*.gem
|
12
|
+
*.rbc
|
13
|
+
/.config
|
14
|
+
/InstalledFiles
|
15
|
+
/spec/examples.txt
|
16
|
+
/test/tmp/
|
17
|
+
/test/version_tmp/
|
18
|
+
|
19
|
+
# Used by dotenv library to load environment variables.
|
20
|
+
# .env
|
21
|
+
|
22
|
+
## Specific to RubyMotion:
|
23
|
+
.dat*
|
24
|
+
.repl_history
|
25
|
+
build/
|
26
|
+
*.bridgesupport
|
27
|
+
build-iPhoneOS/
|
28
|
+
build-iPhoneSimulator/
|
29
|
+
|
30
|
+
## Specific to RubyMotion (use of CocoaPods):
|
31
|
+
#
|
32
|
+
# We recommend against adding the Pods directory to your .gitignore. However
|
33
|
+
# you should judge for yourself, the pros and cons are mentioned at:
|
34
|
+
# https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
|
35
|
+
#
|
36
|
+
# vendor/Pods/
|
37
|
+
|
38
|
+
## Documentation cache and generated files:
|
39
|
+
/.yardoc/
|
40
|
+
/rdoc/
|
41
|
+
|
42
|
+
## Environment normalization:
|
43
|
+
/vendor/bundle
|
44
|
+
/lib/bundler/man/
|
45
|
+
|
46
|
+
# for a library or gem, you might want to ignore these files since the code is
|
47
|
+
# intended to run in multiple environments; otherwise, check them in:
|
48
|
+
# Gemfile.lock
|
49
|
+
# .ruby-version
|
50
|
+
# .ruby-gemset
|
51
|
+
|
52
|
+
# unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
|
53
|
+
.rvmrc
|
54
|
+
### SublimeText template
|
55
|
+
# cache files for sublime text
|
56
|
+
*.tmlanguage.cache
|
57
|
+
*.tmPreferences.cache
|
58
|
+
*.stTheme.cache
|
59
|
+
|
60
|
+
# workspace files are user-specific
|
61
|
+
*.sublime-workspace
|
62
|
+
|
63
|
+
# project files should be checked into the repository, unless a significant
|
64
|
+
# proportion of contributors will probably not be using SublimeText
|
65
|
+
# *.sublime-project
|
66
|
+
|
67
|
+
# sftp configuration file
|
68
|
+
sftp-config.json
|
69
|
+
|
70
|
+
# Package control specific files
|
71
|
+
Package Control.last-run
|
72
|
+
Package Control.ca-list
|
73
|
+
Package Control.ca-bundle
|
74
|
+
Package Control.system-ca-bundle
|
75
|
+
Package Control.cache/
|
76
|
+
Package Control.ca-certs/
|
77
|
+
bh_unicode_properties.cache
|
78
|
+
|
79
|
+
# Sublime-github package stores a github token in this file
|
80
|
+
# https://packagecontrol.io/packages/sublime-github
|
81
|
+
GitHub.sublime-settings
|
82
|
+
### KDevelop4 template
|
83
|
+
*.kdev4
|
84
|
+
.kdev4/
|
85
|
+
### Linux template
|
86
|
+
*~
|
87
|
+
|
88
|
+
# temporary files which can be created if a process still has a handle open of a deleted file
|
89
|
+
.fuse_hidden*
|
90
|
+
|
91
|
+
# KDE directory preferences
|
92
|
+
.directory
|
93
|
+
|
94
|
+
# Linux trash folder which might appear on any partition or disk
|
95
|
+
.Trash-*
|
96
|
+
|
97
|
+
# .nfs files are created when an open file is removed but is still being accessed
|
98
|
+
.nfs*
|
99
|
+
### Eclipse template
|
100
|
+
|
101
|
+
.metadata
|
102
|
+
bin/
|
103
|
+
tmp/
|
104
|
+
*.tmp
|
105
|
+
*.bak
|
106
|
+
*.swp
|
107
|
+
*~.nib
|
108
|
+
local.properties
|
109
|
+
.settings/
|
110
|
+
.loadpath
|
111
|
+
.recommenders
|
112
|
+
|
113
|
+
# Eclipse Core
|
114
|
+
.project
|
115
|
+
|
116
|
+
# External tool builders
|
117
|
+
.externalToolBuilders/
|
118
|
+
|
119
|
+
# Locally stored "Eclipse launch configurations"
|
120
|
+
*.launch
|
121
|
+
|
122
|
+
# PyDev specific (Python IDE for Eclipse)
|
123
|
+
*.pydevproject
|
124
|
+
|
125
|
+
# CDT-specific (C/C++ Development Tooling)
|
126
|
+
.cproject
|
127
|
+
|
128
|
+
# JDT-specific (Eclipse Java Development Tools)
|
129
|
+
.classpath
|
130
|
+
|
131
|
+
# Java annotation processor (APT)
|
132
|
+
.factorypath
|
133
|
+
|
134
|
+
# PDT-specific (PHP Development Tools)
|
135
|
+
.buildpath
|
136
|
+
|
137
|
+
# sbteclipse plugin
|
138
|
+
.target
|
139
|
+
|
140
|
+
# Tern plugin
|
141
|
+
.tern-project
|
142
|
+
|
143
|
+
# TeXlipse plugin
|
144
|
+
.texlipse
|
145
|
+
|
146
|
+
# STS (Spring Tool Suite)
|
147
|
+
.springBeans
|
148
|
+
|
149
|
+
# Code Recommenders
|
150
|
+
.recommenders/
|
151
|
+
### VisualStudioCode template
|
152
|
+
.vscode/*
|
153
|
+
!.vscode/settings.json
|
154
|
+
!.vscode/tasks.json
|
155
|
+
!.vscode/launch.json
|
156
|
+
!.vscode/extensions.json
|
157
|
+
### JetBrains template
|
158
|
+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
|
159
|
+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
|
160
|
+
|
161
|
+
# User-specific stuff:
|
162
|
+
.idea/
|
163
|
+
|
164
|
+
## File-based project format:
|
165
|
+
*.iws
|
166
|
+
|
167
|
+
## Plugin-specific files:
|
168
|
+
|
169
|
+
# IntelliJ
|
170
|
+
/out/
|
171
|
+
|
172
|
+
# mpeltonen/sbt-idea plugin
|
173
|
+
.idea_modules/
|
174
|
+
|
175
|
+
# JIRA plugin
|
176
|
+
atlassian-ide-plugin.xml
|
177
|
+
|
178
|
+
# Crashlytics plugin (for Android Studio and IntelliJ)
|
179
|
+
com_crashlytics_export_strings.xml
|
180
|
+
crashlytics.properties
|
181
|
+
crashlytics-build.properties
|
182
|
+
fabric.properties
|
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at lbnetid+gh@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Laurent B.
|
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,78 @@
|
|
1
|
+
# Signature Generator
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/lbriais/signature_generator.svg)](https://travis-ci.org/lbriais/signature_generator)
|
4
|
+
[![Gem Version](https://badge.fury.io/rb/signature_generator.svg)](http://badge.fury.io/rb/signature_generator)
|
5
|
+
|
6
|
+
|
7
|
+
This gem provides the `sg` executable to generate signature files from templates.
|
8
|
+
Variables used in the template, can be provided at run-time either by:
|
9
|
+
|
10
|
+
* Providing values on command line
|
11
|
+
* Providing values in config file
|
12
|
+
* Interactively
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'signature_generator'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
$ bundle
|
25
|
+
|
26
|
+
Or install it yourself as:
|
27
|
+
|
28
|
+
$ gem install signature_generator
|
29
|
+
|
30
|
+
## Usage
|
31
|
+
|
32
|
+
By default, the template is taken from STDIN and the result is produced on STDOUT. Of course both template and
|
33
|
+
result files can be specified on command line (see `sg --help` to see all options).
|
34
|
+
|
35
|
+
### Template
|
36
|
+
|
37
|
+
The template is actually an [ERB](http://www.stuartellis.name/articles/erb/) template.
|
38
|
+
|
39
|
+
### Resulting file
|
40
|
+
|
41
|
+
By default the result is _minified_ using the [kangax minifier](https://github.com/kangax/html-minifier/). You can disable
|
42
|
+
this behaviour by specifying `--no-minify` on the command line.
|
43
|
+
|
44
|
+
### Substituting variables
|
45
|
+
|
46
|
+
You can specify variables on the command line using the following syntax: `--var varname1=value1 --var varname2=value2 ...`
|
47
|
+
|
48
|
+
Here is a real-life usage example:
|
49
|
+
|
50
|
+
$ sg -f ./my_template.html.erb -o my_signature_file.html --force --var varname1=value1 --var varname2=value2
|
51
|
+
|
52
|
+
As this gem is using [easy_app_helper], it means that anything you can provide on the command line can
|
53
|
+
be actually provided by a config file. Read [easy_app_helper] documentation for further info.
|
54
|
+
|
55
|
+
__Any variable value not provided by the command line or a config file will actually be requested interactively at run time.__
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests.
|
60
|
+
You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
61
|
+
|
62
|
+
To install this gem onto your local machine, run `bundle exec rake install`.
|
63
|
+
To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`,
|
64
|
+
which will create a git tag for the version, push git commits and tags, and push the `.gem` file
|
65
|
+
to [rubygems.org](https://rubygems.org).
|
66
|
+
|
67
|
+
## Contributing
|
68
|
+
|
69
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lbriais/signature_generator.
|
70
|
+
This project is intended to be a safe, welcoming space for collaboration, and contributors are expected
|
71
|
+
to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
72
|
+
|
73
|
+
|
74
|
+
## License
|
75
|
+
|
76
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
77
|
+
|
78
|
+
[easy_app_helper]: https://github.com/lbriais/easy_app_helper "easy_app_helper Gem'
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'bundler/setup'
|
4
|
+
require 'signature_generator'
|
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
|
data/bin/setup
ADDED
data/exe/sg
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# coding: utf-8
|
3
|
+
# This file has been generated by easy_app_helper Gem on the Sun Dec 11 12:11:18 2016
|
4
|
+
# See 'https://rubygems.org/gems/easy_app_helper'
|
5
|
+
|
6
|
+
require 'rubygems'
|
7
|
+
require 'bundler/setup'
|
8
|
+
|
9
|
+
require 'easy_app_helper'
|
10
|
+
require 'easy_app_helper/scripts'
|
11
|
+
require 'signature_generator'
|
12
|
+
require 'html_minifier'
|
13
|
+
|
14
|
+
module SignatureGenerator
|
15
|
+
class SgMasterScript < EasyAppHelper::Scripts::Master
|
16
|
+
|
17
|
+
# If you want to manage sub-commands a-la-git, include following
|
18
|
+
# include EasyAppHelper::Scripts::SubCommandManager
|
19
|
+
|
20
|
+
NAME = 'Sg'
|
21
|
+
DESCRIPTION = 'Description of sg'
|
22
|
+
|
23
|
+
attr_reader :template_io, :output_io, :context
|
24
|
+
|
25
|
+
def initialize
|
26
|
+
super(NAME, SignatureGenerator::VERSION, DESCRIPTION, 'sg')
|
27
|
+
end
|
28
|
+
|
29
|
+
def add_script_options
|
30
|
+
## Create here your extra command-line options
|
31
|
+
## Here under are examples using potentially gem config layer to display default option value...
|
32
|
+
## Check Slop documentation for further info.
|
33
|
+
config.add_command_line_section do |slop|
|
34
|
+
slop.on :f, :'template-file', 'Specify the signature template file. Default is STDIN.', argument: true, as: String
|
35
|
+
slop.on :o, :'output-file', 'Specify the output file for the signature. Default is STDOUT.', argument: true, as: String
|
36
|
+
slop.on :force, 'Force overwriting output file.', argument: false
|
37
|
+
slop.on :var=, 'Define variables in the form name=value', argument: true, as: Array
|
38
|
+
slop.on :n, :'no-minify', 'Will not minify the resulting html signature. By default will do', argument: false
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def do_process
|
43
|
+
# Your code here.
|
44
|
+
content = template_io.read
|
45
|
+
logger.debug content
|
46
|
+
processor = SignatureGenerator::Processor.new context
|
47
|
+
signature = processor.transform content
|
48
|
+
logger.debug signature
|
49
|
+
unless config[:'no-minify']
|
50
|
+
minifier = HtmlMinifier::Minifier.new collapseWhitespace: true, collapseInlineTagWhitespace: true
|
51
|
+
signature = minifier.minify signature
|
52
|
+
logger.debug 'Minifying resulting signature'
|
53
|
+
logger.debug signature
|
54
|
+
end
|
55
|
+
output_io.puts signature
|
56
|
+
ensure
|
57
|
+
template_io.close
|
58
|
+
output_io.close
|
59
|
+
end
|
60
|
+
|
61
|
+
def check_config
|
62
|
+
# Check the config and raise an exception if incorrect.
|
63
|
+
config[:var] ||=[]
|
64
|
+
@context = {}
|
65
|
+
config[:var].each do |definition|
|
66
|
+
valid = false
|
67
|
+
definition.match(/^\s*(?<var_name>[a-z][a-z0-9_]*)\s*=\s*(?<var_value>.+)\s*$/) do |md|
|
68
|
+
logger.warning "Overwriting existing variable '#{md['var_name']}' !" if context[md['var_name']]
|
69
|
+
context[md['var_name'].to_sym] = md['var_value']
|
70
|
+
valid = true
|
71
|
+
end
|
72
|
+
raise SignatureGenerator::Error, 'Invalid property specified !' unless valid
|
73
|
+
end
|
74
|
+
|
75
|
+
@template_io = case config[:'template-file']
|
76
|
+
when NilClass
|
77
|
+
logger.debug 'Template from STDIN'
|
78
|
+
STDIN
|
79
|
+
when String
|
80
|
+
file = File.expand_path(config[:'template-file'])
|
81
|
+
raise SignatureGenerator::Error, 'Invalid template file specified !' unless File.readable? file
|
82
|
+
io = File.open file, 'r'
|
83
|
+
logger.debug "Template from file '#{file}'"
|
84
|
+
io
|
85
|
+
end
|
86
|
+
@output_io = case config[:'output-file']
|
87
|
+
when NilClass
|
88
|
+
logger.debug 'Signature to STDOUT'
|
89
|
+
STDOUT
|
90
|
+
when String
|
91
|
+
file = File.expand_path(config[:'output-file'])
|
92
|
+
if File.exists? file
|
93
|
+
raise SignatureGenerator::Error, 'Output file already exists ! Use --force' unless config[:force]
|
94
|
+
end
|
95
|
+
io = File.open file, 'w'
|
96
|
+
logger.debug "Signature generated into file '#{file}'"
|
97
|
+
io
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
104
|
+
SignatureGenerator::SgMasterScript.new.run
|
@@ -0,0 +1,26 @@
|
|
1
|
+
|
2
|
+
module SignatureGenerator
|
3
|
+
|
4
|
+
class Context
|
5
|
+
|
6
|
+
def initialize(hash={})
|
7
|
+
@internal_hash = hash
|
8
|
+
end
|
9
|
+
|
10
|
+
def []=(key,val)
|
11
|
+
internal_hash[key] = val
|
12
|
+
end
|
13
|
+
|
14
|
+
def method_missing(*args)
|
15
|
+
method_name = args.shift
|
16
|
+
return internal_hash[method_name] if internal_hash[method_name]
|
17
|
+
super(method_name, *args)
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
|
22
|
+
attr_reader :internal_hash
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'erb'
|
2
|
+
|
3
|
+
module SignatureGenerator
|
4
|
+
|
5
|
+
class Processor
|
6
|
+
|
7
|
+
include EasyAppHelper
|
8
|
+
include EasyAppHelper::Input
|
9
|
+
MAX_RETRY = 3
|
10
|
+
|
11
|
+
attr_reader :results, :context
|
12
|
+
|
13
|
+
def initialize(context={})
|
14
|
+
self.context = context
|
15
|
+
end
|
16
|
+
|
17
|
+
def transform(template, context = self.context)
|
18
|
+
counters = {}
|
19
|
+
begin
|
20
|
+
@results = ERB.new(template, nil, '-').result(context_as_binding context)
|
21
|
+
rescue NameError => e
|
22
|
+
missing_var = e.name
|
23
|
+
counters[missing_var] ||= 0
|
24
|
+
counters[missing_var] += 1
|
25
|
+
debug_msg = "Variable not provided: #{missing_var} (attempt ##{counters[missing_var]})"
|
26
|
+
logger.debug debug_msg
|
27
|
+
if counters[missing_var] > MAX_RETRY
|
28
|
+
logger.error 'Maximum retry number exceeded. Aborting !'
|
29
|
+
raise e
|
30
|
+
end
|
31
|
+
user_input = get_user_input "Please enter value for '#{missing_var}' > "
|
32
|
+
context[missing_var] = user_input unless user_input.nil? or user_input.empty?
|
33
|
+
retry
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def context=(context)
|
38
|
+
raise SignatureGenerator::Error, 'Context cannot be nil' if context.nil?
|
39
|
+
@context = case context
|
40
|
+
when Hash
|
41
|
+
SignatureGenerator::Context.new context
|
42
|
+
when SignatureGenerator::Context
|
43
|
+
context
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
private
|
48
|
+
|
49
|
+
def context_as_binding(context)
|
50
|
+
context.instance_eval do
|
51
|
+
binding
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'signature_generator/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = 'signature_generator'
|
8
|
+
spec.version = SignatureGenerator::VERSION
|
9
|
+
spec.authors = ['Laurent B.']
|
10
|
+
spec.email = ['lbnetid+gh@gmail.com']
|
11
|
+
|
12
|
+
spec.summary = %q{Generates an HTML signature to be used in mail UA from template.}
|
13
|
+
spec.description = %q{Generates an HTML signature to be used in mail UA from template with multiple mechanisms for substitution.}
|
14
|
+
spec.homepage = 'https://github.com/lbriais/signature_generator'
|
15
|
+
spec.license = 'MIT'
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = 'exe'
|
19
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
20
|
+
spec.require_paths = ['lib']
|
21
|
+
|
22
|
+
spec.add_development_dependency 'bundler', '~> 1.11'
|
23
|
+
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
+
spec.add_development_dependency 'pry'
|
25
|
+
spec.add_development_dependency 'rspec'
|
26
|
+
|
27
|
+
spec.add_dependency 'easy_app_helper', '~> 4.2'
|
28
|
+
spec.add_dependency 'html_minifier'
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,147 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: signature_generator
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Laurent B.
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-12 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.11'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.11'
|
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: pry
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rspec
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: easy_app_helper
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '4.2'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '4.2'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: html_minifier
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Generates an HTML signature to be used in mail UA from template with
|
98
|
+
multiple mechanisms for substitution.
|
99
|
+
email:
|
100
|
+
- lbnetid+gh@gmail.com
|
101
|
+
executables:
|
102
|
+
- sg
|
103
|
+
extensions: []
|
104
|
+
extra_rdoc_files: []
|
105
|
+
files:
|
106
|
+
- ".gitignore"
|
107
|
+
- ".rspec"
|
108
|
+
- ".travis.yml"
|
109
|
+
- CODE_OF_CONDUCT.md
|
110
|
+
- Gemfile
|
111
|
+
- LICENSE.txt
|
112
|
+
- README.md
|
113
|
+
- Rakefile
|
114
|
+
- bin/console
|
115
|
+
- bin/setup
|
116
|
+
- exe/sg
|
117
|
+
- lib/signature_generator.rb
|
118
|
+
- lib/signature_generator/context.rb
|
119
|
+
- lib/signature_generator/error.rb
|
120
|
+
- lib/signature_generator/processor.rb
|
121
|
+
- lib/signature_generator/version.rb
|
122
|
+
- signature_generator.gemspec
|
123
|
+
homepage: https://github.com/lbriais/signature_generator
|
124
|
+
licenses:
|
125
|
+
- MIT
|
126
|
+
metadata: {}
|
127
|
+
post_install_message:
|
128
|
+
rdoc_options: []
|
129
|
+
require_paths:
|
130
|
+
- lib
|
131
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
132
|
+
requirements:
|
133
|
+
- - ">="
|
134
|
+
- !ruby/object:Gem::Version
|
135
|
+
version: '0'
|
136
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
|
+
requirements:
|
138
|
+
- - ">="
|
139
|
+
- !ruby/object:Gem::Version
|
140
|
+
version: '0'
|
141
|
+
requirements: []
|
142
|
+
rubyforge_project:
|
143
|
+
rubygems_version: 2.4.5.1
|
144
|
+
signing_key:
|
145
|
+
specification_version: 4
|
146
|
+
summary: Generates an HTML signature to be used in mail UA from template.
|
147
|
+
test_files: []
|