static-shell-templates 0.0.2 → 0.1.0

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: 0aa09d54fb9670714b482cf8c06111ff5b6c3184
4
- data.tar.gz: 2d9cb9936e9ae7b5917c8c62f9abb84836ca3e9c
3
+ metadata.gz: 0e0952a3b3b070660cac9a55e453537b5de2d5ec
4
+ data.tar.gz: c7d60994aa9bbd9d5361899fb5e4cae55a427bf6
5
5
  SHA512:
6
- metadata.gz: 0e2db5ca88c46a91fec208ad30bbbc13a67d4a536b38df15d27d1e02175ba75a7d2ef73e0ea9cb1869f826d684aba0ff796a2ad2cca93fcbaacf0f578e5408c3
7
- data.tar.gz: 827a074cddfdcbd810c91de915cf880aa7f2d6af9a6b5d23e06b5895013990fac5fc96cf86f7de517ea9a827e393556b724df75fe70fe9b18a5267cd295a9e9e
6
+ metadata.gz: 0cd8c27dff81d2035d1d45d384cffcb0b34167784ebd32b455c1e09a52583274263cee97c18255b4bff421b5da50755ce3b5eae5a9505cfaf4d2543548ff2c5c
7
+ data.tar.gz: 413485530d040a7ad8e0f2231777dbf05b13b5c177b2ebe0c0253ebaa057cccfc9b6d2c550bd93f416b86b6e858fff0255f8c01e550aa0b02add5866148c12e0
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
data/Gemfile CHANGED
@@ -2,3 +2,7 @@ source 'https://rubygems.org'
2
2
 
3
3
  # Specify your gem's dependencies in static-shell-templates.gemspec
4
4
  gemspec
5
+
6
+ gem 'sinatra'
7
+ gem 'sinatra-contrib'
8
+ gem 'shotgun'
@@ -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
@@ -11,6 +11,7 @@ release:
11
11
  bundle install
12
12
  bundle exec rake release
13
13
  bundle exec rake bump:minor
14
+ git push origin master
14
15
 
15
16
  define RUBYGEMS_CREDENTIALS=
16
17
  ---
@@ -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
File without changes
@@ -0,0 +1,2 @@
1
+ #! /bin/bash
2
+ #template: source: https://absolutely-nonexisting-url.com.zz
@@ -0,0 +1,3 @@
1
+ #! /bin/bash
2
+ #template: source: http://bit.ly/you_need
3
+
@@ -43,12 +43,27 @@ module StaticShellTemplates
43
43
  end
44
44
 
45
45
  def content
46
- response = Net::HTTP.get_response @source
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}
@@ -1,3 +1,3 @@
1
1
  module StaticShellTemplates
2
- VERSION = '0.0.2'
2
+ VERSION = '0.1.0'
3
3
  end
@@ -0,0 +1,6 @@
1
+ #! /bin/bash
2
+ #template: source: https://gist.githubusercontent.com/gmatheu/302aec1e3afb254bde8b/raw/857da1981e3ab2234ac7bd48fbce13eb10ef40dc/log-functions
3
+
4
+ echo $(type info)
5
+ info "TEST"
6
+
@@ -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
+
@@ -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
+ });
@@ -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.2
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-13 00:00:00.000000000 Z
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