static-shell-templates 0.0.2 → 0.1.0
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/.gitignore +0 -1
- data/Gemfile +4 -0
- data/Gemfile.lock +145 -0
- data/Makefile +1 -0
- data/Procfile +1 -0
- data/app.rb +32 -0
- data/examples/existing.sh +0 -0
- data/examples/missing-source.sh +2 -0
- data/examples/redirect.sh +3 -0
- data/lib/static_shell_templates.rb +17 -2
- data/lib/static_shell_templates/version.rb +1 -1
- data/public/examples/basic.sh +6 -0
- data/public/index.html +58 -0
- data/public/index.js +25 -0
- data/test/simple.bats +21 -0
- metadata +10 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 0e0952a3b3b070660cac9a55e453537b5de2d5ec
|
|
4
|
+
data.tar.gz: c7d60994aa9bbd9d5361899fb5e4cae55a427bf6
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0cd8c27dff81d2035d1d45d384cffcb0b34167784ebd32b455c1e09a52583274263cee97c18255b4bff421b5da50755ce3b5eae5a9505cfaf4d2543548ff2c5c
|
|
7
|
+
data.tar.gz: 413485530d040a7ad8e0f2231777dbf05b13b5c177b2ebe0c0253ebaa057cccfc9b6d2c550bd93f416b86b6e858fff0255f8c01e550aa0b02add5866148c12e0
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
PATH
|
|
2
|
+
remote: .
|
|
3
|
+
specs:
|
|
4
|
+
static-shell-templates (0.1.0)
|
|
5
|
+
thor
|
|
6
|
+
|
|
7
|
+
GEM
|
|
8
|
+
remote: https://rubygems.org/
|
|
9
|
+
specs:
|
|
10
|
+
addressable (2.3.8)
|
|
11
|
+
ast (2.1.0)
|
|
12
|
+
astrolabe (1.3.1)
|
|
13
|
+
parser (~> 2.2)
|
|
14
|
+
backports (3.6.7)
|
|
15
|
+
bump (0.5.3)
|
|
16
|
+
byebug (8.2.1)
|
|
17
|
+
coderay (1.1.0)
|
|
18
|
+
coolline (0.5.0)
|
|
19
|
+
unicode_utils (~> 1.4)
|
|
20
|
+
crack (0.4.2)
|
|
21
|
+
safe_yaml (~> 1.0.0)
|
|
22
|
+
diff-lcs (1.2.5)
|
|
23
|
+
ffi (1.9.10)
|
|
24
|
+
formatador (0.2.5)
|
|
25
|
+
fuubar (2.0.0)
|
|
26
|
+
rspec (~> 3.0)
|
|
27
|
+
ruby-progressbar (~> 1.4)
|
|
28
|
+
guard (2.13.0)
|
|
29
|
+
formatador (>= 0.2.4)
|
|
30
|
+
listen (>= 2.7, <= 4.0)
|
|
31
|
+
lumberjack (~> 1.0)
|
|
32
|
+
nenv (~> 0.1)
|
|
33
|
+
notiffany (~> 0.0)
|
|
34
|
+
pry (>= 0.9.12)
|
|
35
|
+
shellany (~> 0.0)
|
|
36
|
+
thor (>= 0.18.1)
|
|
37
|
+
guard-compat (1.2.1)
|
|
38
|
+
guard-rspec (4.6.4)
|
|
39
|
+
guard (~> 2.1)
|
|
40
|
+
guard-compat (~> 1.1)
|
|
41
|
+
rspec (>= 2.99.0, < 4.0)
|
|
42
|
+
guard-rubocop (1.2.0)
|
|
43
|
+
guard (~> 2.0)
|
|
44
|
+
rubocop (~> 0.20)
|
|
45
|
+
listen (3.0.3)
|
|
46
|
+
rb-fsevent (>= 0.9.3)
|
|
47
|
+
rb-inotify (>= 0.9)
|
|
48
|
+
lumberjack (1.0.9)
|
|
49
|
+
method_source (0.8.2)
|
|
50
|
+
multi_json (1.11.2)
|
|
51
|
+
nenv (0.2.0)
|
|
52
|
+
notiffany (0.0.8)
|
|
53
|
+
nenv (~> 0.1)
|
|
54
|
+
shellany (~> 0.0)
|
|
55
|
+
parser (2.2.3.0)
|
|
56
|
+
ast (>= 1.1, < 3.0)
|
|
57
|
+
powerpack (0.1.1)
|
|
58
|
+
pry (0.10.3)
|
|
59
|
+
coderay (~> 1.1.0)
|
|
60
|
+
method_source (~> 0.8.1)
|
|
61
|
+
slop (~> 3.4)
|
|
62
|
+
pry-byebug (3.3.0)
|
|
63
|
+
byebug (~> 8.0)
|
|
64
|
+
pry (~> 0.10)
|
|
65
|
+
pry-coolline (0.2.5)
|
|
66
|
+
coolline (~> 0.5)
|
|
67
|
+
rack (1.6.4)
|
|
68
|
+
rack-protection (1.5.3)
|
|
69
|
+
rack
|
|
70
|
+
rack-test (0.6.3)
|
|
71
|
+
rack (>= 1.0)
|
|
72
|
+
rainbow (2.0.0)
|
|
73
|
+
rake (10.1.0)
|
|
74
|
+
rb-fsevent (0.9.6)
|
|
75
|
+
rb-inotify (0.9.5)
|
|
76
|
+
ffi (>= 0.5.0)
|
|
77
|
+
rspec (3.3.0)
|
|
78
|
+
rspec-core (~> 3.3.0)
|
|
79
|
+
rspec-expectations (~> 3.3.0)
|
|
80
|
+
rspec-mocks (~> 3.3.0)
|
|
81
|
+
rspec-core (3.3.2)
|
|
82
|
+
rspec-support (~> 3.3.0)
|
|
83
|
+
rspec-expectations (3.3.1)
|
|
84
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
85
|
+
rspec-support (~> 3.3.0)
|
|
86
|
+
rspec-mocks (3.3.2)
|
|
87
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
|
88
|
+
rspec-support (~> 3.3.0)
|
|
89
|
+
rspec-support (3.3.0)
|
|
90
|
+
rubocop (0.34.2)
|
|
91
|
+
astrolabe (~> 1.3)
|
|
92
|
+
parser (>= 2.2.2.5, < 3.0)
|
|
93
|
+
powerpack (~> 0.1)
|
|
94
|
+
rainbow (>= 1.99.1, < 3.0)
|
|
95
|
+
ruby-progressbar (~> 1.4)
|
|
96
|
+
rubocop-rspec (1.3.1)
|
|
97
|
+
ruby-progressbar (1.7.5)
|
|
98
|
+
safe_yaml (1.0.4)
|
|
99
|
+
shellany (0.0.1)
|
|
100
|
+
shotgun (0.9.1)
|
|
101
|
+
rack (>= 1.0)
|
|
102
|
+
sinatra (1.4.6)
|
|
103
|
+
rack (~> 1.4)
|
|
104
|
+
rack-protection (~> 1.4)
|
|
105
|
+
tilt (>= 1.3, < 3)
|
|
106
|
+
sinatra-contrib (1.4.6)
|
|
107
|
+
backports (>= 2.0)
|
|
108
|
+
multi_json
|
|
109
|
+
rack-protection
|
|
110
|
+
rack-test
|
|
111
|
+
sinatra (~> 1.4.0)
|
|
112
|
+
tilt (>= 1.3, < 3)
|
|
113
|
+
slop (3.6.0)
|
|
114
|
+
thor (0.19.1)
|
|
115
|
+
tilt (2.0.1)
|
|
116
|
+
unicode_utils (1.4.0)
|
|
117
|
+
webmock (1.21.0)
|
|
118
|
+
addressable (>= 2.3.6)
|
|
119
|
+
crack (>= 0.3.2)
|
|
120
|
+
|
|
121
|
+
PLATFORMS
|
|
122
|
+
ruby
|
|
123
|
+
|
|
124
|
+
DEPENDENCIES
|
|
125
|
+
bump
|
|
126
|
+
bundler (~> 1.7)
|
|
127
|
+
fuubar
|
|
128
|
+
guard
|
|
129
|
+
guard-rspec
|
|
130
|
+
guard-rubocop
|
|
131
|
+
pry
|
|
132
|
+
pry-byebug
|
|
133
|
+
pry-coolline
|
|
134
|
+
rake (~> 10.0)
|
|
135
|
+
rspec
|
|
136
|
+
rubocop
|
|
137
|
+
rubocop-rspec
|
|
138
|
+
shotgun
|
|
139
|
+
sinatra
|
|
140
|
+
sinatra-contrib
|
|
141
|
+
static-shell-templates!
|
|
142
|
+
webmock
|
|
143
|
+
|
|
144
|
+
BUNDLED WITH
|
|
145
|
+
1.10.6
|
data/Makefile
CHANGED
data/Procfile
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
web: bundle exec ruby app.rb
|
data/app.rb
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
require 'sinatra'
|
|
2
|
+
require 'sinatra/json'
|
|
3
|
+
require 'static_shell_templates'
|
|
4
|
+
|
|
5
|
+
set :port, ENV['PORT'] || 5000
|
|
6
|
+
get '/' do
|
|
7
|
+
File.read(File.join('public', 'index.html'))
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
post '/replace' do
|
|
11
|
+
p params
|
|
12
|
+
script = params['script'];
|
|
13
|
+
template = StaticShellTemplates::Template.new script
|
|
14
|
+
replaced = template.replace
|
|
15
|
+
|
|
16
|
+
json script: params['script'], replaced: replaced
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
post '/upload' do
|
|
20
|
+
unless params[:file] &&
|
|
21
|
+
(tmpfile = params[:file][:tempfile]) &&
|
|
22
|
+
(name = params[:file][:filename])
|
|
23
|
+
@error = "No file selected"
|
|
24
|
+
return haml(:upload)
|
|
25
|
+
end
|
|
26
|
+
STDERR.puts "Uploading file, original name #{name.inspect}"
|
|
27
|
+
while blk = tmpfile.read(65536)
|
|
28
|
+
# here you would write it to its final location
|
|
29
|
+
STDERR.puts blk.inspect
|
|
30
|
+
end
|
|
31
|
+
"Upload complete"
|
|
32
|
+
end
|
data/examples/existing.sh
CHANGED
|
File without changes
|
|
@@ -43,12 +43,27 @@ module StaticShellTemplates
|
|
|
43
43
|
end
|
|
44
44
|
|
|
45
45
|
def content
|
|
46
|
-
response =
|
|
47
|
-
fail Error, "Content not found: #{@source}" if response.code != '200'
|
|
46
|
+
response = fetch @source
|
|
48
47
|
|
|
49
48
|
response.body
|
|
50
49
|
end
|
|
51
50
|
|
|
51
|
+
private def fetch(uri_str, limit = 10)
|
|
52
|
+
raise ArgumentError, 'too many HTTP redirects' if limit == 0
|
|
53
|
+
|
|
54
|
+
response = Net::HTTP.get_response(URI(uri_str))
|
|
55
|
+
|
|
56
|
+
case response
|
|
57
|
+
when Net::HTTPSuccess then
|
|
58
|
+
response
|
|
59
|
+
when Net::HTTPRedirection then
|
|
60
|
+
location = response['location']
|
|
61
|
+
fetch(location, limit - 1)
|
|
62
|
+
else
|
|
63
|
+
fail Error, "Content not found: #{@source}"
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
52
67
|
def output
|
|
53
68
|
%(#{@header}
|
|
54
69
|
#{content}
|
data/public/index.html
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html>
|
|
3
|
+
<head>
|
|
4
|
+
<!-- Standard Meta -->
|
|
5
|
+
<meta charset="utf-8" />
|
|
6
|
+
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
|
|
7
|
+
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
|
|
8
|
+
|
|
9
|
+
<title>Static Shell Templates</title>
|
|
10
|
+
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.7/semantic.min.css">
|
|
11
|
+
|
|
12
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.4/jquery.min.js"></script>
|
|
13
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/semantic-ui/2.1.7/semantic.min.js"></script>
|
|
14
|
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/1.0.12/vue.min.js"></script>
|
|
15
|
+
<script src="./index.js"></script>
|
|
16
|
+
</head>
|
|
17
|
+
|
|
18
|
+
<body>
|
|
19
|
+
<h1 class="ui center aligned header">Static Shell Templates</h1>
|
|
20
|
+
<h2 class="ui center aligned header">Try it out! Enter your script with templates:</h2>
|
|
21
|
+
<div class="ui container">
|
|
22
|
+
<div id="sandbox" class="ui segments">
|
|
23
|
+
<div class="ui segment">
|
|
24
|
+
<div class="ui form">
|
|
25
|
+
<div class="field">
|
|
26
|
+
<label>Templated Script</label>
|
|
27
|
+
<textarea v-model="script"></textarea>
|
|
28
|
+
</div>
|
|
29
|
+
<div class="ui large buttons right floated">
|
|
30
|
+
<button class="ui button left attached" v-on:click="loadExample">Load Example</button>
|
|
31
|
+
<div class="or"></div>
|
|
32
|
+
<button class="positive ui button right attached" v-on:click="replace" v-bind:class="{ 'loading': isReplacing}">
|
|
33
|
+
Replace
|
|
34
|
+
</button>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="field">
|
|
37
|
+
<label>Replaced Script</label>
|
|
38
|
+
<textarea readonly="true" v-model="replaced"></textarea>
|
|
39
|
+
</div>
|
|
40
|
+
</div>
|
|
41
|
+
</div>
|
|
42
|
+
<!-- <div class="ui segment">Content</div> -->
|
|
43
|
+
</div>
|
|
44
|
+
</div>
|
|
45
|
+
|
|
46
|
+
<!-- Content JS HERE !-->
|
|
47
|
+
<style>
|
|
48
|
+
h1.ui.center.header {
|
|
49
|
+
margin-top: 1em;
|
|
50
|
+
}
|
|
51
|
+
h2.ui.center.header {
|
|
52
|
+
margin: 2em 0em 1em;
|
|
53
|
+
}
|
|
54
|
+
</style>
|
|
55
|
+
|
|
56
|
+
</body>
|
|
57
|
+
</html>
|
|
58
|
+
|
data/public/index.js
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
$( document ).ready(function() {
|
|
2
|
+
data = {
|
|
3
|
+
script: '',
|
|
4
|
+
replaced: '',
|
|
5
|
+
isReplacing: false
|
|
6
|
+
};
|
|
7
|
+
var toggleIsReplacing = () => { data.isReplacing = !data.isReplacing };
|
|
8
|
+
app = new Vue({
|
|
9
|
+
el: '#sandbox',
|
|
10
|
+
data: data,
|
|
11
|
+
methods: {
|
|
12
|
+
loadExample: (event) => {
|
|
13
|
+
$.get('examples/basic.sh').done((d) => {data.script = d})
|
|
14
|
+
},
|
|
15
|
+
replace: (event) => {
|
|
16
|
+
toggleIsReplacing();
|
|
17
|
+
$.post('replace', {script: data.script})
|
|
18
|
+
.done((d) => {
|
|
19
|
+
data.replaced = d.replaced;
|
|
20
|
+
})
|
|
21
|
+
.always(toggleIsReplacing);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
});
|
data/test/simple.bats
CHANGED
|
@@ -19,3 +19,24 @@
|
|
|
19
19
|
[[ ${lines[0]} =~ "INFO: TEST" ]]
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
@test "follow redirect" {
|
|
23
|
+
run bash -c 'bundle exec static_shell_templates replace examples/redirect.sh'
|
|
24
|
+
|
|
25
|
+
echo "${lines[@]}"
|
|
26
|
+
[ $status = 0 ]
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
@test "error exit code when template source is not found" {
|
|
30
|
+
run bash -c 'bundle exec static_shell_templates replace examples/missing-source.sh'
|
|
31
|
+
|
|
32
|
+
echo "${lines[@]}"
|
|
33
|
+
[ $status = 1 ]
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
@test "error exit code when input file is not found" {
|
|
37
|
+
run bash -c 'bundle exec static_shell_templates replace do-not-exist.sh'
|
|
38
|
+
|
|
39
|
+
echo "${lines[@]}"
|
|
40
|
+
[ $status = 1 ]
|
|
41
|
+
}
|
|
42
|
+
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: static-shell-templates
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.0
|
|
4
|
+
version: 0.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Gonzalo Matheu
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2015-12-
|
|
11
|
+
date: 2015-12-30 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|
|
@@ -240,18 +240,26 @@ files:
|
|
|
240
240
|
- ".ruby-gemset"
|
|
241
241
|
- ".ruby-version"
|
|
242
242
|
- Gemfile
|
|
243
|
+
- Gemfile.lock
|
|
243
244
|
- Guardfile
|
|
244
245
|
- LICENSE.txt
|
|
245
246
|
- Makefile
|
|
247
|
+
- Procfile
|
|
246
248
|
- README.md
|
|
247
249
|
- Rakefile
|
|
248
250
|
- Vagrantfile
|
|
251
|
+
- app.rb
|
|
249
252
|
- bin/static_shell_templates
|
|
250
253
|
- build.bats
|
|
251
254
|
- examples/basic.sh
|
|
252
255
|
- examples/existing.sh
|
|
256
|
+
- examples/missing-source.sh
|
|
257
|
+
- examples/redirect.sh
|
|
253
258
|
- lib/static_shell_templates.rb
|
|
254
259
|
- lib/static_shell_templates/version.rb
|
|
260
|
+
- public/examples/basic.sh
|
|
261
|
+
- public/index.html
|
|
262
|
+
- public/index.js
|
|
255
263
|
- spec/spec_helper.rb
|
|
256
264
|
- spec/static_shell_templates/include_spec.rb
|
|
257
265
|
- spec/static_shell_templates/template_spec.rb
|