diff --git a/README.md b/README.md
index 4171bc5..7207e89 100644
--- a/README.md
+++ b/README.md
@@ -2,3 +2,11 @@
# Thoughter
Definitely not a Twitter clone.
+
+Edited by: Carlyse Jordan
+TIY
+03/16/17
+
+This was a homework exercise used to get more practice with asynchronous DOM
+and ajax testing using tools such as mocha(describe/module library), chai(assertion
+framework) and karma as the test runner.
diff --git a/_config.yml b/_config.yml
new file mode 100644
index 0000000..3397c9a
--- /dev/null
+++ b/_config.yml
@@ -0,0 +1 @@
+theme: jekyll-theme-architect
\ No newline at end of file
diff --git a/gruntfile.js b/gruntfile.js
new file mode 100644
index 0000000..ec9ee63
--- /dev/null
+++ b/gruntfile.js
@@ -0,0 +1,80 @@
+module.exports = function configureGrunt(gruntConfig){
+
+ gruntConfig.initConfig({
+ clean: ['build/'],
+
+ copy: {
+ htmlcopy: {
+
+ files: [ {
+ src: 'src/*.html',
+ dest: 'build/',
+ expand: true
+ }
+ ]
+ }
+ },
+ copythejquery: {
+ files: [
+ {
+ src: ['jquery.js'],
+ dest: 'build/js/vendor/',
+ expand: true
+ }
+ ]
+
+ },
+
+ copythejs:{
+ files: [
+ {
+ cwd: 'src/',
+ src: ['**/*.js'],
+ dest: 'build/',
+ expand: true
+ }
+ ]
+ },
+
+ sass: {
+ all: {
+ files: {
+ 'build/style.csss':'src/sass/main.scss'
+ }
+ }
+ },
+ jshint: {
+ appjs: {
+ options: {
+ jshintrc: '.jshintrc'
+ },
+ files: {
+ src: ['src/**/*.js']
+ }
+ }
+ },
+ karma: {
+ all: {
+
+ options:{
+ //if Im using grunt to run karma (tests), then we DON'T need a app.conf.js
+ //file for karma separatelly
+ //Same options from Conf.js file
+ frameworks: ['mocha', 'chai'],
+ browsers: ['Chrome'],
+ singleRun: true,
+ files: [
+ 'src/**/*.js',
+ 'tests/specs/**/*.js'
+ ]
+ }
+ }
+ }
+
+});
+require('load-grunt-tasks')(gruntConfig);
+
+//create a task called "alias" to run multiple OTHER tasks
+//can create more aliases!
+gruntConfig.registerTask('build',['jshint','karma','clean','copy','sass']);
+};
diff --git a/npm-debug.log b/npm-debug.log
new file mode 100644
index 0000000..f5b27e5
--- /dev/null
+++ b/npm-debug.log
@@ -0,0 +1,39 @@
+0 info it worked if it ends with ok
+1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'install' ]
+2 info using npm@3.10.10
+3 info using node@v6.9.5
+4 silly loadCurrentTree Starting
+5 silly install loadCurrentTree
+6 silly install readLocalPackageData
+7 silly rollbackFailedOptional Starting
+8 silly rollbackFailedOptional Finishing
+9 silly runTopLevelLifecycles Finishing
+10 silly install printInstalled
+11 verbose stack Error: Failed to parse json
+11 verbose stack Trailing comma in object at 9:3
+11 verbose stack },
+11 verbose stack ^
+11 verbose stack at parseError (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:390:11)
+11 verbose stack at parseJson (/usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:79:23)
+11 verbose stack at /usr/local/lib/node_modules/npm/node_modules/read-package-json/read-json.js:48:5
+11 verbose stack at /usr/local/lib/node_modules/npm/node_modules/graceful-fs/graceful-fs.js:78:16
+11 verbose stack at tryToString (fs.js:455:3)
+11 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:442:12)
+12 verbose cwd /Users/carlyse.jordan/TIYDC/wk5-day3/thoughter
+13 error Darwin 15.6.0
+14 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "install"
+15 error node v6.9.5
+16 error npm v3.10.10
+17 error file /Users/carlyse.jordan/TIYDC/wk5-day3/thoughter/package.json
+18 error code EJSONPARSE
+19 error Failed to parse json
+19 error Trailing comma in object at 9:3
+19 error },
+19 error ^
+20 error File: /Users/carlyse.jordan/TIYDC/wk5-day3/thoughter/package.json
+21 error Failed to parse package.json data.
+21 error package.json must be actual JSON, not just JavaScript.
+21 error
+21 error This is not a bug in npm.
+21 error Tell the package author to fix their package.json file. JSON.parse
+22 verbose exit [ 1, true ]
diff --git a/package.json b/package.json
new file mode 100644
index 0000000..6f7a6bb
--- /dev/null
+++ b/package.json
@@ -0,0 +1,35 @@
+{
+ "name": "wk5-day3",
+ "version": "1.0.0",
+ "description": "this is code for homework",
+ "main": "src/js/recent-thoughts.js",
+ "dependencies": {
+ "chai": "^3.5.0",
+ "karma": "^1.5.0",
+ },
+ "devDependencies": {
+ "chai": "^3.5.0",
+ "grunt": "^1.0.1",
+ "grunt-contrib-clean": "^1.0.0",
+ "grunt-contrib-copy": "^1.0.0",
+ "grunt-contrib-jshint": "^1.1.0",
+ "grunt-contrib-sass": "^1.0.0",
+ "jquery": "^3.2.0",
+ "karma": "^1.5.0",
+ "load-grunt-tasks": "^3.5.2",
+ "mocha": "^3.2.0",
+ },
+ "scripts": {
+ "test": "karma start thoughter.conf.js"
+ },
+ "author": "Carlyse Jordan",
+ "license": "ISC",
+ "repository": {
+ "type": "git",
+ "url": "git+https://github.com/Carlysej89/thoughter.git"
+ },
+ "bugs": {
+ "url": "https://github.com/Carlysej89/thoughter/issues"
+ },
+ "homepage": "https://github.com/Carlysej89/thoughter#readme"
+}
diff --git a/src/index.html b/src/index.html
new file mode 100644
index 0000000..d257fa8
--- /dev/null
+++ b/src/index.html
@@ -0,0 +1,21 @@
+
+
+
+
+ Thoughter
+
+
+
+
+
+
+
+
Thoughter
+
+
+
+
+
+
+
+
diff --git a/src/js/new-thought.js b/src/js/new-thought.js
new file mode 100644
index 0000000..f56e972
--- /dev/null
+++ b/src/js/new-thought.js
@@ -0,0 +1,36 @@
+(function() {
+
+ window.thoughter = window.thoughter || {};
+
+ /**
+ * Creates a new thought with the given text
+ *
+ * @param {String} text The text to use for the thought - this is REQUIRED!
+ * @return {Promise} The resolved promise will have the new thought data object in it
+ */
+ window.thoughter.createThought = function createThought(text) {
+ if (typeof(text) !== 'string' || !text.length) {
+ return Promise.reject('Please provide text for this new thought');
+ }
+
+ return fetch(
+ 'http://thoughter.herokuapp.com/api/Thoughts',
+ {
+ method: 'post',
+ headers: {
+ 'Content-Type': 'application/json'
+ },
+ body: JSON.stringify({ content: text })
+ }
+ )
+ .then(function handleResponse(res) {
+ if (res.status > 299) {
+ console.error('Looks like a bad status code:', res.status);
+ return Promise.reject('Sorry, but there was a problem with your request.');
+ } else {
+ return res.json()
+ }
+ });
+ };
+
+})();
diff --git a/src/js/recent-thoughts.js b/src/js/recent-thoughts.js
index c548e79..4a446ef 100644
--- a/src/js/recent-thoughts.js
+++ b/src/js/recent-thoughts.js
@@ -10,50 +10,61 @@
* @return {void}
*/
window.thoughter.showRecent = function showRecent(thoughts = []) {
+ // this is creating a function (showRecent)which takes an arg (thought = [])
if (!Array.isArray(thoughts)) {
+ //if (thoughts) is not an array return nothing,
return;
}
- recent = document.querySelector('.recent');
- thoughts.forEach(function showThought(thought) {
+ let recent = document.querySelector('.recent');
+ //selecting an element with the class name of recent and defining recent
+ thoughts.forEach(function showThought(thoughts) {
+ //for each object in the array called thoughts
if (!thought.content || !thought.createTime || !thought.id) {
+ //if the thought has no content or createTime or an id we don't want it, so we return
return;
}
let thoughtUI = document.createElement('article');
+ //creating an element (article) while setting it to a variable
thoughtUI.classList.add('panel');
+ //adding the class panel to the article 'thoughtUI'
thoughtUI.classList.add('panel-info');
+ //adding class panel-info to the article 'thoughtUI'
thoughtUI.setAttribute('id', 'thought-' + thought.id);
+ //setting an id to thoughtUI
thoughtUI.innerHTML = `Posted ${thoughts.createTime}
${thought.content}
`;
+ //adding HTML to the article
recent.appendChild(thoughtUI);
+ //adding the recent class to the article thoughtUI
});
};
- /**
- * Retrieves the most recent thoughts, using the provided count as the limit
- *
- * @param {Number} count How many thoughts to limit to, must be a positive number (defaults to 10)
- * @return {Promise} The resolved promise will have the data array as the argument
- */
- window.thoughter.getRecent = function getRecent(count = 10) {
- if (typeof(count) !== 'number' || count < 1) {
- return Promise.reject('Sorry, but the count must be a positive number');
- }
-
- return fetch(
- 'http://thoughter.herokuapp.com/api/Thoughts?filter={"order":"createTime DESC","limit":' + count + '}'
- )
- .then(function handleResponse(res) {
- if (res.status > 299) {
- console.error('Looks like a bad status code:', res.status);
- return Promise.reject('Sorry, but there was a problem with your request.');
- } else {
- return res.json();
- }
- });
- };
+ // /**
+ // * Retrieves the most recent thoughts, using the provided count as the limit
+ // *
+ // * @param {Number} count How many thoughts to limit to, must be a positive number (defaults to 10)
+ // * @return {Promise} The resolved promise will have the data array as the argument
+ // */
+ // window.thoughter.getRecent = function getRecent(count = 10) {
+ // if (typeof(count) !== 'number' || count < 1) {
+ // return Promise.reject('Sorry, but the count must be a positive number');
+ // }
+ //
+ // return fetch(
+ // 'http://thoughter.herokuapp.com/api/Thoughts?filter={"order":"createTime DESC","limit":' + count + '}'
+ // )
+ // .then(function handleResponse(res) {
+ // if (res.status > 299) {
+ // console.error('Looks like a bad status code:', res.status);
+ // return Promise.reject('Sorry, but there was a problem with your request.');
+ // } else {
+ // return res.json();
+ // }
+ // });
+ // };
})();
diff --git a/src/recent-thoughts.js b/src/recent-thoughts.js
new file mode 100644
index 0000000..ed6a2d7
--- /dev/null
+++ b/src/recent-thoughts.js
@@ -0,0 +1,70 @@
+(function() {
+ 'use strict';
+
+ window.thoughter = window.thoughter || {};
+
+ /**
+ * Shows the provided thought data on the page in the `.recent` element
+ *
+ * @param {Array} thoughts The array of thought objects to display
+ * @return {void}
+ */
+ window.thoughter.showRecent = function showRecent(thoughts = []) {
+ // this is creating a function (showRecent)which takes an arg (thought = [])
+ if (!Array.isArray(thoughts)) {
+ //if (thoughts) is not an array return nothing,
+ return;
+ }
+
+ let recent = document.querySelector('.recent');
+ //selecting an element with the class name of recent and defining recent
+ thoughts.forEach(function showThought(thoughts) {
+ //for each object in the array called thoughts
+ if (!thought.content || !thought.createTime || !thought.id) {
+ //if the thought has no content or createTime or an id we don't want it, so we return
+ return;
+ }
+
+ let thoughtUI = document.createElement('article');
+ //creating an element (article) while setting it to a variable
+ thoughtUI.classList.add('panel');
+ //adding the class panel to the article 'thoughtUI'
+ thoughtUI.classList.add('panel-info');
+ //adding class panel-info to the article 'thoughtUI'
+ thoughtUI.setAttribute('id', 'thought-' + thought.id);
+ //setting an id to thoughtUI
+ thoughtUI.innerHTML = `Posted ${thoughts.createTime}
+
+
${thought.content}
+ `;
+ //adding HTML to the article
+ recent.appendChild(thoughtUI);
+ //adding the recent class to the article thoughtUI
+ });
+ };
+
+ // /**
+ // * Retrieves the most recent thoughts, using the provided count as the limit
+ // *
+ // * @param {Number} count How many thoughts to limit to, must be a positive number (defaults to 10)
+ // * @return {Promise} The resolved promise will have the data array as the argument
+ // */
+ // window.thoughter.getRecent = function getRecent(count = 10) {
+ // if (typeof(count) !== 'number' || count < 1) {
+ // return Promise.reject('Sorry, but the count must be a positive number');
+ // }
+ //
+ // return fetch(
+ // 'http://thoughter.herokuapp.com/api/Thoughts?filter={"order":"createTime DESC","limit":' + count + '}'
+ // )
+ // .then(function handleResponse(res) {
+ // if (res.status > 299) {
+ // console.error('Looks like a bad status code:', res.status);
+ // return Promise.reject('Sorry, but there was a problem with your request.');
+ // } else {
+ // return res.json();
+ // }
+ // });
+ // };
+
+})();
diff --git a/src/sass/header.scss b/src/sass/header.scss
new file mode 100644
index 0000000..aed64e2
--- /dev/null
+++ b/src/sass/header.scss
@@ -0,0 +1,10 @@
+
+header {
+ border-bottom: $themeBorder;
+
+ h1 {
+ font-size: $topHeaderFontSize;
+ font-weight: bold;
+ margin-left: $topHeaderShift;
+ }
+}
diff --git a/src/sass/login.scss b/src/sass/login.scss
new file mode 100644
index 0000000..2a0f74b
--- /dev/null
+++ b/src/sass/login.scss
@@ -0,0 +1,7 @@
+
+.login {
+ form {
+ width: $loginWidth;
+ margin: 0 auto;
+ }
+}
diff --git a/src/sass/main.scss b/src/sass/main.scss
new file mode 100644
index 0000000..c915712
--- /dev/null
+++ b/src/sass/main.scss
@@ -0,0 +1,6 @@
+
+@import 'variables';
+@import 'header';
+@import 'login';
+//@import 'new-thought';
+@import 'recent';
diff --git a/src/sass/recent.scss b/src/sass/recent.scss
new file mode 100644
index 0000000..938e465
--- /dev/null
+++ b/src/sass/recent.scss
@@ -0,0 +1,10 @@
+
+.recent {
+ width: $recentContainerWidth;
+ margin: 0 auto;
+ display: flex;
+
+ article {
+ flex: 0 0 calc((100% / $thoughtColumns) - $thoughtMargin);
+ }
+}
diff --git a/src/sass/variables.scss b/src/sass/variables.scss
new file mode 100644
index 0000000..85ac3f8
--- /dev/null
+++ b/src/sass/variables.scss
@@ -0,0 +1,11 @@
+
+$themeFontColor: #222222;
+$themeBorder: 1px solid #99bbff;
+$topHeaderFontSize: 1.2em;
+$topHeaderShift: 5em;
+
+$loginWidth: 60%;
+
+$recentContainerWidth: 90%;
+$thoughtColumns: 2;
+$thoughtMargin: 2em;
diff --git a/src/specs/thoughter.specs.js b/src/specs/thoughter.specs.js
new file mode 100644
index 0000000..658daba
--- /dev/null
+++ b/src/specs/thoughter.specs.js
@@ -0,0 +1,44 @@
+(function() {
+ 'use strict';
+ let expect = chai.expect;
+
+ describe('test run', function(){
+ it('should be true', function(){
+ expect(true).to.be.true;
+ });
+ describe('recent module', function(){
+ describe('show recent function', function(){
+ beforeEach(function(){
+ // I need to add an element with a class of recent
+ let recentTag = document.createElement('main');
+ recentTag.className = 'recent';
+ document.querySelector('body').appendChild(recentTag);
+ });
+
+ afterEach(function(){
+
+ let recentTag = document.querySelector('main');
+ recentTag.className = 'recent';
+ recentTag.parentNode.removeChild(recentTag);
+
+ });
+ it('should be a function', function(){
+ expect(window.thoughter.showRecent).to.be.a('function');
+
+ });
+ it('should check for all the properties in each array', function(){
+ window.thoughter.showRecent([
+ {
+ content: '',
+ createTime: '',
+ id: ' '
+ }
+ ]);
+ let recent = document.querySelectorAll('main.recent article');
+ expect(recent.length).to.equal(1);
+ });
+ });
+
+ });
+ });
+}());
diff --git a/thoughter.conf.js b/thoughter.conf.js
new file mode 100644
index 0000000..9a171b7
--- /dev/null
+++ b/thoughter.conf.js
@@ -0,0 +1,16 @@
+module.exports = function karmaConfig( config ){
+ config.set({
+ // Karma will inject the mocha and chai JS files into its test runner HTMl
+
+ frameworks: ['mocha', 'chai'],
+ browsers: ['Chrome'],
+ singleRun: true,
+ files: [
+ 'src/**/*.js',
+ //globbing pattern - look an the src/ directory and ANY subdirectory
+ //for ANY file that ends in .js
+ 'node_modules/sinon/pkg/sinon-2.0.0.js',
+ 'tests/specs/**/*.js'
+ ]
+ });
+};