source: Dev/trunk/src/qed-client/css/old/tutorial.less @ 443

Last change on this file since 443 was 443, checked in by hendrikvanantwerpen, 12 years ago

Reorganized for Node --- the SVN gods hate us all!

Lost all historical info on moved files, because SVN is a f *.

Also we have Node now, serving both the static content and forwarding
database requests.

File size: 4.1 KB
Line 
1//Variables and operations
2@variable: value;
3@variable2; @variable + value;  // /*-+, etc...
4//Variables are a constant!
5
6//You can use variables in varnames - eval()??
7@varName: "This is the value";
8@var: "varName";
9property: @@var; // read this as: Paste @var into X for the expression 'property is variable X'
10//property = variable(variable(a));
11
12//Mixins
13.mixin {
14        border-top: 1px solid #fff;     //Compilation preserves, so can be used as actual class in HTML
15}
16.mixin () {
17        border-top: 1px solid #fff;     //Compilation does not preserve, only for LESS purposes.
18}
19.mixin (@color: #default) {
20        border-top: 1px solid @color;   //Arguments.
21}
22.mixin (@x: 0, @y: 0) {
23        margin: @arguments;     //Use this to get space-separated list of all arguments!
24}
25
26// The following two mixins use a switch argument, behaving like an if/else or switch(arg1){}.
27.mixin (black, @color) {
28        border-top: 1px solid #fff;
29        background-color: black;
30}
31.mixin (white, @color) {
32        border-top: 1px solid #fff;
33        background-color: white;
34}
35
36//Match on arity (argument count):
37.mixin (@a) {
38        content: "Only if one arg: @{a}";
39}
40.mixin (@a, @b) {
41        content: "When two args: @{a}, @{b}";
42}
43
44//GUARDS! When you want to match on expressions!
45.mixin (@a) when (lightness(@a) >= 50%) {
46        background-color: black;
47}
48
49.mixin (@a) when (isnumber(@a)), (isstring(@a)) {
50        //This matches when @a is a string OR number (comma separated guards)
51}
52.mixin (@a) when (iscolor(@a)) and (lightness(@a) < 50%) {
53        // This matches when @a is a color with lightness under 50% (AND separated guards)
54}
55.mixin (@a) when not (@a > 0) {
56        //derp. Not keyword werkt ook
57}
58
59/*Expressions:
60- iscolor
61- isnumber
62- isstring
63- iskeyword?
64- isurl
65
66isnumber specifiek:
67- ispixel
68- ispercentage
69- isem
70*/
71
72.parent {
73        .descendant {
74                //descendant selector, evaluates to .parent .descendant{}
75        }
76        &.concat {
77                //concatenate selector, evaluates to .parent.concat{}
78        }
79        &[dojo-type="Button"] {
80                // works as well, evaluates to .parent[dojo-type="Button"]{}
81        }
82        &:hover {
83                //sets hover property for .parent:hover !!
84        }
85}
86
87// Operations: Can be applied to all numbers, color and variables. //These can be nested as well!
88@base: 5%;
89@other: @base + #aaa; //apaarently, LESS understands and converts these units?
90@var123: 1px + 5; // Output will be in px as well, since you specified them.
91border: (@width * 2) solid black; // Use brackets in compound statements!
92
93// Color operations: all colours are first converted to HSL space
94lighten/darken  //lightness (%)
95saturate/desaturate     //saturation (%)
96fadein/fadeout/fade     //transparency. fade sets absolute alpha, the others are relative to @color passed in (%)
97spin //hue, degrees spun on colour wheel (unitless number)
98mix // mix two colours.
99
100hue/saturation/lightness/alpha //return these for @color passed as argument
101@new = hsl(hue(@old), 45%, 90%); // generate new colour
102
103//Math functions!
104round, ceil, floor      //do what you'd expect.
105percentage      //returns rational as percentage
106
107//NAMESPACES
108#nameSpace {
109        .button() {
110                //stuff
111        }
112}
113
114.header a {
115        #nameSpace > .button;   // Access namespace variables:) CANNOT DO THIS WITH VARIABLES!!!!
116}
117
118/* These will be added to compiled CSS */
119// These won't, and are for use in LESS sheet only
120
121@import "lib.less";
122@import "lib";  //assumed to be LESS file
123@import "file.css";     //normal css imports
124
125
126//String interpolation: Same as DOJO templates, with @ instead of $
127@base-url: "http://assets.fnord.com";
128background-image: url("@{base-url}/images/bg.png");
129
130//String escapes:
131~"stuffffff"; //Will be added to compiled CSS as-is. Useful for retarded MS-specific (invalid CSS) statements/hacks
132
133//Wait, WHUT
134//JAVASCRIPT EVALUATION?!?!?!?!
135
136@var: `"hello".toUpperCase() + '!'`; // Wrap stuff in backticks and it will eval before compilation! :D
137@str: "hello";
138@var: ~`"@{str}".toUpperCase() + '!'`;  //You can still use string interp for this! Why the ~ though?
139
140@height: `document.body.clientHeight`; //WTF. How does this even work if it is compiled serverside?
141@color: color(`window.colors.baseColor`);       //Use color() to parse JS colours as CSS colours
142@darkcolor: darken(@color, 10%);
Note: See TracBrowser for help on using the repository browser.