Skip to content

Commit 9a73f1f

Browse files
committed
Massive, gross refactor - switched to CKEditor and fully implemented saving and Media library functionality
1 parent 7f5241c commit 9a73f1f

18 files changed

+465
-78
lines changed

.env.example

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
#
2+
# Asset Configuration
3+
#
4+
CONTENT_SNIPPETS_EDIT_CSS_URL=https://s3.amazonaws.com/cortex-content-snippets/content-snippets-edit.css
5+
CKEDITOR_PLUGINS_URL=http://stg.admin.cbcortex.com/ckeditor-plugins/

.gitignore

+6
Original file line numberDiff line numberDiff line change
@@ -37,3 +37,9 @@ coverage
3737
# Dependency directories
3838
node_modules
3939
bower_components
40+
41+
# Proprietary components
42+
redactor.*
43+
44+
# Sensitive Environment-Specific Data
45+
.env

README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
# Content Snippets
1+
# Content Snippets (Edit)
22

3-
A tool to enable in-page editing of elements, with an adaptable content backend. Drop this into a Web page, compose with a content adapter and credentials via a server framework of your choosing, and begin editing!
3+
A tool to enable in-page editing of elements with [Cortex](https://github.com/cortex-cms) as a backend.
44

55
### Building/Watching
66

@@ -12,6 +12,8 @@ $ npm install
1212
$ bower install
1313
```
1414

15+
You will also need to host/locate several CKEditor plugins, which should be available via any hosted Cortex instance. See `main.js` for further information.
16+
1517
Now you can build or watch the project! Built and Compiled assets will be plopped into the `dist` directory.
1618

1719
```sh
@@ -24,4 +26,4 @@ $ gulp compile
2426

2527
### Configuration
2628

27-
Coming soon..
29+
Before using or distributing `content-snippets-edit`, the `.env` file should be configured. Copy and rename the `.env.example` provided and configure to match the environment.

bower.json

+3-8
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
{
2-
"name": "content-snippets",
2+
"name": "content-snippets-edit",
33
"version": "0.0.1",
44
"ignore": [
55
"**/.*",
66
"node_modules",
77
"components"
88
],
99
"dependencies": {
10-
"riot": "~2.0.15",
11-
"q": "~1.3.0",
12-
"qajax": "[email protected]:cb-talent-development/qajax#master",
13-
"underscore": "1.8.3"
14-
},
15-
"resolutions": {
16-
"q": "~1.3.0"
10+
"materialize": "~0.97",
11+
"normalize-scss": "~3.0"
1712
}
1813
}

gulpfile.js

+32-36
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
'use strict';
22

3-
var applicationName = 'content-snippets',
3+
require('dotenv').load();
4+
var applicationName = 'content-snippets-edit',
45
basePaths = {
56
src: 'src/app/',
6-
dest: 'dist/'
7+
dest: 'dist/',
8+
bower: 'bower_components'
79
},
810
paths = {
911
scripts: {
@@ -16,10 +18,12 @@ var applicationName = 'content-snippets',
1618
}
1719
},
1820
appFiles = {
19-
styles: paths.styles.src,
20-
scripts: paths.scripts.src + '**/*.js'
21+
styles: paths.styles.src + 'main.scss',
22+
scripts: paths.scripts.src + '**/*.js',
23+
riot: '**/tags/**'
2124
},
2225
vendorFiles = {
26+
styles: 'src/vendor/**/*.css',
2327
scripts: 'src/vendor/**/*.js'
2428
},
2529
destFilenames = {
@@ -29,51 +33,43 @@ var applicationName = 'content-snippets',
2933
styleMin: applicationName + '.min.css'
3034
},
3135
gulp = require('gulp'),
32-
es = require('event-stream'),
36+
streamqueue = require('streamqueue'),
3337
bowerFiles = require('main-bower-files'),
3438
plugins = require("gulp-load-plugins")({
3539
pattern: ['gulp-*', 'gulp.*'],
3640
replaceString: /\bgulp[\-.]/
37-
});
38-
39-
var changeEvent = function (evt) {
40-
plugins.util.log('File', plugins.util.colors.cyan(evt.path.replace(new RegExp('/.*(?=/' + basePaths.src + ')/'), '')), 'was', plugins.util.colors.magenta(evt.type));
41-
};
42-
43-
var scriptsStream = function () {
44-
return gulp.src([appFiles.scripts, vendorFiles.scripts, '!**/tags/**']);
45-
};
46-
47-
var riotStream = function () {
48-
return gulp.src('**/tags/**')
49-
.pipe(plugins.riot());
50-
};
51-
52-
var bowerStream = function () {
53-
return gulp.src(bowerFiles({
41+
}),
42+
changeEvent = function (event) {
43+
plugins.util.log('File', plugins.util.colors.cyan(event.path.replace(new RegExp('/.*(?=/' + basePaths.src + ')/'), '')), 'was', plugins.util.colors.magenta(event.type));
44+
},
45+
scriptsStream = gulp.src([vendorFiles.scripts, appFiles.scripts, '!**/tags/**']),
46+
riotStream = gulp.src(appFiles.riot)
47+
.pipe(plugins.riot()),
48+
bowerStream = gulp.src(bowerFiles({
5449
filter: '**/*.js'
55-
}));
56-
};
57-
58-
gulp.task('sass', function () {
59-
return plugins.rubySass(appFiles.styles)
50+
})),
51+
sassStream = plugins.rubySass(appFiles.styles, {loadPath: basePaths.bower})
6052
.on('error', function (err) {
6153
new plugins.util.PluginError('SASS', err, {showStack: true});
62-
})
54+
}),
55+
vendorStylesStream = gulp.src(vendorFiles.styles);
56+
57+
gulp.task('styles', function () {
58+
return streamqueue({objectMode: true}, sassStream, vendorStylesStream)
6359
.pipe(plugins.concat(destFilenames.style))
6460
.pipe(plugins.autoprefixer('last 2 versions', 'safari 5', 'ie 8', 'ie 9', 'opera 12.1', 'ios 6', 'android 4', 'Firefox >= 4'))
6561
.pipe(plugins.size())
6662
.pipe(gulp.dest(paths.styles.dest));
6763
});
6864

6965
gulp.task('scripts', function () {
70-
return es.merge(scriptsStream(), riotStream(), bowerStream())
66+
return streamqueue({objectMode: true}, bowerStream, riotStream, scriptsStream)
7167
.pipe(plugins.concat(destFilenames.script))
7268
.pipe(plugins.size())
7369
.pipe(gulp.dest(paths.scripts.dest));
7470
});
7571

76-
gulp.task('minify-css', ['sass'], function () {
72+
gulp.task('minify-styles', ['styles'], function () {
7773
return gulp.src(paths.styles.dest + destFilenames.style)
7874
.pipe(plugins.combineMq())
7975
.pipe(plugins.minifyCss())
@@ -88,17 +84,17 @@ gulp.task('minify-scripts', ['scripts'], function () {
8884
.pipe(gulp.dest(paths.scripts.dest));
8985
});
9086

91-
gulp.task('build', ['sass', 'scripts']);
87+
gulp.task('build', ['styles', 'scripts']);
9288

9389
gulp.task('watch', ['build'], function () {
94-
gulp.watch(appFiles.styles + '**/*.scss', ['sass']).on('change', function (evt) {
95-
changeEvent(evt);
90+
gulp.watch([paths.styles.src + '**/*.scss', vendorFiles.styles], ['styles']).on('change', function (event) {
91+
changeEvent(event);
9692
});
97-
gulp.watch([appFiles.scripts, vendorFiles.scripts], ['scripts']).on('change', function (evt) {
98-
changeEvent(evt);
93+
gulp.watch([appFiles.scripts, vendorFiles.scripts, appFiles.riot], ['scripts']).on('change', function (event) {
94+
changeEvent(event);
9995
});
10096
});
10197

102-
gulp.task('compile', ['minify-scripts', 'minify-css']);
98+
gulp.task('compile', ['minify-scripts', 'minify-styles']);
10399

104100
gulp.task('default', ['build']);

package.json

+21-19
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,36 @@
11
{
2-
"name": "content-snippets",
2+
"name": "content-snippets-edit",
33
"version": "0.0.1",
44
"description": "A tool to enable in-page editing of elements, with an adaptable content backend",
5-
"author": "Alex Tharp <toastercup@gmail.com>",
6-
"license": "MIT",
7-
"repository": "git://github.com/toastercup/content-snippets.git",
5+
"author": "CB Content Enablement Product Team <ContentEnablementProductTeam@careerbuilder.com>",
6+
"license": "Apache-2.0",
7+
"repository": "git://github.com/cortex-cms/content-snippets-edit.git",
88
"keywords": [
99
"editable",
1010
"snippet",
1111
"cms",
12-
"content"
12+
"content",
13+
"edit"
1314
],
1415
"devDependencies": {
15-
"event-stream": "~3.3.0",
16-
"main-bower-files": "~2.7.0",
17-
"gulp": "~3.8.11",
18-
"gulp-load-plugins": "~0.10.0",
19-
"gulp-autoprefixer": "~2.2.0",
20-
"gulp-concat": "~2.5.2",
21-
"gulp-ruby-sass": "~1.0.5",
22-
"gulp-riot": "~0.2.14",
23-
"gulp-size": "~1.2.1",
24-
"gulp-util": "~3.0.4",
25-
"gulp-uglify": "~1.2.0",
16+
"gulp": "~3.9.0",
17+
"gulp-load-plugins": "~1.0.0",
18+
"gulp-autoprefixer": "~3.1.0",
19+
"gulp-concat": "~2.6.0",
20+
"gulp-ruby-sass": "~2.0.5",
21+
"gulp-riot": "~0.3.1",
22+
"gulp-size": "~2.0.0",
23+
"gulp-util": "~3.0.7",
24+
"gulp-uglify": "~1.4.2",
2625
"gulp-combine-mq": "~0.4.0",
27-
"gulp-minify-css": "~1.1.1",
26+
"gulp-minify-css": "~1.2.1",
2827
"gulp-rename": "~1.2.2",
29-
"gulp-ignore": "~1.2.1"
28+
"gulp-ignore": "~2.0.1",
29+
"main-bower-files": "~2.9.0",
30+
"streamqueue": "~1.1.1",
31+
"dotenv": "~1.2.0"
3032
},
3133
"engines": {
32-
"node": ">=0.10.0"
34+
"node": ">=4.2.1"
3335
}
3436
}

src/app/config.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
(function(global) {
2+
'use strict';
3+
4+
_.extend(global.config, {
5+
CONTENT_SNIPPETS_EDIT_CSS_URL: process.env.CONTENT_SNIPPETS_EDIT_CSS_URL,
6+
CKEDITOR_PLUGINS_URL: process.env.CKEDITOR_PLUGINS_URL
7+
});
8+
}(this));

src/app/constants.js

+11-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,16 @@
11
(function(global) {
22
'use strict';
33

4-
global.ACTIONS = {
5-
};
4+
_.extend(global.constants.ACTIONS, {
5+
MEDIAS_CHANGED: 'medias_changed',
6+
MEDIAS_NEXT: 'medias_next',
7+
MEDIAS_PREVIOUS: 'medias_previous',
8+
MEDIAS_SEARCH: 'medias_search',
9+
INSERT_MEDIA: 'insert_media'
10+
});
611

7-
global.settings = {
8-
API_ROUTES: {
9-
}
10-
};
12+
_.extend(global.constants.FRAME_ACTIONS, {
13+
GET_MEDIAS: 'get_medias',
14+
MEDIAS_DATA: 'medias_data'
15+
});
1116
}(this));

src/app/main.js

+27-6
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
11
(function(global) {
2-
var stores = {
3-
};
2+
'use strict';
43

5-
for (var k in stores) {
6-
RiotControl.addStore(stores[k]);
7-
}
4+
$('body').prepend( $('<toolbar></toolbar>') );
5+
$('body').append( $('<media-library></media-library>') );
6+
$('head').append( $('<link rel="stylesheet" type="text/css" />').attr('href', 'http://fonts.googleapis.com/css?family=Roboto:400,500,700,300,100') );
7+
$('head').append( $('<link rel="stylesheet" type="text/css" />').attr('href', 'https://fonts.googleapis.com/icon?family=Material+Icons') );
8+
$('head').append( $('<link rel="stylesheet" type="text/css" />').attr('href', config.CONTENT_SNIPPETS_EDIT_CSS_URL) );
9+
$.getScript('https://cdn.ckeditor.com/4.5.4/standard/ckeditor.js', function() {
10+
global.CKEDITOR.config.autoParagraph = false;
11+
global.CKEDITOR.config.allowedContent = true;
12+
global.CKEDITOR.plugins.addExternal( 'media-selector', global.config.CKEDITOR_PLUGINS_URL + 'media-selector/', 'plugin.js' );
13+
global.CKEDITOR.plugins.addExternal( 'sourcedialog', global.config.CKEDITOR_PLUGINS_URL + 'sourcedialog/', 'plugin.js' );
14+
global.CKEDITOR.plugins.addExternal( 'codemirror', global.config.CKEDITOR_PLUGINS_URL + 'codemirror/', 'plugin.js' );
15+
global.CKEDITOR.config.extraPlugins = 'media-selector,sourcedialog';
16+
global.CKEDITOR.config.removePlugins = 'image,sourcearea';
817

9-
global.stores = stores;
18+
var stores = {
19+
MediasStore: new MediasStore()
20+
};
1021

22+
for (var k in stores) {
23+
RiotControl.addStore(stores[k]);
24+
}
25+
26+
_.extend(global.stores, stores);
27+
28+
riot.mount('snippet');
29+
riot.mount('media-library');
30+
riot.mount('toolbar');
31+
});
1132
}(this));

src/app/sass/components/_icons.scss

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
.material-icons {
2+
font-family: 'Material Icons';
3+
font-weight: normal;
4+
font-style: normal;
5+
font-size: 24px;
6+
line-height: 1;
7+
letter-spacing: normal;
8+
text-transform: none;
9+
display: inline-block;
10+
word-wrap: normal;
11+
-moz-font-feature-settings: 'liga';
12+
-moz-osx-font-smoothing: grayscale;
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
// Materialize's Modal is terrible in the most terrible way. We should move to something else ASAP.
2+
// Also, it turns out Materialize is just poor in general.
3+
4+
.modal {
5+
width: 80%;
6+
overflow-x: hidden;
7+
z-index: 10000 !important; // Just above CKEditor
8+
9+
.modal-content {
10+
width: 100% !important;
11+
overflow-y: scroll !important;
12+
height: calc(100% - 45px) !important;
13+
}
14+
15+
.modal-footer {
16+
height: auto !important;
17+
18+
.btn-flat {
19+
margin: auto !important;
20+
}
21+
}
22+
23+
&.modal-fixed-footer {
24+
height: 80%;
25+
max-height: 80%;
26+
}
27+
}

src/app/sass/components/_reset.scss

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
* {
2+
vertical-align: baseline;
3+
font-weight: inherit;
4+
font-family: inherit;
5+
font-style: inherit;
6+
font-size: 100%;
7+
border: 0 none;
8+
outline: 0;
9+
padding: 0;
10+
margin: 0;
11+
line-height: 1.5;
12+
}

0 commit comments

Comments
 (0)