hanami 1.0.0 → 1.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/FEATURES.md +12 -0
- data/README.md +3 -0
- data/bin/hanami +3 -3
- data/hanami.gemspec +9 -9
- data/lib/hanami.rb +27 -0
- data/lib/hanami/action/routing_helpers.rb +1 -1
- data/lib/hanami/application_configuration.rb +0 -8
- data/lib/hanami/application_name.rb +1 -3
- data/lib/hanami/application_namespace.rb +1 -1
- data/lib/hanami/cli/commands.rb +101 -0
- data/lib/hanami/cli/commands/assets.rb +16 -0
- data/lib/hanami/cli/commands/assets/precompile.rb +42 -0
- data/lib/hanami/cli/commands/command.rb +180 -0
- data/lib/hanami/cli/commands/console.rb +95 -0
- data/lib/hanami/cli/commands/db.rb +30 -0
- data/lib/hanami/cli/commands/db/apply.rb +32 -0
- data/lib/hanami/cli/commands/db/console.rb +44 -0
- data/lib/hanami/cli/commands/db/create.rb +32 -0
- data/lib/hanami/cli/commands/db/drop.rb +32 -0
- data/lib/hanami/cli/commands/db/migrate.rb +39 -0
- data/lib/hanami/cli/commands/db/prepare.rb +32 -0
- data/lib/hanami/cli/commands/db/version.rb +32 -0
- data/lib/hanami/cli/commands/destroy.rb +26 -0
- data/lib/hanami/cli/commands/destroy/action.rb +131 -0
- data/lib/hanami/cli/commands/destroy/app.rb +159 -0
- data/lib/hanami/cli/commands/destroy/mailer.rb +74 -0
- data/lib/hanami/cli/commands/destroy/migration.rb +51 -0
- data/lib/hanami/cli/commands/destroy/model.rb +84 -0
- data/lib/hanami/cli/commands/generate.rb +28 -0
- data/lib/hanami/cli/commands/generate/action.rb +224 -0
- data/lib/hanami/cli/commands/generate/action/action.erb +8 -0
- data/lib/hanami/cli/commands/generate/action/action_spec.minitest.erb +11 -0
- data/lib/hanami/{generators/action/action_spec.rspec.tt → cli/commands/generate/action/action_spec.rspec.erb} +1 -3
- data/lib/hanami/cli/commands/generate/action/action_without_view.erb +9 -0
- data/lib/hanami/cli/commands/generate/action/view.erb +5 -0
- data/lib/hanami/cli/commands/generate/action/view_spec.minitest.erb +15 -0
- data/lib/hanami/{generators/action/view_spec.rspec.tt → cli/commands/generate/action/view_spec.rspec.erb} +2 -4
- data/lib/hanami/cli/commands/generate/app.rb +231 -0
- data/lib/hanami/{generators/app/application.rb.tt → cli/commands/generate/app/application.erb} +6 -6
- data/lib/hanami/{generators → cli/commands/generate}/app/favicon.ico +0 -0
- data/lib/hanami/{generators/action/template.tt → cli/commands/generate/app/gitkeep.erb} +0 -0
- data/lib/hanami/cli/commands/generate/app/layout.erb +7 -0
- data/lib/hanami/cli/commands/generate/app/layout_spec.minitest.erb +11 -0
- data/lib/hanami/cli/commands/generate/app/layout_spec.rspec.erb +11 -0
- data/lib/hanami/{generators/app/config/routes.rb.tt → cli/commands/generate/app/routes.erb} +0 -0
- data/lib/hanami/{generators/app/templates/application.html.erb.tt → cli/commands/generate/app/template.erb.erb} +1 -1
- data/lib/hanami/{generators/app/templates/application.html.haml.tt → cli/commands/generate/app/template.haml.erb} +1 -1
- data/lib/hanami/{generators/app/templates/application.html.slim.tt → cli/commands/generate/app/template.slim.erb} +1 -1
- data/lib/hanami/cli/commands/generate/mailer.rb +94 -0
- data/lib/hanami/cli/commands/generate/mailer/mailer.erb +7 -0
- data/lib/hanami/cli/commands/generate/mailer/mailer_spec.minitest.erb +7 -0
- data/lib/hanami/cli/commands/generate/mailer/mailer_spec.rspec.erb +5 -0
- data/lib/hanami/cli/commands/generate/migration.rb +41 -0
- data/lib/hanami/{generators/migration/migration.rb.tt → cli/commands/generate/migration/migration.erb} +0 -0
- data/lib/hanami/cli/commands/generate/model.rb +98 -0
- data/lib/hanami/cli/commands/generate/model/entity.erb +2 -0
- data/lib/hanami/cli/commands/generate/model/entity_spec.minitest.erb +5 -0
- data/lib/hanami/cli/commands/generate/model/entity_spec.rspec.erb +3 -0
- data/lib/hanami/{generators/model/migration.rb.tt → cli/commands/generate/model/migration.erb} +1 -1
- data/lib/hanami/cli/commands/generate/model/repository.erb +2 -0
- data/lib/hanami/cli/commands/generate/model/repository_spec.minitest.erb +5 -0
- data/lib/hanami/cli/commands/generate/model/repository_spec.rspec.erb +3 -0
- data/lib/hanami/cli/commands/generate/secret.rb +48 -0
- data/lib/hanami/cli/commands/new.rb +575 -0
- data/lib/hanami/{generators/application/container/.env.development.tt → cli/commands/new/.env.development.erb} +1 -1
- data/lib/hanami/{generators/application/container/.env.test.tt → cli/commands/new/.env.test.erb} +1 -1
- data/lib/hanami/{generators/app/config/initializers/.gitkeep → cli/commands/new/.gitkeep.erb} +0 -0
- data/lib/hanami/cli/commands/new/Gemfile.erb +57 -0
- data/lib/hanami/cli/commands/new/README.md.erb +35 -0
- data/lib/hanami/{generators/application/container/config.ru.tt → cli/commands/new/config.ru.erb} +0 -0
- data/lib/hanami/{generators/application/container/config/boot.rb.tt → cli/commands/new/config/boot.erb} +0 -0
- data/lib/hanami/{generators/application/container/config/environment.rb.tt → cli/commands/new/config/environment.erb} +8 -8
- data/lib/hanami/{generators/application/container/gitignore.tt → cli/commands/new/gitignore.erb} +0 -0
- data/lib/hanami/{generators/application/container/gitignore_with_sqlite.tt → cli/commands/new/gitignore_with_sqlite.erb} +0 -0
- data/lib/hanami/cli/commands/new/hanamirc.erb +3 -0
- data/lib/hanami/cli/commands/new/lib/project.erb +2 -0
- data/lib/hanami/{generators/application/container/Rakefile.minitest.tt → cli/commands/new/minitest/Rakefile.erb} +0 -0
- data/lib/hanami/{generators/application/container/features_helper.rb.minitest.tt → cli/commands/new/minitest/features_helper.erb} +0 -0
- data/lib/hanami/{generators/application/container/spec_helper.rb.minitest.tt → cli/commands/new/minitest/spec_helper.erb} +0 -0
- data/lib/hanami/{generators/application/container/Rakefile.rspec.tt → cli/commands/new/rspec/Rakefile.erb} +0 -0
- data/lib/hanami/{generators/application/container/capybara.rb.rspec.tt → cli/commands/new/rspec/capybara.erb} +0 -0
- data/lib/hanami/{generators/application/container/features_helper.rb.rspec.tt → cli/commands/new/rspec/features_helper.erb} +0 -0
- data/lib/hanami/{generators/application/container/rspec.rspec.tt → cli/commands/new/rspec/rspec.erb} +0 -0
- data/lib/hanami/{generators/application/container/spec_helper.rb.rspec.tt → cli/commands/new/rspec/spec_helper.erb} +0 -0
- data/lib/hanami/{generators/application/container/.gitignore → cli/commands/new/schema.sql.erb} +0 -0
- data/lib/hanami/cli/commands/project.rb +421 -0
- data/lib/hanami/cli/commands/routes.rb +21 -0
- data/lib/hanami/cli/commands/server.rb +39 -0
- data/lib/hanami/cli/commands/templates.rb +31 -0
- data/lib/hanami/cli/commands/version.rb +19 -0
- data/lib/hanami/common_logger.rb +14 -4
- data/lib/hanami/components.rb +39 -1
- data/lib/hanami/components/components.rb +36 -1
- data/lib/hanami/config/sessions.rb +1 -1
- data/lib/hanami/environment.rb +20 -50
- data/lib/hanami/hanamirc.rb +7 -30
- data/lib/hanami/middleware.rb +0 -26
- data/lib/hanami/static.rb +1 -1
- data/lib/hanami/templates/welcome.html.erb +1 -1
- data/lib/hanami/version.rb +1 -1
- data/lib/hanami/welcome.rb +1 -11
- metadata +125 -135
- data/lib/hanami/cli.rb +0 -154
- data/lib/hanami/cli_base.rb +0 -49
- data/lib/hanami/cli_sub_commands/assets.rb +0 -24
- data/lib/hanami/cli_sub_commands/db.rb +0 -138
- data/lib/hanami/cli_sub_commands/destroy.rb +0 -115
- data/lib/hanami/cli_sub_commands/generate.rb +0 -150
- data/lib/hanami/commands/apps.rb +0 -4
- data/lib/hanami/commands/assets/precompile.rb +0 -26
- data/lib/hanami/commands/command.rb +0 -77
- data/lib/hanami/commands/console.rb +0 -107
- data/lib/hanami/commands/db/apply.rb +0 -19
- data/lib/hanami/commands/db/console.rb +0 -41
- data/lib/hanami/commands/db/create.rb +0 -19
- data/lib/hanami/commands/db/drop.rb +0 -19
- data/lib/hanami/commands/db/migrate.rb +0 -30
- data/lib/hanami/commands/db/prepare.rb +0 -19
- data/lib/hanami/commands/db/version.rb +0 -19
- data/lib/hanami/commands/generate/abstract.rb +0 -76
- data/lib/hanami/commands/generate/action.rb +0 -322
- data/lib/hanami/commands/generate/app.rb +0 -154
- data/lib/hanami/commands/generate/mailer.rb +0 -131
- data/lib/hanami/commands/generate/migration.rb +0 -75
- data/lib/hanami/commands/generate/model.rb +0 -132
- data/lib/hanami/commands/generate/secret_token.rb +0 -37
- data/lib/hanami/commands/new/abstract.rb +0 -178
- data/lib/hanami/commands/new/app.rb +0 -129
- data/lib/hanami/commands/new/container.rb +0 -119
- data/lib/hanami/commands/routes.rb +0 -26
- data/lib/hanami/commands/server.rb +0 -32
- data/lib/hanami/generators/action/action.rb.tt +0 -8
- data/lib/hanami/generators/action/action_spec.minitest.tt +0 -12
- data/lib/hanami/generators/action/action_without_view.rb.tt +0 -9
- data/lib/hanami/generators/action/view.rb.tt +0 -5
- data/lib/hanami/generators/action/view_spec.minitest.tt +0 -16
- data/lib/hanami/generators/app/.gitkeep.tt +0 -1
- data/lib/hanami/generators/app/views/application_layout.rb.tt +0 -7
- data/lib/hanami/generators/application/container/.gitkeep +0 -1
- data/lib/hanami/generators/application/container/Gemfile.tt +0 -56
- data/lib/hanami/generators/application/container/config/initializers/.gitkeep +0 -0
- data/lib/hanami/generators/application/container/db/.gitkeep +0 -1
- data/lib/hanami/generators/application/container/hanamirc.tt +0 -4
- data/lib/hanami/generators/application/container/lib/chirp/entities/.gitkeep +0 -1
- data/lib/hanami/generators/application/container/lib/chirp/mailers/.gitkeep +0 -0
- data/lib/hanami/generators/application/container/lib/chirp/mailers/templates/.gitkeep +0 -0
- data/lib/hanami/generators/application/container/lib/chirp/repositories/.gitkeep +0 -1
- data/lib/hanami/generators/application/container/lib/project.rb.tt +0 -2
- data/lib/hanami/generators/application/container/schema.sql.tt +0 -0
- data/lib/hanami/generators/database_config.rb +0 -114
- data/lib/hanami/generators/generatable.rb +0 -69
- data/lib/hanami/generators/generator.rb +0 -52
- data/lib/hanami/generators/mailer/mailer.rb.tt +0 -7
- data/lib/hanami/generators/mailer/mailer_spec.rb.minitest.tt +0 -7
- data/lib/hanami/generators/mailer/mailer_spec.rb.rspec.tt +0 -5
- data/lib/hanami/generators/mailer/template.html.tt +0 -0
- data/lib/hanami/generators/mailer/template.txt.tt +0 -0
- data/lib/hanami/generators/model/entity.rb.tt +0 -2
- data/lib/hanami/generators/model/entity_spec.minitest.tt +0 -5
- data/lib/hanami/generators/model/entity_spec.rspec.tt +0 -3
- data/lib/hanami/generators/model/repository.rb.tt +0 -2
- data/lib/hanami/generators/model/repository_spec.minitest.tt +0 -5
- data/lib/hanami/generators/model/repository_spec.rspec.tt +0 -3
- data/lib/hanami/generators/template_engine.rb +0 -44
- data/lib/hanami/generators/test_framework.rb +0 -55
@@ -0,0 +1,11 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
|
3
|
+
describe <%= app.classify %>::Controllers::<%= controller.classify %>::<%= action.classify %> do
|
4
|
+
let(:action) { <%= app.classify %>::Controllers::<%= controller.classify %>::<%= action.classify %>.new }
|
5
|
+
let(:params) { Hash[] }
|
6
|
+
|
7
|
+
it 'is successful' do
|
8
|
+
response = action.call(params)
|
9
|
+
response[0].must_equal 200
|
10
|
+
end
|
11
|
+
end
|
@@ -1,6 +1,4 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
RSpec.describe <%= config[:app] %>::Controllers::<%= config[:controller] %>::<%= config[:action] %> do
|
1
|
+
RSpec.describe <%= app.classify %>::Controllers::<%= controller.classify %>::<%= action.classify %> do
|
4
2
|
let(:action) { described_class.new }
|
5
3
|
let(:params) { Hash[] }
|
6
4
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative '../../../spec_helper'
|
2
|
+
|
3
|
+
describe <%= app.classify %>::Views::<%= controller.classify %>::<%= action.classify %> do
|
4
|
+
let(:exposures) { Hash[foo: 'bar'] }
|
5
|
+
let(:template) { Hanami::View::Template.new('<%= template %>') }
|
6
|
+
let(:view) { <%= app.classify %>::Views::<%= controller.classify %>::<%= action.classify %>.new(template, exposures) }
|
7
|
+
let(:rendered) { view.render }
|
8
|
+
|
9
|
+
it 'exposes #foo' do
|
10
|
+
skip 'This is an auto-generated test. Edit it and add your own tests.'
|
11
|
+
|
12
|
+
# Example
|
13
|
+
view.foo.must_equal exposures.fetch(:foo)
|
14
|
+
end
|
15
|
+
end
|
@@ -1,8 +1,6 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
RSpec.describe <%= config[:app] %>::Views::<%= config[:controller] %>::<%= config[:action] %> do
|
1
|
+
RSpec.describe <%= app.classify %>::Views::<%= controller.classify %>::<%= action.classify %> do
|
4
2
|
let(:exposures) { Hash[foo: 'bar'] }
|
5
|
-
let(:template) { Hanami::View::Template.new('<%=
|
3
|
+
let(:template) { Hanami::View::Template.new('<%= template %>') }
|
6
4
|
let(:view) { described_class.new(template, exposures) }
|
7
5
|
let(:rendered) { view.render }
|
8
6
|
|
@@ -0,0 +1,231 @@
|
|
1
|
+
module Hanami
|
2
|
+
class CLI
|
3
|
+
module Commands
|
4
|
+
module Generate
|
5
|
+
# @since 1.1.0
|
6
|
+
# @api private
|
7
|
+
class App < Command # rubocop:disable Metrics/ClassLength
|
8
|
+
requires "environment"
|
9
|
+
|
10
|
+
desc "Generate an app"
|
11
|
+
|
12
|
+
argument :app, required: true, desc: "The application name (eg. `web`)"
|
13
|
+
option :application_base_url, desc: "The app base URL (eg. `/api/v1`)"
|
14
|
+
|
15
|
+
example [
|
16
|
+
"admin # Generate `admin` app",
|
17
|
+
"api --application-base-url=/api/v1 # Generate `api` app and mount at `/api/v1`"
|
18
|
+
]
|
19
|
+
|
20
|
+
# @since 1.1.0
|
21
|
+
# @api private
|
22
|
+
#
|
23
|
+
# rubocop:disable Metrics/AbcSize
|
24
|
+
# rubocop:disable Metrics/MethodLength
|
25
|
+
def call(app:, application_base_url: nil, **options)
|
26
|
+
app = Utils::String.underscore(app)
|
27
|
+
template = options.fetch(:template)
|
28
|
+
base_url = application_base_url || "/#{app}"
|
29
|
+
context = Context.new(app: app, base_url: base_url, test: options.fetch(:test), template: template, options: options)
|
30
|
+
|
31
|
+
assert_valid_base_url!(context)
|
32
|
+
|
33
|
+
generate_app(context)
|
34
|
+
generate_routes(context)
|
35
|
+
generate_layout(context)
|
36
|
+
generate_template(context)
|
37
|
+
generate_favicon(context)
|
38
|
+
|
39
|
+
create_controllers_directory(context)
|
40
|
+
create_assets_images_directory(context)
|
41
|
+
create_assets_javascripts_directory(context)
|
42
|
+
create_assets_stylesheets_directory(context)
|
43
|
+
|
44
|
+
create_spec_features_directory(context)
|
45
|
+
create_spec_controllers_directory(context)
|
46
|
+
generate_layout_spec(context)
|
47
|
+
|
48
|
+
inject_require_app(context)
|
49
|
+
inject_mount_app(context)
|
50
|
+
|
51
|
+
append_development_http_session_secret(context)
|
52
|
+
append_test_http_session_secret(context)
|
53
|
+
end
|
54
|
+
# rubocop:enable Metrics/MethodLength
|
55
|
+
# rubocop:enable Metrics/AbcSize
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
# @since 1.1.0
|
60
|
+
# @api private
|
61
|
+
def assert_valid_base_url!(context)
|
62
|
+
if Utils::Blank.blank?(context.base_url) # rubocop:disable Style/GuardClause
|
63
|
+
warn "`' is not a valid URL"
|
64
|
+
exit(1)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# @since 1.1.0
|
69
|
+
# @api private
|
70
|
+
def generate_app(context)
|
71
|
+
source = templates.find("application.erb")
|
72
|
+
destination = project.app_application(context)
|
73
|
+
|
74
|
+
generate_file(source, destination, context)
|
75
|
+
say(:create, destination)
|
76
|
+
end
|
77
|
+
|
78
|
+
# @since 1.1.0
|
79
|
+
# @api private
|
80
|
+
def generate_routes(context)
|
81
|
+
source = templates.find("routes.erb")
|
82
|
+
destination = project.app_routes(context)
|
83
|
+
|
84
|
+
generate_file(source, destination, context)
|
85
|
+
say(:create, destination)
|
86
|
+
end
|
87
|
+
|
88
|
+
# @since 1.1.0
|
89
|
+
# @api private
|
90
|
+
def generate_layout(context)
|
91
|
+
source = templates.find("layout.erb")
|
92
|
+
destination = project.app_layout(context)
|
93
|
+
|
94
|
+
generate_file(source, destination, context)
|
95
|
+
say(:create, destination)
|
96
|
+
end
|
97
|
+
|
98
|
+
# @since 1.1.0
|
99
|
+
# @api private
|
100
|
+
def generate_template(context)
|
101
|
+
source = templates.find("template.#{context.template}.erb")
|
102
|
+
destination = project.app_template(context)
|
103
|
+
|
104
|
+
generate_file(source, destination, context)
|
105
|
+
say(:create, destination)
|
106
|
+
end
|
107
|
+
|
108
|
+
# @since 1.1.0
|
109
|
+
# @api private
|
110
|
+
def generate_favicon(context)
|
111
|
+
source = templates.find("favicon.ico")
|
112
|
+
destination = project.app_favicon(context)
|
113
|
+
|
114
|
+
files.cp(source, destination)
|
115
|
+
say(:create, destination)
|
116
|
+
end
|
117
|
+
|
118
|
+
# @since 1.1.0
|
119
|
+
# @api private
|
120
|
+
def create_controllers_directory(context)
|
121
|
+
source = templates.find("gitkeep.erb")
|
122
|
+
destination = project.keep(project.controllers(context))
|
123
|
+
|
124
|
+
generate_file(source, destination, context)
|
125
|
+
say(:create, destination)
|
126
|
+
end
|
127
|
+
|
128
|
+
# @since 1.1.0
|
129
|
+
# @api private
|
130
|
+
def create_assets_images_directory(context)
|
131
|
+
source = templates.find("gitkeep.erb")
|
132
|
+
destination = project.keep(project.images(context))
|
133
|
+
|
134
|
+
generate_file(source, destination, context)
|
135
|
+
say(:create, destination)
|
136
|
+
end
|
137
|
+
|
138
|
+
# @since 1.1.0
|
139
|
+
# @api private
|
140
|
+
def create_assets_javascripts_directory(context)
|
141
|
+
source = templates.find("gitkeep.erb")
|
142
|
+
destination = project.keep(project.javascripts(context))
|
143
|
+
|
144
|
+
generate_file(source, destination, context)
|
145
|
+
say(:create, destination)
|
146
|
+
end
|
147
|
+
|
148
|
+
# @since 1.1.0
|
149
|
+
# @api private
|
150
|
+
def create_assets_stylesheets_directory(context)
|
151
|
+
source = templates.find("gitkeep.erb")
|
152
|
+
destination = project.keep(project.stylesheets(context))
|
153
|
+
|
154
|
+
generate_file(source, destination, context)
|
155
|
+
say(:create, destination)
|
156
|
+
end
|
157
|
+
|
158
|
+
# @since 1.1.0
|
159
|
+
# @api private
|
160
|
+
def create_spec_features_directory(context)
|
161
|
+
source = templates.find("gitkeep.erb")
|
162
|
+
destination = project.keep(project.features_spec(context))
|
163
|
+
|
164
|
+
generate_file(source, destination, context)
|
165
|
+
say(:create, destination)
|
166
|
+
end
|
167
|
+
|
168
|
+
# @since 1.1.0
|
169
|
+
# @api private
|
170
|
+
def create_spec_controllers_directory(context)
|
171
|
+
source = templates.find("gitkeep.erb")
|
172
|
+
destination = project.keep(project.controllers_spec(context))
|
173
|
+
|
174
|
+
generate_file(source, destination, context)
|
175
|
+
say(:create, destination)
|
176
|
+
end
|
177
|
+
|
178
|
+
# @since 1.1.0
|
179
|
+
# @api private
|
180
|
+
def generate_layout_spec(context)
|
181
|
+
source = templates.find("layout_spec.#{context.options.fetch(:test)}.erb")
|
182
|
+
destination = project.app_layout_spec(context)
|
183
|
+
|
184
|
+
generate_file(source, destination, context)
|
185
|
+
say(:create, destination)
|
186
|
+
end
|
187
|
+
|
188
|
+
# @since 1.1.0
|
189
|
+
# @api private
|
190
|
+
def inject_require_app(context)
|
191
|
+
content = "require_relative '../apps/#{context.app}/application'"
|
192
|
+
destination = project.environment(context)
|
193
|
+
|
194
|
+
files.inject_line_after(destination, /require_relative '\.\.\/lib\/.*'/, content)
|
195
|
+
say(:insert, destination)
|
196
|
+
end
|
197
|
+
|
198
|
+
# @since 1.1.0
|
199
|
+
# @api private
|
200
|
+
def inject_mount_app(context)
|
201
|
+
content = " mount #{context.app.classify}::Application, at: '#{context.base_url}'"
|
202
|
+
destination = project.environment(context)
|
203
|
+
|
204
|
+
files.inject_line_after(destination, /Hanami.configure do/, content)
|
205
|
+
say(:insert, destination)
|
206
|
+
end
|
207
|
+
|
208
|
+
# @since 1.1.0
|
209
|
+
# @api private
|
210
|
+
def append_development_http_session_secret(context)
|
211
|
+
content = %(#{context.app.upcase}_SESSIONS_SECRET="#{project.app_sessions_secret}")
|
212
|
+
destination = project.env(context, "development")
|
213
|
+
|
214
|
+
files.append(destination, content)
|
215
|
+
say(:append, destination)
|
216
|
+
end
|
217
|
+
|
218
|
+
# @since 1.1.0
|
219
|
+
# @api private
|
220
|
+
def append_test_http_session_secret(context)
|
221
|
+
content = %(#{context.app.upcase}_SESSIONS_SECRET="#{project.app_sessions_secret}")
|
222
|
+
destination = project.env(context, "test")
|
223
|
+
|
224
|
+
files.append(destination, content)
|
225
|
+
say(:append, destination)
|
226
|
+
end
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
data/lib/hanami/{generators/app/application.rb.tt → cli/commands/generate/app/application.erb}
RENAMED
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'hanami/helpers'
|
2
2
|
require 'hanami/assets'
|
3
3
|
|
4
|
-
module <%=
|
4
|
+
module <%= app.classify %>
|
5
5
|
class Application < Hanami::Application
|
6
6
|
configure do
|
7
7
|
##
|
@@ -81,7 +81,7 @@ module <%= config[:classified_app_name] %>
|
|
81
81
|
#
|
82
82
|
# See: http://www.rubydoc.info/gems/rack/Rack/Session/Cookie
|
83
83
|
#
|
84
|
-
# sessions :cookie, secret: ENV['<%=
|
84
|
+
# sessions :cookie, secret: ENV['<%= app.upcase %>_SESSIONS_SECRET']
|
85
85
|
|
86
86
|
# Configure Rack middleware for this application
|
87
87
|
#
|
@@ -116,7 +116,7 @@ module <%= config[:classified_app_name] %>
|
|
116
116
|
|
117
117
|
# The layout to be used by all views
|
118
118
|
#
|
119
|
-
layout :application # It will load <%=
|
119
|
+
layout :application # It will load <%= app.classify %>::Views::ApplicationLayout
|
120
120
|
|
121
121
|
# The relative path to templates
|
122
122
|
#
|
@@ -254,7 +254,7 @@ module <%= config[:classified_app_name] %>
|
|
254
254
|
# FRAMEWORKS
|
255
255
|
#
|
256
256
|
|
257
|
-
# Configure the code that will yield each time <%=
|
257
|
+
# Configure the code that will yield each time <%= app.classify %>::Action is included
|
258
258
|
# This is useful for sharing common functionality
|
259
259
|
#
|
260
260
|
# See: http://www.rubydoc.info/gems/hanami-controller#Configuration
|
@@ -263,13 +263,13 @@ module <%= config[:classified_app_name] %>
|
|
263
263
|
# before :authenticate! # run an authentication before callback
|
264
264
|
end
|
265
265
|
|
266
|
-
# Configure the code that will yield each time <%=
|
266
|
+
# Configure the code that will yield each time <%= app.classify %>::View is included
|
267
267
|
# This is useful for sharing common functionality
|
268
268
|
#
|
269
269
|
# See: http://www.rubydoc.info/gems/hanami-view#Configuration
|
270
270
|
view.prepare do
|
271
271
|
include Hanami::Helpers
|
272
|
-
include <%=
|
272
|
+
include <%= app.classify %>::Assets::Helpers
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
File without changes
|
File without changes
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe <%= app.classify %>::Views::ApplicationLayout do
|
4
|
+
let(:layout) { <%= app.classify %>::Views::ApplicationLayout.new(template, {}) }
|
5
|
+
let(:rendered) { layout.render }
|
6
|
+
let(:template) { Hanami::View::Template.new('apps/<%= app %>/templates/application.html.<%= template %>') }
|
7
|
+
|
8
|
+
it 'contains application name' do
|
9
|
+
rendered.must_include('<%= app.classify %>')
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
RSpec.describe <%= app.classify %>::Views::ApplicationLayout do
|
4
|
+
let(:layout) { <%= app.classify %>::Views::ApplicationLayout.new(template, {}) }
|
5
|
+
let(:rendered) { layout.render }
|
6
|
+
let(:template) { Hanami::View::Template.new('apps/<%= app %>/templates/application.html.<%= template %>') }
|
7
|
+
|
8
|
+
it 'contains application name' do
|
9
|
+
expect(rendered).to include('<%= app.classify %>')
|
10
|
+
end
|
11
|
+
end
|
File without changes
|
@@ -0,0 +1,94 @@
|
|
1
|
+
module Hanami
|
2
|
+
class CLI
|
3
|
+
module Commands
|
4
|
+
module Generate
|
5
|
+
# @since 1.1.0
|
6
|
+
# @api private
|
7
|
+
class Mailer < Command
|
8
|
+
requires "environment"
|
9
|
+
|
10
|
+
desc "Generate a mailer"
|
11
|
+
|
12
|
+
argument :mailer, required: true, desc: "The mailer name (eg. `welcome`)"
|
13
|
+
|
14
|
+
option :from, desc: "The default `from` field of the mail"
|
15
|
+
option :to, desc: "The default `to` field of the mail"
|
16
|
+
option :subject, desc: "The mail subject"
|
17
|
+
|
18
|
+
example [
|
19
|
+
"welcome # Basic usage",
|
20
|
+
'welcome --from="noreply@example.com" # Generate with default `from` value',
|
21
|
+
'announcement --to="users@example.com" # Generate with default `to` value',
|
22
|
+
'forgot_password --subject="Your password reset" # Generate with default `subject`'
|
23
|
+
]
|
24
|
+
|
25
|
+
# @since 1.1.0
|
26
|
+
# @api private
|
27
|
+
def call(mailer:, **options)
|
28
|
+
from = options.fetch(:from, DEFAULT_FROM)
|
29
|
+
to = options.fetch(:to, DEFAULT_TO)
|
30
|
+
subject = options.fetch(:subject, DEFAULT_SUBJECT)
|
31
|
+
context = Context.new(mailer: mailer, test: options.fetch(:test), from: from, to: to, subject: subject, options: options)
|
32
|
+
|
33
|
+
generate_mailer(context)
|
34
|
+
generate_mailer_spec(context)
|
35
|
+
generate_text_template(context)
|
36
|
+
generate_html_template(context)
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
|
41
|
+
# @since 1.1.0
|
42
|
+
# @api private
|
43
|
+
DEFAULT_FROM = "'<from>'".freeze
|
44
|
+
|
45
|
+
# @since 1.1.0
|
46
|
+
# @api private
|
47
|
+
DEFAULT_TO = "'<to>'".freeze
|
48
|
+
|
49
|
+
# @since 1.1.0
|
50
|
+
# @api private
|
51
|
+
DEFAULT_SUBJECT = "'Hello'".freeze
|
52
|
+
|
53
|
+
# @since 1.1.0
|
54
|
+
# @api private
|
55
|
+
def generate_mailer(context)
|
56
|
+
source = templates.find("mailer.erb")
|
57
|
+
destination = project.mailer(context)
|
58
|
+
|
59
|
+
generate_file(source, destination, context)
|
60
|
+
say(:create, destination)
|
61
|
+
end
|
62
|
+
|
63
|
+
# @since 1.1.0
|
64
|
+
# @api private
|
65
|
+
def generate_mailer_spec(context)
|
66
|
+
source = templates.find("mailer_spec.#{context.test}.erb")
|
67
|
+
destination = project.mailer_spec(context)
|
68
|
+
|
69
|
+
generate_file(source, destination, context)
|
70
|
+
say(:create, destination)
|
71
|
+
end
|
72
|
+
|
73
|
+
# @since 1.1.0
|
74
|
+
# @api private
|
75
|
+
def generate_text_template(context)
|
76
|
+
destination = project.mailer_template(context, "txt")
|
77
|
+
|
78
|
+
files.touch(destination)
|
79
|
+
say(:create, destination)
|
80
|
+
end
|
81
|
+
|
82
|
+
# @since 1.1.0
|
83
|
+
# @api private
|
84
|
+
def generate_html_template(context)
|
85
|
+
destination = project.mailer_template(context, "html")
|
86
|
+
|
87
|
+
files.touch(destination)
|
88
|
+
say(:create, destination)
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|