Skip to content

Commit d96946c

Browse files
committed
Merge branch 'release/v9.0.7'
2 parents b0561ea + 7ce99d0 commit d96946c

File tree

10 files changed

+249
-200
lines changed

10 files changed

+249
-200
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ startScripts {
1818
mainClassName = 'dev.alpas.alpasdev.StartKt'
1919

2020
group 'dev.alpas.alpasdev'
21-
version '0.9.6'
21+
version '0.9.7'
2222

2323
repositories {
2424
jcenter()

src/main/resources/docs/alpas-console.md

Lines changed: 52 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -4,39 +4,40 @@
44
- [Registering Commands](#register)
55
- [Writing Output](#writing-output)
66

7-
As you may have noticed already, Alpas comes with a bunch of console commands—such as `make:controller`, `make:job`,
8-
`route:list` etc.—to assist you performing some tasks from the command-line. You run an Alpas command by
9-
prepending it with `alpas`. To see a list of all the Alpas commands as well as a short description for
10-
each, you can use `alpas help` command.
7+
As you may have already noticed, Alpas comes with a bunch of console commands—`make:controller`, `make:job`,
8+
`route:list` etc. to name a few—to assist you in performing some tasks from a command-line. You run an
9+
Alpas command by prepending it with `alpas`.
10+
11+
To see a list of all the Alpas commands as well as a short description for each, you can use `alpas list` command.
1112

1213
<a name="custom-commands"></a>
1314
### [Custom Commands](#custom-commands)
1415

1516
If the core Alpas commands are not enough for you, it is easy to create your own. Alpas actually wraps
1617
[clikt][clikt] command library in its own thin wrapper. Clikt is very powerful library that makes
17-
writing command line interfaces simple and intuitive.
18+
writing command line interfaces simple and intuitive. It has pretty much everything you would
19+
ever need to create powerful command-line interfaces.
1820

1921
<a name="simple-commands"></a>
2022
#### [Simple Commands](#simple-commands)
2123

22-
When writing a simple custom command, all you have to do is extend `dev.alpas.console.Command` class and override
23-
the `run()` method. The `Command` constructor receives a number of optional parameters allowing you to
24-
configure your commands the way you want it. This includes help text, summary text etc.
24+
When writing a simple custom command, all you have to do is extend `dev.alpas.console.Command` class and
25+
override the `run()` method. The `Command` constructor receives a number of optional parameters allowing
26+
you to configure your commands the way you want it. This includes help text, summary text etc.
2527

26-
The easiest way to create a command is by using `make:command` Alpas command, which will generate a new
27-
command under `console/commands` folder.
28+
The easiest way to create a command is by using `make:command` Alpas command, which will
29+
generate a new command under `console/commands` folder.
2830

2931
```bash
3032

3133
$ alpas make:command GreetCommand
3234

3335
```
3436

35-
<span class="line-numbers" data-start="2">
37+
<span class="line-numbers" data-start="2" data-file="console/commands/GreetCommand.kt">
3638

3739
```kotlin
3840

39-
// console/commands/GreetCommand.kt
4041
class GreetCommand : Command(name = "greet", help = "Say hello.") {
4142
private val name by argument()
4243
override fun run() {
@@ -48,7 +49,7 @@ class GreetCommand : Command(name = "greet", help = "Say hello.") {
4849

4950
</span>
5051

51-
After [registering the above command](#register), you can call it like so:
52+
After [registering this new command](#register), you can call it like so:
5253

5354
```bash
5455

@@ -61,22 +62,25 @@ $ alpas greet you
6162
<a name="generator-commands"></a>
6263
#### [Generator Commands](#generator-commands)
6364

64-
Generator commands are the commands that generate some files when invoked. `make:command` is actually an example
65-
of a generator command and so is `make:controller`. While you can use a simple command like `GreetCommand`
66-
above to write a generator command, you have to wired few things to get it right.
65+
Generator commands create some files and folders when invoked. `make:command` is actually an example of a
66+
generator command and so is `make:controller`.
67+
68+
While you can use a simple command like `GreetCommand` above to write a generator
69+
command, you have to wired few things to get it right.
70+
71+
Instead of extending `dev.alpas.console.Command` class, you can extend `dev.alpas.console.GeneratorCommand`
72+
class to make your life much easier while writing generator commands. While it may not always satisfy
73+
all your needs, but most of the times it does and even it doesn't, it's a good place to start.
6774

68-
Instead of extending `dev.alpas.console.Command` class, you can extend `dev.alpas.console.GeneratorCommand` class
69-
to make your life much easier while writing such generator commands. While it may not always satisfy all your
70-
needs for writing a generator command, but most of the times it does. You can pass `--generator` or `-g`
71-
to `make:command` command to create a generator type command for you. Then all you have to do is
72-
override one abstract method—`populateOutputFile()`.
75+
You can pass `--generator` or `-g` to `make:command` command to create a generator type command
76+
for you. Then all you have to do is override one abstract method—`populateOutputFile()`.
7377

7478
Let's see an example of how we can write a `make:sandwich` generator command that creates a `NameOfSandwich.kt`
75-
file under `sandwiches` folder, creating the folder if it already doesn't exist.
79+
file under `sandwiches` folder, creating this folder if it already doesn't exist.
7680

7781
<div class="ordered-list">
7882

79-
1. Create a command
83+
1. Create the command itself:
8084

8185
```bash
8286

@@ -86,12 +90,11 @@ $ alpas make:command MakeSandwich -g
8690

8791
2. Modify `console/commands/MakeSandwich.kt` file to:
8892

89-
<span class="line-numbers" data-start="2">
93+
<span class="line-numbers" data-start="2" data-file="console/commands/MakeSandwich.kt">
9094

9195

9296
```kotlin
9397

94-
// console/commands/MakeSandwich.kt
9598
class MakeSandwich(srcPackage: String) :
9699
GeneratorCommand(srcPackage, name = "make:sandwich", help = "Make a sandwich.") {
97100

@@ -103,6 +106,7 @@ class MakeSandwich(srcPackage: String) :
103106

104107
val dir = "sandwiches"
105108
val file = File(sourceOutputPath(dir, *parentDirs), "${filename.toPascalCase()}.kt")
109+
106110
return OutputFile()
107111
.target(file)
108112
.packageName(makePackageName(dir, *parentDirs))
@@ -131,36 +135,39 @@ class MakeSandwich(srcPackage: String) :
131135

132136
</span>
133137

134-
Notice that we have a couple of placeholders in the code—`StubPackageName` and `StubClazzName` both of which will
135-
be replaced with proper texts automatically when we invoke this command.
138+
Notice that we have a couple of placeholders in the code—`StubPackageName` and `StubClazzName` both
139+
of which will be replaced with proper texts automatically when we actually run the command.
136140

137141
3. Register this command in `ConsoleKernel` class:
138142

139-
<span class="line-numbers" data-start="10">
143+
<span class="line-numbers" data-start="10" data-file="ConsoleKernel.kt">
140144

141145

142146
```kotlin
143147

144-
// ConsoleKernel.kt
145148
// ...
149+
146150
override fun commands(app: Application): List<Command> {
147151
return listOf(MakeSandwich(app.srcPackage))
148152
}
153+
149154
// ...
150155

151156
```
152157

153158
</span>
154159

155-
4. Now we are ready to make a sandwich.
160+
4. Now we are ready to make ourselves a sandwich or two:
156161

157162
```bash
158163

159164
$ alpas make:sandwich club
160165

161166
```
162167

163-
This command will generate a `sandwiches/Club.kt` file. You can actually create multiple sandwiches in one go:
168+
This command will generate a `sandwiches/Club.kt` file.
169+
170+
You can actually create multiple sandwiches in one go:
164171

165172
```bash
166173

@@ -177,31 +184,34 @@ After you have created your own commands, you must register them with the app ot
177184
to you. You can register a command in a number of ways—the easiest one is by overriding `commands()` method
178185
in `ConsoleKernel` class and returning a list of all your commands.
179186

180-
<span class="line-numbers" data-start="10">
187+
<span class="line-numbers" data-start="10" data-file="ConsoleKernel.kt">
181188

182189
```kotlin
183190

184-
// ConsoleKernel.kt
185191
// ...
192+
186193
override fun commands(app: Application): List<Command> {
187194
return listOf(GreetCommand())
188195
}
196+
189197
// ...
190198

191199
```
192200

193201
</span>
194202

203+
An alternative way is by creating and registering a new [Service Provider](/docs/service-providers).
204+
195205
> /tip/ <span>Clikt comes with many other powerful features such as `parameters`, `flags`, `choice options`,
196-
`input prompts`, `password masking` and much more. The best part of it is that the features are properly
197-
documented with lots of real-world examples. We highly recommend [consulting its documentation][clikt]
198-
when creating your own commands.</span>
206+
>`input prompts`, `password masking` and much more. The best part of it is that the features are properly
207+
>documented with lots of real-world examples. We highly recommend [consulting its documentation][clikt]
208+
>when creating your own commands.</span>
199209
200210
<a name="writing-output"></a>
201211
### [Writing Output](#writing-output)
202212

203-
When you need to write some output to the console, you can use `info`, `success`, `warning`, and `error` methods.
204-
Most of these methods not only respect `--quiet` flag but also use proper ANSI colors for their purpose.
213+
When you need to write some output to the console, you can use `info`, `success`, `warning`, and `error`
214+
methods. Most of these methods respect `--quiet` flag and also use proper ANSI colors for their purpose.
205215

206216
```kotlin
207217

@@ -218,9 +228,10 @@ success("Yay! This is working.")
218228
```
219229

220230
If you need more control over coloring the output, you can use `withColors()` method. Alpas uses the full-featured
221-
text styling [Mordant](https://github.com/ajalt/mordant) library for coloring. This allows you to color the
222-
output anyway you want. Keep in mind that `withColors()` **won't** print anything if `--quiet` flag is set.
231+
text styling [Mordant][mordant] library for coloring console outputs. This allows you to color the output
232+
anyway you want. Keep in mind that `withColors()` **won't** print anything if `--quiet` flag is set.
223233

224-
> /power/ <span>Alpas Console is proudly powered by [Clikt][clikt].
234+
> /power/ <span>Alpas Console is proudly powered by [Clikt][clikt] and [Mordant][mordant].
225235
226236
[clikt]: https://ajalt.github.io/clikt/
237+
[mordant]: https://github.com/ajalt/mordant

src/main/resources/docs/controllers.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,10 @@ Or you can use `alpas make:controller` Alpas command to create one or multiple c
2222
```bash
2323

2424
# creates AdminController.kt file under controllers/admin folder
25-
alpas make:controller admin/AdminController
25+
$ alpas make:controller admin/AdminController
2626

2727
# creates DocsController.kt and HomeController.kt files under controllers folder
28-
alpas make:controller DocsController HomeController
28+
$ alpas make:controller DocsController HomeController
2929

3030
```
3131

src/main/resources/docs/mail.md

Lines changed: 32 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
- [Debugging Emails](#debugging-emails)
66
- [Custom Mail Driver](#custom-mail-driver)
77

8-
Alpas uses [Simple Java Mail](https://github.com/bbottema/simple-java-mail) library and sprinkles it with some of
9-
its own APIs to make it easy for you to send emails from within your app. You can start with an SMTP driver or a
10-
local file driver or write one of your own drivers.
8+
Alpas uses [Simple Java Mail](https://github.com/bbottema/simple-java-mail) library and sprinkles it
9+
with some of its own APIs to make it easy for you to send emails from within your app. You can
10+
start with an SMTP driver or a local file driver or write one of your own drivers.
1111

1212
<a name="available-drivers"></a>
1313
### [Available Drivers](#available-drivers)
@@ -24,28 +24,32 @@ Currently, Alpas comes bundled with 2 mail drivers:
2424
<a name="getting-started"></a>
2525
### [Getting Started](#getting-started)
2626

27-
If you open `configs/MailConfig.kt`, you'll notice that Alpas has lazily loaded two drivers for you `smpt` for SMTP
28-
Driver and `local` for the Local Mail Driver. You can get an instance of one of these drivers during the runtime
29-
by calling `driver()` method on `MailConfig` class and optionally passing the name of the driver. You can decide
30-
to always use a specific driver by setting `MAIL_DRIVER` variable to one of the driver names.
27+
If you open `configs/MailConfig.kt`, you'll notice that Alpas has lazily loaded two drivers for you`smpt` for SMTP
28+
Driver and `local` for the Local Mail Driver.You can get an instance of one of these drivers during the runtime
29+
by calling `driver()` method on `MailConfig` class. You can pass the name of a driver or use the default driver.
30+
You can decide to always use a specific driver by setting `MAIL_DRIVER` variable to one of the driver names.
3131

3232
<a name="composing-and-sending-emails"></a>
3333
### [Composing and Sending Emails](#composing-and-sending-emails)
3434

35-
To compose an email create an instance of `MailMessage` class and set the properties such as `to`, `subject`,
35+
To compose an email, create an instance of `MailMessage` class and set the properties such as `to`,`subject`,
3636
`message` etc. Once the mail is composed, send it via one of the mail drivers' `send()` method.
3737

3838
<span class="line-numbers" data-start="5">
3939

4040
```kotlin
4141

4242
fun send(call: HttpCall) {
43+
//...
44+
4345
val mail = MailMessage().apply {
4446
to = "hello@example.com"
4547
subject = "Hello There!"
4648
message = "Just want to say hi!"
4749
}
4850
call.config<MailConfig>().driver().send(mail)
51+
52+
//...
4953
}
5054

5155
```
@@ -55,8 +59,8 @@ fun send(call: HttpCall) {
5559
<a name="using-view-templates"></a>
5660
### [Using View Templates](#using-view-templates)
5761

58-
While composing a mail, instead of using plain text, you could also call `view()` method and pass the name of
59-
the view template and an optional argument map to render the email's content.
62+
While composing an email, instead of using plain text, you can also call `view()` method and pass
63+
the name of the view template, and an optional argument map to render the email's content.
6064

6165
<span class="line-numbers" data-start="5">
6266

@@ -82,32 +86,31 @@ fun send(call: HttpCall) {
8286
<a name="debugging-emails"></a>
8387
### [Debugging Emails](#debugging-emails)
8488

85-
During development, it is very convenient to save email messages locally for debugging. Alpas supports saving all
86-
your email messages to `storage/mails` folder by using `LocalMailDriver`. To use this driver, make sure the value of
87-
`MAIL_DRIVER` is set to `local` in your `.env` file.
89+
During development, it is very convenient to save email messages locally for debugging. Alpas supports
90+
saving all your email messages to `storage/mails` folder by using `LocalMailDriver`. To use this
91+
driver, make sure the value of `MAIL_DRIVER` is set to `local` in your `.env` file.
8892

89-
If you really want to send emails across the wire for real testing during development, you could use a service
90-
like [Mailtrap](https://mailtrap.io/), which collects all your emails in a dummy demo inbox.
93+
If you really wish to send emails across the wire for real testing during development, you can use a
94+
service like [Mailtrap](https://mailtrap.io/), which collects all your emails in a dummy demo inbox.
9195

9296
<a name="custom-mail-driver"></a>
9397
### [Custom Mail Driver](#custom-mail-driver)
9498

9599
It is easy to add a custom driver. All you have to do is create a class that implements
96-
`dev.alpas.mailing.drivers.MailDriver` interface and override `send(mail: MailMessage)` method. Eventually, register
97-
this new driver in `MailConfig` class with a name.
100+
`dev.alpas.mailing.drivers.MailDriver` interface and override `send(mail: MailMessage)`
101+
method. Eventually, register this new driver in `MailConfig` class under a name.
98102

99-
Let's see and example of how to write your own [SparkPost](https://sparkpost.com) driver by wrapping their
100-
official [Java client API](https://github.com/SparkPost/java-sparkpost).
103+
Let's see and example of how to write your own [SparkPost](https://sparkpost.com) driver by
104+
wrapping their official [Java client API](https://github.com/SparkPost/java-sparkpost).
101105

102106
<div class="ordered-list">
103107

104-
1. Create the driver
108+
1. Create the driver:
105109

106-
<span class="line-numbers" data-start="2">
110+
<span class="line-numbers" data-start="2" data-file="SparkPostMailDriver.kt">
107111

108112
```kotlin
109113

110-
// SparkPostMailDriver.kt
111114
import dev.alpas.mailing.MailMessage
112115
import dev.alpas.mailing.drivers.MailDriver
113116

@@ -122,13 +125,12 @@ class SparkPostDriver(val apiKey: String, defaultFromAddress: String) : MailDriv
122125

123126
</span>
124127

125-
2. Register the driver
128+
2. Register the driver:
126129

127-
<span class="line-numbers" data-start="3">
130+
<span class="line-numbers" data-start="3" data-file="configs/MailConfig.kt">
128131

129132
```kotlin
130133

131-
// configs/MailConfig.kt
132134
class MailConfig(env: Environment) : BaseConfig(env) {
133135
init {
134136
// ...
@@ -144,19 +146,23 @@ class MailConfig(env: Environment) : BaseConfig(env) {
144146

145147
</span>
146148

147-
3. Use the driver
149+
3. Use the driver:
148150

149151
<span class="line-numbers" data-start="5">
150152

151153
```kotlin
152154

153155
fun send(call: HttpCall) {
156+
//...
157+
154158
val mail = MailMessage().apply {
155159
to = "hello@example.com"
156160
subject = "Hello There!"
157161
message = "Just want to say hi!"
158162
}
159163
call.config<MailConfig>().driver("sparkpost").send(mail)
164+
165+
//...
160166
}
161167

162168
```

src/main/resources/docs/middleware.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ it under `middleware` folder.
2121

2222
```bash
2323

24-
alpas make:middleware AdminOnlyMiddleware
24+
$ alpas make:middleware AdminOnlyMiddleware
2525

2626
```
2727

0 commit comments

Comments
 (0)