dry-web-roda 0.5.1 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/dry-web-roda.gemspec +3 -2
- data/lib/dry/web/roda/application.rb +11 -0
- data/lib/dry/web/roda/skeletons/app/lib/__underscored_app_name__/views/welcome.rb.tt +11 -0
- data/lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/application.rb.tt +6 -10
- data/lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/view_context.rb.tt +6 -0
- data/lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/view_controller.rb.tt +13 -0
- data/lib/dry/web/roda/skeletons/app/system/boot/view.rb.tt +3 -0
- data/lib/dry/web/roda/skeletons/app/system/boot.rb.tt +0 -1
- data/lib/dry/web/roda/skeletons/app/web/templates/welcome.html.slim +1 -0
- data/lib/dry/web/roda/skeletons/umbrella/Gemfile +1 -1
- data/lib/dry/web/roda/skeletons/umbrella/bin/setup +1 -1
- data/lib/dry/web/roda/skeletons/umbrella/lib/__underscored_app_name__/view_context.rb.tt +39 -0
- data/lib/dry/web/roda/version.rb +1 -1
- data/lib/roda/plugins/dry_view.rb +35 -0
- data/spec/spec_helper.rb +0 -21
- metadata +34 -69
- data/lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/page.rb.tt +0 -6
- data/lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/view.rb.tt +0 -19
- data/lib/dry/web/roda/skeletons/umbrella/lib/__underscored_app_name__/page.rb.tt +0 -48
- data/lib/dry/web/roda/skeletons/umbrella/lib/roda_plugins.rb +0 -34
- data/spec/dummy/apps/main/lib/main/entities/user.rb +0 -5
- data/spec/dummy/apps/main/lib/main/persistence/repositories/users.rb +0 -15
- data/spec/dummy/apps/main/lib/main/transactions/register_user.rb +0 -21
- data/spec/dummy/apps/main/lib/main/views/users/index.rb +0 -17
- data/spec/dummy/apps/main/log/.gitkeep +0 -0
- data/spec/dummy/apps/main/log/app.log +0 -1
- data/spec/dummy/apps/main/requests/users.rb +0 -5
- data/spec/dummy/apps/main/system/boot.rb +0 -12
- data/spec/dummy/apps/main/system/main/application.rb +0 -17
- data/spec/dummy/apps/main/system/main/container.rb +0 -16
- data/spec/dummy/apps/main/system/main/import.rb +0 -5
- data/spec/dummy/apps/main/system/main/requests.rb +0 -22
- data/spec/dummy/apps/main/system/main/view.rb +0 -21
- data/spec/dummy/apps/main/web/routes/users.rb +0 -19
- data/spec/dummy/apps/main/web/templates/layouts/app.html.slim +0 -6
- data/spec/dummy/apps/main/web/templates/users/index/_list.html.slim +0 -3
- data/spec/dummy/apps/main/web/templates/users/index/_list_item.html.slim +0 -1
- data/spec/dummy/apps/main/web/templates/users/index.html.slim +0 -3
- data/spec/dummy/bin/console +0 -6
- data/spec/dummy/config/application.yml +0 -4
- data/spec/dummy/config.ru +0 -3
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/shared/persistence/db.rb +0 -9
- data/spec/dummy/shared/persistence.rb +0 -12
- data/spec/dummy/system/boot.rb +0 -8
- data/spec/dummy/system/dummy/application.rb +0 -7
- data/spec/dummy/system/dummy/container.rb +0 -14
- data/spec/request/users_spec.rb +0 -35
- data/spec/support/helpers.rb +0 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae7be8dfee807179e26795b99b21373e09af8136
|
4
|
+
data.tar.gz: b0617d0d7ead77a504ba4caa3487bb5c171814d0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22456e206baab37dcb943358c5a4ccf99d85b1365b4d0a56756ac0eaa87a19f82ec1cf684c75df3a20b6da5245f7a255b1369d09c7bdafd92f92c532fb631e75
|
7
|
+
data.tar.gz: 9b5832e568862fd71249c29f9580b0937a2157cacbdd0f25baa75a803dc73b30b550ca430baa86f3601c44ff23e0de3dff963a847464ed805ec223fbb6c4001e
|
data/dry-web-roda.gemspec
CHANGED
@@ -20,8 +20,9 @@ Gem::Specification.new do |spec|
|
|
20
20
|
|
21
21
|
spec.required_ruby_version = '>= 2.1.0'
|
22
22
|
|
23
|
-
spec.add_runtime_dependency "dry-web", "~> 0.
|
24
|
-
spec.add_runtime_dependency "dry-
|
23
|
+
spec.add_runtime_dependency "dry-web", "~> 0.6", ">= 0.6.0"
|
24
|
+
spec.add_runtime_dependency "dry-monitor"
|
25
|
+
spec.add_runtime_dependency "dry-configurable", "~> 0.2"
|
25
26
|
spec.add_runtime_dependency "inflecto", "~> 0.0"
|
26
27
|
spec.add_runtime_dependency "roda", "~> 2.14"
|
27
28
|
spec.add_runtime_dependency "roda-flow", "~> 0.3"
|
@@ -13,6 +13,13 @@ module Dry
|
|
13
13
|
|
14
14
|
plugin :multi_route
|
15
15
|
plugin :flow
|
16
|
+
plugin :error_handler
|
17
|
+
|
18
|
+
def self.configure(&block)
|
19
|
+
container = super
|
20
|
+
use(container[:rack_monitor])
|
21
|
+
container
|
22
|
+
end
|
16
23
|
|
17
24
|
def self.resolve(name)
|
18
25
|
config.container[name]
|
@@ -29,6 +36,10 @@ module Dry
|
|
29
36
|
def self.root
|
30
37
|
config.container.config.root
|
31
38
|
end
|
39
|
+
|
40
|
+
def notifications
|
41
|
+
self.class[:notifications]
|
42
|
+
end
|
32
43
|
end
|
33
44
|
end
|
34
45
|
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "<%= config[:underscored_app_name] %>/view_controller"
|
2
|
+
|
3
|
+
module <%= config[:camel_cased_app_name] %>
|
4
|
+
module Views
|
5
|
+
class Welcome < <%= config[:camel_cased_app_name] %>::ViewController
|
6
|
+
configure do |config|
|
7
|
+
config.template = "welcome"
|
8
|
+
end
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
@@ -1,7 +1,5 @@
|
|
1
|
-
require "rack/csrf"
|
2
1
|
require "dry/web/roda/application"
|
3
2
|
require_relative "container"
|
4
|
-
require "roda_plugins"
|
5
3
|
|
6
4
|
module <%= config[:camel_cased_app_name] %>
|
7
5
|
class Application < Dry::Web::Roda::Application
|
@@ -13,19 +11,17 @@ module <%= config[:camel_cased_app_name] %>
|
|
13
11
|
opts[:root] = Pathname(__FILE__).join("../..").realpath.dirname
|
14
12
|
|
15
13
|
use Rack::Session::Cookie, key: "<%= config[:underscored_app_name] %>.session", secret: <%= config[:camel_cased_umbrella_name] %>::Container.settings.session_secret
|
16
|
-
use Rack::Csrf, raise: true
|
17
14
|
|
15
|
+
plugin :csrf, raise: true
|
18
16
|
plugin :flash
|
19
|
-
|
20
|
-
plugin :view
|
21
|
-
plugin :page
|
22
|
-
|
23
|
-
def name
|
24
|
-
:<%= config[:underscored_app_name] %>
|
25
|
-
end
|
17
|
+
plugin :dry_view
|
26
18
|
|
27
19
|
route do |r|
|
28
20
|
r.multi_route
|
21
|
+
|
22
|
+
r.root do
|
23
|
+
r.view "welcome"
|
24
|
+
end
|
29
25
|
end
|
30
26
|
|
31
27
|
load_routes!
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require "slim"
|
2
|
+
require "dry-view"
|
3
|
+
require "<%= config[:underscored_app_name] %>/container"
|
4
|
+
|
5
|
+
module <%= config[:camel_cased_app_name] %>
|
6
|
+
class ViewController < Dry::View::Controller
|
7
|
+
configure do |config|
|
8
|
+
config.paths = [Container.root.join("web/templates")]
|
9
|
+
config.context = Container["view_context"]
|
10
|
+
config.layout = "application"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -4,7 +4,6 @@ require_relative "<%= config[:underscored_app_name] %>/container"
|
|
4
4
|
end
|
5
5
|
|
6
6
|
require "<%= config[:underscored_app_name] %>/application"
|
7
|
-
require "<%= config[:underscored_app_name] %>/view"
|
8
7
|
require "<%= config[:underscored_app_name] %>/transactions"
|
9
8
|
|
10
9
|
<%= config[:camel_cased_app_name] %>::Container.require "transactions/**/*.rb"
|
@@ -0,0 +1 @@
|
|
1
|
+
h1 Welcome to dry-web-roda!
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module <%= config[:camel_cased_app_name] %>
|
2
|
+
class ViewContext
|
3
|
+
attr_reader :attrs
|
4
|
+
|
5
|
+
def initialize(attrs = {})
|
6
|
+
@attrs = attrs
|
7
|
+
end
|
8
|
+
|
9
|
+
def csrf_token
|
10
|
+
self[:csrf_token]
|
11
|
+
end
|
12
|
+
|
13
|
+
def csrf_metatag
|
14
|
+
self[:csrf_metatag]
|
15
|
+
end
|
16
|
+
|
17
|
+
def csrf_tag
|
18
|
+
self[:csrf_tag]
|
19
|
+
end
|
20
|
+
|
21
|
+
def flash
|
22
|
+
self[:flash]
|
23
|
+
end
|
24
|
+
|
25
|
+
def flash?
|
26
|
+
%i[notice alert].any? { |type| flash[type] }
|
27
|
+
end
|
28
|
+
|
29
|
+
def with(new_attrs)
|
30
|
+
self.class.new(attrs.merge(new_attrs))
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def [](name)
|
36
|
+
attrs.fetch(name)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
data/lib/dry/web/roda/version.rb
CHANGED
@@ -0,0 +1,35 @@
|
|
1
|
+
class Roda
|
2
|
+
module RodaPlugins
|
3
|
+
module DryView
|
4
|
+
def self.load_dependencies(app)
|
5
|
+
app.plugin :csrf
|
6
|
+
app.plugin :flash
|
7
|
+
app.plugin :flow
|
8
|
+
end
|
9
|
+
|
10
|
+
module InstanceMethods
|
11
|
+
def view_context
|
12
|
+
self.class["view_context"].with(view_context_options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def view_context_options
|
16
|
+
{
|
17
|
+
flash: flash,
|
18
|
+
csrf_token: Rack::Csrf.token(request.env),
|
19
|
+
csrf_metatag: Rack::Csrf.metatag(request.env),
|
20
|
+
csrf_tag: Rack::Csrf.tag(request.env),
|
21
|
+
}
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
module RequestMethods
|
26
|
+
def view(name, options = {})
|
27
|
+
options = {context: scope.view_context}.merge(options)
|
28
|
+
is to: "views.#{name}", call_with: [options]
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
register_plugin :dry_view, DryView
|
34
|
+
end
|
35
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -17,29 +17,8 @@ ENV['RACK_ENV'] = 'test'
|
|
17
17
|
|
18
18
|
SPEC_ROOT = Pathname(__FILE__).dirname
|
19
19
|
|
20
|
-
Dir[SPEC_ROOT.join('support/*.rb').to_s].each { |f| require f }
|
21
|
-
Dir[SPEC_ROOT.join('shared/*.rb').to_s].each { |f| require f }
|
22
|
-
|
23
|
-
require SPEC_ROOT.join('dummy/system/boot').to_s
|
24
|
-
|
25
|
-
module Test; end
|
26
|
-
|
27
20
|
RSpec.configure do |config|
|
28
21
|
config.disable_monkey_patching!
|
29
22
|
|
30
|
-
config.before(:suite) do
|
31
|
-
Dummy::Application.freeze
|
32
|
-
end
|
33
|
-
|
34
23
|
config.include Rack::Test::Methods, type: :request
|
35
|
-
config.include Helpers
|
36
|
-
|
37
|
-
config.before do
|
38
|
-
@test_constants = Test.constants
|
39
|
-
end
|
40
|
-
|
41
|
-
config.after do
|
42
|
-
added_constants = Test.constants - @test_constants
|
43
|
-
added_constants.each { |name| Test.send(:remove_const, name) }
|
44
|
-
end
|
45
24
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dry-web-roda
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Piotr Solnica
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dry-web
|
@@ -16,28 +16,48 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '0.
|
19
|
+
version: '0.6'
|
20
|
+
- - ">="
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 0.6.0
|
20
23
|
type: :runtime
|
21
24
|
prerelease: false
|
22
25
|
version_requirements: !ruby/object:Gem::Requirement
|
23
26
|
requirements:
|
24
27
|
- - "~>"
|
25
28
|
- !ruby/object:Gem::Version
|
26
|
-
version: '0.
|
29
|
+
version: '0.6'
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: 0.6.0
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: dry-monitor
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '0'
|
40
|
+
type: :runtime
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
27
47
|
- !ruby/object:Gem::Dependency
|
28
48
|
name: dry-configurable
|
29
49
|
requirement: !ruby/object:Gem::Requirement
|
30
50
|
requirements:
|
31
51
|
- - "~>"
|
32
52
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
53
|
+
version: '0.2'
|
34
54
|
type: :runtime
|
35
55
|
prerelease: false
|
36
56
|
version_requirements: !ruby/object:Gem::Requirement
|
37
57
|
requirements:
|
38
58
|
- - "~>"
|
39
59
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
60
|
+
version: '0.2'
|
41
61
|
- !ruby/object:Gem::Dependency
|
42
62
|
name: inflecto
|
43
63
|
requirement: !ruby/object:Gem::Requirement
|
@@ -176,16 +196,19 @@ files:
|
|
176
196
|
- lib/dry/web/roda/generators/app.rb
|
177
197
|
- lib/dry/web/roda/generators/umbrella.rb
|
178
198
|
- lib/dry/web/roda/skeletons/app/lib/__underscored_app_name__/.keep
|
199
|
+
- lib/dry/web/roda/skeletons/app/lib/__underscored_app_name__/views/welcome.rb.tt
|
179
200
|
- lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/application.rb.tt
|
180
201
|
- lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/container.rb.tt
|
181
202
|
- lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/import.rb.tt
|
182
|
-
- lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/page.rb.tt
|
183
203
|
- lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/transactions.rb.tt
|
184
|
-
- lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/
|
204
|
+
- lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/view_context.rb.tt
|
205
|
+
- lib/dry/web/roda/skeletons/app/system/__underscored_app_name__/view_controller.rb.tt
|
185
206
|
- lib/dry/web/roda/skeletons/app/system/boot.rb.tt
|
207
|
+
- lib/dry/web/roda/skeletons/app/system/boot/view.rb.tt
|
186
208
|
- lib/dry/web/roda/skeletons/app/transactions/example.rb.tt
|
187
209
|
- lib/dry/web/roda/skeletons/app/web/routes/example.rb.tt
|
188
210
|
- lib/dry/web/roda/skeletons/app/web/templates/layouts/application.html.slim
|
211
|
+
- lib/dry/web/roda/skeletons/app/web/templates/welcome.html.slim
|
189
212
|
- lib/dry/web/roda/skeletons/umbrella/.gitignore
|
190
213
|
- lib/dry/web/roda/skeletons/umbrella/Gemfile
|
191
214
|
- lib/dry/web/roda/skeletons/umbrella/README.md.tt
|
@@ -196,12 +219,11 @@ files:
|
|
196
219
|
- lib/dry/web/roda/skeletons/umbrella/config/settings.yml.tt
|
197
220
|
- lib/dry/web/roda/skeletons/umbrella/db/sample_data.rb
|
198
221
|
- lib/dry/web/roda/skeletons/umbrella/db/seed.rb
|
199
|
-
- lib/dry/web/roda/skeletons/umbrella/lib/__underscored_app_name__/page.rb.tt
|
200
222
|
- lib/dry/web/roda/skeletons/umbrella/lib/__underscored_app_name__/repository.rb.tt
|
201
223
|
- lib/dry/web/roda/skeletons/umbrella/lib/__underscored_app_name__/transactions.rb.tt
|
224
|
+
- lib/dry/web/roda/skeletons/umbrella/lib/__underscored_app_name__/view_context.rb.tt
|
202
225
|
- lib/dry/web/roda/skeletons/umbrella/lib/persistence/commands/.keep
|
203
226
|
- lib/dry/web/roda/skeletons/umbrella/lib/persistence/relations/.keep
|
204
|
-
- lib/dry/web/roda/skeletons/umbrella/lib/roda_plugins.rb
|
205
227
|
- lib/dry/web/roda/skeletons/umbrella/lib/types.rb
|
206
228
|
- lib/dry/web/roda/skeletons/umbrella/log/.keep
|
207
229
|
- lib/dry/web/roda/skeletons/umbrella/spec/app_helper.rb
|
@@ -217,36 +239,8 @@ files:
|
|
217
239
|
- lib/dry/web/roda/skeletons/umbrella/system/boot/logger.rb.tt
|
218
240
|
- lib/dry/web/roda/skeletons/umbrella/system/boot/rom.rb.tt
|
219
241
|
- lib/dry/web/roda/version.rb
|
220
|
-
-
|
221
|
-
- spec/dummy/apps/main/lib/main/persistence/repositories/users.rb
|
222
|
-
- spec/dummy/apps/main/lib/main/transactions/register_user.rb
|
223
|
-
- spec/dummy/apps/main/lib/main/views/users/index.rb
|
224
|
-
- spec/dummy/apps/main/log/.gitkeep
|
225
|
-
- spec/dummy/apps/main/log/app.log
|
226
|
-
- spec/dummy/apps/main/requests/users.rb
|
227
|
-
- spec/dummy/apps/main/system/boot.rb
|
228
|
-
- spec/dummy/apps/main/system/main/application.rb
|
229
|
-
- spec/dummy/apps/main/system/main/container.rb
|
230
|
-
- spec/dummy/apps/main/system/main/import.rb
|
231
|
-
- spec/dummy/apps/main/system/main/requests.rb
|
232
|
-
- spec/dummy/apps/main/system/main/view.rb
|
233
|
-
- spec/dummy/apps/main/web/routes/users.rb
|
234
|
-
- spec/dummy/apps/main/web/templates/layouts/app.html.slim
|
235
|
-
- spec/dummy/apps/main/web/templates/users/index.html.slim
|
236
|
-
- spec/dummy/apps/main/web/templates/users/index/_list.html.slim
|
237
|
-
- spec/dummy/apps/main/web/templates/users/index/_list_item.html.slim
|
238
|
-
- spec/dummy/bin/console
|
239
|
-
- spec/dummy/config.ru
|
240
|
-
- spec/dummy/config/application.yml
|
241
|
-
- spec/dummy/log/.gitkeep
|
242
|
-
- spec/dummy/shared/persistence.rb
|
243
|
-
- spec/dummy/shared/persistence/db.rb
|
244
|
-
- spec/dummy/system/boot.rb
|
245
|
-
- spec/dummy/system/dummy/application.rb
|
246
|
-
- spec/dummy/system/dummy/container.rb
|
247
|
-
- spec/request/users_spec.rb
|
242
|
+
- lib/roda/plugins/dry_view.rb
|
248
243
|
- spec/spec_helper.rb
|
249
|
-
- spec/support/helpers.rb
|
250
244
|
homepage: https://github.com/dry-rb/dry-web-roda
|
251
245
|
licenses:
|
252
246
|
- MIT
|
@@ -267,38 +261,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
267
261
|
version: '0'
|
268
262
|
requirements: []
|
269
263
|
rubyforge_project:
|
270
|
-
rubygems_version: 2.
|
264
|
+
rubygems_version: 2.6.9
|
271
265
|
signing_key:
|
272
266
|
specification_version: 4
|
273
267
|
summary: Roda integration for dry-web apps
|
274
268
|
test_files:
|
275
|
-
- spec/dummy/apps/main/lib/main/entities/user.rb
|
276
|
-
- spec/dummy/apps/main/lib/main/persistence/repositories/users.rb
|
277
|
-
- spec/dummy/apps/main/lib/main/transactions/register_user.rb
|
278
|
-
- spec/dummy/apps/main/lib/main/views/users/index.rb
|
279
|
-
- spec/dummy/apps/main/log/.gitkeep
|
280
|
-
- spec/dummy/apps/main/log/app.log
|
281
|
-
- spec/dummy/apps/main/requests/users.rb
|
282
|
-
- spec/dummy/apps/main/system/boot.rb
|
283
|
-
- spec/dummy/apps/main/system/main/application.rb
|
284
|
-
- spec/dummy/apps/main/system/main/container.rb
|
285
|
-
- spec/dummy/apps/main/system/main/import.rb
|
286
|
-
- spec/dummy/apps/main/system/main/requests.rb
|
287
|
-
- spec/dummy/apps/main/system/main/view.rb
|
288
|
-
- spec/dummy/apps/main/web/routes/users.rb
|
289
|
-
- spec/dummy/apps/main/web/templates/layouts/app.html.slim
|
290
|
-
- spec/dummy/apps/main/web/templates/users/index.html.slim
|
291
|
-
- spec/dummy/apps/main/web/templates/users/index/_list.html.slim
|
292
|
-
- spec/dummy/apps/main/web/templates/users/index/_list_item.html.slim
|
293
|
-
- spec/dummy/bin/console
|
294
|
-
- spec/dummy/config.ru
|
295
|
-
- spec/dummy/config/application.yml
|
296
|
-
- spec/dummy/log/.gitkeep
|
297
|
-
- spec/dummy/shared/persistence.rb
|
298
|
-
- spec/dummy/shared/persistence/db.rb
|
299
|
-
- spec/dummy/system/boot.rb
|
300
|
-
- spec/dummy/system/dummy/application.rb
|
301
|
-
- spec/dummy/system/dummy/container.rb
|
302
|
-
- spec/request/users_spec.rb
|
303
269
|
- spec/spec_helper.rb
|
304
|
-
- spec/support/helpers.rb
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require "slim"
|
2
|
-
require "dry-view"
|
3
|
-
require "<%= config[:underscored_app_name] %>/container"
|
4
|
-
require "<%= config[:underscored_app_name] %>/page"
|
5
|
-
|
6
|
-
module <%= config[:camel_cased_app_name] %>
|
7
|
-
Container.register "page", Page.new
|
8
|
-
|
9
|
-
class View < Dry::View::Layout
|
10
|
-
setting :root, Container.root.join("web/templates")
|
11
|
-
setting :scope, Container["page"]
|
12
|
-
setting :formats, {html: :slim}
|
13
|
-
setting :name, "application"
|
14
|
-
|
15
|
-
def locals(options)
|
16
|
-
super.merge(options[:scope].view_locals)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1,48 +0,0 @@
|
|
1
|
-
module <%= config[:camel_cased_app_name] %>
|
2
|
-
class Page
|
3
|
-
attr_reader :options
|
4
|
-
|
5
|
-
def initialize(options = {})
|
6
|
-
@options = options
|
7
|
-
end
|
8
|
-
|
9
|
-
def view_locals
|
10
|
-
{
|
11
|
-
csrf_token: csrf_token,
|
12
|
-
csrf_tag: csrf_tag,
|
13
|
-
}
|
14
|
-
end
|
15
|
-
|
16
|
-
def csrf_token
|
17
|
-
self[:csrf_token].()
|
18
|
-
end
|
19
|
-
|
20
|
-
def csrf_metatag
|
21
|
-
self[:csrf_metatag].()
|
22
|
-
end
|
23
|
-
|
24
|
-
def csrf_tag
|
25
|
-
self[:csrf_tag].()
|
26
|
-
end
|
27
|
-
|
28
|
-
def flash
|
29
|
-
self[:flash]
|
30
|
-
end
|
31
|
-
|
32
|
-
def flash?
|
33
|
-
%i[notice alert].any? { |type| flash[type] }
|
34
|
-
end
|
35
|
-
|
36
|
-
def with_flash(flash)
|
37
|
-
with(flash: flash)
|
38
|
-
end
|
39
|
-
|
40
|
-
def with(new_options)
|
41
|
-
self.class.new(options.merge(new_options))
|
42
|
-
end
|
43
|
-
|
44
|
-
def [](name)
|
45
|
-
options.fetch(name)
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
@@ -1,34 +0,0 @@
|
|
1
|
-
require "roda"
|
2
|
-
require "rack/csrf"
|
3
|
-
|
4
|
-
class Roda
|
5
|
-
module RodaPlugins
|
6
|
-
module Page
|
7
|
-
module InstanceMethods
|
8
|
-
def current_page
|
9
|
-
page.with_flash(flash)
|
10
|
-
end
|
11
|
-
|
12
|
-
def page
|
13
|
-
self.class["page"].with(
|
14
|
-
csrf_token: -> { Rack::Csrf.token(request.env) },
|
15
|
-
csrf_metatag: -> { Rack::Csrf.metatag(request.env) },
|
16
|
-
csrf_tag: -> { Rack::Csrf.tag(request.env) },
|
17
|
-
)
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
|
-
module View
|
23
|
-
module RequestMethods
|
24
|
-
def view(name, overrides = {})
|
25
|
-
options = {scope: scope.current_page}.merge(overrides)
|
26
|
-
is to: "views.#{name}", call_with: [options]
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
register_plugin :page, Page
|
32
|
-
register_plugin :view, View
|
33
|
-
end
|
34
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'dry-monads'
|
2
|
-
require 'main/entities/user'
|
3
|
-
require 'main/import'
|
4
|
-
|
5
|
-
module Main
|
6
|
-
module Transactions
|
7
|
-
class RegisterUser
|
8
|
-
include Dry::Monads::Either::Mixin
|
9
|
-
|
10
|
-
include Main::Import['persistence.db']
|
11
|
-
|
12
|
-
def call(params)
|
13
|
-
if params['name']
|
14
|
-
Right(db[:users] << Main::Entities::User.new(*params.values_at('id', 'name')))
|
15
|
-
else
|
16
|
-
Left(validation: 'name is missing')
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'main/view'
|
2
|
-
|
3
|
-
module Main
|
4
|
-
module Views
|
5
|
-
module Users
|
6
|
-
class Index < Main::View
|
7
|
-
configure do |config|
|
8
|
-
config.template = 'users/index'
|
9
|
-
end
|
10
|
-
|
11
|
-
def locals(options)
|
12
|
-
{ users: [{ name: 'Jane' }, { name: 'Joe' }] }
|
13
|
-
end
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
File without changes
|
@@ -1 +0,0 @@
|
|
1
|
-
# Logfile created on 2016-04-21 14:19:48 +1000 by logger.rb/53141
|
@@ -1,12 +0,0 @@
|
|
1
|
-
require_relative 'main/container'
|
2
|
-
|
3
|
-
Main::Container.finalize! do |container|
|
4
|
-
require 'logger'
|
5
|
-
container.register(:logger, Logger.new(container.root.join('log/app.log')))
|
6
|
-
end
|
7
|
-
|
8
|
-
require 'main/application'
|
9
|
-
require 'main/view'
|
10
|
-
require 'main/requests'
|
11
|
-
|
12
|
-
Main::Container.require('requests/**/*.rb')
|
@@ -1,17 +0,0 @@
|
|
1
|
-
require 'dry/web/roda/application'
|
2
|
-
require_relative 'container'
|
3
|
-
|
4
|
-
module Main
|
5
|
-
class Application < Dry::Web::Roda::Application
|
6
|
-
configure do |config|
|
7
|
-
config.routes = 'web/routes'.freeze
|
8
|
-
config.container = Main::Container
|
9
|
-
end
|
10
|
-
|
11
|
-
route do |r|
|
12
|
-
r.multi_route
|
13
|
-
end
|
14
|
-
|
15
|
-
load_routes!
|
16
|
-
end
|
17
|
-
end
|
@@ -1,16 +0,0 @@
|
|
1
|
-
require 'dry/web/container'
|
2
|
-
|
3
|
-
module Main
|
4
|
-
class Container < Dry::Web::Container
|
5
|
-
configure do |config|
|
6
|
-
config.root = Pathname(__FILE__).join('../..').realpath.dirname.freeze
|
7
|
-
config.auto_register = 'lib'
|
8
|
-
end
|
9
|
-
|
10
|
-
require root.join('../../shared/persistence').to_s
|
11
|
-
|
12
|
-
import Persistence::Container
|
13
|
-
|
14
|
-
load_paths!('lib')
|
15
|
-
end
|
16
|
-
end
|
@@ -1,22 +0,0 @@
|
|
1
|
-
require_relative 'container'
|
2
|
-
require 'dry-transaction'
|
3
|
-
|
4
|
-
module Main
|
5
|
-
module Requests
|
6
|
-
class Registrar
|
7
|
-
attr_reader :container
|
8
|
-
|
9
|
-
def initialize(container)
|
10
|
-
@container = container
|
11
|
-
end
|
12
|
-
|
13
|
-
def define(identifier, &block)
|
14
|
-
container.register(identifier, Dry.Transaction(container: container, &block))
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def self.define(&block)
|
19
|
-
yield(Registrar.new(Container))
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
@@ -1,21 +0,0 @@
|
|
1
|
-
require 'slim'
|
2
|
-
require 'dry-view'
|
3
|
-
|
4
|
-
require_relative 'container'
|
5
|
-
|
6
|
-
module Main
|
7
|
-
class Page
|
8
|
-
def title
|
9
|
-
'Woohaa'
|
10
|
-
end
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
module Main
|
15
|
-
class View < Dry::View::Layout
|
16
|
-
setting :root, Container.root.join('web/templates')
|
17
|
-
setting :scope, Page.new
|
18
|
-
setting :formats, {html: :slim}
|
19
|
-
setting :name, 'app'.freeze
|
20
|
-
end
|
21
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
class Main::Application
|
2
|
-
route('users') do |r|
|
3
|
-
r.get(to: 'main.views.users.index')
|
4
|
-
|
5
|
-
r.resolve('main.requests.users.create') do |t|
|
6
|
-
r.post do
|
7
|
-
t.(r[:user]) do |m|
|
8
|
-
m.success do
|
9
|
-
response.status = 201
|
10
|
-
end
|
11
|
-
|
12
|
-
m.failure do |err|
|
13
|
-
r.redirect '/users'
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
li == user[:name]
|
data/spec/dummy/bin/console
DELETED
data/spec/dummy/config.ru
DELETED
data/spec/dummy/log/.gitkeep
DELETED
File without changes
|
data/spec/dummy/system/boot.rb
DELETED
@@ -1,14 +0,0 @@
|
|
1
|
-
require 'dry/web/container'
|
2
|
-
|
3
|
-
module Dummy
|
4
|
-
class Container < Dry::Web::Container
|
5
|
-
# we need to override default here because we run tests from within the
|
6
|
-
# project root and our app is in spec/dummy
|
7
|
-
configure do |config|
|
8
|
-
config.root = Pathname(__FILE__).dirname.join('../..')
|
9
|
-
config.auto_register = 'lib'
|
10
|
-
end
|
11
|
-
|
12
|
-
load_paths! 'lib'
|
13
|
-
end
|
14
|
-
end
|
data/spec/request/users_spec.rb
DELETED
@@ -1,35 +0,0 @@
|
|
1
|
-
require 'main/entities/user'
|
2
|
-
|
3
|
-
RSpec.describe '/users', type: :request do
|
4
|
-
describe 'GET /users' do
|
5
|
-
it 'renders hello template' do
|
6
|
-
get '/users'
|
7
|
-
|
8
|
-
expect(last_response).to be_ok
|
9
|
-
|
10
|
-
expect(last_response.body).to eql(
|
11
|
-
'<!DOCTYPE html><html><head><title>Woohaa</title></head><body><h1>Users</h1><div class="users"><ul><li>Jane</li><li>Joe</li></ul></div></body></html>'
|
12
|
-
)
|
13
|
-
end
|
14
|
-
end
|
15
|
-
|
16
|
-
describe 'POST /users' do
|
17
|
-
it 'creates a user' do
|
18
|
-
user = { id: '1', name: 'Jane' }
|
19
|
-
|
20
|
-
post '/users', user: user
|
21
|
-
|
22
|
-
expect(last_response).to be_created
|
23
|
-
|
24
|
-
expect(container['main.persistence.repositories.users'].all).to eql([Main::Entities::User.new('1', 'Jane')])
|
25
|
-
end
|
26
|
-
|
27
|
-
it 'redirects when name is missing' do
|
28
|
-
user = { id: '1' }
|
29
|
-
|
30
|
-
post '/users', user: user
|
31
|
-
|
32
|
-
expect(last_response).to be_redirect
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|