startback 0.19.4 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +10 -0
- data/lib/startback/version.rb +3 -3
- metadata +18 -25
- data/lib/startback/web/magic_assets/ng_html_transformer.rb +0 -80
- data/lib/startback/web/magic_assets/rake_tasks.rb +0 -64
- data/lib/startback/web/magic_assets.rb +0 -98
- data/spec/unit/web/fixtures/assets/app/hello.es6 +0 -4
- data/spec/unit/web/fixtures/assets/app/hello.html +0 -1
- data/spec/unit/web/fixtures/assets/index.es6 +0 -1
- data/spec/unit/web/test_magic_assets.rb +0 -82
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 85db266a4c72694e948fc85a4bd7e4923f0ecce7afeb9976a1d6033d120a8191
|
4
|
+
data.tar.gz: fb68dc41bc6acc1bd6dda521146d5f0f444f81c6824137d64dd1393d78db0199
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a56a2fc06d115226421684fc78441ee22b111fd3fd8a2d1ab18cf5a44ab5f699df7b43e5eebb6be2ac5e968c157f4c6c20e1e74f5b44faabc7130965099c9c59
|
7
|
+
data.tar.gz: 0c75bea563030c189613f45d29f61fed3869777f4987f8e6bc6af1b169fbf3184e4f561d2c655d3efdadfd250cfe44d397cff03d40e8048c6f80a0d597a31d5a
|
data/README.md
CHANGED
@@ -11,3 +11,13 @@ Currently,
|
|
11
11
|
1. is handled using extra support on top of Sinatra
|
12
12
|
2. is handled using Startback specific classes
|
13
13
|
3. is handled using Bmg
|
14
|
+
|
15
|
+
## Public API
|
16
|
+
|
17
|
+
This gem uses semantics versioning and has reached it's 1.0 version. The public
|
18
|
+
API is defined as follows:
|
19
|
+
|
20
|
+
* All ruby classes, require path, constructor arguments, and public methods.
|
21
|
+
|
22
|
+
* The `enspirit/startback:api` and `enspirit/startback:web` docker images and
|
23
|
+
main `CMD`.
|
data/lib/startback/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: startback
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Bernard Lambeau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-06-
|
11
|
+
date: 2023-06-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rspec
|
@@ -36,40 +36,40 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: 0.
|
39
|
+
version: '0.6'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
version: '0.
|
42
|
+
version: '0.7'
|
43
43
|
type: :development
|
44
44
|
prerelease: false
|
45
45
|
version_requirements: !ruby/object:Gem::Requirement
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: 0.
|
49
|
+
version: '0.6'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
|
-
version: '0.
|
52
|
+
version: '0.7'
|
53
53
|
- !ruby/object:Gem::Dependency
|
54
54
|
name: webspicy
|
55
55
|
requirement: !ruby/object:Gem::Requirement
|
56
56
|
requirements:
|
57
57
|
- - ">="
|
58
58
|
- !ruby/object:Gem::Version
|
59
|
-
version: 0.
|
59
|
+
version: 0.26.0
|
60
60
|
- - "<"
|
61
61
|
- !ruby/object:Gem::Version
|
62
|
-
version: '0.
|
62
|
+
version: '0.27'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
67
|
- - ">="
|
68
68
|
- !ruby/object:Gem::Version
|
69
|
-
version: 0.
|
69
|
+
version: 0.26.0
|
70
70
|
- - "<"
|
71
71
|
- !ruby/object:Gem::Version
|
72
|
-
version: '0.
|
72
|
+
version: '0.27'
|
73
73
|
- !ruby/object:Gem::Dependency
|
74
74
|
name: rake
|
75
75
|
requirement: !ruby/object:Gem::Requirement
|
@@ -170,20 +170,20 @@ dependencies:
|
|
170
170
|
requirements:
|
171
171
|
- - ">="
|
172
172
|
- !ruby/object:Gem::Version
|
173
|
-
version: '
|
173
|
+
version: '5.0'
|
174
174
|
- - "<"
|
175
175
|
- !ruby/object:Gem::Version
|
176
|
-
version: '
|
176
|
+
version: '6.0'
|
177
177
|
type: :runtime
|
178
178
|
prerelease: false
|
179
179
|
version_requirements: !ruby/object:Gem::Requirement
|
180
180
|
requirements:
|
181
181
|
- - ">="
|
182
182
|
- !ruby/object:Gem::Version
|
183
|
-
version: '
|
183
|
+
version: '5.0'
|
184
184
|
- - "<"
|
185
185
|
- !ruby/object:Gem::Version
|
186
|
-
version: '
|
186
|
+
version: '6.0'
|
187
187
|
- !ruby/object:Gem::Dependency
|
188
188
|
name: bunny
|
189
189
|
requirement: !ruby/object:Gem::Requirement
|
@@ -290,20 +290,20 @@ dependencies:
|
|
290
290
|
requirements:
|
291
291
|
- - ">="
|
292
292
|
- !ruby/object:Gem::Version
|
293
|
-
version: '
|
293
|
+
version: '2.0'
|
294
294
|
- - "<"
|
295
295
|
- !ruby/object:Gem::Version
|
296
|
-
version: '
|
296
|
+
version: '3.0'
|
297
297
|
type: :runtime
|
298
298
|
prerelease: false
|
299
299
|
version_requirements: !ruby/object:Gem::Requirement
|
300
300
|
requirements:
|
301
301
|
- - ">="
|
302
302
|
- !ruby/object:Gem::Version
|
303
|
-
version: '
|
303
|
+
version: '2.0'
|
304
304
|
- - "<"
|
305
305
|
- !ruby/object:Gem::Version
|
306
|
-
version: '
|
306
|
+
version: '3.0'
|
307
307
|
- !ruby/object:Gem::Dependency
|
308
308
|
name: tzinfo-data
|
309
309
|
requirement: !ruby/object:Gem::Requirement
|
@@ -441,9 +441,6 @@ files:
|
|
441
441
|
- lib/startback/web/catch_all.rb
|
442
442
|
- lib/startback/web/cors_headers.rb
|
443
443
|
- lib/startback/web/health_check.rb
|
444
|
-
- lib/startback/web/magic_assets.rb
|
445
|
-
- lib/startback/web/magic_assets/ng_html_transformer.rb
|
446
|
-
- lib/startback/web/magic_assets/rake_tasks.rb
|
447
444
|
- lib/startback/web/middleware.rb
|
448
445
|
- lib/startback/web/prometheus.rb
|
449
446
|
- lib/startback/web/shield.rb
|
@@ -476,15 +473,11 @@ files:
|
|
476
473
|
- spec/unit/test_event.rb
|
477
474
|
- spec/unit/test_operation.rb
|
478
475
|
- spec/unit/test_support.rb
|
479
|
-
- spec/unit/web/fixtures/assets/app/hello.es6
|
480
|
-
- spec/unit/web/fixtures/assets/app/hello.html
|
481
|
-
- spec/unit/web/fixtures/assets/index.es6
|
482
476
|
- spec/unit/web/test_api.rb
|
483
477
|
- spec/unit/web/test_auto_caching.rb
|
484
478
|
- spec/unit/web/test_catch_all.rb
|
485
479
|
- spec/unit/web/test_cors_headers.rb
|
486
480
|
- spec/unit/web/test_healthcheck.rb
|
487
|
-
- spec/unit/web/test_magic_assets.rb
|
488
481
|
- tasks/test.rake
|
489
482
|
homepage: https://www.enspirit.be
|
490
483
|
licenses:
|
@@ -1,80 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Web
|
3
|
-
class MagicAssets
|
4
|
-
#
|
5
|
-
# Plugin for MagicAssets that compiles .html angular templates in the
|
6
|
-
# assets structure to javascript files filling angular's template cache.
|
7
|
-
#
|
8
|
-
# Heavily inspired, yet over-simplified version, of angular-rails-templates
|
9
|
-
# See https://github.com/pitr/angular-rails-templates, licensed under MIT
|
10
|
-
#
|
11
|
-
# Example:
|
12
|
-
#
|
13
|
-
# use Startback::Web::MagicAssets, {
|
14
|
-
# plugins: [Startback::Web::MagicAssets::NgHtmlTransfomer.new]
|
15
|
-
# }
|
16
|
-
#
|
17
|
-
class NgHtmlTransformer
|
18
|
-
|
19
|
-
DEFAULT_OPTIONS = {
|
20
|
-
:path => '/assets',
|
21
|
-
:ng_module => 'templates',
|
22
|
-
:mime_type => 'text/ng-html',
|
23
|
-
:extensions => [".html"]
|
24
|
-
}
|
25
|
-
|
26
|
-
def initialize(options = {})
|
27
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
28
|
-
end
|
29
|
-
attr_reader :options
|
30
|
-
|
31
|
-
def install(sprockets)
|
32
|
-
sprockets.register_mime_type options[:mime_type], extensions: options[:extensions]
|
33
|
-
sprockets.register_transformer options[:mime_type], 'application/javascript', self
|
34
|
-
end
|
35
|
-
|
36
|
-
TPL = <<-EOF
|
37
|
-
angular.module("<%= ng_module %>").run(["$templateCache", function($templateCache) {
|
38
|
-
$templateCache.put("<%= angular_template_name %>", <%= html %>)
|
39
|
-
}]);
|
40
|
-
EOF
|
41
|
-
|
42
|
-
# inspired by Rails' action_view/helpers/javascript_helper.rb
|
43
|
-
JS_ESCAPE_MAP = {
|
44
|
-
'\\' => '\\\\',
|
45
|
-
"\r\n" => '\n',
|
46
|
-
"\n" => '\n',
|
47
|
-
"\r" => '\n',
|
48
|
-
'"' => '\\"',
|
49
|
-
"'" => "\\'"
|
50
|
-
}
|
51
|
-
|
52
|
-
# We want to deliver the shortist valid javascript escaped string
|
53
|
-
# Count the number of " vs '
|
54
|
-
# If more ', escape "
|
55
|
-
# If more ", escape '
|
56
|
-
# If equal, prefer to escape "
|
57
|
-
|
58
|
-
def escape_javascript(raw)
|
59
|
-
if raw
|
60
|
-
quote = raw.count(%{'}) >= raw.count(%{"}) ? %{"} : %{'}
|
61
|
-
escaped = raw.gsub(/(\\|\r\n|[\n\r#{quote}])/u) {|match| JS_ESCAPE_MAP[match] }
|
62
|
-
"#{quote}#{escaped}#{quote}"
|
63
|
-
else
|
64
|
-
'""'
|
65
|
-
end
|
66
|
-
end
|
67
|
-
|
68
|
-
def call(input)
|
69
|
-
file_path = input[:filename]
|
70
|
-
angular_template_name = "#{options[:path]}/#{input[:name]}.html"
|
71
|
-
source_file = file_path
|
72
|
-
ng_module = options[:ng_module]
|
73
|
-
html = escape_javascript(input[:data].chomp)
|
74
|
-
ERB.new(TPL).result(binding)
|
75
|
-
end
|
76
|
-
|
77
|
-
end # class NgHtmlTransformer
|
78
|
-
end # class MagicAssets
|
79
|
-
end # module Web
|
80
|
-
end # module Startback
|
@@ -1,64 +0,0 @@
|
|
1
|
-
module Startback
|
2
|
-
module Web
|
3
|
-
class MagicAssets
|
4
|
-
class RakeTasks
|
5
|
-
|
6
|
-
DEFAULT_OPTIONS = {
|
7
|
-
:namespace => :assets
|
8
|
-
}
|
9
|
-
|
10
|
-
def initialize(rake, options)
|
11
|
-
@rake = rake
|
12
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
13
|
-
install
|
14
|
-
end
|
15
|
-
attr_reader :rake, :options
|
16
|
-
|
17
|
-
private
|
18
|
-
|
19
|
-
def install
|
20
|
-
require 'securerandom'
|
21
|
-
|
22
|
-
ns = options[:namespace]
|
23
|
-
target_folder = options[:target]
|
24
|
-
assets = options[:assets]
|
25
|
-
assets = MagicAssets.new(assets) if assets.is_a?(Hash)
|
26
|
-
version = SecureRandom.urlsafe_base64
|
27
|
-
|
28
|
-
rake.instance_exec do
|
29
|
-
namespace(ns) do
|
30
|
-
|
31
|
-
desc 'Cleans generated assets'
|
32
|
-
task :clean do
|
33
|
-
FileUtils.rm_rf target_folder
|
34
|
-
end
|
35
|
-
|
36
|
-
task :prepare do
|
37
|
-
FileUtils.mkdir_p target_folder
|
38
|
-
(target_folder/"VERSION").write(version)
|
39
|
-
end
|
40
|
-
|
41
|
-
desc 'compile javascript assets'
|
42
|
-
task :compile_js do
|
43
|
-
assets['vendor.js'].write_to(target_folder/"vendor-#{version}.min.js")
|
44
|
-
assets['app.js'].write_to(target_folder/"app-#{version}.min.js")
|
45
|
-
puts "successfully compiled js assets"
|
46
|
-
end
|
47
|
-
|
48
|
-
desc 'compile css assets'
|
49
|
-
task :compile_css do
|
50
|
-
assets['vendor.css'].write_to(target_folder/"vendor-#{version}.min.css")
|
51
|
-
assets['app.css'].write_to(target_folder/"app-#{version}.min.css")
|
52
|
-
puts "successfully compiled css assets"
|
53
|
-
end
|
54
|
-
|
55
|
-
desc 'compile assets'
|
56
|
-
task :compile => [:clean, :prepare, :compile_js, :compile_css]
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
end
|
62
|
-
end # class MagicAssets
|
63
|
-
end # module Web
|
64
|
-
end # module Startback
|
@@ -1,98 +0,0 @@
|
|
1
|
-
require 'sprockets'
|
2
|
-
module Startback
|
3
|
-
module Web
|
4
|
-
#
|
5
|
-
# Rack application & middleware that can be used to simplify javascript
|
6
|
-
# and css assets management, using Sprockets.
|
7
|
-
#
|
8
|
-
# Example:
|
9
|
-
#
|
10
|
-
# # Used as rack app, typically under a path
|
11
|
-
# Rack::Builder.new do
|
12
|
-
# map '/assets' do
|
13
|
-
# run Startback::Web::MagicAssets.new({
|
14
|
-
# folder: "/path/to/assets/src"
|
15
|
-
# })
|
16
|
-
# end
|
17
|
-
# run MyApp
|
18
|
-
# end
|
19
|
-
#
|
20
|
-
# # Used as a rack middleware, e.g. in a Sinatra application
|
21
|
-
# use Startback::Web::MagicAssets, {
|
22
|
-
# folder: "/path/to/assets/src",
|
23
|
-
# path: "/assets"
|
24
|
-
# }
|
25
|
-
#
|
26
|
-
# Sprocket configuration can be done through the `:sprocket` option:
|
27
|
-
#
|
28
|
-
# use Startback::Web::MagicAssets, {
|
29
|
-
# sprockets: {
|
30
|
-
# :css_compressor => :scss
|
31
|
-
# }
|
32
|
-
# }
|
33
|
-
#
|
34
|
-
class MagicAssets
|
35
|
-
|
36
|
-
DEFAULT_OPTIONS = {
|
37
|
-
sprockets: {},
|
38
|
-
plugins: {}
|
39
|
-
}
|
40
|
-
|
41
|
-
def initialize(app, options = {})
|
42
|
-
app, options = nil, app if app.is_a?(Hash)
|
43
|
-
@app = app
|
44
|
-
@options = DEFAULT_OPTIONS.merge(options)
|
45
|
-
@sprockets = build_sprockets
|
46
|
-
end
|
47
|
-
attr_reader :sprockets
|
48
|
-
|
49
|
-
def call(env)
|
50
|
-
if new_env = is_match?(env)
|
51
|
-
@sprockets.call(new_env)
|
52
|
-
else
|
53
|
-
@app.call(env)
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
def [](*args, &bl)
|
58
|
-
@sprockets.[](*args, &bl)
|
59
|
-
end
|
60
|
-
|
61
|
-
private
|
62
|
-
|
63
|
-
def path
|
64
|
-
@options[:path]
|
65
|
-
end
|
66
|
-
|
67
|
-
def is_match?(env)
|
68
|
-
if @app.nil?
|
69
|
-
# Not used as a middleware, use this env and match
|
70
|
-
env
|
71
|
-
elsif env['PATH_INFO'].start_with?(path)
|
72
|
-
# Used as a middleware, and PATH_INFO starts with the
|
73
|
-
# assets path => strip it for sprockets
|
74
|
-
env.merge("PATH_INFO" => env["PATH_INFO"].sub(path, ""))
|
75
|
-
else
|
76
|
-
# No match, let @app execute with the untouched environment
|
77
|
-
nil
|
78
|
-
end
|
79
|
-
end
|
80
|
-
|
81
|
-
def build_sprockets
|
82
|
-
Sprockets::Environment.new.tap{|s|
|
83
|
-
Array(@options[:folder]).each do |folder|
|
84
|
-
s.append_path(folder)
|
85
|
-
end
|
86
|
-
@options[:sprockets].each_pair do |k,v|
|
87
|
-
s.public_send(:"#{k}=", v)
|
88
|
-
end
|
89
|
-
@options[:plugins].each do |p|
|
90
|
-
p.install(s)
|
91
|
-
end
|
92
|
-
}
|
93
|
-
end
|
94
|
-
|
95
|
-
end # class MagicAssets
|
96
|
-
end # module Web
|
97
|
-
end # module Startback
|
98
|
-
require_relative 'magic_assets/rake_tasks'
|
@@ -1 +0,0 @@
|
|
1
|
-
<p>Hello {{who}}</p>
|
@@ -1 +0,0 @@
|
|
1
|
-
//= require_tree ./app
|
@@ -1,82 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
require 'startback/web/magic_assets'
|
3
|
-
require 'startback/web/magic_assets/ng_html_transformer'
|
4
|
-
|
5
|
-
module Startback
|
6
|
-
module Web
|
7
|
-
describe MagicAssets do
|
8
|
-
include Rack::Test::Methods
|
9
|
-
|
10
|
-
context 'when used as an app' do
|
11
|
-
let(:app){
|
12
|
-
MagicAssets.new({
|
13
|
-
folder: Path.dir/"fixtures/assets"
|
14
|
-
})
|
15
|
-
}
|
16
|
-
|
17
|
-
it 'works as expected' do
|
18
|
-
get "/index.js"
|
19
|
-
expect(last_response.status).to eql(200)
|
20
|
-
expect(last_response.body).to match(/function test/)
|
21
|
-
end
|
22
|
-
|
23
|
-
it 'delegates a [] call to sprockets' do
|
24
|
-
result = app['index.js']
|
25
|
-
expect(result.to_s).to match(/function test/)
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'returns a 404 on unknown' do
|
29
|
-
get '/nosuchone.js'
|
30
|
-
expect(last_response.status).to eql(404)
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
context 'when used as a middleware' do
|
35
|
-
let(:app){
|
36
|
-
Rack::Builder.new do
|
37
|
-
use MagicAssets, {
|
38
|
-
folder: Path.dir/"fixtures/assets",
|
39
|
-
path: "/my-assets"
|
40
|
-
}
|
41
|
-
run ->(t){
|
42
|
-
[200, {}, ["Hello world"]]
|
43
|
-
}
|
44
|
-
end
|
45
|
-
}
|
46
|
-
|
47
|
-
it 'lets unrelated things pass' do
|
48
|
-
get "/hello"
|
49
|
-
expect(last_response.status).to eql(200)
|
50
|
-
expect(last_response.body).to eql("Hello world")
|
51
|
-
end
|
52
|
-
|
53
|
-
it 'serves the assets under the chosen path' do
|
54
|
-
get "/my-assets/index.js"
|
55
|
-
expect(last_response.status).to eql(200)
|
56
|
-
expect(last_response.body).to match(/function test/)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
context 'when registering the NgHtmlTransformer' do
|
61
|
-
let(:app){
|
62
|
-
plugin = MagicAssets::NgHtmlTransformer.new({
|
63
|
-
ng_module: "test.templates"
|
64
|
-
})
|
65
|
-
MagicAssets.new({
|
66
|
-
folder: Path.dir/"fixtures/assets",
|
67
|
-
plugins: [plugin]
|
68
|
-
})
|
69
|
-
}
|
70
|
-
|
71
|
-
it 'works as expected' do
|
72
|
-
get "/index.js"
|
73
|
-
expect(last_response.status).to eql(200)
|
74
|
-
expect(last_response.body).to match(/function test/)
|
75
|
-
expect(last_response.body).to match(/Hello \{\{who\}\}/)
|
76
|
-
expect(last_response.body).to match(/angular.module\("test.templates"\)/)
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|
81
|
-
end
|
82
|
-
end
|