dry-web-web_pipe 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +37 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +31 -0
  5. data/CHANGELOG.md +283 -0
  6. data/CONTRIBUTING.md +29 -0
  7. data/Gemfile +36 -0
  8. data/LICENSE +22 -0
  9. data/README.md +72 -0
  10. data/Rakefile +6 -0
  11. data/dry-web-web_pipe.gemspec +33 -0
  12. data/exe/dry-web-web_pipe +6 -0
  13. data/lib/dry/web/web_pipe/cli/generate.rb +18 -0
  14. data/lib/dry/web/web_pipe/cli.rb +26 -0
  15. data/lib/dry/web/web_pipe/generate.rb +52 -0
  16. data/lib/dry/web/web_pipe/generators/abstract_generator.rb +54 -0
  17. data/lib/dry/web/web_pipe/generators/abstract_project.rb +116 -0
  18. data/lib/dry/web/web_pipe/generators/flat_project.rb +43 -0
  19. data/lib/dry/web/web_pipe/generators/inflections.rb +21 -0
  20. data/lib/dry/web/web_pipe/generators/sub_app.rb +68 -0
  21. data/lib/dry/web/web_pipe/generators/umbrella_project.rb +29 -0
  22. data/lib/dry/web/web_pipe/templates/.env.test.tt +1 -0
  23. data/lib/dry/web/web_pipe/templates/.env.tt +2 -0
  24. data/lib/dry/web/web_pipe/templates/.gitignore.tt +11 -0
  25. data/lib/dry/web/web_pipe/templates/.keep +0 -0
  26. data/lib/dry/web/web_pipe/templates/.rspec +2 -0
  27. data/lib/dry/web/web_pipe/templates/Gemfile +47 -0
  28. data/lib/dry/web/web_pipe/templates/README.md.tt +15 -0
  29. data/lib/dry/web/web_pipe/templates/Rakefile.tt +109 -0
  30. data/lib/dry/web/web_pipe/templates/application.html.slim +3 -0
  31. data/lib/dry/web/web_pipe/templates/config.ru.tt +7 -0
  32. data/lib/dry/web/web_pipe/templates/console.tt +7 -0
  33. data/lib/dry/web/web_pipe/templates/container.rb.tt +17 -0
  34. data/lib/dry/web/web_pipe/templates/flat_project/boot.rb.tt +12 -0
  35. data/lib/dry/web/web_pipe/templates/flat_project/root.rb.tt +16 -0
  36. data/lib/dry/web/web_pipe/templates/flat_project/router.rb.tt +8 -0
  37. data/lib/dry/web/web_pipe/templates/flat_project/web.rb.tt +52 -0
  38. data/lib/dry/web/web_pipe/templates/import.rb.tt +5 -0
  39. data/lib/dry/web/web_pipe/templates/monitor.rb.tt +10 -0
  40. data/lib/dry/web/web_pipe/templates/operation.rb.tt +11 -0
  41. data/lib/dry/web/web_pipe/templates/persistence.rb.tt +36 -0
  42. data/lib/dry/web/web_pipe/templates/repository.rb.tt +11 -0
  43. data/lib/dry/web/web_pipe/templates/sample_data.rb +1 -0
  44. data/lib/dry/web/web_pipe/templates/seed.rb +1 -0
  45. data/lib/dry/web/web_pipe/templates/settings.rb.tt +10 -0
  46. data/lib/dry/web/web_pipe/templates/setup +7 -0
  47. data/lib/dry/web/web_pipe/templates/spec/db_spec_helper.rb.tt +23 -0
  48. data/lib/dry/web/web_pipe/templates/spec/factories/example.rb +9 -0
  49. data/lib/dry/web/web_pipe/templates/spec/spec_helper.rb.tt +61 -0
  50. data/lib/dry/web/web_pipe/templates/spec/support/db/factory.rb +8 -0
  51. data/lib/dry/web/web_pipe/templates/spec/support/db/helpers.rb.tt +13 -0
  52. data/lib/dry/web/web_pipe/templates/spec/support/web/helpers.rb.tt +9 -0
  53. data/lib/dry/web/web_pipe/templates/spec/web_spec_helper.rb +37 -0
  54. data/lib/dry/web/web_pipe/templates/subapp/boot.rb.tt +5 -0
  55. data/lib/dry/web/web_pipe/templates/subapp/container.rb.tt +21 -0
  56. data/lib/dry/web/web_pipe/templates/subapp/import.rb.tt +7 -0
  57. data/lib/dry/web/web_pipe/templates/subapp/root.rb.tt +18 -0
  58. data/lib/dry/web/web_pipe/templates/subapp/router.rb.tt +10 -0
  59. data/lib/dry/web/web_pipe/templates/subapp/view.rb.tt +17 -0
  60. data/lib/dry/web/web_pipe/templates/subapp/view_context.rb.tt +8 -0
  61. data/lib/dry/web/web_pipe/templates/subapp/web.rb.tt +54 -0
  62. data/lib/dry/web/web_pipe/templates/subapp/welcome.rb.tt +13 -0
  63. data/lib/dry/web/web_pipe/templates/types.rb +6 -0
  64. data/lib/dry/web/web_pipe/templates/umbrella_project/boot.rb.tt +18 -0
  65. data/lib/dry/web/web_pipe/templates/umbrella_project/router.rb.tt +8 -0
  66. data/lib/dry/web/web_pipe/templates/view.rb.tt +15 -0
  67. data/lib/dry/web/web_pipe/templates/view_context.rb.tt +31 -0
  68. data/lib/dry/web/web_pipe/templates/welcome.html.slim +1 -0
  69. data/lib/dry/web/web_pipe/templates/welcome.rb.tt +11 -0
  70. data/lib/dry/web/web_pipe/version.rb +7 -0
  71. data/lib/dry-web-web_pipe.rb +1 -0
  72. data/script/ci +67 -0
  73. data/script/setup +47 -0
  74. data/script/teardown +42 -0
  75. data/spec/integration/new_app_spec.rb +21 -0
  76. data/spec/spec_helper.rb +22 -0
  77. data/spec/support/app.rb +64 -0
  78. data/spec/support/bundler.rb +113 -0
  79. data/spec/support/cli.rb +47 -0
  80. data/spec/support/directories.rb +37 -0
  81. data/spec/support/env.rb +84 -0
  82. data/spec/support/files.rb +59 -0
  83. data/spec/support/project.rb +60 -0
  84. data/spec/support/requests.rb +5 -0
  85. data/spec/support/silently.rb +28 -0
  86. data/spec/unit/generators/inflections_spec.rb +33 -0
  87. metadata +268 -0
@@ -0,0 +1,54 @@
1
+ require "dry/web/web_pipe/generate"
2
+ require "dry/web/web_pipe/generators/inflections"
3
+
4
+ module Dry
5
+ module Web
6
+ module WebPipe
7
+ module Generators
8
+ class AbstractGenerator
9
+ attr_reader :target_dir, :options
10
+
11
+ def initialize(target_dir, options = {})
12
+ @target_dir = target_dir
13
+ @options = options
14
+ @templates = []
15
+ populate_templates
16
+ @templates.freeze
17
+ end
18
+
19
+ def call
20
+ templates.each do |source, target|
21
+ generator.(source, target)
22
+ end
23
+ post_process_callback
24
+ end
25
+
26
+ private
27
+ attr_reader :templates
28
+
29
+ def add_template(source, target)
30
+ templates << [source, target]
31
+ end
32
+
33
+ def generator
34
+ @generator ||= Generate.new(destination, template_scope)
35
+ end
36
+
37
+ def post_process_callback; end
38
+
39
+ def underscored_project_name
40
+ @underscored_project_name ||= Inflections.underscored_name(target_dir)
41
+ end
42
+
43
+ def template_scope
44
+ fail NotImplementedError
45
+ end
46
+
47
+ def destination
48
+ fail NotImplementedError
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,116 @@
1
+ require "securerandom"
2
+ require "dry/web/web_pipe/generators/abstract_generator"
3
+
4
+ module Dry
5
+ module Web
6
+ module WebPipe
7
+ module Generators
8
+ class AbstractProject < AbstractGenerator
9
+ def populate_templates
10
+ add_bin
11
+ add_config
12
+ add_db
13
+ add_log
14
+ add_spec
15
+ add_lib
16
+ add_system
17
+ add_boot
18
+ add_application
19
+ add_config_files
20
+ end
21
+
22
+ private
23
+
24
+ def destination
25
+ target_dir
26
+ end
27
+
28
+ def template_scope
29
+ {
30
+ underscored_project_name: underscored_project_name,
31
+ camel_cased_app_name: Inflections.camel_cased_name(target_dir)
32
+ }
33
+ end
34
+
35
+ def add_bin
36
+ add_template('console.tt', 'bin/console')
37
+ add_template('setup', 'bin/setup')
38
+ end
39
+
40
+ def add_config
41
+ add_template('.env.tt', '.env')
42
+ add_template('.env.test.tt', '.env.test')
43
+ end
44
+
45
+ def add_db
46
+ add_template('sample_data.rb', 'db/sample_data.rb')
47
+ add_template('seed.rb', 'db/seed.rb')
48
+ end
49
+
50
+ def add_lib
51
+ add_template('types.rb', 'lib/types.rb')
52
+ add_template('operation.rb.tt', "lib/#{underscored_project_name}/operation.rb")
53
+ add_template('repository.rb.tt', "lib/#{underscored_project_name}/repository.rb")
54
+ add_template('.keep', 'lib/persistence/relations/.keep')
55
+ add_template('.keep', 'lib/persistence/commands/.keep')
56
+ add_template('view_context.rb.tt', "lib/#{underscored_project_name}/view_context.rb")
57
+ add_template('view.rb.tt', "lib/#{underscored_project_name}/view.rb")
58
+ end
59
+
60
+ def add_log
61
+ add_template('.keep', 'log/.keep')
62
+ end
63
+
64
+ def add_spec
65
+ add_template('.rspec', '.rspec')
66
+
67
+ # Base spec helpers
68
+ add_template('spec/web_spec_helper.rb', 'spec/web_spec_helper.rb')
69
+ add_template('spec/db_spec_helper.rb.tt', 'spec/db_spec_helper.rb')
70
+ add_template('spec/spec_helper.rb.tt', 'spec/spec_helper.rb')
71
+
72
+ # DB support
73
+ add_template('spec/support/db/factory.rb', 'spec/support/db/factory.rb')
74
+ add_template('spec/support/db/helpers.rb.tt', 'spec/support/db/helpers.rb')
75
+ add_template('spec/factories/example.rb', 'spec/factories/example.rb')
76
+
77
+ # Web support
78
+ add_template('spec/support/web/helpers.rb.tt', 'spec/support/web/helpers.rb')
79
+ end
80
+
81
+ def add_system
82
+ add_system_lib
83
+ add_system_boot
84
+ end
85
+
86
+ def add_boot
87
+ raise NotImplementedError
88
+ end
89
+
90
+ def add_application
91
+ raise NotImplementedError
92
+ end
93
+
94
+ def add_system_lib
95
+ add_template("container.rb.tt", "system/#{underscored_project_name}/container.rb")
96
+ add_template("import.rb.tt", "system/#{underscored_project_name}/import.rb")
97
+ end
98
+
99
+ def add_system_boot
100
+ add_template("monitor.rb.tt", "system/boot/monitor.rb")
101
+ add_template("persistence.rb.tt", "system/boot/persistence.rb")
102
+ add_template("settings.rb.tt", "system/boot/settings.rb")
103
+ end
104
+
105
+ def add_config_files
106
+ add_template('.gitignore.tt', '.gitignore')
107
+ add_template('Gemfile', 'Gemfile')
108
+ add_template('Rakefile.tt', 'Rakefile')
109
+ add_template('config.ru.tt', 'config.ru')
110
+ add_template('README.md.tt', 'README.md')
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -0,0 +1,43 @@
1
+ require "securerandom"
2
+ require "dry/web/web_pipe/generators/abstract_project"
3
+
4
+ module Dry
5
+ module Web
6
+ module WebPipe
7
+ module Generators
8
+ class FlatProject < AbstractProject
9
+ def populate_templates
10
+ super
11
+ add_views
12
+ add_actions
13
+ add_web
14
+ end
15
+
16
+ private
17
+
18
+ def add_boot
19
+ add_template("flat_project/boot.rb.tt", "system/boot.rb")
20
+ end
21
+
22
+ def add_application
23
+ add_template("flat_project/router.rb.tt", "system/#{underscored_project_name}/router.rb")
24
+ end
25
+
26
+ def add_views
27
+ add_template('welcome.rb.tt', "lib/#{underscored_project_name}/views/welcome.rb")
28
+ end
29
+
30
+ def add_actions
31
+ add_template('flat_project/web.rb.tt', "lib/#{underscored_project_name}/web.rb")
32
+ add_template('flat_project/root.rb.tt', "lib/#{underscored_project_name}/actions/root.rb")
33
+ end
34
+
35
+ def add_web
36
+ add_template('application.html.slim', 'web/templates/layouts/application.html.slim')
37
+ add_template('welcome.html.slim', 'web/templates/welcome.html.slim')
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,21 @@
1
+ require "inflecto"
2
+
3
+ module Dry
4
+ module Web
5
+ module WebPipe
6
+ module Generators
7
+ module Inflections
8
+ module_function
9
+
10
+ def underscored_name(name)
11
+ Inflecto.underscore(name)
12
+ end
13
+
14
+ def camel_cased_name(name)
15
+ Inflecto.camelize(underscored_name(name))
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,68 @@
1
+ require "dry/web/web_pipe/generators/abstract_generator"
2
+
3
+ module Dry
4
+ module Web
5
+ module WebPipe
6
+ module Generators
7
+ class SubApp < AbstractGenerator
8
+ def populate_templates
9
+ add_lib
10
+ add_system
11
+ add_web
12
+ end
13
+
14
+ private
15
+
16
+ def destination
17
+ options.fetch(:to) { File.join("apps", target_dir) }
18
+ end
19
+
20
+ def umbrella_name
21
+ options.fetch(:umbrella)
22
+ end
23
+
24
+ def underscored_umbrella_name
25
+ Inflections.underscored_name(umbrella_name)
26
+ end
27
+
28
+ def lib_path
29
+ "lib/#{underscored_umbrella_name}/#{underscored_project_name}"
30
+ end
31
+
32
+ def system_lib_path
33
+ "system/#{underscored_umbrella_name}/#{underscored_project_name}"
34
+ end
35
+
36
+ def add_lib
37
+ add_template('subapp/web.rb.tt', "#{lib_path}/web.rb")
38
+ add_template('subapp/root.rb.tt', "#{lib_path}/actions/root.rb")
39
+ add_template('subapp/view_context.rb.tt', "#{lib_path}/view_context.rb")
40
+ add_template('subapp/view.rb.tt', "#{lib_path}/view.rb")
41
+ add_template('subapp/welcome.rb.tt', "#{lib_path}/views/welcome.rb")
42
+ end
43
+
44
+ def add_system
45
+ add_template("subapp/router.rb.tt", "#{system_lib_path}/router.rb")
46
+ add_template('subapp/container.rb.tt', "#{system_lib_path}/container.rb")
47
+ add_template('subapp/import.rb.tt', "#{system_lib_path}/import.rb")
48
+ add_template('subapp/boot.rb.tt', 'system/boot.rb')
49
+ end
50
+
51
+ def add_web
52
+ add_template('application.html.slim', 'web/templates/layouts/application.html.slim')
53
+ add_template('welcome.html.slim', 'web/templates/welcome.html.slim')
54
+ end
55
+
56
+ def template_scope
57
+ {
58
+ underscored_project_name: underscored_project_name,
59
+ camel_cased_app_name: Inflections.camel_cased_name(target_dir),
60
+ underscored_umbrella_name: underscored_umbrella_name,
61
+ camel_cased_umbrella_name: Inflections.camel_cased_name(umbrella_name),
62
+ }
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,29 @@
1
+ require "securerandom"
2
+ require "dry/web/web_pipe/generators/abstract_project"
3
+ require "dry/web/web_pipe/generators/sub_app"
4
+
5
+ module Dry
6
+ module Web
7
+ module WebPipe
8
+ module Generators
9
+ class UmbrellaProject < AbstractProject
10
+ private
11
+
12
+ def add_boot
13
+ add_template("umbrella_project/boot.rb.tt", "system/boot.rb")
14
+ end
15
+
16
+ def add_application
17
+ add_template("umbrella_project/router.rb.tt", "system/#{underscored_project_name}/router.rb")
18
+ end
19
+
20
+ def post_process_callback
21
+ Dir.chdir(target_dir) do
22
+ Generators::SubApp.new("main", umbrella: target_dir).call
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1 @@
1
+ DATABASE_URL='postgres://localhost/<%= config[:underscored_project_name] %>_test'
@@ -0,0 +1,2 @@
1
+ DATABASE_URL='postgres://localhost/<%= config[:underscored_project_name] %>_development'
2
+ SESSION_SECRET='<%= SecureRandom.hex %>'
@@ -0,0 +1,11 @@
1
+ # Ignore app settings (copy to .example.env.* to check in example files)
2
+ /.env*
3
+
4
+ # RSpec
5
+ /spec/examples.txt
6
+
7
+ # Logs
8
+ /log/*.log
9
+
10
+ # Temp files
11
+ tmp/*
File without changes
@@ -0,0 +1,2 @@
1
+ --color
2
+ --require spec_helper
@@ -0,0 +1,47 @@
1
+ source "https://rubygems.org"
2
+
3
+ gem "rake"
4
+
5
+ # Web framework
6
+ gem "dry-system", "~> 0.9"
7
+ gem "dry-web", "~> 0.7"
8
+ gem "dry-web-web_pipe", "~> 0.1"
9
+ gem "puma"
10
+ gem "rack_csrf"
11
+ gem "hanami-router", "~> 1.3"
12
+ gem "web_pipe", "~> 0.8"
13
+ gem "rack-flash3", "~> 1.0"
14
+
15
+ gem "rack", ">= 2.0"
16
+
17
+ # Database persistence
18
+ gem "pg"
19
+ gem "rom", "~> 5.1"
20
+ gem "rom-sql", "~> 3.0"
21
+
22
+ # Application dependencies
23
+ gem "dry-matcher", "~> 0.7"
24
+ gem "dry-monads", "~> 1.2"
25
+ gem "dry-struct", "~> 1.0"
26
+ gem "dry-transaction", "~> 0.13"
27
+ gem "dry-types", "~> 1.1"
28
+ gem "dry-validation", "~> 1.0"
29
+ gem "dry-view", "~> 0.7"
30
+ gem "slim"
31
+
32
+ group :development, :test do
33
+ gem "pry-byebug", platform: :mri
34
+ end
35
+
36
+ group :development do
37
+ gem "rerun"
38
+ end
39
+
40
+ group :test do
41
+ gem "capybara"
42
+ gem "capybara-screenshot"
43
+ gem "database_cleaner"
44
+ gem "poltergeist"
45
+ gem "rspec"
46
+ gem "rom-factory", "~> 0.5"
47
+ end
@@ -0,0 +1,15 @@
1
+ # <%= config[:camel_cased_app_name] %>
2
+
3
+ Welcome! You’ve generated an app using dry-web-web_pipe.
4
+
5
+ ## First steps
6
+
7
+ 1. Run `bundle`
8
+ 2. Review `.env` & `.env.test` (and make a copy to e.g. `.example.env` if you want example settings checked in). In
9
+ particular, ensure that your PostgreSQL username and password are specified in the `DATABASE_URL` variable as follows:
10
+ `postgres://username:password@your_host/...`.
11
+ 3. Run `bundle exec rake db:create` to create the development database.
12
+ 4. Run `RACK_ENV=test bundle exec rake db:create` to create the test database.
13
+ 5. Add your own steps to `bin/setup`
14
+ 6. Run the app with `bundle exec rerun -- rackup --port 4000 config.ru`
15
+ 7. Initialize git with `git init` and make your initial commit
@@ -0,0 +1,109 @@
1
+ require "bundler/setup"
2
+ require "pry-byebug" unless ENV["RACK_ENV"] == "production"
3
+ require "rom/sql/rake_task"
4
+ require "shellwords"
5
+ require_relative "system/<%= config[:underscored_project_name] %>/container"
6
+
7
+ begin
8
+ require "rspec/core/rake_task"
9
+ RSpec::Core::RakeTask.new :spec
10
+ task default: [:spec]
11
+ rescue LoadError
12
+ end
13
+
14
+ def db
15
+ <%= config[:camel_cased_app_name] %>::Container["persistence.db"]
16
+ end
17
+
18
+ def settings
19
+ <%= config[:camel_cased_app_name] %>::Container["settings"]
20
+ end
21
+
22
+ def database_uri
23
+ require "uri"
24
+ URI.parse(settings.database_url)
25
+ end
26
+
27
+ def postgres_env_vars(uri)
28
+ {}.tap do |vars|
29
+ vars["PGHOST"] = uri.host.to_s
30
+ vars["PGPORT"] = uri.port.to_s if uri.port
31
+ vars["PGUSER"] = uri.user.to_s if uri.user
32
+ vars["PGPASSWORD"] = uri.password.to_s if uri.password
33
+ end
34
+ end
35
+
36
+ namespace :db do
37
+ task :setup do
38
+ <%= config[:camel_cased_app_name] %>::Container.init :persistence
39
+ end
40
+
41
+ desc "Print current database schema version"
42
+ task version: :setup do
43
+ version =
44
+ if db.tables.include?(:schema_migrations)
45
+ db[:schema_migrations].order(:filename).last[:filename]
46
+ else
47
+ "not available"
48
+ end
49
+
50
+ puts "Current schema version: #{version}"
51
+ end
52
+
53
+ desc "Create database"
54
+ task :create do
55
+ if system("which createdb", out: File::NULL)
56
+ uri = database_uri
57
+ system(postgres_env_vars(uri), "createdb #{Shellwords.escape(uri.path[1..-1])}")
58
+ else
59
+ puts "You must have Postgres installed to create a database"
60
+ exit 1
61
+ end
62
+ end
63
+
64
+ desc "Drop database"
65
+ task :drop do
66
+ if system("which dropdb", out: File::NULL)
67
+ uri = database_uri
68
+ system(postgres_env_vars(uri), "dropdb #{Shellwords.escape(uri.path[1..-1])}")
69
+ else
70
+ puts "You must have Postgres installed to drop a database"
71
+ exit 1
72
+ end
73
+ end
74
+
75
+ desc "Migrate database up to latest migration available"
76
+ task :migrate do
77
+ # Enhance the migration task provided by ROM
78
+
79
+ # Once it finishes, dump the db structure
80
+ Rake::Task["db:structure:dump"].execute
81
+
82
+ # And print the current migration version
83
+ Rake::Task["db:version"].execute
84
+ end
85
+
86
+ namespace :structure do
87
+ desc "Dump database structure to db/structure.sql"
88
+ task :dump do
89
+ if system("which pg_dump", out: File::NULL)
90
+ uri = database_uri
91
+ system(postgres_env_vars(uri), "pg_dump -s -x -O #{Shellwords.escape(uri.path[1..-1])}", out: "db/structure.sql")
92
+ else
93
+ puts "You must have pg_dump installed to dump the database structure"
94
+ end
95
+ end
96
+ end
97
+
98
+ desc "Load seed data into the database"
99
+ task :seed do
100
+ seed_data = File.join("db", "seed.rb")
101
+ load(seed_data) if File.exist?(seed_data)
102
+ end
103
+
104
+ desc "Load a small, representative set of data so that the application can start in a useful state (for development)."
105
+ task :sample_data do
106
+ sample_data = File.join("db", "sample_data.rb")
107
+ load(sample_data) if File.exist?(sample_data)
108
+ end
109
+ end
@@ -0,0 +1,3 @@
1
+ html
2
+ body
3
+ == yield
@@ -0,0 +1,7 @@
1
+ require_relative "system/boot"
2
+
3
+ # MethodOverride middleware has to be used at the router level, so that
4
+ # `hanami-router` can be aware of it
5
+ use Rack::MethodOverride
6
+
7
+ run <%= config[:camel_cased_app_name] %>::ROUTER
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "dry/web/console"
5
+ require_relative "../system/boot"
6
+
7
+ Dry::Web::Console.start
@@ -0,0 +1,17 @@
1
+ require "dry/web/container"
2
+ require "dry/system/components"
3
+ require 'dry-monitor'
4
+ Dry::Monitor.load_extensions(:rack)
5
+
6
+ module <%= config[:camel_cased_app_name] %>
7
+ class Container < Dry::Web::Container
8
+ configure do
9
+ config.name = :<%= config[:underscored_project_name] %>
10
+ config.listeners = true
11
+ config.default_namespace = "<%= config[:underscored_project_name] %>"
12
+ config.auto_register = %w[lib/<%= config[:underscored_project_name] %>]
13
+ end
14
+
15
+ load_paths! "lib"
16
+ end
17
+ end
@@ -0,0 +1,12 @@
1
+ require "bundler/setup"
2
+
3
+ begin
4
+ require "pry-byebug"
5
+ rescue LoadError
6
+ end
7
+
8
+ require_relative "<%= config[:underscored_project_name] %>/container"
9
+
10
+ <%= config[:camel_cased_app_name] %>::Container.finalize!
11
+
12
+ require_relative "<%= config[:underscored_project_name] %>/router"
@@ -0,0 +1,16 @@
1
+ require "web_pipe"
2
+ require "<%= config[:underscored_project_name] %>/web"
3
+
4
+ module <%= config[:camel_cased_app_name] %>
5
+ module Actions
6
+ class Root
7
+ include WebPipe
8
+
9
+ compose :web, Web.new
10
+
11
+ plug(:view) do |conn|
12
+ conn.view('views.welcome')
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,8 @@
1
+ require "hanami/router"
2
+ require "<%= config[:underscored_project_name] %>/container"
3
+
4
+ module <%= config[:camel_cased_app_name] %>
5
+ ROUTER = Hanami::Router.new do
6
+ root to: Container["actions.root"]
7
+ end
8
+ end
@@ -0,0 +1,52 @@
1
+ require "web_pipe"
2
+ require 'web_pipe/plugs/content_type'
3
+ require "web_pipe/plugs/config"
4
+ require "rack/csrf"
5
+ require "rack/session/cookie"
6
+ require 'rack-flash'
7
+ require "<%= config[:underscored_project_name] %>/container"
8
+
9
+ WebPipe.load_extensions(
10
+ :container,
11
+ :cookies,
12
+ :flash,
13
+ :dry_schema,
14
+ :dry_view,
15
+ :params,
16
+ :redirect,
17
+ :router_params,
18
+ :session,
19
+ :url
20
+ )
21
+
22
+ module <%= config[:camel_cased_app_name] %>
23
+ class Web
24
+ include WebPipe
25
+
26
+ use :cookies, Rack::Session::Cookie, key: "<%= config[:underscored_project_name] %>.session", secret: Container["settings"].session_secret
27
+ use :csrf, Rack::Csrf, raise: true
28
+ use :flash, Rack::Flash
29
+
30
+ plug :config, WebPipe::Plugs::Config.(
31
+ container: Container,
32
+
33
+ view_context: lambda do |conn|
34
+ {
35
+ flash: conn.flash,
36
+ csrf_token: Rack::Csrf.token(conn.env),
37
+ csrf_metatag: Rack::Csrf.metatag(conn.env),
38
+ csrf_tag: Rack::Csrf.tag(conn.env)
39
+ }
40
+ end,
41
+
42
+ sanitization_handler: lambda do |conn, result|
43
+ conn.
44
+ set_status(500).
45
+ set_response_body("Params #{conn.params} do not conform with the schema: #{result.errors.inspect}").
46
+ halt
47
+ end
48
+ )
49
+
50
+ plug :content_type, WebPipe::Plugs::ContentType.('text/html')
51
+ end
52
+ end
@@ -0,0 +1,5 @@
1
+ require_relative "container"
2
+
3
+ module <%= config[:camel_cased_app_name] %>
4
+ Import = <%= config[:camel_cased_app_name] %>::Container.injector
5
+ end