Skip to content

Commit 6aeb69a

Browse files
Merge pull request #31 from dutchenkoOleg/master
1.7.1
2 parents 33db296 + 5a4ab27 commit 6aeb69a

25 files changed

+770
-468
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 Wezom
3+
Copyright (c) 2018 WezomAgency
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

README.md

Lines changed: 9 additions & 301 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# R2D2
22

33
![working in progress](https://img.shields.io/badge/Status-WIP-red.svg)
4-
[![license](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/dutchenkoOleg/node-w3c-validator/blob/master/LICENSE)
4+
[![license](https://img.shields.io/badge/License-MIT-blue.svg)](https://github.com/WezomAgency/r2d2/blob/master/LICENSE)
55
[![WezomAgency](https://img.shields.io/badge/composer-require-orange.svg)](https://packagist.org/packages/wezom-agency/r2d2)
66
[![WezomAgency](https://img.shields.io/badge/Wezom-Agency-red.svg)](https://github.com/WezomAgency)
77

@@ -11,326 +11,34 @@
1111

1212
---
1313

14-
### *Table of contents*
15-
16-
- [Install](#install)
17-
- [Setup](#setup)
18-
- [API](#api)
19-
- [eject](#eject)
20-
- [instance::set](#instanceset)
21-
- [instance::fileUrl](#instancefileurl)
22-
- [instance::fileContent](#instancefilecontent)
23-
- [instance::resourceUrl](#instanceresourceurl)
24-
- [instance::resourceContent](#instanceresourcecontent)
25-
- [instance::str2number](#instancestr2number)
26-
27-
---
2814

2915

30-
31-
# Install
16+
### Install
3217

3318
```bash
3419
composer require wezom-agency/r2d2
3520
```
3621

3722
---
3823

39-
# Setup
24+
### Setup
4025

4126
in your core app file:
4227

4328
```php
44-
use WezomAgency\R2D2;
45-
46-
R2D2::eject()->set('KEY', VALUE);
47-
48-
```
49-
50-
List of settings:
51-
52-
- `debug: bool = false`
53-
- `host: string = ''`
54-
- `protocol: string = 'http://'`
55-
- `rootPath: string = ''`
56-
- `resourceRelativePath: string = ''` - _"shortcut"_ to your resources/assets directory
57-
- `svgSpritemapPath: string = ''` - default path to svg sprite map file
58-
59-
60-
Example of settings
61-
62-
```php
63-
use WezomAgency\R2D2;
64-
65-
R2D2::eject()
66-
->set(debug, true)
67-
->set('host', $_SERVER['HTTP_HOST'])
68-
->set('protocol', 'https://')
69-
->set('rootPath', './')
70-
->set('resourceRelativePath', '/my/path/to/resources/')
71-
->set(
72-
'svgSpritemapPath',
73-
R2D2::eject()->resourceUrl('assets/svg/common.svg', true)
74-
);
75-
```
76-
77-
---
78-
79-
# API
80-
81-
## eject
82-
83-
:arrow_up: [_Table of contents_](#table-of-contents)
84-
85-
```php
86-
R2D2::eject() instance
29+
WezomAgency\R2D2::eject()->set('KEY', VALUE);
8730
```
8831

89-
Ejecting R2D2 instance.
90-
Below a list of instance methods
91-
92-
93-
---
94-
95-
## instance::set
96-
97-
Setup instance
98-
99-
:arrow_up: [_Table of contents_](#table-of-contents)
100-
101-
```php
102-
R2D2::eject()->set($key, $value) instance
103-
```
104-
105-
_Parameters:_
106-
107-
| Name | Data type | Default value | Description |
108-
| :--------- | :-------- | :------------ | :------------- |
109-
| **$name** | _string_ | | settings name |
110-
| **$value** | _any_ | | settings value |
111-
112-
List of available settings and their values, see above ([#setup section](#setup))
113-
114-
32+
[See list of all settings ►](https://github.com/WezomAgency/r2d2/blob/master/docs/api/instance-set.md)
11533

11634
---
11735

118-
## instance::fileUrl
119-
120-
:arrow_up: [_Table of contents_](#table-of-contents)
121-
122-
Generate file URL
123-
124-
```php
125-
R2D2::eject()->fileUrl($url, $timestamp = false, $absolute = false) string
126-
```
127-
128-
129-
_Parameters:_
130-
131-
| Name | Data type | Default value | Description |
132-
| :------------- | :-------- | :------------ | :------------- |
133-
| **$url** | _string_ | | file relative url, from site root, e.q `/assets/css/my.css` |
134-
| **$timestamp** | _boolean_ | `false` | set file versioning with query pair `?time=xxx`, if file doesn't exist - query will be empty string |
135-
| **$absolute** | _boolean_ | `false` | generate absolute url, with `protocol` and `host` setting (see [#setup section](#setup)) |
136-
137-
_Returns:_ URL
138-
139-
140-
#### Usage example
141-
142-
```php
143-
<?php
144-
145-
use WezomAgency\R2D2;
146-
147-
// in core app file:
148-
// R2D2::eject()
149-
// ->set('host', 'my-site.com')
150-
// ->set('protocol', 'https://')
151-
152-
?>
153-
<link rel="stylesheet" href="<?= R2D2::eject()->fileUrl('/assets/css/style1.css'); ?>">
154-
<link rel="stylesheet" href="<?= R2D2::eject()->fileUrl('/assets/css/style2.css', true); ?>">
155-
<link rel="stylesheet" href="<?= R2D2::eject()->fileUrl('/assets/css/style3.css', true, true); ?>">
156-
```
157-
#### Result
158-
159-
```html
160-
<link rel="stylesheet" href="/assets/css/style1.css">
161-
<link rel="stylesheet" href="/assets/css/style2.css?time=1545054627">
162-
<link rel="stylesheet" href="https://my-site.com/assets/css/style3.css?time=1545054627">
163-
```
36+
### API
16437

38+
[See docs sections ►](https://github.com/WezomAgency/r2d2/blob/master/docs/index.md)
16539

16640
---
16741

168-
## instance::fileContent
169-
170-
:arrow_up: [_Table of contents_](#table-of-contents)
171-
172-
Get file contents
173-
174-
```php
175-
R2D2::eject()->fileContent($path) string
176-
```
177-
178-
_Parameters:_
179-
180-
| Name | Data type | Default value | Description |
181-
| :------------- | :-------- | :------------ | :------------- |
182-
| **$path** | _string_ | | file relative url, from the `rootPath` (see [#setup section](#setup)) |
183-
184-
_Returns:_ file contents
185-
186-
187-
#### Usage example
188-
189-
```php
190-
<?php
191-
192-
use WezomAgency\R2D2;
193-
194-
// in core app file:
195-
// R2D2::eject()
196-
// ->set('rootPath', './')
197-
198-
?>
199-
<style><?= R2D2::eject()->fileContent('/assets/css/critical.css'); ?></style>
200-
```
201-
#### Result
202-
203-
```html
204-
<style>html{font:14px/1.3em Arial;color:#222}h1{color:red;font-size:2em}.wysiswyg{font-size:16px;line-height:normal}</style>
205-
```
206-
207-
208-
209-
---
210-
211-
## instance::resourceUrl
212-
213-
:arrow_up: [_Table of contents_](#table-of-contents)
214-
215-
This is the same method as [`instance::fileUrl`](#instancefileurl).
216-
The only difference is in the relative path that is used to create a full URL.
217-
218-
This can be useful for frequently used paths that have a large nesting of directories.
219-
You can _"save"_ initial part of the path, and specify the rest when calling the method.
220-
221-
222-
```php
223-
R2D2::eject()->resourceUrl($url, $timestamp = false, $absolute = false) string
224-
```
225-
226-
227-
_Parameters:_
228-
229-
| Name | Data type | Default value | Description |
230-
| :------------- | :-------- | :------------ | :------------- |
231-
| **$url** | _string_ | | file relative url, from the `resourceRelativePath` (see [#setup section](#setup)) |
232-
| **$timestamp** | _boolean_ | `false` | set file versioning with query pair `?time=xxx`, if file doesn't exist - query will be empty string |
233-
| **$absolute** | _boolean_ | `false` | generate absolute url, with `protocol` and `host` setting (see [#setup section](#setup)) |
234-
235-
_Returns:_ URL
236-
237-
238-
#### Usage example
239-
240-
```php
241-
<?php
242-
243-
use WezomAgency\R2D2;
244-
245-
// in core app file:
246-
// R2D2::eject()
247-
// ->set('resourceRelativePath', '/my/path/to/resources/folder')
248-
249-
?>
250-
<link rel="stylesheet" href="<?= R2D2::eject()->resourceUrl('css/style1.css'); ?>">
251-
<link rel="stylesheet" href="<?= R2D2::eject()->resourceUrl('css/style2.css', true); ?>">
252-
<link rel="stylesheet" href="<?= R2D2::eject()->resourceUrl('css/style3.css', true, true); ?>">
253-
```
254-
#### Result
255-
256-
```html
257-
<link rel="stylesheet" href="/my/path/to/resources/folder/css/style1.css">
258-
<link rel="stylesheet" href="/my/path/to/resources/folder/css/style2.css?time=1545054627">
259-
<link rel="stylesheet" href="https://my-site.com/my/path/to/resources/folder/css/style3.css?time=1545054627">
260-
```
261-
262-
263-
---
264-
265-
### instance::resourceContent
266-
267-
:arrow_up: [_Table of contents_](#table-of-contents)
268-
269-
This is the same method as [`instance::fileContent`](#instancefilecontent).
270-
The only difference is in the relative path that is used to create a full path to the file.
271-
272-
This can be useful for frequently used paths that have a large nesting of directories.
273-
You can _"save"_ initial part of the path, and specify the rest when calling the method.
274-
275-
```php
276-
R2D2::eject()->resourceContent($path) string
277-
```
278-
279-
_Parameters:_
280-
281-
| Name | Data type | Default value | Description |
282-
| :------------- | :-------- | :------------ | :------------- |
283-
| **$path** | _string_ | | file relative url, from the `rootPath` (see [#setup section](#setup)) |
284-
285-
_Returns:_ file content
286-
287-
288-
#### Usage example
289-
290-
```php
291-
<?php
292-
293-
use WezomAgency\R2D2;
294-
295-
// in core app file:
296-
// R2D2::eject()
297-
// ->set('rootPath', './')
298-
// ->set('resourceRelativePath', '/my/path/to/resources/folder')
299-
300-
?>
301-
<style><?= R2D2::eject()->resourceContent('css/critical.css'); ?></style>
302-
<!-- will get content from file ./my/path/to/resources/folder/css/critical.css -->
303-
```
304-
#### Result
305-
306-
```html
307-
<style>html{font:14px/1.3em Arial;color:#222}h1{color:red;font-size:2em}.wysiswyg{font-size:16px;line-height:normal}</style>
308-
```
309-
310-
311-
312-
313-
314-
---
315-
316-
### instance::str2number
317-
318-
:arrow_up: [_Table of contents_](#table-of-contents)
319-
320-
This method is used to convert string attribute values to numbers.
321-
322-
```php
323-
R2D2::eject()->str2number($value = '', $int = false) float|int
324-
```
325-
326-
_Parameters:_
327-
328-
| Name | Data type | Default value | Description |
329-
| :------------- | :--------- | :------------ | :-------------------- |
330-
| **$value** | _string_ | empty string | html attr value |
331-
| **$int** | _boolean_ | `false` | returns only integers |
332-
333-
_Returns:_ float / int / 0 - if `$value` includes `%` character
334-
335-
42+
### License
33643

44+
[MIT License ►](https://github.com/WezomAgency/r2d2/blob/master/LICENSE)

docs/api/eject.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# R2D2::eject(): instance
2+
3+
[Docs](../index.md) |
4+
[► Next `instance->attr()`](instance-attr.md)
5+
6+
`R2D2` was written with accordance to Singleton pattern.
7+
Method `eject` is instance getter method.
8+
9+
10+
```php
11+
R2D2::eject(): instance
12+
```
13+
14+
----
15+
16+
[Docs](../index.md) |
17+
[▲ Top](#) |
18+
[► Next `instance->attr()`](instance-attr.md)
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# R2D2::eject()->attrJsonEncode()
2+
3+
[Docs](../index.md) |
4+
[◄ Prev `instance->attrs()`](instance-attrs.md) |
5+
[► Next `instance->attrTextValue()`](instance-attr-text-value.md)
6+
7+
----
8+
9+
*... description*
10+
11+
----
12+
13+
[Docs](../index.md) |
14+
[▲ Top](#) |
15+
[◄ Prev `instance->attrs()`](instance-attrs.md) |
16+
[► Next `instance->attrTextValue()`](instance-attr-text-value.md)

0 commit comments

Comments
 (0)