Skip to content
This repository was archived by the owner on Apr 3, 2023. It is now read-only.

Commit efb9637

Browse files
author
kevin.bonduelle
committed
feat(remcalc): Initial commit
Signed-off-by: kevin.bonduelle <[email protected]>
0 parents  commit efb9637

21 files changed

+3094
-0
lines changed

.babelrc

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"presets": ["es2015"],
3+
"plugins": [
4+
"add-module-exports"
5+
]
6+
}

.editorconfig

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
indent_style = space
6+
indent_size = 4
7+
end_of_line = lf
8+
insert_final_newline = true
9+
trim_trailing_whitespace = true

.eslintignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/dist/**/*.js

.eslintrc.js

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
module.exports = {
2+
root: true,
3+
extends: 'airbnb-base',
4+
rules: {
5+
'indent': ["error", 4],
6+
'no-param-reassign': 0
7+
}
8+
};

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/node_modules
2+
/*.log*

CONTRIBUTING.md

+126
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
# Contributing to project ovh-ui-kit
2+
3+
This project accepts contributions. In order to contribute, you should
4+
pay attention to a few things:
5+
6+
1. your code must be tested
7+
2. your code must follow the coding style rules
8+
3. your code must be documented
9+
4. your work must be signed (see below)
10+
5. you may contribute through GitHub Pull Requests
11+
12+
# Coding style rules
13+
14+
* lint: `eslint lib`
15+
* test: `node test`
16+
* build: `webpack`
17+
18+
# Submitting Modifications
19+
20+
The contributions should be submitted through Github Pull Requests and
21+
follow the DCO which is defined below.
22+
23+
# Licensing for new files
24+
25+
ovh-ui-kit is licensed under a modified BSD-3-Clause license. Anything
26+
contributed to ovh-ui-kit must be released under this license.
27+
28+
When introducing a new file into the project, please make sure it has a
29+
copyright header making clear under which license it's being released.
30+
31+
# Developer Certificate of Origin (DCO)
32+
33+
To improve tracking of contributions to this project we will use a
34+
process modeled on the modified DCO 1.1 and use a "sign-off" procedure
35+
on patches that are being emailed around or contributed in any other
36+
way.
37+
38+
The sign-off is a simple line at the end of the explanation for the
39+
patch, which certifies that you wrote it or otherwise have the right
40+
to pass it on as an open-source patch. The rules are pretty simple:
41+
if you can certify the below:
42+
43+
```
44+
By making a contribution to this project, I certify that:
45+
46+
(a) The contribution was created in whole or in part by me and I have
47+
the right to submit it under the open source license indicated in
48+
the file; or
49+
50+
(b) The contribution is based upon previous work that, to the best of
51+
my knowledge, is covered under an appropriate open source License
52+
and I have the right under that license to submit that work with
53+
modifications, whether created in whole or in part by me, under
54+
the same open source license (unless I am permitted to submit
55+
under a different license), as indicated in the file; or
56+
57+
(c) The contribution was provided directly to me by some other person
58+
who certified (a), (b) or (c) and I have not modified it.
59+
60+
(d) The contribution is made free of any other party's intellectual
61+
property claims or rights.
62+
63+
(e) I understand and agree that this project and the contribution are
64+
public and that a record of the contribution (including all
65+
personal information I submit with it, including my sign-off) is
66+
maintained indefinitely and may be redistributed consistent with
67+
this project or the open source license(s) involved.
68+
```
69+
70+
then you just add a line saying
71+
72+
Signed-off-by: Random J Developer <[email protected]>
73+
74+
using your real name (sorry, no pseudonyms or anonymous contributions.)
75+
76+
77+
# Setup your environment
78+
79+
**ovh-ui-kit-documentation** showcases **ovh-ui-kit**'s components and
80+
doubles as a development environment. This section provides a guide to
81+
a local development installation.
82+
83+
## Yarn
84+
85+
### ovh-ui-kit
86+
87+
1. Start from your workspace directory
88+
example:`~/workspace`
89+
2. `git clone` the **ovh-ui-less** repository locally
90+
3. Move to the `ovh-ui-less` directory
91+
4. Link `ovh-ui-less` to yarn links
92+
93+
```
94+
cd <your workspace directory>
95+
git clone <ovh-ui-less repository>
96+
cd ovh-ui-kit
97+
yarn link
98+
```
99+
100+
### ovh-ui-kit-documentation
101+
102+
1. Start from your workspace directory
103+
example:`~/workspace`
104+
2. `git clone` the ovh-ui-kit-documentation` repository locally
105+
3. Move to the `ovh-ui-kit` directory
106+
4. Install external dependencies
107+
5. Use your local `ovh-ui-kit` repository instead of the remote dependency
108+
6. Launch `ovh-ui-kit` in watch mode
109+
110+
```
111+
cd <your workspace directory>
112+
git clone <ovh-ui-kit-documentation repository>
113+
cd ovh-ui-kit-documentation
114+
yarn install
115+
yarn link ovh-ui-kit
116+
yarn start
117+
```
118+
119+
## NPM
120+
121+
For those using npm instead of yarn here is a list of equivalences: <https://yarnpkg.com/en/docs/migrating-from-npm>
122+
123+
## Commits
124+
125+
All commits in this project must follow this specific message convention: <https://gist.github.com/stephenparish/9941e89d80e2bc58a153>
126+

LICENSE.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Copyright (c) 2013-2016, OVH SAS.
2+
All rights reserved.
3+
4+
Redistribution and use in source and binary forms, with or without
5+
modification, are permitted provided that the following conditions are met:
6+
7+
* Redistributions of source code must retain the above copyright
8+
notice, this list of conditions and the following disclaimer.
9+
* Redistributions in binary form must reproduce the above copyright
10+
notice, this list of conditions and the following disclaimer in the
11+
documentation and/or other materials provided with the distribution.
12+
* Neither the name of OVH SAS nor the
13+
names of its contributors may be used to endorse or promote products
14+
derived from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY OVH SAS AND CONTRIBUTORS ``AS IS'' AND ANY
17+
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
DISCLAIMED. IN NO EVENT SHALL OVH SAS AND CONTRIBUTORS BE LIABLE FOR ANY
20+
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21+
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22+
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23+
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25+
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

README.md

+90
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# less-plugin-remcalc
2+
3+
Simply adds `rem-base` and `rem-calc` functions to LESS.
4+
5+
## Installation
6+
7+
```
8+
yarn add --dev "git+ssh://[email protected]:7999/UXTOOLS/less-plugin-remcalc.git"
9+
```
10+
11+
## Usage
12+
13+
### lessc
14+
15+
On the command line:
16+
17+
```
18+
lessc file.less --remcalc
19+
```
20+
21+
### node
22+
23+
```js
24+
var remcalc = require('less-plugin-remcalc');
25+
26+
less.render(data, { plugins: [remcalc] }).then(...);
27+
```
28+
29+
### grunt (grunt-contrib-less)
30+
31+
Register the plugin in your `Gruntfile.js`:
32+
33+
```js
34+
less: {
35+
options: {
36+
plugins: [
37+
require('less-plugin-remcalc')
38+
]
39+
}
40+
}
41+
```
42+
43+
### webpack (less-loader)
44+
45+
```js
46+
var RemcalcPlugin = require('less-plugin-remcalc');
47+
48+
module.exports = {
49+
...
50+
lessLoader: {
51+
lessPlugins: [
52+
RemcalcPlugin
53+
]
54+
}
55+
};
56+
```
57+
58+
## Examples
59+
60+
### Basic
61+
62+
```less
63+
.card {
64+
min-width: rem-calc(64px);
65+
}
66+
67+
.card {
68+
min-width: rem-calc(64);
69+
}
70+
```
71+
72+
### Overriding the rem base
73+
74+
Default base is `16px` but you can override it at any time (here with `12px`):
75+
76+
```less
77+
.card {
78+
padding: rem-calc(20px, 12px);
79+
}
80+
```
81+
82+
You can also act globally on the rem base, using:
83+
84+
```less
85+
@rem-base: rem-base(10px); // will globally override the rem base.
86+
87+
.card {
88+
min-width: rem-calc(20px); // is now equivalent to rem-calc(20px, 10px);
89+
}
90+
```

dist/plugin.js

+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
(function(e, a) { for(var i in a) e[i] = a[i]; }(exports, /******/ (function(modules) { // webpackBootstrap
2+
/******/ // The module cache
3+
/******/ var installedModules = {};
4+
5+
/******/ // The require function
6+
/******/ function __webpack_require__(moduleId) {
7+
8+
/******/ // Check if module is in cache
9+
/******/ if(installedModules[moduleId])
10+
/******/ return installedModules[moduleId].exports;
11+
12+
/******/ // Create a new module (and put it into the cache)
13+
/******/ var module = installedModules[moduleId] = {
14+
/******/ exports: {},
15+
/******/ id: moduleId,
16+
/******/ loaded: false
17+
/******/ };
18+
19+
/******/ // Execute the module function
20+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
21+
22+
/******/ // Flag the module as loaded
23+
/******/ module.loaded = true;
24+
25+
/******/ // Return the exports of the module
26+
/******/ return module.exports;
27+
/******/ }
28+
29+
30+
/******/ // expose the modules object (__webpack_modules__)
31+
/******/ __webpack_require__.m = modules;
32+
33+
/******/ // expose the module cache
34+
/******/ __webpack_require__.c = installedModules;
35+
36+
/******/ // __webpack_public_path__
37+
/******/ __webpack_require__.p = "";
38+
39+
/******/ // Load entry module and return exports
40+
/******/ return __webpack_require__(0);
41+
/******/ })
42+
/************************************************************************/
43+
/******/ ([
44+
/* 0 */
45+
/***/ function(module, exports, __webpack_require__) {
46+
47+
'use strict';
48+
49+
Object.defineProperty(exports, "__esModule", {
50+
value: true
51+
});
52+
53+
var _functions = __webpack_require__(1);
54+
55+
var _functions2 = _interopRequireDefault(_functions);
56+
57+
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
58+
59+
exports.default = {
60+
install: function install(less) {
61+
less.functions.functionRegistry.addMultiple((0, _functions2.default)(less));
62+
}
63+
};
64+
module.exports = exports['default'];
65+
66+
/***/ },
67+
/* 1 */
68+
/***/ function(module, exports) {
69+
70+
'use strict';
71+
72+
Object.defineProperty(exports, "__esModule", {
73+
value: true
74+
});
75+
76+
exports.default = function (less) {
77+
var registry = less.functions.functionRegistry;
78+
var Dimension = less.tree.Dimension;
79+
80+
return {
81+
'rem-base': function remBase(base) {
82+
if (!base) {
83+
return less.data['rem-base'] || new Dimension(16, 'px');
84+
}
85+
base = new Dimension(registry.get('unit')(base).value, 'px');
86+
less.data['rem-base'] = base;
87+
88+
return base;
89+
},
90+
'rem-calc': function remCalc(value, base) {
91+
base = base || registry.get('rem-base')();
92+
var baseUnit = registry.get('get-unit')(base).value.backupUnit;
93+
base = registry.get('unit')(base).value;
94+
95+
if (baseUnit === '%') {
96+
base = base / 100 * 16;
97+
}
98+
99+
if (baseUnit === 'rem') {
100+
base *= 16;
101+
}
102+
103+
if (baseUnit === 'em') {
104+
base *= 16;
105+
}
106+
107+
if (!value) {
108+
return new Dimension(0);
109+
}
110+
111+
var calculus = parseFloat((value.value / base).toFixed(3));
112+
113+
return new Dimension(calculus, 'rem');
114+
}
115+
};
116+
};
117+
118+
module.exports = exports['default'];
119+
120+
/***/ }
121+
/******/ ])));

0 commit comments

Comments
 (0)