Skip to content

Commit 8477b0e

Browse files
committed
Initial commit
0 parents  commit 8477b0e

File tree

359 files changed

+13877
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

359 files changed

+13877
-0
lines changed

.crystal-version

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.35.0

.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*.cr]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true

.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/docs/
2+
/lib/
3+
/bin/
4+
/.shards/
5+
*.dwarf
6+
start_server
7+
*.dwarf
8+
*.local.cr
9+
.env
10+
/tmp
11+
/public/js
12+
/public/css
13+
/public/mix-manifest.json
14+
/node_modules
15+
yarn-error.log

.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: crystal
2+
addons:
3+
chrome: stable
4+
services:
5+
- postgresql
6+
before_install:
7+
# Setup chromedriver for LuckyFlow
8+
- sudo apt-get install chromium-chromedriver
9+
10+
# Setup assets
11+
- yarn install
12+
- yarn prod
13+
script:
14+
- crystal spec
15+
# Uncomment the next line if you'd like Travis to check code formatting
16+
# - crystal tool format spec src --check
17+
cache:
18+
yarn: true
19+
directories:
20+
- bin/lucky
21+
- lib
22+
- .shards

Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: ./app
2+
release: lucky db.migrate

Procfile.dev

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
system_check: script/system_check && sleep 100000
2+
web: lucky watch --reload-browser
3+
assets: yarn watch

README.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
# lucky_diff
2+
3+
This is a project written using [Lucky](https://luckyframework.org). Enjoy!
4+
5+
### Setting up the project
6+
7+
1. [Install required dependencies](https://luckyframework.org/guides/getting-started/installing#install-required-dependencies)
8+
1. Update database settings in `config/database.cr`
9+
1. Run `script/setup`
10+
1. Run `lucky dev` to start the app
11+
12+
### Learning Lucky
13+
14+
Lucky uses the [Crystal](https://crystal-lang.org) programming language. You can learn about Lucky from the [Lucky Guides](https://luckyframework.org/guides/getting-started/why-lucky).

bs-config.js

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
| Browser-sync config file
3+
|
4+
| For up-to-date information about the options:
5+
| http://www.browsersync.io/docs/options/
6+
|
7+
*/
8+
9+
module.exports = {
10+
snippetOptions: {
11+
rule: {
12+
match: /<\/head>/i,
13+
fn: function (snippet, match) {
14+
return snippet + match;
15+
}
16+
}
17+
},
18+
files: ["public/css/**/*.css", "public/js/**/*.js"],
19+
watchEvents: ["change"],
20+
open: false,
21+
browser: "default",
22+
ghostMode: false,
23+
ui: false,
24+
online: false,
25+
logConnections: false
26+
};

config/authentic.cr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require "./server"
2+
3+
Authentic.configure do |settings|
4+
settings.secret_key = Lucky::Server.settings.secret_key_base
5+
6+
unless Lucky::Env.production?
7+
fastest_encryption_possible = 4
8+
settings.encryption_cost = fastest_encryption_possible
9+
end
10+
end

config/colors.cr

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# This enables the color output when in development or test
2+
# Check out the Colorize docs for more information
3+
# https://crystal-lang.org/api/Colorize.html
4+
Colorize.enabled = Lucky::Env.development? || Lucky::Env.test?

config/cookies.cr

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
require "./server"
2+
3+
Lucky::Session.configure do |settings|
4+
settings.key = "_lucky_diff_session"
5+
end
6+
7+
Lucky::CookieJar.configure do |settings|
8+
settings.on_set = ->(cookie : HTTP::Cookie) {
9+
# If ForceSSLHandler is enabled, only send cookies over HTTPS
10+
cookie.secure(Lucky::ForceSSLHandler.settings.enabled)
11+
12+
# By default, don't allow reading cookies with JavaScript
13+
cookie.http_only(true)
14+
15+
# You can set other defaults for cookies here. For example:
16+
#
17+
# cookie.expires(1.year.from_now).domain("mydomain.com")
18+
}
19+
end

config/database.cr

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
database_name = "lucky_diff_#{Lucky::Env.name}"
2+
3+
AppDatabase.configure do |settings|
4+
if Lucky::Env.production?
5+
settings.url = ENV.fetch("DATABASE_URL")
6+
else
7+
settings.url = ENV["DATABASE_URL"]? || Avram::PostgresURL.build(
8+
database: database_name,
9+
hostname: ENV["DB_HOST"]? || "localhost",
10+
port: ENV["DB_PORT"]? || "5432",
11+
# Some common usernames are "postgres", "root", or your system username (run 'whoami')
12+
username: ENV["DB_USERNAME"]? || "postgres",
13+
# Some Postgres installations require no password. Use "" if that is the case.
14+
password: ENV["DB_PASSWORD"]? || "postgres"
15+
)
16+
end
17+
end
18+
19+
Avram.configure do |settings|
20+
settings.database_to_migrate = AppDatabase
21+
22+
# In production, allow lazy loading (N+1).
23+
# In development and test, raise an error if you forget to preload associations
24+
settings.lazy_load_enabled = Lucky::Env.production?
25+
end

config/email.cr

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
BaseEmail.configure do |settings|
2+
if Lucky::Env.production?
3+
# If you don't need to send emails, set the adapter to DevAdapter instead:
4+
#
5+
# settings.adapter = Carbon::DevAdapter.new
6+
#
7+
# If you do need emails, get a key from SendGrid and set an ENV variable
8+
send_grid_key = send_grid_key_from_env
9+
settings.adapter = Carbon::SendGridAdapter.new(api_key: send_grid_key)
10+
else
11+
settings.adapter = Carbon::DevAdapter.new
12+
end
13+
end
14+
15+
private def send_grid_key_from_env
16+
ENV["SEND_GRID_KEY"]? || raise_missing_key_message
17+
end
18+
19+
private def raise_missing_key_message
20+
puts "Missing SEND_GRID_KEY. Set the SEND_GRID_KEY env variable to 'unused' if not sending emails, or set the SEND_GRID_KEY ENV var.".colorize.red
21+
exit(1)
22+
end

config/env.cr

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module Lucky::Env
2+
extend self
3+
4+
{% for env in [:development, :test, :production] %}
5+
def {{ env.id }}?
6+
name == {{ env.id.stringify }}
7+
end
8+
{% end %}
9+
10+
def name
11+
ENV["LUCKY_ENV"]? || "development"
12+
end
13+
end

config/error_handler.cr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Lucky::ErrorHandler.configure do |settings|
2+
settings.show_debug_output = !Lucky::Env.production?
3+
end

config/html_page.cr

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Lucky::HTMLPage.configure do |settings|
2+
settings.render_component_comments = !Lucky::Env.production?
3+
end

config/log.cr

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
require "file_utils"
2+
3+
if Lucky::Env.test?
4+
# Logs to `tmp/test.log` so you can see what's happening without having
5+
# a bunch of log output in your spec results.
6+
FileUtils.mkdir_p("tmp")
7+
8+
backend = Log::IOBackend.new(File.new("tmp/test.log", mode: "w"))
9+
backend.formatter = Lucky::PrettyLogFormatter.proc
10+
Log.dexter.configure(:debug, backend)
11+
elsif Lucky::Env.production?
12+
# Lucky uses JSON in production so logs can be searched more easily
13+
#
14+
# If you want logs like in develpoment use 'Lucky::PrettyLogFormatter.proc'.
15+
backend = Log::IOBackend.new
16+
backend.formatter = Dexter::JSONLogFormatter.proc
17+
Log.dexter.configure(:info, backend)
18+
else
19+
# Use a pretty formatter printing to STDOUT in development
20+
backend = Log::IOBackend.new
21+
backend.formatter = Lucky::PrettyLogFormatter.proc
22+
Log.dexter.configure(:debug, backend)
23+
end
24+
25+
# Lucky only logs when before/after pipes halt by redirecting, or rendering a
26+
# response. Pipes that run without halting are not logged.
27+
#
28+
# If you want to log every pipe that runs, set the log level to ':info'
29+
Lucky::ContinuedPipeLog.dexter.configure(:none)
30+
31+
# Lucky only logs failed queries by default.
32+
#
33+
# Set the log to ':info' to log all queries
34+
Avram::QueryLog.dexter.configure(:none)
35+
36+
# Skip logging static assets requests in development
37+
Lucky::LogHandler.configure do |settings|
38+
if Lucky::Env.development?
39+
settings.skip_if = ->(context : HTTP::Server::Context) {
40+
context.request.method.downcase == "get" &&
41+
context.request.resource.starts_with?(/\/css\/|\/js\/|\/assets\/|\/favicon\.ico/)
42+
}
43+
end
44+
end

config/route_helper.cr

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# This is used when generating URLs for your application
2+
Lucky::RouteHelper.configure do |settings|
3+
if Lucky::Env.production?
4+
# Example: https://my_app.com
5+
settings.base_uri = ENV.fetch("APP_DOMAIN")
6+
else
7+
# Set domain to the default host/port in development/test
8+
settings.base_uri = "http://localhost:#{Lucky::ServerSettings.port}"
9+
end
10+
end

config/server.cr

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
# Here is where you configure the Lucky server
2+
#
3+
# Look at config/route_helper.cr if you want to change the domain used when
4+
# generating links with `Action.url`.
5+
Lucky::Server.configure do |settings|
6+
if Lucky::Env.production?
7+
settings.secret_key_base = secret_key_from_env
8+
settings.host = "0.0.0.0"
9+
settings.port = ENV["PORT"].to_i
10+
settings.gzip_enabled = true
11+
# By default certain content types will be gzipped.
12+
# For a full list look in
13+
# https://github.com/luckyframework/lucky/blob/master/src/lucky/server.cr
14+
# To add additional extensions do something like this:
15+
# config.gzip_content_types << "content/type"
16+
else
17+
settings.secret_key_base = "xS78KiLuLlxWVibUX3Ef5wlHHHVqnj6INQHlRbOQ9yI="
18+
# Change host/port in config/watch.yml
19+
# Alternatively, you can set the DEV_PORT env to set the port for local development
20+
settings.host = Lucky::ServerSettings.host
21+
settings.port = Lucky::ServerSettings.port
22+
end
23+
24+
# By default Lucky will serve static assets in development and production.
25+
#
26+
# However you could use a CDN when in production like this:
27+
#
28+
# Lucky::Server.configure do |settings|
29+
# if Lucky::Env.production?
30+
# settings.asset_host = "https://mycdnhost.com"
31+
# else
32+
# settings.asset_host = ""
33+
# end
34+
# end
35+
settings.asset_host = "" # Lucky will serve assets
36+
end
37+
38+
Lucky::ForceSSLHandler.configure do |settings|
39+
# To force SSL in production, uncomment the lines below.
40+
# This will cause http requests to be redirected to https:
41+
#
42+
# settings.enabled = Lucky::Env.production?
43+
# settings.strict_transport_security = {max_age: 1.year, include_subdomains: true}
44+
#
45+
# Or, leave it disabled:
46+
settings.enabled = false
47+
end
48+
49+
private def secret_key_from_env
50+
ENV["SECRET_KEY_BASE"]? || raise_missing_secret_key_in_production
51+
end
52+
53+
private def raise_missing_secret_key_in_production
54+
puts "Please set the SECRET_KEY_BASE environment variable. You can generate a secret key with 'lucky gen.secret_key'".colorize.red
55+
exit(1)
56+
end

config/watch.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
host: 127.0.0.1
2+
port: 5000

db/migrations/.keep

Whitespace-only changes.

docker-compose.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
version: "3.6"
2+
3+
services:
4+
postgres:
5+
image: postgres:12-alpine
6+
environment:
7+
- POSTGRES_PASSWORD=postgres
8+
ports:
9+
- target: 5432
10+
published: 5432
11+
volumes:
12+
- type: volume
13+
source: postgres_data_lucky_diff
14+
target: /var/lib/postgresql/data
15+
16+
volumes:
17+
postgres_data_lucky_diff:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.34.0

generated/my_app_v_21/.editorconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*.cr]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 2
9+
trim_trailing_whitespace = true

generated/my_app_v_21/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/docs/
2+
/lib/
3+
/bin/
4+
/.shards/
5+
*.dwarf
6+
start_server
7+
*.dwarf
8+
*.local.cr
9+
.env
10+
/tmp
11+
/public/js
12+
/public/css
13+
/public/mix-manifest.json
14+
/node_modules
15+
yarn-error.log

generated/my_app_v_21/.travis.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
language: crystal
2+
addons:
3+
chrome: stable
4+
services:
5+
- postgresql
6+
before_install:
7+
# Setup chromedriver for LuckyFlow
8+
- sudo apt-get install chromium-chromedriver
9+
10+
# Setup assets
11+
- yarn install
12+
- yarn prod
13+
script:
14+
- crystal spec
15+
# Uncomment the next line if you'd like Travis to check code formatting
16+
# - crystal tool format spec src --check
17+
cache:
18+
yarn: true
19+
directories:
20+
- bin/lucky
21+
- lib
22+
- .shards

generated/my_app_v_21/Procfile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
web: ./app
2+
release: lucky db.migrate

generated/my_app_v_21/Procfile.dev

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
system_check: script/system_check && sleep 100000
2+
web: lucky watch --reload-browser
3+
assets: yarn watch

0 commit comments

Comments
 (0)