Skip to content

Commit 26c00cc

Browse files
author
carl@connectedbrains.com
committed
Added some selector doc and codepens
1 parent 871a862 commit 26c00cc

9 files changed

+201
-97
lines changed

_config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
title: GSS
22
permalink: /:categories/:title
33
pygments: true
4-
version: "1.0.4-beta"
4+
version: "2.0.0"
55
markdown: redcarpet
66
exclude:
77
- "README.md"

bower_components/gss/CONTRIBUTING.md

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Contributing Guidelines
2+
3+
Guidelines for contributing to GSS.
4+
5+
6+
## Issues
7+
8+
Issues are most appropriate for bugs and other problems encountered using GSS. Ideally, include a demo project (GitHub repo, CodePen, JSFiddle, etc) that focuses on the issue.
9+
10+
Please search existing issues before filing new ones.
11+
12+
13+
## Pull requests
14+
15+
Pull requests should be issued from dedicated branches, as opposed to `master`.
16+
17+
It may be worth opening an issue to discuss feature requests and major changes before attemping to implement them.
18+
19+
Prefixing a pull request will `[WIP]` and committing early is a good way to get feedback without too much investment.
20+
21+
22+
## Questions
23+
24+
When questions are asked, consider providing an answer by opening a pull request against the GSS documentation.
25+
26+
27+
## Dependencies
28+
29+
Dependencies should be referenced by an appropriate version number or tag and never by overly-permissive references such as branch names or `*`. In the case that a dependency has no available versions or tags, use a git commit SHA.
30+
31+
32+
## Releases
33+
34+
Releases should always be made from `master` and follow [semantic versioning](http://semver.org/).
35+
36+
References in code to the version number should be updated before building for distribution and tagging a new release.
37+
38+
Prefer using the [GitHub UI](https://github.com/gss/engine/releases/new) and provide useful release notes.
39+
40+
Lastly, releases should be published to npm by running `npm publish`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global.GSS = require('../src/GSS')
2+
global.GSS.Document = require('../src/Document')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
global.GSS = require('../src/GSS')
2+
global.GSS.Document = require('../src/Document')
3+
global.GSS.Parser = require('ccss-compiler')
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
global.GSS = require('../src/GSS')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
global.GSS = require('../src/GSS')
2+
global.GSS.Parser = require('ccss-compiler')
+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012 The Polymer Authors. All rights reserved.
3+
* Use of this source code is governed by a BSD-style
4+
* license that can be found in the LICENSE file.
5+
*/
6+
7+
if (typeof window != 'undefined')
8+
if (typeof WeakMap === 'undefined') {
9+
(function() {
10+
var defineProperty = Object.defineProperty;
11+
var counter = Date.now() % 1e9;
12+
13+
var WeakMap = function() {
14+
this.name = '__st' + (Math.random() * 1e9 >>> 0) + (counter++ + '__');
15+
};
16+
17+
WeakMap.prototype = {
18+
set: function(key, value) {
19+
var entry = key[this.name];
20+
if (entry && entry[0] === key)
21+
entry[1] = value;
22+
else
23+
defineProperty(key, this.name, {value: [key, value], writable: true});
24+
},
25+
get: function(key) {
26+
var entry;
27+
return (entry = key[this.name]) && entry[0] === key ?
28+
entry[1] : undefined;
29+
},
30+
'delete': function(key) {
31+
this.set(key, undefined);
32+
}
33+
};
34+
35+
window.WeakMap = WeakMap;
36+
})();
37+
}

guides/_posts/2015-01-06-constraints.html

+50-69
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,26 @@
55
color: b
66
layout: post
77
---
8+
Soon after the W3C introduced Cascading Style Sheets, [Greg Badros](http://www.badros.com/greg/), the author of the Cassowary Constraint
9+
Solver & [recently retired Facebook VP](http://allthingsd.com/20130920/facebook-engineering-and-products-vp-greg-badros-to-leave-company/),
10+
proposed [Constraint CSS (CCSS)](http://www.cs.washington.edu/research/constraints/web/ccss-uwtr.pdf) as a general solution for CSS layout.
11+
Back in '99 Badros demonstrated *responsive* layouts with CCSS that today's designers still can't reproduce without grinding out piles of JavaScript.
12+
For more than a decade, no one seemed to take notice outside academia... Until Apple implemented Cassowary & Greg's pioneering concepts in its new
13+
AutoLayout engine with the launch of OS X Lion. Despite the evolutionary leap for app developers, web designer's have had to settle
14+
with [float-based](http://www.sitepoint.com/give-floats-the-flick-in-css-layouts/) & table-based layouts that have remained unimproved to this day.
815

9-
Constraints allows you to design great layout.
16+
> "We should contemplate how very, very far behind the web platform is in making it delightful to build the sorts of things that are work-a-day in native environments." <a href="http://infrequently.org/2012/02/misdirection/">Alex Russell</a>
1017

11-
## Constraints
18+
The foundation of GSS is a modernized implementation of CCSS. From CCSS primitives other, more exotic layout API's can and are accomplished.
1219

13-
Constraints express [relationships between variables](#constraintsaretwoways) that [may or may not hold](#mayofmaynothold). You can constrain any numerical style property of an element, not just its position & size.
20+
## Constraints, the basics
21+
22+
Constraints express [relationships between variables](#constraintsaretwoways) that [may or may not hold](#mayofmaynothold). You can constrain any
23+
numerical style property of an element, not just its position & size.
1424

1525
For example, if I want all paragraph tags to have line-height greater than 16px and less than 1/12th the size of the window:
1626

17-
{% highlight css %}
27+
{% highlight css %}
1828

1929
p[line-height] >= 16;
2030
p[line-height] <= ::window[height] / 12;
@@ -78,23 +88,19 @@
7888

7989
{% highlight css %}
8090

81-
#gss {
82-
width: == 200;
83-
}
84-
85-
#cassowary {
86-
width: == 200;
87-
}
88-
89-
#gss[width] + #cassowary[width] == 350;
91+
#gss[width] == 200;
92+
#cassowary[width] == 200;
93+
#gss[width] + #cassowary[width] == 350;
9094

9195
{% endhighlight %}
9296

9397
In the previous example, we're asking GSS to give the `#GSS` and `#cassowary` elements a width of 200px and we
9498
later declare a constraint for the sum of these two elements to be equal to 350px. In this case, one of these
95-
two constraints will not hold. As we'll see later in the documentation you can influence the constraints solving
96-
by given more intent to GSS about what you want. <a href="http://codepen.io/cbchouinard/pen/XJROdV" target="_blank">Live example.</a>
99+
two constraint will not hold. <a href="http://codepen.io/cbchouinard/pen/XJROdV" target="_blank">Live example.</a>
100+
101+
As we'll see next, you can influence the constraints solving by given more information to GSS about your intent.
97102

103+
<a name="strenghts"></a>
98104
### Strenghts
99105
Strenghts allows you to guide GSS in your layout intention by giving the GSS constraints solver more details about which constraints you prioritize.
100106

@@ -121,80 +127,42 @@
121127

122128
`!medium` is the default for all constraints when no strenght is explicitly defined.
123129

124-
Using the [May or may not hold example](#mayofmaynothold) example we saw previously,
125-
we'll give in the following example more strenghts to the each individual `width` to
130+
Using the [May or may not hold](#mayofmaynothold) example we saw previously,
131+
we'll now give a stronger strenght to each individual `width` constraints to
126132
make sure they overcome the sum constraints: <a href="http://codepen.io/cbchouinard/pen/bNRbQg" target="_blank">Live example.</a>
127133

128-
129134
#### !require strenght
130135
`!require` is a special strength that guarantees the constraint will hold, otherwise everything breaks.
131136

132-
**Pro Tip** Use `!require` carefully & sparingly. `!require`'s quickly lead to systems where
137+
**Pro Tip** Use `!require` carefully & sparingly. `!require`'s quickly lead to systems where
133138
all required constraints cannot be satisfied.
134139

135140
For example, the following GSS expressions will be unsolvable:
136141

137142
{% highlight css %}
138143

139-
#gss {
140-
width: == 200 !require;
141-
}
142-
143-
#cassowary {
144-
width: == 200 !require;
145-
}
146-
147-
#gss[width] + #cassowary[width] == 350 !require;
144+
#gss[width] == 200 !require;
145+
#cassowary[width] == 200 !require;
146+
#gss[width] + #cassowary[width] == 350 !require;
148147

149148
{% endhighlight %}
150149

151-
We're asking GSS to find a solution where the width of the #gss and #cassowary element must absolutely be 200px
152-
and their sum must absolutly be 350px which is impossible.
150+
We're asking GSS to find a solution where the widths of the #gss and #cassowary element must be 200px
151+
and their sum must be 350px which is impossible.
153152

154153
### Constraints order
155154
Generally speaking, later constraint statements are more powerful than earlier ones. There could be exception
156-
to this behavior as well see in the following sections.
155+
to this behavior as we'll see in the following sections.
157156

158-
Taking the [May or may not hold example](#mayofmaynothold) we saw previously, by changing the order you'll get a
157+
Taking the [May or may not hold example](#mayofmaynothold) we saw previously, by changing the order of the constraints you'll get a
159158
different result. <a href="http://codepen.io/cbchouinard/pen/rawBRr" target="_blank">Live example.</a>
160159

161-
## Stays <a name="stays"></a>
162-
163-
Ambiguity can be largely overcome by declaring more constraints, but what about situations like:
164-
165-
{% highlight css %}
166-
167-
#box[right] == ::window[right];
168-
#box[width] >= 100;
169-
#box[left] >= 100;
170-
171-
/* the #box's width will stretch */
172-
173-
{% endhighlight %}
174-
175-
Will the `#box` move or stretch to satisfy the last constraint? Again, the later constraint statements are more
176-
powerful than later ones, so the box's width would stretch. You can control this by either changing the order in
177-
which the constraints are declared or by using a `stay` like so:
178-
179-
{% highlight css %}
180-
181-
#box[right] == ::window[right];
182-
#box[width] >= 100;
183-
#box[left] >= 100;
184-
@stay(#box[width]);
185-
186-
/* the #box's position will move */
187-
{% endhighlight %}
188-
189-
190-
Many `stay`s can be declared at once with `@stay([var1],[var2],[var3])`.
191-
192-
160+
<a name="lineararithmetic"></a>
193161
## Linear Arithmetic
194162

195163
Cassowary only allows for "Linear Arithmetic" constraints, you can do simple math operations like `+`, `-`, `*` and `/`,
196164
but all expressions must be linear (of the form `y = mx + b`). Basically, you can do most things except multiply or
197-
divide two constraint variables.
165+
divide two constraint variables. <a href="http://codepen.io/cbchouinard/pen/MYvOWO" target="_blank">Live example.</a>
198166

199167
{% highlight css %}
200168

@@ -204,7 +172,7 @@
204172

205173
{% endhighlight %}
206174

207-
I wish we could go non-linear, but we can't because math.
175+
We wish we could go non-linear, but we can't because math.
208176

209177
## Units of measurement
210178
Default unit in GSS are pixels. GSS also supports the following units:
@@ -214,10 +182,23 @@
214182
#pourcentage[width] == 10%;
215183
{% endhighlight %}
216184

185+
<a name="selectors"></a>
217186
## Selectors
218187

219-
GSS Selectors guide: [view all selectors](/guides/selectors)
188+
GSS supports many selectors to allow you to select elements for which you want to declare constraints.
220189

190+
{% highlight css %}
191+
.className > #someElm ~ div {
192+
width: == 100;
193+
}
194+
{% endhighlight %}
195+
196+
Since we have a lot of selector we've dedicated a guide for them. We invite you to scroll all the way
197+
down in that guide, there's some useful information there: [GSS Selectors Guide](/guides/selectors)
198+
199+
Note that this guide is refering to [ruleset](rulesets) which are covered next.
200+
201+
<a name="rulesets"></a>
221202
## Rulesets
222203
GSS allows you to declare constraint using ruleset as with CSS:
223204

@@ -289,7 +270,7 @@
289270
In this example `(^ #elm)` will search for a `#elm` element contained in the current element having
290271
the `.container` class. <a href="http://codepen.io/cbchouinard/pen/yyXPej" target="_blank">Live example.</a>
291272

292-
273+
<a name="variablesandscope"></a>
293274
## Variables and scope
294275
Declaring a variable in GSS is as simple as using it:
295276

@@ -690,6 +671,6 @@
690671

691672
{% endhighlight %}
692673

693-
In this example we are constraining `#elmA` and `#elmB` against the virtual element.
674+
In this example we are constraining `#elmA` and `#elmB` against the virtual element.
694675

695676
Virtuals are very handy with [VFL](/guides/vfl-guide).

0 commit comments

Comments
 (0)