Skip to content

Commit 857fcc8

Browse files
authored
Clarify docs (#389)
* Rewrite most of documentation. * Make creating the `$openstack` object more clear. * Rename and rearrange main operations as CRUDL (Create, Read, Update, Delete, List)
1 parent b5d1fc6 commit 857fcc8

File tree

256 files changed

+1709
-1847
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

256 files changed

+1709
-1847
lines changed

doc/_exts/osdoc.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from docutils.parsers.rst import Directive
2+
from docutils import nodes
3+
4+
5+
class OsDoc(Directive):
6+
required_arguments = 1
7+
has_content = True
8+
9+
def run(self):
10+
full_url = self.arguments[0]
11+
title = 'official documentation'
12+
13+
text = []
14+
text.extend([
15+
nodes.Text('More information can be found in the '),
16+
nodes.reference(title, title, internal=False, refuri=self.arguments[0]),
17+
nodes.Text('.')
18+
])
19+
20+
return [nodes.paragraph(
21+
'',
22+
'',
23+
nodes.Text('More information can be found in the '),
24+
nodes.reference(title, title, internal=False, refuri=full_url),
25+
nodes.Text('.')
26+
)]
27+
28+
29+
def setup(app):
30+
app.add_directive('osdoc', OsDoc)
31+
return {'version': '0.1'}

doc/_exts/samples.py

Lines changed: 27 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,41 @@
11
from docutils import nodes
2-
from sphinx.addnodes import download_reference
2+
from docutils.parsers.rst import directives
33
from sphinx.directives.code import LiteralInclude
44
import re
55

6+
from sphinx.util.typing import OptionSpec
7+
8+
69
class Sample(LiteralInclude):
10+
option_spec: OptionSpec = {
11+
'full': directives.flag,
12+
}
13+
14+
def run(self):
15+
self.arguments[0] = "/../samples/" + self.arguments[0]
16+
self.options['language'] = 'php'
717

8-
def run(self):
9-
self.arguments[0] = "/../samples/" + self.arguments[0]
10-
self.options['language'] = 'php'
18+
pattern = r"[\s+]?(\<\?php.*?]\);)"
1119

12-
pattern = r"[\s+]?(\<\?php.*?]\);)"
20+
code_block = super(Sample, self).run()[0]
21+
if 'full' in self.options:
22+
return [code_block]
1323

14-
code_block = super(Sample, self).run()[0]
15-
string = str(code_block[0])
24+
string = str(code_block[0])
1625

17-
match = re.match(pattern, string, re.S)
18-
if match is None:
19-
return [code_block]
26+
match = re.match(pattern, string, re.S)
27+
if match is None:
28+
return [code_block]
2029

21-
auth_str = match.group(1).strip()
22-
main_str = re.sub(pattern, "", string, 0, re.S).strip()
30+
main_str = re.sub(pattern, "", string, 0, re.S).strip()
31+
if main_str == '':
32+
return [code_block]
2333

24-
show_hide_btn = download_reference(reftarget=self.arguments[0])
34+
return [
35+
nodes.literal_block(main_str, main_str, language="php")
36+
]
2537

26-
return [
27-
show_hide_btn,
28-
nodes.literal_block(auth_str, auth_str, language="php"),
29-
nodes.literal_block(main_str, main_str, language="php")]
3038

3139
def setup(app):
32-
app.add_directive('sample', Sample)
33-
return {'version': '0.1'}
40+
app.add_directive('sample', Sample)
41+
return {'version': '0.1'}

doc/_static/css/custom.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
summary {
2+
margin-bottom: 1rem;
3+
cursor: pointer;
4+
}

doc/common/create-service.rst

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
Create Service
2+
==============
3+
4+
In order to work with the service you have to :doc:`setup the client </setup>` first.
5+
6+
Service can be created via :substitution-code:`|method|()` method of the ``OpenStack`` object.
7+
8+
.. code-block:: php
9+
:substitutions:
10+
11+
$service = $openstack->|method|();
12+
13+
A list of additional options can be passed to the method. For example, to change the region:
14+
15+
.. code-block:: php
16+
:substitutions:
17+
18+
$service = $openstack->|method|(['region' => '{region}']);

doc/common/service.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
In order to work with |models| you have to :doc:`create the service <create>` first.

doc/conf.py

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,23 @@
2323
lexers['php-annotations'] = PhpLexer(startinline=True, linenos=1)
2424
primary_domain = 'php'
2525

26-
extensions = ['samples', 'refdoc', 'sphinx.ext.autodoc', 'sphinx.ext.autosummary', 'sphinxcontrib.phpdomain']
26+
extensions = [
27+
'samples',
28+
'refdoc',
29+
'osdoc',
30+
'sphinx.ext.autodoc',
31+
'sphinx.ext.autosummary',
32+
'sphinxcontrib.phpdomain',
33+
'sphinx_toolbox.collapse',
34+
'sphinx_substitution_extensions',
35+
]
2736
source_suffix = '.rst'
2837
master_doc = 'index'
2938
project = u'php-opencloud'
3039
copyright = u'2015-2023, PHP OpenCloud & contributors'
3140
version = '1.12'
3241
release = '1.12.1'
33-
exclude_patterns = ['_build']
42+
exclude_patterns = ['_build', 'common']
3443
pygments_style = 'sphinx'
3544

3645
html_theme = 'sphinx_rtd_theme'
@@ -39,6 +48,13 @@
3948
# Output file base name for HTML help builder.
4049
htmlhelp_basename = 'php-openclouddoc'
4150

51+
# These folders are copied to the documentation's HTML output
52+
html_static_path = ['_static']
53+
54+
html_css_files = [
55+
'css/custom.css',
56+
]
57+
4258
latex_documents = [
4359
('index', 'php-opencloud.tex', u'php-opencloud Documentation',
4460
u'Jamie Hannaford', 'manual'),

doc/index.rst

Lines changed: 11 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,23 @@
11
Welcome to the OpenStack SDK for PHP!
22
=====================================
33

4-
Requirements
5-
------------
6-
7-
* PHP >= 7, < 9
8-
* cURL extension
9-
10-
Installation
11-
------------
12-
13-
You must install this library through Composer:
14-
15-
.. code-block:: bash
4+
About
5+
-----
166

17-
composer require php-opencloud/openstack
7+
OpenStack SDK allows PHP developers to easily connect to OpenStack APIs in a simple and idiomatic way.
8+
This binding is specifically designed for OpenStack APIs, but other provider SDKs are available.
9+
Multiple OpenStack services, and versions of services, are supported.
1810

19-
If you do not have Composer installed, please read the `Composer installation instructions`_.
20-
21-
Once you have installed the SDK as a dependency of your project, you will need to load Composer’s autoloader
22-
(which registers all the required namespaces). To do this, place the following line of PHP code at the top of your
23-
application’s PHP files:
24-
25-
.. code-block:: php
26-
27-
require 'vendor/autoload.php';
28-
29-
This assumes your application's PHP files are located in the same folder as ``vendor/``. If your files are located
30-
elsewhere, please supply the path to vendor/autoload.php in the require statement above.
11+
.. toctree::
12+
install
13+
setup
3114

3215
Supported services
3316
------------------
3417

3518
.. toctree::
3619
:glob:
37-
:maxdepth: 1
20+
:maxdepth: 0
3821

3922
services/**/index
4023

@@ -49,6 +32,5 @@ Contributing
4932
If you'd like to contribute to the project, or require help running the unit/integration tests, please view the
5033
`contributing guidelines`_.
5134

52-
.. _Composer installation instructions: `https://getcomposer.org/doc/00-intro.md`
53-
.. _Github repo: `https://github.com/php-opencloud/openstack`
54-
.. _contributing guidelines: `https://github.com/php-opencloud/openstack/blob/master/CONTRIBUTING.md`
35+
.. _Github repo: https://github.com/php-opencloud/openstack
36+
.. _contributing guidelines: https://github.com/php-opencloud/openstack/blob/master/CONTRIBUTING.md

doc/install.rst

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
Installation
2+
============
3+
4+
Requirements
5+
------------
6+
7+
* PHP >= 7, < 9
8+
* cURL extension
9+
10+
Install via composer
11+
--------------------
12+
13+
You must install this library through Composer:
14+
15+
.. code-block:: bash
16+
17+
composer require php-opencloud/openstack
18+
19+
If you do not have Composer installed, please read the `Composer installation instructions`_.
20+
21+
Include autoloader
22+
------------------
23+
24+
Once you have installed the SDK as a dependency of your project, you will need to load Composer’s autoloader
25+
(which registers all the required namespaces). To do this, place the following line of PHP code at the top of your
26+
application’s PHP files:
27+
28+
.. code-block:: php
29+
30+
require 'vendor/autoload.php';
31+
32+
This assumes your application's PHP files are located in the same folder as ``vendor/``. If your files are located
33+
elsewhere, please supply the path to vendor/autoload.php in the require statement above.
34+
35+
.. _Composer installation instructions: https://getcomposer.org/doc/00-intro.md

doc/requirements.txt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,4 @@
11
sphinxcontrib-phpdomain>=0.11.0
2-
sphinx-rtd-theme>=0.5.1
2+
sphinx-rtd-theme>=0.5.1
3+
sphinx-toolbox>=3.5.0
4+
sphinx-substitution-extensions

doc/services/block-storage/v2/index.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Block Storage v2
33

44
Block Storage v2 API is deprecated since Pike release and was removed in the Xena release.
55
It is recommended to use Block Storage v3 API instead. However most of endpoints are identical, so if you still need
6-
to use Block Storage v2 API, you can use the change `$openstack->blockStorageV3()` to `$openstack->blockStorageV2()` in examples.
6+
to use Block Storage v2 API, you can use the change ``$openstack->blockStorageV3()`` to ``$openstack->blockStorageV2()`` in examples.
77
In most cases it will work without any other changes.
88

9-
.. sample:: BlockStorage/v2/create_service.php
9+
.. sample:: BlockStorage/v2/create.php

0 commit comments

Comments
 (0)