Skip to content

Commit

Permalink
Merge pull request #178 from drashland/issue-#175-support-deno-doc
Browse files Browse the repository at this point in the history
Issue #175 support deno doc
  • Loading branch information
ebebbington committed Apr 15, 2020
2 parents 4d9fc0c + c723b1b commit d15467f
Show file tree
Hide file tree
Showing 36 changed files with 142 additions and 156 deletions.
2 changes: 1 addition & 1 deletion README.md
Expand Up @@ -23,7 +23,7 @@
```typescript
// File: app.ts

import Drash from "https://deno.land/x/drash@v0.39.5/mod.ts";
import { Drash } from "https://deno.land/x/drash@v0.39.5/mod.ts";

class HomeResource extends Drash.Http.Resource {
static paths = ["/"];
Expand Down
7 changes: 6 additions & 1 deletion console/tests
@@ -1,6 +1,11 @@
#!/bin/bash

(
export DRASH_PROCESS="test"
export DRASH_ROOT_DIR=$PWD
deno --allow-net --allow-read --allow-write --allow-env tests/test.ts
deno --allow-net --allow-read --allow-write --allow-env tests/test.ts \
&& cd example_app \
&& deno --allow-net --allow-read --allow-write --allow-env app_test.ts \
&& deno --allow-net --allow-read --allow-write --allow-env app_two_test.ts \
&& cd -
)
45 changes: 24 additions & 21 deletions mod.ts
Expand Up @@ -4,50 +4,51 @@
// REQUIREMENTS.md

// Compilers
import template_engine from "./src/compilers/template_engine.ts";
import { TemplateEngine as template_engine } from "./src/compilers/template_engine.ts";

// Dictionaries
import * as log_levels from "./src/dictionaries/log_levels.ts";
import mime_db from "./src/dictionaries/mime_db.json";

// Exceptions
import http_exception from "./src/exceptions/http_exception.ts";
import http_middleware_exception from "./src/exceptions/http_middleware_exception.ts";
import http_response_exception from "./src/exceptions/http_response_exception.ts";
import name_collision_exception from "./src/exceptions/name_collision_exception.ts";
import { HttpException as http_exception } from "./src/exceptions/http_exception.ts";
import { HttpMiddlewareException as http_middleware_exception } from "./src/exceptions/http_middleware_exception.ts";
import { HttpResponseException as http_response_exception } from "./src/exceptions/http_response_exception.ts";
import { NameCollisionException as name_collision_exception } from "./src/exceptions/name_collision_exception.ts";

// Http
import middleware from "./src/http/middleware.ts";
import resource from "./src/http/resource.ts";
import response from "./src/http/response.ts";
import server from "./src/http/server.ts";
import { Middleware as middleware } from "./src/http/middleware.ts";
import { Resource as resource } from "./src/http/resource.ts";
import { Response as response } from "./src/http/response.ts";
import { Server as server } from "./src/http/server.ts";

// Interfaces
import interface_logger_configs from "./src/interfaces/logger_configs.ts";
import interface_log_level_structure from "./src/interfaces/log_level_structure.ts";
import interface_parsed_request_body from "./src/interfaces/parsed_request_body.ts";
import interface_server_configs from "./src/interfaces/server_configs.ts";
import interface_response_options from "./src/interfaces/response_options.ts"
import { LoggerConfigs as interface_logger_configs } from "./src/interfaces/logger_configs.ts";
import { LogLevelStructure as interface_log_level_structure } from "./src/interfaces/log_level_structure.ts";
import { ParsedRequestBody as interface_parsed_request_body } from "./src/interfaces/parsed_request_body.ts";
import { ServerConfigs as interface_server_configs } from "./src/interfaces/server_configs.ts";
import { ResponseOptions as interface_response_options } from "./src/interfaces/response_options.ts"

// Loggers
import base_logger from "./src/core_loggers/logger.ts";
import console_logger from "./src/core_loggers/console_logger.ts";
import file_logger from "./src/core_loggers/file_logger.ts";
import { Logger as base_logger } from "./src/core_loggers/logger.ts";
import { ConsoleLogger as console_logger } from "./src/core_loggers/console_logger.ts";
import { FileLogger as file_logger } from "./src/core_loggers/file_logger.ts";

// Services
import http_service from "./src/services/http_service.ts";
import http_request_service from "./src/services/http_request_service.ts";
import { HttpService as http_service } from "./src/services/http_service.ts";
import { HttpRequestService as http_request_service } from "./src/services/http_request_service.ts";
import { StringService as string_service } from "./src/services/string_service.ts";

import * as util_members from "./src/util/members.ts";

////////////////////////////////////////////////////////////////////////////////
// FILE MARKER: NAMESPACE - DRASH //////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////
//
// Usage: import Drash from "/path/to/drash/mod.ts";
// Usage: import { Drash } from "/path/to/drash/mod.ts";
//

namespace Drash {
export namespace Drash {
// TODO: Remove this when the docs don't need it
export namespace Util {
export const Exports = util_members;
Expand Down Expand Up @@ -110,6 +111,8 @@ namespace Drash {
export const HttpService = new http_service();
export type HttpRequestService = http_request_service;
export const HttpRequestService = new http_request_service();
export type StringService = string_service;
export const StringService = string_service;
}

/**
Expand Down
31 changes: 29 additions & 2 deletions src/compilers/template_engine.ts
@@ -1,14 +1,41 @@
const decoder = new TextDecoder();

export default class TemplateEngine {
export class TemplateEngine {

/**
* @description
* A property to hold the base path to the template(s).
*
* @property string views_path
*/
public views_path: string = "";

// FILE MARKER: CONSTRUCTOR //////////////////////////////////////////////////

/**
* @description
* Construct an object of this class.
*
* @param string viewsPath
* The base path to the template(s).
*/

constructor(viewsPath: string) {
this.views_path = viewsPath;
}

public render(template: string, data: any) {
// FILE MARKER: METHODS - PUBLIC /////////////////////////////////////////////

/**
* Render a template file and replace all template variables with the
* specified data.
*
* @param string template
* The template to render.
* @param any data
* The data that should be rendered with the template.
*/
public render(template: string, data: any): string {
let code: any = "with(obj) { var r=[];\n";
let cursor: any = 0;
let html: string = decoder.decode(Deno.readFileSync(this.views_path + template));
Expand Down
6 changes: 3 additions & 3 deletions src/core_loggers/console_logger.ts
@@ -1,5 +1,5 @@
import Drash from "../../mod.ts";
import Logger from "./logger.ts";
import { Drash } from "../../mod.ts";
import { Logger } from "./logger.ts";

/**
* @memberof Drash.CoreLoggers
Expand All @@ -8,7 +8,7 @@ import Logger from "./logger.ts";
* @description
* This logger allows you to log messages to the console.
*/
export default class ConsoleLogger extends Logger {
export class ConsoleLogger extends Logger {
/**
* @description
* Construct an object of this class.
Expand Down
6 changes: 3 additions & 3 deletions src/core_loggers/file_logger.ts
@@ -1,5 +1,5 @@
import Drash from "../../mod.ts";
import Logger from "./logger.ts";
import { Drash } from "../../mod.ts";
import { Logger } from "./logger.ts";

/**
* @memberof Drash.CoreLoggers
Expand All @@ -8,7 +8,7 @@ import Logger from "./logger.ts";
* @description
* This logger allows you to log messages to a file.
*/
export default class FileLogger extends Logger {
export class FileLogger extends Logger {
/**
* @description
* The file this logger will write log messages to.
Expand Down
21 changes: 10 additions & 11 deletions src/core_loggers/logger.ts
@@ -1,5 +1,4 @@
import Drash from "../../mod.ts";
import LogLevels from "../dictionaries/log_levels.ts";
import { Drash } from "../../mod.ts";

/**
* @memberof Drash.CoreLoggers
Expand All @@ -8,7 +7,7 @@ import LogLevels from "../dictionaries/log_levels.ts";
* @description
* This Logger is the base logger class for all logger classes.
*/
export default abstract class Logger {
export abstract class Logger {
/**
* @description
* See Drash.Interfaces.LoggerConfigs
Expand Down Expand Up @@ -49,7 +48,7 @@ export default abstract class Logger {
}

configs.level = configs.level ? configs.level.toLowerCase() : "debug";
if (!LogLevels.get(configs.level)) {
if (!Drash.Dictionaries.LogLevels.get(configs.level)) {
configs.level = "debug";
}

Expand Down Expand Up @@ -88,7 +87,7 @@ export default abstract class Logger {
* The log message.
*/
public debug(message: string): string | void {
return this.sendToWriteMethod(LogLevels.get("debug"), message);
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("debug"), message);
}

/**
Expand All @@ -99,7 +98,7 @@ export default abstract class Logger {
* The log message.
*/
public error(message: string): string | void {
return this.sendToWriteMethod(LogLevels.get("error"), message);
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("error"), message);
}

/**
Expand All @@ -110,7 +109,7 @@ export default abstract class Logger {
* The log message.
*/
public fatal(message: string): string | void {
return this.sendToWriteMethod(LogLevels.get("fatal"), message);
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("fatal"), message);
}

/**
Expand All @@ -121,7 +120,7 @@ export default abstract class Logger {
* The log message.
*/
public info(message: string): string | void {
return this.sendToWriteMethod(LogLevels.get("info"), message);
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("info"), message);
}

/**
Expand All @@ -132,7 +131,7 @@ export default abstract class Logger {
* The log message.
*/
public trace(message: string): string | void {
return this.sendToWriteMethod(LogLevels.get("trace"), message);
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("trace"), message);
}

/**
Expand All @@ -143,7 +142,7 @@ export default abstract class Logger {
* The log message.
*/
public warn(message: string): string | void {
return this.sendToWriteMethod(LogLevels.get("warn"), message);
return this.sendToWriteMethod(Drash.Dictionaries.LogLevels.get("warn"), message);
}

// FILE MARKER: METHODS - PROTECTED //////////////////////////////////////////
Expand Down Expand Up @@ -212,7 +211,7 @@ export default abstract class Logger {
// wants to output FATAL log messages (has a rank of 400), then any log
// message with a rank greater than that (ERROR, WARN, INFO, DEBUG, TRACE)
// will NOT be processed.
const level = LogLevels.get(key);
const level = Drash.Dictionaries.LogLevels.get(key);
if (!level) {
return;
}
Expand Down
4 changes: 1 addition & 3 deletions src/dictionaries/log_levels.ts
@@ -1,4 +1,4 @@
import Drash from "../../mod.ts";
import { Drash } from "../../mod.ts";

/**
* @memberof Drash.Dictionaries
Expand Down Expand Up @@ -36,5 +36,3 @@ export const LogLevels = new Map<string, Drash.Interfaces.LogLevelStructure>([
["trace", { name: "Trace", rank: LogLevel.Trace }],
["all", { name: "All", rank: LogLevel.All }],
]);

export default LogLevels;
2 changes: 1 addition & 1 deletion src/exceptions/http_exception.ts
Expand Up @@ -5,7 +5,7 @@
* @description
* This class gives you a way to throw HTTP errors semantically.
*/
export default class HttpException extends Error {
export class HttpException extends Error {
/**
* @description
* A property to hold the HTTP response code associated with this
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/http_middleware_exception.ts
Expand Up @@ -8,7 +8,7 @@
* comes when you want to check which exception was thrown via
* exception.constructor.name.
*/
export default class HttpMiddlewareException extends Error {
export class HttpMiddlewareException extends Error {
/**
* @description
* A property to hold the HTTP response code associated with this
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/http_response_exception.ts
Expand Up @@ -8,7 +8,7 @@
* comes when you want to check which exception was thrown via
* exception.constructor.name.
*/
export default class HttpResponseException extends Error {
export class HttpResponseException extends Error {
/**
* @description
* A property to hold the HTTP response code associated with this
Expand Down
2 changes: 1 addition & 1 deletion src/exceptions/name_collision_exception.ts
Expand Up @@ -7,7 +7,7 @@
* if you try to add two loggers via Drash.addLogger() with the same name,
* then this exception will be thrown because the names are colliding.
*/
export default class NameCollisionException extends Error {
export class NameCollisionException extends Error {
/**
* @description
* A property to hold the error message associated with this
Expand Down
4 changes: 2 additions & 2 deletions src/http/middleware.ts
@@ -1,4 +1,4 @@
import Drash from "../../mod.ts";
import { Drash } from "../../mod.ts";

/**
* @memberof Drash.Http
Expand All @@ -7,7 +7,7 @@ import Drash from "../../mod.ts";
* @description
* This is the base middleware class for all middleware classes.
*/
export default abstract class Middleware {
export abstract class Middleware {
/**
* @description
* A property to hold the name of this middleware class. This property is
Expand Down
4 changes: 2 additions & 2 deletions src/http/resource.ts
@@ -1,4 +1,4 @@
import Drash from "../../mod.ts";
import { Drash } from "../../mod.ts";

/**
* @memberof Drash.Http
Expand All @@ -8,7 +8,7 @@ import Drash from "../../mod.ts";
* This is the base resource class for all resources. All resource classes
* must be derived from this class.
*/
export default class Resource {
export class Resource {
/**
* @description
* A property to hold the middleware this resource uses.
Expand Down
4 changes: 2 additions & 2 deletions src/http/response.ts
@@ -1,4 +1,4 @@
import Drash from "../../mod.ts";
import { Drash } from "../../mod.ts";
import { STATUS_TEXT, Status } from "../../deps.ts";
import { setCookie, delCookie, Cookie } from "../../deps.ts";
const decoder = new TextDecoder();
Expand All @@ -10,7 +10,7 @@ const decoder = new TextDecoder();
* @description
* Response handles sending a response to the client making the request.
*/
export default class Response {
export class Response {
/**
* @description
* A property to hold the body of this response.
Expand Down
9 changes: 4 additions & 5 deletions src/http/server.ts
@@ -1,6 +1,5 @@
import Drash from "../../mod.ts";
import { Drash } from "../../mod.ts";
import { STATUS_TEXT, Status, serve } from "../../deps.ts";
import Resource from "./resource.ts";

interface RunOptions {
address?: string | any; // Use any to be more dynamic instead of using Pick
Expand All @@ -16,7 +15,7 @@ interface RunOptions {
* appropriate responses, and handling any errors that bubble up within the
* request-resource-response lifecycle.
*/
export default class Server {
export class Server {
static REGEX_URI_MATCHES = new RegExp(/(:[^(/]+|{[^0-9][^}]*})/, "g");
static REGEX_URI_REPLACEMENT = "([^/]+)";
protected trackers = {
Expand Down Expand Up @@ -433,8 +432,8 @@ export default class Server {
* Returns an instance of the resourceClass passed in, and setting the
* `paths` and `middleware` properties
*/
public getResourceObject(resourceClass: any, request: any): Resource {
let resourceObj: Resource = new resourceClass(
public getResourceObject(resourceClass: any, request: any): Drash.Http.Resource {
let resourceObj: Drash.Http.Resource = new resourceClass(
request,
new Drash.Http.Response(request, {
views_path: this.configs.views_path,
Expand Down
2 changes: 1 addition & 1 deletion src/interfaces/log_level_structure.ts
Expand Up @@ -13,7 +13,7 @@
* Drash.Dictionaries.LogLevels.LogLevel enum member to see the ranking
* structure of the log levels.
*/
export default interface LogLevelStructure {
export interface LogLevelStructure {
name: string;
rank: number;
}

0 comments on commit d15467f

Please sign in to comment.