Skip to content

Commit 9b54c29

Browse files
Initial commit
0 parents  commit 9b54c29

32 files changed

+7338
-0
lines changed

.DS_Store

6 KB
Binary file not shown.

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
node_modules/
2+
build/

.idea/misc.xml

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/modules.xml

+8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/workspace.xml

+279
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

+312
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,312 @@
1+
DON'T CLONE THIS BUT USE THE DOWNLOAD OPTION TO SAVE AN ARCHIVE VERSION.
2+
3+
> This version of the blueprint uses Polymer2! Once Polymer3 and its surroundings have been matured the blueprint will be updated.
4+
5+
# Blueprint for componentized eXistdb apps
6+
7+
## What is it?
8+
9+
An 'componentized' webapp in the eXistdb context is one that uses W3C Web Components specifically using
10+
the Polymer polyfill library.
11+
12+
## What's in the box
13+
14+
* a common minimal directory structure (more dirs can be added of course)
15+
* all needed configuration files
16+
* useful development tooling (bower, gulp, Polymer CLI, Ant)
17+
18+
NOTE: the tooling seems diverse as it's using so many different tools but all have their purpose which is explained further down.
19+
It's a goal of this app template to simplify the usage of all these tools by preconfiguring them and give you the necessary information
20+
about their usage.
21+
22+
## Before you start
23+
24+
What will be needed up-front:
25+
26+
* an installation of eXistdb (3.0 or above recommended)
27+
* a nodejs installation (see below for instructions)
28+
* if using Polymer an installation of the [Polymer CLI](https://www.polymer-project.org/1.0/start/toolbox/set-up) (highly recommended)
29+
* Apache Ant configured
30+
31+
## Setting up a new application
32+
33+
Don't be scared by this list. It can be done in 3 minutes. Thanks to Chris Misztur there is a more visual description of the process [here](https://medium.com/@chrismisztur/exist-db-polymer-exform-client-61e58b1e4000).
34+
35+
1. download this blueprint as a zip
36+
1. unpack the zip in your favorite development folder
37+
1. this creates a folder with starts with 'exform-client-'
38+
1. rename the folder to give it your new projectname
39+
1. execute ´npm install' to install bower and gulp support. Note: do NOT bower install yet. This will be done by Polymer CLI. However if you don't intend to use that you'll have to setup bower yourself.
40+
1. execute ´ant init´ to name your new app. This will put the new name into all needed config files
41+
42+
After these steps a full deployable xar application has been created. Your projectname was filled into all relevant place to configure the app. Of course you
43+
can further refine the default controller.xql, add authentication, data and xqueries and so on.
44+
45+
46+
## Setting up Polymer
47+
48+
Note: you do NOT have to setup bower manually. This will be done by Polymer CLI automatically.
49+
50+
For Polymer development is [Polymer CLI](https://www.polymer-project.org/2.0/start/toolbox/set-up) is highly recommended
51+
and assumed to be present for the remainder of this document. Please visit the link for installation instructions.
52+
53+
Once you got that running execute these:
54+
55+
1. execute ```polymer init``` to setup for Polymer development (see also below)
56+
1. CLI will ask which kind of template shall be used. Choose one.
57+
1. CLI will ask for name and description
58+
1. CLI will ask to overwrite index.html. Use 'Y' if ´init´ was called for the first time otherwise 'n'
59+
1. CLI will ask to overwrite README.md. Choose 'n' to keep this documentation or get the Polymer generated one. (you'll likely use that for own remarks anyway later)
60+
1. You will need to manually adapt the ´<link rel="import"...´ statements in the index.html file generated. (haven't yet found a way to adapt those)
61+
62+
63+
## Where to go from here
64+
65+
After finishing the above instructions you'll have the setup completed.
66+
67+
Time to go for a test and build the xar with:
68+
69+
```ant [xar]```
70+
71+
Then:
72+
73+
1. deploy that xar into your running eXistdb instance via the packagemanager.
74+
2. open up the app. You should see a simple documentation page not saying much except everything went fine and we have our app alive.
75+
76+
From now on you might want to use ```gulp watch```to automatically sync your local changes
77+
into eXistdb. This is a very fast and convenient way to develop web components with eXistdb.
78+
79+
CAUTION: there one nifty detail to watch. Your html files that are hosting (importing components via html imports)
80+
MUST be well-formed html files following the xhtml rules ( meta and link tags have to use closing syntax '/>').
81+
82+
The Web Components itself are not well-formed markup and are stored as binary HTML in eXistdb.
83+
84+
For more info about the gulp file see below.
85+
86+
### Starting to work
87+
88+
Your work starts by modifying index.html to probably adapting the script and link pathes if necessary. The generated
89+
index.html is a standard Polymer documentation page. I usually copy that to 'doc.html' to not loose it and start modifying
90+
the index.html.
91+
92+
Once index.html is in shape open up your main component file which will be file you created during polymer init (e.g. my-app.html)
93+
and check the polymer import. This is usually not right in this setting and needs to be adapted once to start with 'bower_components'.
94+
95+
You can now go on with actually implementing your Web Component.
96+
97+
### Going on
98+
99+
Eventually you'll need a new component. Just created new ones via ```polymer init``` again to quickly create one. Don't forget to import
100+
it whereever its used.
101+
102+
happy hackin
103+
104+
## Tooling Reference
105+
106+
### What gulp does for you
107+
108+
[gulpjs](http://gulpjs.com/) is a JavaScript build tool and knows hundreds of 'tasks' to help client-side development.
109+
110+
For eXistdb application development there is a custom existdb plugin (task) that can talk to eXistdb and deploy files
111+
from a local disk into eXistdb.
112+
113+
#### Commands
114+
115+
```
116+
gulp deploy
117+
```
118+
119+
will transfer all local files on disk to the target collection in eXistdb. If you've used ´ant init` the target collection
120+
will already be configured for you.
121+
122+
IMPORTANT: the app MUST be deployed once into eXistdb before ´gulp deploy´ or `gulp watch` are run. This is to setup
123+
the application correctly (creating collection, users etc.).
124+
125+
```
126+
gulp watch
127+
```
128+
129+
can be started in a terminal once (in the root of your project) and will then watch all files on disk and deploy them into eXistdb
130+
ONCE THEY'VE CHANGED. This is very convenient if you prefer a workflow 'from workspace to database'.
131+
132+
### What [Polymer CLI](https://www.polymer-project.org/2.0/start/toolbox/set-up) does for you
133+
134+
Polymer CLI is a powerful tool when working with Polymer.
135+
136+
#### Commands:
137+
138+
```
139+
polymer init
140+
```
141+
142+
With this command you can create a single new Polymer Web Component or even a whole new application. It must be executed
143+
in the root of your project.
144+
145+
IMPORANT: when run initially the Polymer CLI will download all JavaScript dependencies it needs for Polymer development. When run
146+
to create new components later on (after setup) you should answer all 'overwrite' questions of the CLI with 'n' to keep the originals.
147+
148+
```
149+
polymer serve -o
150+
```
151+
152+
can be used to start a local server that open the index page. This is fine for a quick view if the component is running
153+
as expected. For serious development i recommend to use gulp for deployment (see above).
154+
155+
```
156+
polymer build
157+
```
158+
159+
160+
will create a production version of all your Polymer Web Components compressed into index.html. It also will remove
161+
all unneeded dependencies from 'bower_components'. This command should be executed once the app is ready for production as
162+
it reduces the footprint dramatically.
163+
164+
```
165+
polymer test
166+
```
167+
168+
will run Polymer tests found in directory 'test'.
169+
170+
NOTE: this is not working perfectly for now so please be aware that it might fail due to browser loading/shutdown problems. The
171+
actuals tests however should pass. We'll have to look for a more stable solution in the future.
172+
173+
The relevant test framework can be found here: [web-component-tester](https://github.com/Polymer/web-component-tester)
174+
175+
### What [Ant](https://ant.apache.org/) does for you
176+
177+
Ant (as always in eXistdb app development) does the final packaging as a xar app. In this app template the standard build.xml
178+
is extended to wrap the ´build` command of the Polymer CLI when the target 'production-xar' is called.
179+
180+
```
181+
ant init
182+
```
183+
184+
As described above this must be called once you create your project to rename the relevant parts of the various config-files.
185+
186+
187+
```
188+
ant xar
189+
```
190+
191+
This is the default and creates a xar file for deployment into eXistdb. Run this and use eXistdb Package Manager to
192+
install the app into eXistdb before ever calling ´gulp deploy` or `gulp watch`.
193+
194+
```
195+
ant production-xar
196+
```
197+
198+
will call ´polymer init´ to make sure all Web Components are optimized before packaging the xar. This is highly recommended to prepare
199+
your app for production deployment.
200+
201+
202+
203+
### What bower does for you
204+
205+
bowerjs is a client-side dependency management tool. It's widely adapted in the web development world. It works with a 'bower.json' file
206+
that contains all necessary information. By default all client-side dependencies are kept in a directory called 'bower_components'. In app template
207+
this file will be created by Polymer CLI.
208+
209+
bower.json will also serve as a meta-information provider when you want to distribute a component
210+
for use with bower in an external application. If you're interested in this use case please be aware
211+
that the ignores found in 'bower.json.ignores' are added to bower.json.
212+
213+
#### Commands
214+
215+
```
216+
bower install
217+
```
218+
219+
this will read the 'bower.json' file and load all dependencies found there into the local 'bower_components' directory.
220+
Note that it will only load dependencies if they are not yet present so it does some caching.
221+
222+
```
223+
bower search [string]
224+
```
225+
226+
this can be used to localize a dependency you want to use. It will return a list of available resources which then can be installed.
227+
228+
```
229+
bower install --save [resource]
230+
```
231+
232+
this will download the resource and put it into 'bower_components' for usage. Please always use ´--save´ to store the dependency
233+
in bower.json. if you're installing a development time dependency use ´--save-dev´ instead.
234+
235+
236+
237+
### Notes on setting up nodejs
238+
239+
Note: This is a one-timer - you can skip this step if you got mpm on your system already.
240+
241+
Though not strictly required for development it is recommended that you have an installation of nodejs on your system.
242+
It is recommended to use ['nvm'](https://github.com/creationix/nvm) to install nodejs as this eases the process of installation and
243+
allows to keep different versions of it on your system without conflicts.
244+
245+
Nodejs is used within this project to drive the gulp tasks. These allow to:
246+
247+
* build CSS from less
248+
* sync your local files into eXistdb with `gulp deploy` or
249+
* sync your changed files into eXistdb with `gulp watch`
250+
251+
Please refer to the nvm page for installation instruction or use an installation method described
252+
on the nodejs.org homepage.
253+
254+
# Testing Web Components
255+
256+
Polymer comes with a testing framework called Web Component Tester (WCT).
257+
258+
To install it just execute:
259+
260+
```
261+
npm install -g web-component-tester
262+
```
263+
264+
## setup a test
265+
266+
When running Polymer-Cli to create a new element or whole project it will also
267+
create a 'test' directory for you containing an index.html (test suite) plus a
268+
file which is named similar to your new element/project with a '_test' appended.
269+
270+
Please note that having the tests embedded in html is just one way of using WCT.
271+
More information can be found on the github page of [WCT](https://github.com/Polymer/web-component-tester).
272+
273+
Depending on your project layout you should have a look into these files to check
274+
if the import paths are set to the correct locations.
275+
276+
## getting Safari to work
277+
278+
Safari does not work out of the box and needs an extra piece of software. When
279+
running WCT on the commandline (in the root of your project)
280+
281+
```
282+
wct
283+
```
284+
285+
it will spit out an error and display an url to a jar file that needs to installed
286+
to make Safari work. The error also gives instructions on how to install that jar.
287+
288+
## learn more
289+
290+
A note of caution: the video shows an older API of Polymer in the tests which is not used
291+
in Polymer 2 any more. However that is not relevant for the testing procedure itself. You
292+
just shouldn't try to copy/paste and expect it to work.
293+
294+
There's a good polycast that explains the procedures in quite detail and is
295+
highly recommended when starting to test with WCT.
296+
297+
[Unit Testing with Web Components](https://www.youtube.com/watch?v=YBNBr9ECXLo)
298+
299+
## more links
300+
301+
[Testing with Travis and Saucelabs](https://www.youtube.com/watch?v=afy_EEq_4Go)
302+
303+
304+
## Final remark
305+
306+
If you find problems with the information provided above please use the issue-tracker and file a ticket. Same applies to
307+
extensions of the app template that you'd like to suggest.
308+
309+
310+
311+
312+

_element.html

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<link rel="import" href="../polymer/polymer-element.html">
2+
3+
<dom-module id="exf-model">
4+
<template>
5+
<style>
6+
:host {
7+
display: block;
8+
}
9+
</style>
10+
<h2>Hello [[prop1]]!</h2>
11+
</template>
12+
13+
<script>
14+
/**
15+
* `exf-model`
16+
*
17+
*
18+
* @customElement
19+
* @polymer
20+
* @demo demo/index.html
21+
*/
22+
class ExfModel extends Polymer.Element {
23+
static get is() { return 'exf-model'; }
24+
static get properties() {
25+
return {
26+
prop1: {
27+
type: String,
28+
value: 'exf-model'
29+
}
30+
};
31+
}
32+
}
33+
34+
window.customElements.define(ExfModel.is, ExfModel);
35+
</script>
36+
</dom-module>

app-template.iml

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<module type="WEB_MODULE" version="4">
3+
<component name="NewModuleRootManager" inherit-compiler-output="true">
4+
<exclude-output />
5+
<content url="file://$MODULE_DIR$" />
6+
<orderEntry type="inheritedJdk" />
7+
<orderEntry type="sourceFolder" forTests="false" />
8+
</component>
9+
</module>

bower.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"name": "exf-model",
3+
"main": "exf-model.html",
4+
"dependencies": {
5+
"polymer": "Polymer/polymer#^2.0.0"
6+
},
7+
"devDependencies": {
8+
"iron-demo-helpers": "PolymerElements/iron-demo-helpers#^2.0.0",
9+
"web-component-tester": "Polymer/web-component-tester#^6.0.0",
10+
"webcomponentsjs": "webcomponents/webcomponentsjs#^1.0.0"
11+
},
12+
"resolutions": {
13+
"polymer": "^2.0.0"
14+
}
15+
}

0 commit comments

Comments
 (0)