├── .gitignore
├── .meteor
├── .finished-upgraders
├── .gitignore
├── .id
├── packages
├── platforms
├── release
└── versions
├── LICENSE
├── README.md
├── client
├── main.coffee
├── main.css
└── main.jade
├── collections
└── nodes.coffee
├── package.json
├── packages
└── meteor-template2
│ ├── .gitignore
│ ├── LICENSE
│ ├── README.md
│ ├── package.js
│ └── src
│ ├── _export.coffee
│ ├── model-map.coffee
│ ├── reactive-object.js
│ └── template2.coffee
└── server
└── main.js
/.gitignore:
--------------------------------------------------------------------------------
1 | node_modules/
2 | packages/meteor-template-two-way-binding
3 |
--------------------------------------------------------------------------------
/.meteor/.finished-upgraders:
--------------------------------------------------------------------------------
1 | # This file contains information which helps Meteor properly upgrade your
2 | # app when you run 'meteor update'. You should check it into version control
3 | # with your project.
4 |
5 | notices-for-0.9.0
6 | notices-for-0.9.1
7 | 0.9.4-platform-file
8 | notices-for-facebook-graph-api-2
9 | 1.2.0-standard-minifiers-package
10 | 1.2.0-meteor-platform-split
11 | 1.2.0-cordova-changes
12 | 1.2.0-breaking-changes
13 | 1.3.0-split-minifiers-package
14 |
--------------------------------------------------------------------------------
/.meteor/.gitignore:
--------------------------------------------------------------------------------
1 | local
2 |
--------------------------------------------------------------------------------
/.meteor/.id:
--------------------------------------------------------------------------------
1 | # This file contains a token that is unique to your project.
2 | # Check it into your repository along with the rest of this directory.
3 | # It can be used for purposes such as:
4 | # - ensuring you don't accidentally deploy one app on top of another
5 | # - providing package authors with aggregated statistics
6 |
7 | 1ltrk781ii5t2u1jtq24h
8 |
--------------------------------------------------------------------------------
/.meteor/packages:
--------------------------------------------------------------------------------
1 | # Meteor packages used by this project, one per line.
2 | # Check this file (and the other files in this directory) into your repository.
3 | #
4 | # 'meteor add' and 'meteor remove' will edit this file for you,
5 | # but you can also edit it by hand.
6 |
7 | meteor-base # Packages every Meteor app needs to have
8 | mobile-experience # Packages for a great mobile UX
9 | mongo # The database Meteor supports right now
10 | blaze-html-templates # Compile .html files into Meteor Blaze views
11 | reactive-var # Reactive variable for tracker
12 | jquery # Helpful client-side library
13 | tracker # Meteor's client-side reactive programming library
14 |
15 | standard-minifier-css # CSS minifier run for production mode
16 | standard-minifier-js # JS minifier run for production mode
17 | es5-shim # ECMAScript 5 compatibility for older browsers.
18 | ecmascript # Enable ECMAScript2015+ syntax in app code
19 |
20 | autopublish # Publish all data to the clients (for prototyping)
21 | insecure # Allow all DB writes from clients (for prototyping)
22 |
23 | coffeescript
24 | mquandalle:jade
25 | aldeed:simple-schema
26 | aldeed:collection2
27 | comerc:template2
28 |
29 | # moberegger:validated-template
30 | # voidale:helpers-everywhere
31 | # useful:blaze-state
32 | # ouk:template-destruct
33 | # mpowaga:template-schema
34 | # themeteorites:blaze-magic-events
35 | # useful:forms
36 | # comerc:autoform-fixtures
37 |
--------------------------------------------------------------------------------
/.meteor/platforms:
--------------------------------------------------------------------------------
1 | server
2 | browser
3 |
--------------------------------------------------------------------------------
/.meteor/release:
--------------------------------------------------------------------------------
1 | METEOR@1.3.2.4
2 |
--------------------------------------------------------------------------------
/.meteor/versions:
--------------------------------------------------------------------------------
1 | aldeed:collection2@2.9.1
2 | aldeed:collection2-core@1.1.1
3 | aldeed:schema-deny@1.0.1
4 | aldeed:schema-index@1.0.1
5 | aldeed:simple-schema@1.5.3
6 | allow-deny@1.0.4
7 | autopublish@1.0.7
8 | autoupdate@1.2.9
9 | babel-compiler@6.6.4
10 | babel-runtime@0.1.8
11 | base64@1.0.8
12 | binary-heap@1.0.8
13 | blaze@2.1.7
14 | blaze-html-templates@1.0.4
15 | blaze-tools@1.0.8
16 | boilerplate-generator@1.0.8
17 | caching-compiler@1.0.4
18 | caching-html-compiler@1.0.6
19 | callback-hook@1.0.8
20 | check@1.2.1
21 | coffeescript@1.0.17
22 | comerc:template-two-way-binding@1.6.1
23 | comerc:template2@1.5.3
24 | ddp@1.2.5
25 | ddp-client@1.2.7
26 | ddp-common@1.2.5
27 | ddp-server@1.2.6
28 | deps@1.0.12
29 | diff-sequence@1.0.5
30 | ecmascript@0.4.3
31 | ecmascript-runtime@0.2.10
32 | ejson@1.0.11
33 | es5-shim@4.5.10
34 | fastclick@1.0.11
35 | geojson-utils@1.0.8
36 | hot-code-push@1.0.4
37 | html-tools@1.0.9
38 | htmljs@1.0.9
39 | http@1.1.5
40 | id-map@1.0.7
41 | insecure@1.0.7
42 | jquery@1.11.8
43 | launch-screen@1.0.11
44 | livedata@1.0.18
45 | logging@1.0.12
46 | mdg:validation-error@0.2.0
47 | meteor@1.1.14
48 | meteor-base@1.0.4
49 | minifier-css@1.1.11
50 | minifier-js@1.1.11
51 | minifiers@1.1.7
52 | minimongo@1.0.16
53 | mobile-experience@1.0.4
54 | mobile-status-bar@1.0.12
55 | modules@0.6.1
56 | modules-runtime@0.6.3
57 | mongo@1.1.7
58 | mongo-id@1.0.4
59 | mquandalle:jade@0.4.9
60 | mquandalle:jade-compiler@0.4.5
61 | npm-mongo@1.4.43
62 | observe-sequence@1.0.11
63 | ordered-dict@1.0.7
64 | promise@0.6.7
65 | raix:eventemitter@0.1.3
66 | random@1.0.9
67 | reactive-var@1.0.9
68 | reload@1.1.8
69 | retry@1.0.7
70 | routepolicy@1.0.10
71 | spacebars@1.0.11
72 | spacebars-compiler@1.0.11
73 | standard-minifier-css@1.0.6
74 | standard-minifier-js@1.0.6
75 | templating@1.1.9
76 | templating-tools@1.0.4
77 | tracker@1.0.13
78 | ui@1.0.11
79 | underscore@1.0.8
80 | url@1.0.9
81 | webapp@1.2.8
82 | webapp-hashing@1.0.9
83 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | The MIT License (MIT)
2 |
3 | Copyright (c) 2016 comerc
4 |
5 | Permission is hereby granted, free of charge, to any person obtaining a copy
6 | of this software and associated documentation files (the "Software"), to deal
7 | in the Software without restriction, including without limitation the rights
8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 | copies of the Software, and to permit persons to whom the Software is
10 | furnished to do so, subject to the following conditions:
11 |
12 | The above copyright notice and this permission notice shall be included in all
13 | copies or substantial portions of the Software.
14 |
15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 | SOFTWARE.
22 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Template2
2 |
3 | `comerc:template2`
4 |
5 | [MVVM](https://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93viewmodel) for Meteor with [Two-Way Binding](https://github.com/comerc/meteor-template-two-way-binding) via [Model Schema](https://github.com/aldeed/meteor-simple-schema).
6 |
7 | ## Table of Contents
8 |
9 |
10 |
11 | **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
12 |
13 | - [Intro](#intro)
14 | - [Key features](#key-features)
15 | - [How to run Demo](#how-to-run-demo)
16 | - [Installation](#installation)
17 | - [Basic Usage](#basic-usage)
18 | - [API](#api)
19 | - [`onCreated`, `onRendered`, `onDestroyed`](#oncreated-onrendered-ondestroyed)
20 | - [`events`, `helpers`](#events-helpers)
21 | - [`propsSchema: { clean: Function, validate: Function }`](#propsschema--clean-function-validate-function-)
22 | - [`modelSchema: { schema: Function, newContext: Function }`](#modelschema--schema-function-newcontext-function-)
23 | - [`states: { myProperty: defaultValue, … }`](#states--myproperty-defaultvalue-%E2%80%A6-)
24 | - [`viewDoc(callback)`](#viewdoccallback)
25 | - [`modelDoc(doc)`](#modeldocdoc)
26 | - [Two-Way Binding features](#two-way-binding-features)
27 | - [Configuration](#configuration)
28 | - [`Template2Config.propsClean`](#template2configpropsclean)
29 | - [`Template2Config.modelClean`](#template2configmodelclean)
30 | - [TODO](#todo)
31 | - [Inspired by](#inspired-by)
32 | - [License](#license)
33 |
34 |
35 |
36 | ## Intro
37 |
38 | Fork of TemplateController ([what difference](https://github.com/meteor-space/template-controller/issues/35)):
39 |
40 | >**Supports the best practices of writing Blaze templates**
41 | >
42 | >**Blaze is awesome** but writing the Js part of templates always
43 | felt a bit awkward. This package just provides a very thin layer of syntactic
44 | sugar on top of the standard API, so you can follow best practices outlined
45 | in the [Blaze guide](http://guide.meteor.com/blaze.html#reusable-components)
46 | more easily.
47 |
48 | **Now you can turn this:**
49 |
50 | ```handlebars
51 | You have clicked the button {{counter}} times.
52 |
53 | ```
54 |
55 | ```javascript
56 | Template.hello.onCreated(function helloOnCreated() {
57 | // counter starts at 0
58 | this.counter = new ReactiveVar(0);
59 | });
60 |
61 | Template.hello.helpers({
62 | counter() {
63 | return Template.instance().counter.get();
64 | },
65 | });
66 |
67 | Template.hello.events({
68 | 'click button'(event, instance) {
69 | // increment the counter when button is clicked
70 | instance.counter.set(instance.counter.get() + 1);
71 | },
72 | });
73 | ```
74 |
75 | **into that:**
76 |
77 | ```handlebars
78 | You have clicked the button {{state.counter}} times.
79 |
80 | ```
81 |
82 | ```javascript
83 | Template2('hello', {
84 | states: {
85 | counter: 0 // default value
86 | },
87 | events: {
88 | 'click button'() {
89 | // increment the counter when button is clicked
90 | this.state.counter += 1;
91 | }
92 | }
93 | });
94 | ```
95 |
96 | >Yeah i have used [ViewModel](http://viewmodel.org) before – it's also nice, and there are also [Blaze Components](https://github.com/peerlibrary/meteor-blaze-components). My only "problem" with these existing packages is that they introduce new concepts on top of the standard Blaze api. I just wanted less boilerplate and that best practices like setting up ReactiveVars, validating properties passed to a template or accessing Template.instance() become a no-brainer for the whole team.
97 | >
98 | >The idea for this package came up during a Meteor training with some Devs where realized how complicated it is to explain the best practices with Blaze and that they had a ton of questions like "how can i access the template instance in helpers / event handlers" or "how does a template manage state" – which is so basic that it should be the easiest thing in the world.
99 |
100 | ## Key features
101 | - Compatible with Blaze Template - we love it.
102 | - Minimum changes for migration your great project to Template2.
103 | - One time declaration of variables to Model via `` attribute.
104 | - Validate input data and get doc for writing to Model without coding.
105 | - Support of [SimpleSchema](https://github.com/aldeed/meteor-simple-schema), may be extended for support any other Model ([Astronomy](https://github.com/jagi/meteor-astronomy) etc.)
106 | - Usage of Two-Way Binding Features without Model.
107 |
108 | ## How to run Demo
109 |
110 | ```
111 | $ git clone https://github.com/comerc/meteor-template2.git
112 | $ cd meteor-template2
113 | $ meteor
114 | ```
115 |
116 | ...then [http://localhost:3000](http://localhost:3000)
117 |
118 | ## Installation
119 |
120 | In your Meteor app directory, enter:
121 |
122 | ```
123 | $ meteor add comerc:template2
124 | ```
125 |
126 | ## Basic Usage
127 |
128 | ```
129 | $ meteor add aldeed:simple-schema
130 | $ meteor add aldeed:collection2
131 | ```
132 |
133 | ```javascript
134 | Posts = new Mongo.Collection('posts');
135 |
136 | PostSchema = new SimpleSchema({
137 | myValue: {
138 | type: String,
139 | min: 3,
140 | defaultValue: '777'
141 | }
142 | });
143 |
144 | Posts.attachSchema(PostSchema);
145 | ```
146 |
147 | ```handlebars
148 |