Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task complete #8

Open
wants to merge 12 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# assignment_css_garden_of_good_and_evil
Create a CSS garden that adapts to your whims.
# css_garden_of_good_and_evil
CSS garden that adapts to your whims.
53 changes: 53 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
const express = require("express");
const cookieParser = require('cookie-parser');
const intentMiddleware = require('./middleware/intent');
const favoritesMiddleware = require('./middleware/favorites');
const insanityMiddleware = require('./middleware/insanity');

const app = express();
app.use(cookieParser());

//set up handlebars
const exphbs = require('express-handlebars');
app.engine('handlebars', exphbs({
defaultLayout: 'main',
partialsDir: 'views/'
}));
app.set('view engine', 'handlebars');

//set up body parser
const bodyParser = require('body-parser');
app.use(bodyParser.urlencoded({extended: false}));

//setup style css
app.use(express.static(__dirname + '/public'));

//custom middleware
app.use(intentMiddleware);
app.use(favoritesMiddleware);
app.use(insanityMiddleware);


app.get('/', (req , res) => {

const description = req.intentDescription
res.render('index', {description,
intent: req.intent,
insanity: req.insanity
});
});

app.post('/', (req, res) => {

//keep these in a cookie and load with this setting
res.cookie("intent", req.body.position);
res.cookie("food", req.body.food);
res.cookie("color", req.body.colorPicker);
res.cookie("insanity", req.body.insanity);

res.redirect("back");
});

app.listen(3000, () => {
console.log('Listening');
})
45 changes: 45 additions & 0 deletions json_data/description.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"good": {
"likes": ["The Sun", "Peace", "Harmony", "Laughter", "Destroying Evil"],
"dislikes": ["Darkness", "Poverty", "selfisness", "Asparagus "],
"biography" : "This person loves doing good that is all there is to it",
"resume": {
"paladin" : {
"para1": "Trained young fellow paladins in the art of holy war",
"para2": "Restored a old relic sword named Asgbringer",
"para3": "Stopped the resurrection of unholy fiends caused by the king of the lich"
},
"Druid" : {
"para1": "Maintain peace and tranquility of the forest",
"para2": "Mediate into the emerald dream",
"para3": "Heal the wounded with the power of the forest"
},
"Comedian": {
"para1": "Performed for charity at the comedy cellar in NY",
"para2": "Still on tour and making people laugh all over the country"
}
}
},
"evil": {
"likes": ["Darkness", "Poverty", "selfisness", "Asparagus "],
"dislikes": ["The Sun", "Peace", "Harmony", "Laughter", "Destroying Evil"],
"biography" : "This person was born right after a good person was born, he/she exists as yang to the yin",
"resume": {
"Warlock" : {
"para1": "Summon demons from the dark beyond",
"para2": "Corrupt the weak minded",
"para3": "Apply curses and other dark magic on your enemies"
},
"Death Knight" : {
"para1": "Ressurect the dead into ghouls",
"para2": "Bring a plague upon innocent people and their villages",
"para3": "Help them warlocks"
},
"The Joker": {
"para1": "Give batman a tough time",
"para2": "Have psycopathic thoughts and act upon them",
"para3": "Bring the joy of craziness to people of gotham"
}
}
}
}
22 changes: 22 additions & 0 deletions middleware/favorites.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

const favoritesMiddleware = (req, res, next) => {
const favoriteFood = req.cookies.food || "Cheesecake";
const favoriteColor = req.cookies.color || "Blue";

//add to like and dislike list

req.favoriteFood = favoriteFood;
req.favoriteColor = favoriteColor;

if(req.intent == "good"){
req.intentDescription.likes.push(favoriteColor, favoriteFood);
}
if(req.intent == "evil"){
req.intentDescription.dislikes.push(favoriteColor, favoriteFood);
}

next();

};

module.exports = favoritesMiddleware;
10 changes: 10 additions & 0 deletions middleware/insanity.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const insanityMiddleware = (req, res, next) => {
const insanity = req.cookies.insanity || "1";

req.insanity = insanity;

next();

}

module.exports = insanityMiddleware;
18 changes: 18 additions & 0 deletions middleware/intent.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
const fs = require('fs');

const getJson = (intent) => {
const data = fs.readFileSync("./json_data/description.json");
const json = JSON.parse(data);
return json[intent];
};

const intentMiddleware = (req, res, next) => {
const intent = req.cookies.intent || "evil";

req.intent = intent;
req.intentDescription = getJson(intent);

next();
}

module.exports = intentMiddleware;
26 changes: 26 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"name": "assignment_css_garden_of_good_and_evil",
"version": "1.0.0",
"description": "Playing around with cookies",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"repository": {
"type": "git",
"url": "git+https://github.com/Malbaron0/assignment_css_garden_of_good_and_evil.git"
},
"author": "Malyar Baron",
"license": "ISC",
"bugs": {
"url": "https://github.com/Malbaron0/assignment_css_garden_of_good_and_evil/issues"
},
"homepage": "https://github.com/Malbaron0/assignment_css_garden_of_good_and_evil#readme",
"dependencies": {
"body-parser": "^1.17.2",
"cookie-parser": "^1.4.3",
"cookie-session": "^2.0.0-beta.2",
"express": "^4.15.3",
"express-handlebars": "^3.0.0"
}
}
197 changes: 197 additions & 0 deletions public/styles/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,197 @@
h3 {
font-weight: normal;
font-size: 40px;
font-family: 'Amatic SC', cursive;
}

.well {
background: rgb(51,122,183) !important;
color: white;
}

.form-well {
background: rgb(51,180,200) !important;
color: white;
border-radius: 10px;
margin-top: 20px;
}

.container {
display: flex;
align-items: center;
flex-wrap: wrap;
justify-content: center;
}

.form-container {
display: flex;
align-items: center;
flex-wrap: wrap;
justify-content: center;
}

.form-container div {
margin: 10px;
}

.description-container {
display: flex;
justify-content: center;
align-items: center;
}

.header {
text-align: center;
margin: 50px 0;
}

.header h1 {
font-size: 140px;
font-weight: bold;
font-family: 'Amatic SC', cursive;
}

.content {
text-align: center;
width: 100%;
}

.content h2 {
font-size: 60px;
font-family: 'Amatic SC', cursive;
font-weight: bold;
}

.list-container{
display: flex;
justify-content: center;

}

.likes h3{
text-decoration: underline;
font-size: 40px;
font-family: 'Amatic SC', cursive;
}

.dislikes h3{
text-decoration: underline;
font-family: 'Amatic SC', cursive;
font-size: 40px;
}

ul {
list-style-type: none;
padding: 0px;
margin: 40px;
}

.bio {
margin-top: 40px;
}

.job-title {
margin: 50px 0px;
}

.job-title h3 {
text-decoration: underline;
font-size: 40px;
font-family: 'Amatic SC', cursive;
}

.insanity-1 {
transform: rotate(0deg);
}
.insanity-1 h3 {
transform: rotate(0deg);
}

.insanity-1 h2 {
transform: rotate(0deg);
}
.insanity-2 {
font-family: 'Amatic SC', cursive;
transform: rotate(20deg);
}

.insanity-3 {
font-family: 'League Script' !important;
transform: rotate(50deg);
}

.insanity-3 h3{
font-family: 'League Script' !important;
transform: rotate(50deg);
}

.insanity-3 h2{
font-family: 'League Script' !important;
transform: rotate(50deg);
}

.insanity-4 {
font-family: 'League Script' !important;
transform: rotate(80deg);
}

.insanity-4 h3{
font-family: 'League Script' !important;
transform: rotate(80deg);
}

.insanity-4 h2{
font-family: 'League Script' !important;
transform: rotate(80deg);
}


.insanity-5 {
font-family: 'League Script' !important;
transform: rotate(120deg);
background: rebeccapurple;
}

.insanity-5 h3{
font-family: 'League Script' !important;
transform: rotate(1200deg);
background: red;
}

.insanity-5 h2{
font-family: 'League Script' !important;
transform: rotate(120deg);
background: yellow;
}



input[type=range]{
-webkit-appearance: none;
}

input[type=range]::-webkit-slider-runnable-track {
width: 300px;
height: 5px;
background: #ddd;
border: none;
border-radius: 3px;
}

input[type=range]::-webkit-slider-thumb {
-webkit-appearance: none;
border: none;
height: 16px;
width: 16px;
border-radius: 50%;
background:orange;
margin-top: -4px;
}

input[type=range]:focus {
outline: none;
}

input[type=range]:focus::-webkit-slider-runnable-track {
background: #ccc;
}
Loading