dry-web-roda 0.10.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +179 -41
- data/LICENSE +16 -18
- data/README.md +16 -42
- data/{exe → bin}/dry-web-roda +0 -0
- data/dry-web-roda.gemspec +24 -23
- data/lib/dry/web/roda/generators/abstract_project.rb +2 -2
- data/lib/dry/web/roda/generators/inflections.rb +3 -3
- data/lib/dry/web/roda/generators/sub_app.rb +2 -2
- data/lib/dry/web/roda/inflector.rb +9 -0
- data/lib/dry/web/roda/templates/Gemfile +19 -14
- data/lib/dry/web/roda/templates/README.md.tt +8 -5
- data/lib/dry/web/roda/templates/container.rb.tt +2 -0
- data/lib/dry/web/roda/templates/flat_project/boot.rb.tt +2 -0
- data/lib/dry/web/roda/templates/flat_project/web.rb.tt +3 -1
- data/lib/dry/web/roda/templates/monitor.rb.tt +2 -1
- data/lib/dry/web/roda/templates/subapp/container.rb.tt +3 -3
- data/lib/dry/web/roda/templates/subapp/view.rb.tt +17 -0
- data/lib/dry/web/roda/templates/subapp/view_context.rb.tt +8 -0
- data/lib/dry/web/roda/templates/subapp/web.rb.tt +3 -1
- data/lib/dry/web/roda/templates/subapp/welcome.rb.tt +2 -2
- data/lib/dry/web/roda/templates/types.rb +3 -3
- data/lib/dry/web/roda/templates/umbrella_project/boot.rb.tt +2 -0
- data/lib/dry/web/roda/templates/view.rb.tt +15 -0
- data/lib/dry/web/roda/templates/view_context.rb.tt +31 -0
- data/lib/dry/web/roda/templates/welcome.rb.tt +2 -2
- data/lib/dry/web/roda/version.rb +1 -1
- data/lib/roda/plugins/dry_view.rb +6 -3
- metadata +30 -148
- data/.gitignore +0 -37
- data/.rspec +0 -2
- data/.travis.yml +0 -32
- data/CONTRIBUTING.md +0 -29
- data/Gemfile +0 -33
- data/Rakefile +0 -6
- data/lib/dry/web/roda/templates/.gitignore +0 -11
- data/lib/dry/web/roda/templates/.keep +0 -0
- data/lib/dry/web/roda/templates/.rspec +0 -2
- data/lib/dry/web/roda/templates/subapp/view__context.rb.tt +0 -10
- data/lib/dry/web/roda/templates/subapp/view__controller.rb.tt +0 -19
- data/lib/dry/web/roda/templates/view__context.rb.tt +0 -41
- data/lib/dry/web/roda/templates/view__controller.rb.tt +0 -17
- data/script/ci +0 -67
- data/script/setup +0 -47
- data/script/teardown +0 -42
- data/spec/integration/new_app_spec.rb +0 -21
- data/spec/spec_helper.rb +0 -22
- data/spec/support/app.rb +0 -64
- data/spec/support/bundler.rb +0 -113
- data/spec/support/cli.rb +0 -47
- data/spec/support/directories.rb +0 -37
- data/spec/support/env.rb +0 -84
- data/spec/support/files.rb +0 -59
- data/spec/support/project.rb +0 -60
- data/spec/support/requests.rb +0 -5
- data/spec/support/silently.rb +0 -28
- data/spec/unit/generators/inflections_spec.rb +0 -33
File without changes
|
@@ -1,10 +0,0 @@
|
|
1
|
-
require "<%= config[:underscored_umbrella_name] %>/view/context"
|
2
|
-
|
3
|
-
module <%= config[:camel_cased_umbrella_name] %>
|
4
|
-
module <%= config[:camel_cased_app_name] %>
|
5
|
-
module View
|
6
|
-
class Context < <%= config[:camel_cased_umbrella_name] %>::View::Context
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
# auto_register: false
|
2
|
-
|
3
|
-
require "slim"
|
4
|
-
require "dry/view/controller"
|
5
|
-
require "<%= config[:underscored_umbrella_name] %>/<%= config[:underscored_project_name] %>/container"
|
6
|
-
|
7
|
-
module <%= config[:camel_cased_umbrella_name] %>
|
8
|
-
module <%= config[:camel_cased_app_name] %>
|
9
|
-
module View
|
10
|
-
class Controller < Dry::View::Controller
|
11
|
-
configure do |config|
|
12
|
-
config.paths = [Container.root.join("web/templates")]
|
13
|
-
config.context = Container["view.context"]
|
14
|
-
config.layout = "application"
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,41 +0,0 @@
|
|
1
|
-
module <%= config[:camel_cased_app_name] %>
|
2
|
-
module View
|
3
|
-
class Context
|
4
|
-
attr_reader :attrs
|
5
|
-
|
6
|
-
def initialize(attrs = {})
|
7
|
-
@attrs = attrs
|
8
|
-
end
|
9
|
-
|
10
|
-
def csrf_token
|
11
|
-
self[:csrf_token]
|
12
|
-
end
|
13
|
-
|
14
|
-
def csrf_metatag
|
15
|
-
self[:csrf_metatag]
|
16
|
-
end
|
17
|
-
|
18
|
-
def csrf_tag
|
19
|
-
self[:csrf_tag]
|
20
|
-
end
|
21
|
-
|
22
|
-
def flash
|
23
|
-
self[:flash]
|
24
|
-
end
|
25
|
-
|
26
|
-
def flash?
|
27
|
-
%i[notice alert].any? { |type| flash[type] }
|
28
|
-
end
|
29
|
-
|
30
|
-
def with(new_attrs)
|
31
|
-
self.class.new(attrs.merge(new_attrs))
|
32
|
-
end
|
33
|
-
|
34
|
-
private
|
35
|
-
|
36
|
-
def [](name)
|
37
|
-
attrs.fetch(name)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
# auto_register: false
|
2
|
-
|
3
|
-
require "slim"
|
4
|
-
require "dry/view/controller"
|
5
|
-
require "<%= config[:underscored_project_name] %>/container"
|
6
|
-
|
7
|
-
module <%= config[:camel_cased_app_name] %>
|
8
|
-
module View
|
9
|
-
class Controller < Dry::View::Controller
|
10
|
-
configure do |config|
|
11
|
-
config.paths = [Container.root.join("web/templates")]
|
12
|
-
config.context = Container["view.context"]
|
13
|
-
config.layout = "application"
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
data/script/ci
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
|
5
|
-
setup() {
|
6
|
-
./script/setup
|
7
|
-
}
|
8
|
-
|
9
|
-
teardown() {
|
10
|
-
./script/teardown
|
11
|
-
}
|
12
|
-
|
13
|
-
run_all() {
|
14
|
-
bundle exec rake
|
15
|
-
}
|
16
|
-
|
17
|
-
run_unit_tests() {
|
18
|
-
bundle exec rake spec:coverage
|
19
|
-
}
|
20
|
-
|
21
|
-
run_isolation_tests() {
|
22
|
-
local pwd=$PWD
|
23
|
-
local root="$pwd/spec/isolation"
|
24
|
-
|
25
|
-
run_tests $root
|
26
|
-
}
|
27
|
-
|
28
|
-
run_integration_tests() {
|
29
|
-
local pwd=$PWD
|
30
|
-
local root="$pwd/spec/integration"
|
31
|
-
|
32
|
-
run_tests $root
|
33
|
-
}
|
34
|
-
|
35
|
-
run_tests() {
|
36
|
-
local root=$1
|
37
|
-
|
38
|
-
for test in $(find $root -name '*_spec.rb')
|
39
|
-
do
|
40
|
-
run_test $test
|
41
|
-
|
42
|
-
if [ $? -ne 0 ]; then
|
43
|
-
local exit_code=$?
|
44
|
-
echo "Failing test: $test"
|
45
|
-
exit $exit_code
|
46
|
-
fi
|
47
|
-
done
|
48
|
-
}
|
49
|
-
|
50
|
-
run_test() {
|
51
|
-
local test=$1
|
52
|
-
|
53
|
-
printf "\n\n\nRunning: $test\n"
|
54
|
-
COVERAGE=true bundle exec rspec $test
|
55
|
-
}
|
56
|
-
|
57
|
-
main() {
|
58
|
-
setup &&
|
59
|
-
run_all
|
60
|
-
# run_unit_tests &&
|
61
|
-
# run_isolation_tests &&
|
62
|
-
# run_integration_tests
|
63
|
-
}
|
64
|
-
|
65
|
-
trap teardown EXIT
|
66
|
-
|
67
|
-
main
|
data/script/setup
DELETED
@@ -1,47 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
|
5
|
-
declare pwd=$PWD
|
6
|
-
declare cache="$pwd/vendor/cache"
|
7
|
-
|
8
|
-
cleanup() {
|
9
|
-
./script/teardown
|
10
|
-
}
|
11
|
-
|
12
|
-
bundle_package() {
|
13
|
-
bundle package --all
|
14
|
-
echo ""
|
15
|
-
}
|
16
|
-
|
17
|
-
# We may need something like this in future if we use github checkouts of gems
|
18
|
-
# (see `install_hanami_frameworks()` in hanami/hanami's setup script)
|
19
|
-
#
|
20
|
-
# install_from_git_checkouts() { }
|
21
|
-
|
22
|
-
install_base_gem() {
|
23
|
-
bundle exec rake build
|
24
|
-
local pkg=`ls $pwd/pkg/*.gem | sort -r | head -1`
|
25
|
-
|
26
|
-
gem install $pkg > /dev/null
|
27
|
-
mv $pkg $cache
|
28
|
-
|
29
|
-
echo "Installed $pkg (from $(git rev-parse HEAD))"
|
30
|
-
echo ""
|
31
|
-
}
|
32
|
-
|
33
|
-
generate_index() {
|
34
|
-
pushd $cache > /dev/null
|
35
|
-
gem generate_index
|
36
|
-
popd > /dev/null
|
37
|
-
echo ""
|
38
|
-
}
|
39
|
-
|
40
|
-
main() {
|
41
|
-
cleanup &&
|
42
|
-
bundle_package &&
|
43
|
-
install_base_gem &&
|
44
|
-
generate_index
|
45
|
-
}
|
46
|
-
|
47
|
-
main
|
data/script/teardown
DELETED
@@ -1,42 +0,0 @@
|
|
1
|
-
#!/bin/bash
|
2
|
-
set -euo pipefail
|
3
|
-
IFS=$'\n\t'
|
4
|
-
|
5
|
-
remove_bundler_cache() {
|
6
|
-
local pwd=$PWD
|
7
|
-
local cache="$pwd/vendor/cache"
|
8
|
-
|
9
|
-
rm -rf $cache
|
10
|
-
}
|
11
|
-
|
12
|
-
# We may need something like this in future if we use github checkouts of gems
|
13
|
-
# (see `uninstall_hanami_gems()` in hanami/hanami's teardown script)
|
14
|
-
#
|
15
|
-
# uninstall_gems_from_checkouts() { }
|
16
|
-
|
17
|
-
bundle_install() {
|
18
|
-
bundle install > /dev/null
|
19
|
-
}
|
20
|
-
|
21
|
-
advertise_start() {
|
22
|
-
echo -en "Cleaning up.."
|
23
|
-
}
|
24
|
-
|
25
|
-
advertise_end() {
|
26
|
-
echo " done"
|
27
|
-
}
|
28
|
-
|
29
|
-
main() {
|
30
|
-
local ci=${CI:-false}
|
31
|
-
|
32
|
-
if [ "$ci" = true ] ; then
|
33
|
-
echo "Running on CI, skipping cleanup"
|
34
|
-
else
|
35
|
-
advertise_start &&
|
36
|
-
remove_bundler_cache &&
|
37
|
-
bundle_install &&
|
38
|
-
advertise_end
|
39
|
-
fi
|
40
|
-
}
|
41
|
-
|
42
|
-
main
|
@@ -1,21 +0,0 @@
|
|
1
|
-
RSpec.describe "new app", type: :cli do
|
2
|
-
describe "umbrella project" do
|
3
|
-
it "boots and displays a welcome page" do
|
4
|
-
with_project do
|
5
|
-
run_app do |app|
|
6
|
-
expect(app.get("/")).to eq "<html><body><h1>Welcome to dry-web-roda!</h1></body></html>"
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
describe "flat project" do
|
13
|
-
it "boots and displays a welcome page" do
|
14
|
-
with_project arch: "flat" do
|
15
|
-
run_app do |app|
|
16
|
-
expect(app.get("/")).to eq "<html><body><h1>Welcome to dry-web-roda!</h1></body></html>"
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
data/spec/spec_helper.rb
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
require "pry-byebug"
|
2
|
-
|
3
|
-
SPEC_ROOT = Pathname(__dir__)
|
4
|
-
TEST_APP_NAME = "test_app".freeze
|
5
|
-
|
6
|
-
Dir[SPEC_ROOT.join("support/*.rb").to_s].each { |f| require f }
|
7
|
-
|
8
|
-
RSpec.configure do |config|
|
9
|
-
config.disable_monkey_patching!
|
10
|
-
|
11
|
-
config.example_status_persistence_file_path = "spec/examples.txt"
|
12
|
-
|
13
|
-
config.filter_run :focus
|
14
|
-
config.run_all_when_everything_filtered = true
|
15
|
-
|
16
|
-
config.default_formatter = "doc" if config.files_to_run.one?
|
17
|
-
|
18
|
-
config.profile_examples = 10
|
19
|
-
|
20
|
-
config.order = :random
|
21
|
-
Kernel.srand config.seed
|
22
|
-
end
|
data/spec/support/app.rb
DELETED
@@ -1,64 +0,0 @@
|
|
1
|
-
require "net/http"
|
2
|
-
require "uri"
|
3
|
-
require "waitutil"
|
4
|
-
require_relative "silently"
|
5
|
-
|
6
|
-
module RSpec
|
7
|
-
module Support
|
8
|
-
module App
|
9
|
-
private
|
10
|
-
|
11
|
-
class RunningApp
|
12
|
-
attr_reader :port
|
13
|
-
|
14
|
-
def initialize(port)
|
15
|
-
@port = port
|
16
|
-
end
|
17
|
-
|
18
|
-
def get(path)
|
19
|
-
Net::HTTP.get(uri(path))
|
20
|
-
end
|
21
|
-
|
22
|
-
private
|
23
|
-
|
24
|
-
def uri(path)
|
25
|
-
URI("http://0.0.0.0:#{port}#{path}")
|
26
|
-
end
|
27
|
-
end
|
28
|
-
|
29
|
-
def run_app(host: "0.0.0.0", port: "30333", timeout: 10)
|
30
|
-
cmd = "bundle exec rackup -o 0.0.0.0 -p #{port} config.ru"
|
31
|
-
out = Tempfile.new("dry-web-roda-out")
|
32
|
-
|
33
|
-
pid = fork {
|
34
|
-
Bundler.with_clean_env do
|
35
|
-
exec cmd, out: out.path, err: out.path
|
36
|
-
end
|
37
|
-
}
|
38
|
-
|
39
|
-
WaitUtil.wait_for_condition "app available on #{host}:#{port}", timeout_sec: timeout do
|
40
|
-
begin
|
41
|
-
result = WaitUtil.send(:is_tcp_port_open, host, port, WaitUtil::DEFAULT_DELAY_SEC)
|
42
|
-
|
43
|
-
result || begin
|
44
|
-
out.rewind
|
45
|
-
[false, "#{cmd} failed:\n#{out.read}"]
|
46
|
-
end
|
47
|
-
rescue SocketError
|
48
|
-
out.rewind
|
49
|
-
[false, "#{cmd} failed:\n#{out.read}"]
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
yield RunningApp.new(port)
|
54
|
-
ensure
|
55
|
-
Process.kill "TERM", pid
|
56
|
-
Process.wait pid
|
57
|
-
end
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
|
62
|
-
RSpec.configure do |config|
|
63
|
-
config.include RSpec::Support::App, type: :cli
|
64
|
-
end
|
data/spec/support/bundler.rb
DELETED
@@ -1,113 +0,0 @@
|
|
1
|
-
require 'open3'
|
2
|
-
require 'pathname'
|
3
|
-
require_relative 'env'
|
4
|
-
require_relative 'silently'
|
5
|
-
require_relative 'files'
|
6
|
-
|
7
|
-
module RSpec
|
8
|
-
module Support
|
9
|
-
module Bundler
|
10
|
-
def self.root
|
11
|
-
Pathname.new(__dir__).join("..", "..")
|
12
|
-
end
|
13
|
-
|
14
|
-
def self.cache
|
15
|
-
root.join("vendor", "cache")
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.setup
|
19
|
-
return if cache.exist?
|
20
|
-
|
21
|
-
with_clean_env do
|
22
|
-
RSpec::Support.silently "./script/setup"
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.with_clean_env(&blk)
|
27
|
-
::Bundler.with_clean_env(&blk)
|
28
|
-
end
|
29
|
-
|
30
|
-
private
|
31
|
-
|
32
|
-
attr_reader :out, :err, :exitstatus
|
33
|
-
|
34
|
-
def setup_gemfile(gems: [], exclude_gems: [], path: "Gemfile")
|
35
|
-
filtered_content = ::File.readlines(path).
|
36
|
-
drop(1).
|
37
|
-
reject { |l| exclude_gems.any? { |g| l.include?(g) } }
|
38
|
-
|
39
|
-
content = ["source 'file://#{cache}'\n"] + filtered_content + gems.map { |g| "gem #{g}\n" }
|
40
|
-
|
41
|
-
rewrite(path, content)
|
42
|
-
end
|
43
|
-
|
44
|
-
def bundle_install
|
45
|
-
bundle "install --local --no-cache --retry 0 --no-color"
|
46
|
-
end
|
47
|
-
|
48
|
-
def bundle_exec(cmd, env: nil, &blk)
|
49
|
-
bundle("exec #{cmd}", env: env, &blk)
|
50
|
-
end
|
51
|
-
|
52
|
-
def bundle(cmd, env: nil, &blk)
|
53
|
-
ruby_bin = which("ruby")
|
54
|
-
bundle_bin = which("bundle")
|
55
|
-
rack_env = "RACK_ENV=#{env} " unless env.nil?
|
56
|
-
|
57
|
-
system_exec("#{rack_env}#{ruby_bin} -I#{load_paths} #{bundle_bin} #{cmd}", &blk)
|
58
|
-
end
|
59
|
-
|
60
|
-
# Adapted from Bundler source code
|
61
|
-
#
|
62
|
-
# Bundler is released under MIT license
|
63
|
-
# https://github.com/bundler/bundler/blob/master/LICENSE.md
|
64
|
-
#
|
65
|
-
# A special "thank you" goes to Bundler maintainers and contributors.
|
66
|
-
#
|
67
|
-
# rubocop:disable Metrics/AbcSize
|
68
|
-
# rubocop:disable Metrics/MethodLength
|
69
|
-
def system_exec(cmd)
|
70
|
-
Open3.popen3(RSpec::Support::Env.env, cmd) do |stdin, stdout, stderr, wait_thr|
|
71
|
-
yield stdin, stdout, wait_thr if block_given?
|
72
|
-
stdin.close
|
73
|
-
|
74
|
-
@exitstatus = wait_thr && wait_thr.value.exitstatus
|
75
|
-
@out = Thread.new { stdout.read }.value.strip
|
76
|
-
@err = Thread.new { stderr.read }.value.strip
|
77
|
-
end
|
78
|
-
|
79
|
-
(@all_output ||= "") << [
|
80
|
-
"$ #{cmd.to_s.strip}",
|
81
|
-
out,
|
82
|
-
err,
|
83
|
-
@exitstatus ? "# $? => #{@exitstatus}" : "",
|
84
|
-
"\n"
|
85
|
-
].reject(&:empty?).join("\n")
|
86
|
-
|
87
|
-
@out
|
88
|
-
end
|
89
|
-
# rubocop:enable Metrics/MethodLength
|
90
|
-
# rubocop:enable Metrics/AbcSize
|
91
|
-
|
92
|
-
def load_paths
|
93
|
-
[root.join('lib'), root.join('spec')].join(':')
|
94
|
-
end
|
95
|
-
|
96
|
-
def root
|
97
|
-
RSpec::Support::Bundler.root
|
98
|
-
end
|
99
|
-
|
100
|
-
def cache
|
101
|
-
RSpec::Support::Bundler.cache
|
102
|
-
end
|
103
|
-
end
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
RSpec.configure do |config|
|
108
|
-
config.include RSpec::Support::Bundler, type: :cli
|
109
|
-
|
110
|
-
config.before(:all, type: :cli) do
|
111
|
-
RSpec::Support::Bundler.setup
|
112
|
-
end
|
113
|
-
end
|