Skip to content

Commit

Permalink
Merge pull request GrapesJS#12 from artf/dev
Browse files Browse the repository at this point in the history
Updates from dev
  • Loading branch information
artf committed Feb 25, 2016
2 parents 6f3d629 + e6c305f commit f526953
Show file tree
Hide file tree
Showing 14 changed files with 187 additions and 61 deletions.
53 changes: 40 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
# [GrapesJS](http://grapesjs.com) [![Build Status](https://travis-ci.org/artf/grapesjs.svg?branch=master)](https://travis-ci.org/artf/grapesjs)
# [GrapesJS](http://grapesjs.com)

[![Build Status](https://travis-ci.org/artf/grapesjs.svg?branch=master)](https://travis-ci.org/artf/grapesjs)

<p align="center"><img src="http://grapesjs.com/img/grapesjs-demo-template2.jpg" alt="GrapesJS" width="500" align="center"/></p>

GrapesJS is a free and open source Web Template Editor for building HTML templates to be used inside sites, webapps, newsletters or anything else related with HTML.
Be aware that is not a 'Website Builder' but a tool to create only structure and containers for contents. The great thing about GrapesJS is that you can customize it, extend it or even integrate it with your applications.
Mainly GrapesJS was designed to be used inside a [CMS] to speed up creation of dynamic templates. To better understand this concept check the image below


<p align="center"><img src="http://grapesjs.com/img/gjs-concept.png" alt="GrapesJS - Style Manager" height="400" align="center"/></p>


Try it here: http://grapesjs.com/demo.html
Generally any 'template system', that you can find in various applications like CMS, is composed by the **structure** (HTML), **style** (CSS) and **variables**, which are then replaced with other templates and contents on server-side and rendered soon on client.

This demo shows an example of what is possible to achieve: http://grapesjs.com/demo.html

### Features

## Features

* Style Manager, for component styling<br/>
<p align="center"><img src="http://grapesjs.com/img/grapesjs-style-manager.png" alt="GrapesJS - Style Manager" height="400" align="center"/></p>
Expand All @@ -27,12 +35,12 @@ Try it here: http://grapesjs.com/demo.html
* Default built-in commands (basically for creating and managing different components)


### Installation
## Installation

You can get GrapesJS with `bower install grapesjs` or via `git clone https://github.com/artf/grapesjs.git` to directly use it. For development purpose you should follow instructions below.


### Development
## Development

GrapesJS uses [RequireJS](http://requirejs.org/) to organize its files inside `src` folder and [Grunt](http://gruntjs.com/) for build them to `dist`

Expand Down Expand Up @@ -67,7 +75,8 @@ Tests are already available inside browser on `localhost:8000/test`
If [Grunt](http://gruntjs.com/) is already installed globally you could change the port by using `grunt dev --port 9000`


### Usage
## Usage

JQuery is the only hard dependency so you have to include it before use GrapesJS.

```html
Expand All @@ -91,8 +100,10 @@ After that include scripts from GrapesJS with all your configurations and render
Unfortunately with the configuration above you wouldn't see a lot. This because GrapesJS it self is simply empty, adding panels, buttons and other stuff will be your job (actually it's not empty but you need buttons to show them up).
The section below will explain some basic configurations but for a more practical example I suggest to look up the code inside this demo: http://grapesjs.com/demo.html

Documentation is under construction here: [wiki]


### Configuration
## Configuration

For now I only show up some general settings, for more details check source or demo. Examples will be available soon

Expand Down Expand Up @@ -142,12 +153,12 @@ var config = {
```


### API
## API

At the moment `render()` is the only available method but others will be public very soon...


### Testing
## Testing

**ATTENTION: tests are pretty far away from being complete**

Expand All @@ -157,7 +168,14 @@ Tests are run by [PhantomJS](http://phantomjs.org/) using [Mocha](https://mochaj
$ npm run test
```

### Acknowledgements
## Todos before beta release

* **Class Manager** (*in development*) - Ability to assign different classes to components and style them (beacause CSS with only ids is pretty much a pain)
* **Breakpoint Manager** - Resize canvas according to breakpoints established by user (in simple terms, for responsive templates). Will be put into development immediately after Class Manager
* **Style Manager improvements** - Mainly `stack` type is not yet complete


## Acknowledgements

GrapesJS is built on top of this amazing open source projects:

Expand All @@ -169,7 +187,14 @@ GrapesJS is built on top of this amazing open source projects:
* [FontAwesome] - the iconic font and CSS framework


### Contributing
## Support

A star/fork is already a huge motivational support and I'd like to thank all of you for that, but if you want to contribute the project economically and you have this possibility you could use the link below :heart:

[![PayPalMe](http://grapesjs.com/img/ppme.png)](https://paypal.me/grapesjs)


## Contributing

Any kind of help is welcome. At the moment there is no generic guidelines so use usual pull requests and push to `dev` branch

Expand All @@ -184,4 +209,6 @@ BSD 3-clause
[Keymaster]: <https://github.com/madrobby/keymaster>
[CodeMirror]: <http://codemirror.net/>
[Spectrum]: <https://github.com/bgrins/spectrum>
[FontAwesome]: <https://fortawesome.github.io/Font-Awesome/>
[FontAwesome]: <https://fortawesome.github.io/Font-Awesome/>
[wiki]: <https://github.com/artf/grapesjs/wiki>
[CMS]: <https://it.wikipedia.org/wiki/Content_management_system>
2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grapesjs",
"description": "Open source Web Template Editor",
"version": "0.1.1",
"version": "0.1.2",
"author": "Artur Arseniev",
"homepage": "http://grapesjs.com",
"main": [
Expand Down
2 changes: 1 addition & 1 deletion dist/css/grapes.min.css

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions dist/grapes.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "grapesjs",
"description": "Open source Web Template Editor",
"version": "0.1.1",
"version": "0.1.2",
"author": "Artur Arseniev",
"license": "BSD-3-Clause",
"homepage": "http://grapesjs.com",
Expand Down
1 change: 1 addition & 0 deletions src/class_manager/template/classTag.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<%= label %> <span id="<%= pfx %>close">&Cross;</span>
30 changes: 27 additions & 3 deletions src/class_manager/view/ClassTagView.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,43 @@
define(['backbone'],
function (Backbone) {
define(['backbone', 'text!./../template/classTag.html'],
function (Backbone, tagTemplate) {
/**
* @class ClassTagView
* */
return Backbone.View.extend({

template: _.template(tagTemplate),

events: {},

initialize: function(o) {
this.config = o.config || {};
this.pfx = this.config.stylePrefix;
this.className = this.pfx + 'tag';
this.closeId = this.pfx + 'close';
this.events['click #' + this.closeId ] = 'removeTag';

this.delegateEvents();
},

/**
* Remove tag from the selected component
* @param {Object} e
*/
removeTag: function(e){
var comp = this.config.target.get('selectedComponent');

if(comp)
comp.get('classes').remove(this.model);

this.remove();
},

/** @inheritdoc */
render : function(){
this.$el.html(this.model.get('name')+': ' + this.model.get('label'));
this.$el.html( this.template({
label: this.model.get('label'),
pfx: this.pfx,
}));
this.$el.attr('class', this.className);
return this;
},
Expand Down
16 changes: 12 additions & 4 deletions src/class_manager/view/ClassTagsView.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ define(['backbone', 'text!./../template/classTags.html', './ClassTagView'],
this.addBtnId = this.pfx + 'add-tag';
this.newInputId = this.pfx + 'new';
this.events['click #' + this.addBtnId] = 'startNewTag';
this.events['blur #'+this.newInputId] = 'endNewTag';
this.events['keyup #'+this.newInputId] = 'onInputKeyUp';
this.events['blur #' + this.newInputId] = 'endNewTag';
this.events['keyup #' + this.newInputId] = 'onInputKeyUp';

this.target = this.config.target;

Expand Down Expand Up @@ -74,6 +74,9 @@ define(['backbone', 'text!./../template/classTags.html', './ClassTagView'],
* @param {Object} e
*/
componentChanged: function(e){
this.compTarget = this.target.get('selectedComponent');
var models = this.compTarget ? this.compTarget.get('classes').models : [];
this.collection.reset(models);
},

/**
Expand Down Expand Up @@ -102,7 +105,10 @@ define(['backbone', 'text!./../template/classTags.html', './ClassTagView'],
if(this.target){
var cm = this.target.get('ClassManager');
var model = cm.addClass(name);
console.log(model);

if(this.compTarget)
this.compTarget.get('classes').add(model);

}
this.endNewTag();
},
Expand Down Expand Up @@ -142,7 +148,9 @@ define(['backbone', 'text!./../template/classTags.html', './ClassTagView'],
this.addToClasses(model, fragment);
},this);

this.$classes.empty().append(fragment);
if(this.$classes)
this.$classes.empty().append(fragment);

return this;
},

Expand Down
25 changes: 17 additions & 8 deletions src/code_manager/model/JsonGenerator.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
define(['backbone'],
define(['backbone'],
function (Backbone) {
/**
* @class JsonGenerator
* */
return Backbone.Model.extend({

/** @inheritdoc */
getId : function()
{
return 'json';
return 'json';
},

/** @inheritdoc */
build: function(model)
{
var json = model.toJSON();

this.beforeEach(json);

// Avoid jshint 'loopfunc' error
_.each(json,function(v, attr){
var obj = json[attr];
Expand All @@ -30,11 +31,19 @@ define(['backbone'],
}, this);
}
}

}, this);

return json;
},


/**
* Execute on each object
* @param {Object} obj
*/
beforeEach: function(obj) {
delete obj.status;
}

});
});
19 changes: 14 additions & 5 deletions src/dom_components/model/Component.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
define(['backbone','./Components'],
function (Backbone, Components) {
define(['backbone','./Components', 'ClassManager/model/ClassTags'],
function (Backbone, Components, ClassTags) {
/**
* @class Component
* */
Expand All @@ -25,23 +25,32 @@ define(['backbone','./Components'],
initialize: function(o) {
this.config = o || {};
this.defaultC = this.config.components || [];
this.defaultCl = this.config.classes || [];
this.components = new Components(this.defaultC);
this.set('components', this.components);
this.set('classes', new ClassTags(this.defaultCl));
},

/**
* Override original clone method
*/
clone: function()
{
var attr = _.clone(this.attributes),
comp = this.get('components');
attr.components = [];
var attr = _.clone(this.attributes),
comp = this.get('components'),
cls = this.get('classes');
attr.components = [];
attr.classes = [];
if(comp.length){
comp.each(function(md,i){
attr.components[i] = md.clone();
});
}
if(cls.length){
cls.each(function(md,i){
attr.classes[i] = md.clone();
});
}
return new this.constructor(attr);
},

Expand Down
17 changes: 13 additions & 4 deletions src/dom_components/view/ComponentView.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ define(['backbone', './ComponentsView'],
this.listenTo(this.model, 'change:style', this.updateStyle);
this.listenTo(this.model, 'change:attributes', this.updateAttributes);
this.listenTo(this.model, 'change:status', this.updateStatus);
this.listenTo(this.model.get('classes'), 'add remove change', this.updateClasses);
this.$el.data("model", this.model);
this.$el.data("model-comp", this.components);
},
Expand Down Expand Up @@ -109,12 +110,18 @@ define(['backbone', './ComponentsView'],

/**
* Update classe attribute
*
* @return void
* */
updateClasses: function(){
if(this.classe.length)
this.$el.attr('class', this.classe.join(" "));
var str = '';

this.model.get('classes').each(function(model){
str += model.get('name') + ' ';
});

this.$el.attr('class',str.trim());

// Regenerate status class
this.updateStatus();
},

/**
Expand All @@ -127,12 +134,14 @@ define(['backbone', './ComponentsView'],

render: function() {
this.updateAttributes();
this.updateClasses();
this.$el.html(this.model.get('content'));
var view = new ComponentsView({
collection : this.components,
config : this.config,
});
this.$components = view;

// With childNodes lets avoid wrapping 'div'
this.$el.append(view.render(this.$el).el.childNodes);
return this;
Expand Down
Loading

0 comments on commit f526953

Please sign in to comment.