├── .gitignore
├── LICENSE.txt
├── README.md
├── docs
├── Makefile
├── make.bat
└── source
│ ├── conf.py
│ ├── examples.rst
│ ├── img
│ ├── hist.png
│ └── vibed-mongo.png
│ ├── index.rst
│ ├── integration.rst
│ ├── introduction.rst
│ └── links.rst
└── examples
├── 10numbers.txt
├── dub-example
├── application
│ ├── .gitignore
│ ├── dub.json
│ └── source
│ │ └── app.d
└── component
│ ├── .gitignore
│ ├── dub.json
│ └── source
│ └── component
│ ├── mod.d
│ └── package.d
├── helloworld.c
├── helloworld1.d
├── helloworld2.d
├── matplotlib
├── data
│ └── data.txt
├── dub.json
├── source
│ └── app.d
└── views
│ └── show_histogram.py
├── readdoubles1.d
├── readdoubles2.d
└── vibed-mongo
├── .gitignore
├── dub.json
├── dub.selections.json
├── public
├── favicon.ico
├── javascripts
│ └── global.js
└── styles
│ └── style.css
├── source
├── app.d
└── service.d
└── views
├── index.dt
└── layout.dt
/.gitignore:
--------------------------------------------------------------------------------
1 | docs/build
2 |
3 | *.dub
4 |
5 | *.selections.json
6 |
7 | *.sublime-workspace
8 |
9 | *.sublime-project
10 |
11 | *.o
12 |
13 | examples/readdoubles2
14 |
15 | examples/readdoubles1
16 |
17 | examples/matplotlib/.dub/build/application-debug-posix.osx-x86_64-dmd_2067-B22D9B4DC44F841A0861C6CE3D44FC8C/atmosphere_gm_charts
18 |
19 | examples/matplotlib/dub.selections.json
20 |
21 | examples/matplotlib/atmosphere_gm_charts
22 |
23 | examples/matplotlib/plotting_example
24 |
25 | examples/vibed-mongo/vibed-mongo
26 |
27 | examples/dub-example/application/application
28 |
29 | examples/dub-example/component/__test__library__
30 |
31 | examples/dub-example/component/libcomponent.a
32 |
33 | examples/dub-example/application/grep
34 |
--------------------------------------------------------------------------------
/LICENSE.txt:
--------------------------------------------------------------------------------
1 | Boost Software License - Version 1.0 - August 17th, 2003
2 |
3 | Permission is hereby granted, free of charge, to any person or organization
4 | obtaining a copy of the software and accompanying documentation covered by
5 | this license (the "Software") to use, reproduce, display, distribute,
6 | execute, and transmit the Software, and to prepare derivative works of the
7 | Software, and to permit third-parties to whom the Software is furnished to
8 | do so, all subject to the following:
9 |
10 | The copyright notices in the Software and this entire statement, including
11 | the above license grant, this restriction and the following disclaimer,
12 | must be included in all copies of the Software, in whole or in part, and
13 | all derivative works of the Software, unless such copies or derivative
14 | works are solely in the form of machine-executable object code generated by
15 | a source language processor.
16 |
17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 | FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
20 | SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
21 | FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
22 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 | DEALINGS IN THE SOFTWARE.
24 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # thenextafterc [](http://d.readthedocs.org)
2 | [Quick Start with D](http://d.readthedocs.org)
3 |
4 | Authors: Ilya Yaroshenko
5 |
--------------------------------------------------------------------------------
/docs/Makefile:
--------------------------------------------------------------------------------
1 | # Makefile for Sphinx documentation
2 | #
3 |
4 | # You can set these variables from the command line.
5 | SPHINXOPTS =
6 | SPHINXBUILD = sphinx-build
7 | PAPER =
8 | BUILDDIR = build
9 |
10 | # User-friendly check for sphinx-build
11 | ifeq ($(shell which $(SPHINXBUILD) >/dev/null 2>&1; echo $$?), 1)
12 | $(error The '$(SPHINXBUILD)' command was not found. Make sure you have Sphinx installed, then set the SPHINXBUILD environment variable to point to the full path of the '$(SPHINXBUILD)' executable. Alternatively you can add the directory with the executable to your PATH. If you don't have Sphinx installed, grab it from http://sphinx-doc.org/)
13 | endif
14 |
15 | # Internal variables.
16 | PAPEROPT_a4 = -D latex_paper_size=a4
17 | PAPEROPT_letter = -D latex_paper_size=letter
18 | ALLSPHINXOPTS = -d $(BUILDDIR)/doctrees $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
19 | # the i18n builder cannot share the environment and doctrees with the others
20 | I18NSPHINXOPTS = $(PAPEROPT_$(PAPER)) $(SPHINXOPTS) source
21 |
22 | .PHONY: help clean html dirhtml singlehtml pickle json htmlhelp qthelp devhelp epub latex latexpdf text man changes linkcheck doctest coverage gettext
23 |
24 | help:
25 | @echo "Please use \`make ' where is one of"
26 | @echo " html to make standalone HTML files"
27 | @echo " dirhtml to make HTML files named index.html in directories"
28 | @echo " singlehtml to make a single large HTML file"
29 | @echo " pickle to make pickle files"
30 | @echo " json to make JSON files"
31 | @echo " htmlhelp to make HTML files and a HTML help project"
32 | @echo " qthelp to make HTML files and a qthelp project"
33 | @echo " applehelp to make an Apple Help Book"
34 | @echo " devhelp to make HTML files and a Devhelp project"
35 | @echo " epub to make an epub"
36 | @echo " latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter"
37 | @echo " latexpdf to make LaTeX files and run them through pdflatex"
38 | @echo " latexpdfja to make LaTeX files and run them through platex/dvipdfmx"
39 | @echo " text to make text files"
40 | @echo " man to make manual pages"
41 | @echo " texinfo to make Texinfo files"
42 | @echo " info to make Texinfo files and run them through makeinfo"
43 | @echo " gettext to make PO message catalogs"
44 | @echo " changes to make an overview of all changed/added/deprecated items"
45 | @echo " xml to make Docutils-native XML files"
46 | @echo " pseudoxml to make pseudoxml-XML files for display purposes"
47 | @echo " linkcheck to check all external links for integrity"
48 | @echo " doctest to run all doctests embedded in the documentation (if enabled)"
49 | @echo " coverage to run coverage check of the documentation (if enabled)"
50 |
51 | clean:
52 | rm -rf $(BUILDDIR)/*
53 |
54 | html:
55 | $(SPHINXBUILD) -b html $(ALLSPHINXOPTS) $(BUILDDIR)/html
56 | @echo
57 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
58 |
59 | dirhtml:
60 | $(SPHINXBUILD) -b dirhtml $(ALLSPHINXOPTS) $(BUILDDIR)/dirhtml
61 | @echo
62 | @echo "Build finished. The HTML pages are in $(BUILDDIR)/dirhtml."
63 |
64 | singlehtml:
65 | $(SPHINXBUILD) -b singlehtml $(ALLSPHINXOPTS) $(BUILDDIR)/singlehtml
66 | @echo
67 | @echo "Build finished. The HTML page is in $(BUILDDIR)/singlehtml."
68 |
69 | pickle:
70 | $(SPHINXBUILD) -b pickle $(ALLSPHINXOPTS) $(BUILDDIR)/pickle
71 | @echo
72 | @echo "Build finished; now you can process the pickle files."
73 |
74 | json:
75 | $(SPHINXBUILD) -b json $(ALLSPHINXOPTS) $(BUILDDIR)/json
76 | @echo
77 | @echo "Build finished; now you can process the JSON files."
78 |
79 | htmlhelp:
80 | $(SPHINXBUILD) -b htmlhelp $(ALLSPHINXOPTS) $(BUILDDIR)/htmlhelp
81 | @echo
82 | @echo "Build finished; now you can run HTML Help Workshop with the" \
83 | ".hhp project file in $(BUILDDIR)/htmlhelp."
84 |
85 | qthelp:
86 | $(SPHINXBUILD) -b qthelp $(ALLSPHINXOPTS) $(BUILDDIR)/qthelp
87 | @echo
88 | @echo "Build finished; now you can run "qcollectiongenerator" with the" \
89 | ".qhcp project file in $(BUILDDIR)/qthelp, like this:"
90 | @echo "# qcollectiongenerator $(BUILDDIR)/qthelp/QuickStartWithD.qhcp"
91 | @echo "To view the help file:"
92 | @echo "# assistant -collectionFile $(BUILDDIR)/qthelp/QuickStartWithD.qhc"
93 |
94 | applehelp:
95 | $(SPHINXBUILD) -b applehelp $(ALLSPHINXOPTS) $(BUILDDIR)/applehelp
96 | @echo
97 | @echo "Build finished. The help book is in $(BUILDDIR)/applehelp."
98 | @echo "N.B. You won't be able to view it unless you put it in" \
99 | "~/Library/Documentation/Help or install it in your application" \
100 | "bundle."
101 |
102 | devhelp:
103 | $(SPHINXBUILD) -b devhelp $(ALLSPHINXOPTS) $(BUILDDIR)/devhelp
104 | @echo
105 | @echo "Build finished."
106 | @echo "To view the help file:"
107 | @echo "# mkdir -p $$HOME/.local/share/devhelp/QuickStartWithD"
108 | @echo "# ln -s $(BUILDDIR)/devhelp $$HOME/.local/share/devhelp/QuickStartWithD"
109 | @echo "# devhelp"
110 |
111 | epub:
112 | $(SPHINXBUILD) -b epub $(ALLSPHINXOPTS) $(BUILDDIR)/epub
113 | @echo
114 | @echo "Build finished. The epub file is in $(BUILDDIR)/epub."
115 |
116 | latex:
117 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
118 | @echo
119 | @echo "Build finished; the LaTeX files are in $(BUILDDIR)/latex."
120 | @echo "Run \`make' in that directory to run these through (pdf)latex" \
121 | "(use \`make latexpdf' here to do that automatically)."
122 |
123 | latexpdf:
124 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
125 | @echo "Running LaTeX files through pdflatex..."
126 | $(MAKE) -C $(BUILDDIR)/latex all-pdf
127 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
128 |
129 | latexpdfja:
130 | $(SPHINXBUILD) -b latex $(ALLSPHINXOPTS) $(BUILDDIR)/latex
131 | @echo "Running LaTeX files through platex and dvipdfmx..."
132 | $(MAKE) -C $(BUILDDIR)/latex all-pdf-ja
133 | @echo "pdflatex finished; the PDF files are in $(BUILDDIR)/latex."
134 |
135 | text:
136 | $(SPHINXBUILD) -b text $(ALLSPHINXOPTS) $(BUILDDIR)/text
137 | @echo
138 | @echo "Build finished. The text files are in $(BUILDDIR)/text."
139 |
140 | man:
141 | $(SPHINXBUILD) -b man $(ALLSPHINXOPTS) $(BUILDDIR)/man
142 | @echo
143 | @echo "Build finished. The manual pages are in $(BUILDDIR)/man."
144 |
145 | texinfo:
146 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
147 | @echo
148 | @echo "Build finished. The Texinfo files are in $(BUILDDIR)/texinfo."
149 | @echo "Run \`make' in that directory to run these through makeinfo" \
150 | "(use \`make info' here to do that automatically)."
151 |
152 | info:
153 | $(SPHINXBUILD) -b texinfo $(ALLSPHINXOPTS) $(BUILDDIR)/texinfo
154 | @echo "Running Texinfo files through makeinfo..."
155 | make -C $(BUILDDIR)/texinfo info
156 | @echo "makeinfo finished; the Info files are in $(BUILDDIR)/texinfo."
157 |
158 | gettext:
159 | $(SPHINXBUILD) -b gettext $(I18NSPHINXOPTS) $(BUILDDIR)/locale
160 | @echo
161 | @echo "Build finished. The message catalogs are in $(BUILDDIR)/locale."
162 |
163 | changes:
164 | $(SPHINXBUILD) -b changes $(ALLSPHINXOPTS) $(BUILDDIR)/changes
165 | @echo
166 | @echo "The overview file is in $(BUILDDIR)/changes."
167 |
168 | linkcheck:
169 | $(SPHINXBUILD) -b linkcheck $(ALLSPHINXOPTS) $(BUILDDIR)/linkcheck
170 | @echo
171 | @echo "Link check complete; look for any errors in the above output " \
172 | "or in $(BUILDDIR)/linkcheck/output.txt."
173 |
174 | doctest:
175 | $(SPHINXBUILD) -b doctest $(ALLSPHINXOPTS) $(BUILDDIR)/doctest
176 | @echo "Testing of doctests in the sources finished, look at the " \
177 | "results in $(BUILDDIR)/doctest/output.txt."
178 |
179 | coverage:
180 | $(SPHINXBUILD) -b coverage $(ALLSPHINXOPTS) $(BUILDDIR)/coverage
181 | @echo "Testing of coverage in the sources finished, look at the " \
182 | "results in $(BUILDDIR)/coverage/python.txt."
183 |
184 | xml:
185 | $(SPHINXBUILD) -b xml $(ALLSPHINXOPTS) $(BUILDDIR)/xml
186 | @echo
187 | @echo "Build finished. The XML files are in $(BUILDDIR)/xml."
188 |
189 | pseudoxml:
190 | $(SPHINXBUILD) -b pseudoxml $(ALLSPHINXOPTS) $(BUILDDIR)/pseudoxml
191 | @echo
192 | @echo "Build finished. The pseudo-XML files are in $(BUILDDIR)/pseudoxml."
193 |
--------------------------------------------------------------------------------
/docs/make.bat:
--------------------------------------------------------------------------------
1 | @ECHO OFF
2 |
3 | REM Command file for Sphinx documentation
4 |
5 | if "%SPHINXBUILD%" == "" (
6 | set SPHINXBUILD=sphinx-build
7 | )
8 | set BUILDDIR=build
9 | set ALLSPHINXOPTS=-d %BUILDDIR%/doctrees %SPHINXOPTS% source
10 | set I18NSPHINXOPTS=%SPHINXOPTS% source
11 | if NOT "%PAPER%" == "" (
12 | set ALLSPHINXOPTS=-D latex_paper_size=%PAPER% %ALLSPHINXOPTS%
13 | set I18NSPHINXOPTS=-D latex_paper_size=%PAPER% %I18NSPHINXOPTS%
14 | )
15 |
16 | if "%1" == "" goto help
17 |
18 | if "%1" == "help" (
19 | :help
20 | echo.Please use `make ^` where ^ is one of
21 | echo. html to make standalone HTML files
22 | echo. dirhtml to make HTML files named index.html in directories
23 | echo. singlehtml to make a single large HTML file
24 | echo. pickle to make pickle files
25 | echo. json to make JSON files
26 | echo. htmlhelp to make HTML files and a HTML help project
27 | echo. qthelp to make HTML files and a qthelp project
28 | echo. devhelp to make HTML files and a Devhelp project
29 | echo. epub to make an epub
30 | echo. latex to make LaTeX files, you can set PAPER=a4 or PAPER=letter
31 | echo. text to make text files
32 | echo. man to make manual pages
33 | echo. texinfo to make Texinfo files
34 | echo. gettext to make PO message catalogs
35 | echo. changes to make an overview over all changed/added/deprecated items
36 | echo. xml to make Docutils-native XML files
37 | echo. pseudoxml to make pseudoxml-XML files for display purposes
38 | echo. linkcheck to check all external links for integrity
39 | echo. doctest to run all doctests embedded in the documentation if enabled
40 | echo. coverage to run coverage check of the documentation if enabled
41 | goto end
42 | )
43 |
44 | if "%1" == "clean" (
45 | for /d %%i in (%BUILDDIR%\*) do rmdir /q /s %%i
46 | del /q /s %BUILDDIR%\*
47 | goto end
48 | )
49 |
50 |
51 | REM Check if sphinx-build is available and fallback to Python version if any
52 | %SPHINXBUILD% 2> nul
53 | if errorlevel 9009 goto sphinx_python
54 | goto sphinx_ok
55 |
56 | :sphinx_python
57 |
58 | set SPHINXBUILD=python -m sphinx.__init__
59 | %SPHINXBUILD% 2> nul
60 | if errorlevel 9009 (
61 | echo.
62 | echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
63 | echo.installed, then set the SPHINXBUILD environment variable to point
64 | echo.to the full path of the 'sphinx-build' executable. Alternatively you
65 | echo.may add the Sphinx directory to PATH.
66 | echo.
67 | echo.If you don't have Sphinx installed, grab it from
68 | echo.http://sphinx-doc.org/
69 | exit /b 1
70 | )
71 |
72 | :sphinx_ok
73 |
74 |
75 | if "%1" == "html" (
76 | %SPHINXBUILD% -b html %ALLSPHINXOPTS% %BUILDDIR%/html
77 | if errorlevel 1 exit /b 1
78 | echo.
79 | echo.Build finished. The HTML pages are in %BUILDDIR%/html.
80 | goto end
81 | )
82 |
83 | if "%1" == "dirhtml" (
84 | %SPHINXBUILD% -b dirhtml %ALLSPHINXOPTS% %BUILDDIR%/dirhtml
85 | if errorlevel 1 exit /b 1
86 | echo.
87 | echo.Build finished. The HTML pages are in %BUILDDIR%/dirhtml.
88 | goto end
89 | )
90 |
91 | if "%1" == "singlehtml" (
92 | %SPHINXBUILD% -b singlehtml %ALLSPHINXOPTS% %BUILDDIR%/singlehtml
93 | if errorlevel 1 exit /b 1
94 | echo.
95 | echo.Build finished. The HTML pages are in %BUILDDIR%/singlehtml.
96 | goto end
97 | )
98 |
99 | if "%1" == "pickle" (
100 | %SPHINXBUILD% -b pickle %ALLSPHINXOPTS% %BUILDDIR%/pickle
101 | if errorlevel 1 exit /b 1
102 | echo.
103 | echo.Build finished; now you can process the pickle files.
104 | goto end
105 | )
106 |
107 | if "%1" == "json" (
108 | %SPHINXBUILD% -b json %ALLSPHINXOPTS% %BUILDDIR%/json
109 | if errorlevel 1 exit /b 1
110 | echo.
111 | echo.Build finished; now you can process the JSON files.
112 | goto end
113 | )
114 |
115 | if "%1" == "htmlhelp" (
116 | %SPHINXBUILD% -b htmlhelp %ALLSPHINXOPTS% %BUILDDIR%/htmlhelp
117 | if errorlevel 1 exit /b 1
118 | echo.
119 | echo.Build finished; now you can run HTML Help Workshop with the ^
120 | .hhp project file in %BUILDDIR%/htmlhelp.
121 | goto end
122 | )
123 |
124 | if "%1" == "qthelp" (
125 | %SPHINXBUILD% -b qthelp %ALLSPHINXOPTS% %BUILDDIR%/qthelp
126 | if errorlevel 1 exit /b 1
127 | echo.
128 | echo.Build finished; now you can run "qcollectiongenerator" with the ^
129 | .qhcp project file in %BUILDDIR%/qthelp, like this:
130 | echo.^> qcollectiongenerator %BUILDDIR%\qthelp\QuickStartWithD.qhcp
131 | echo.To view the help file:
132 | echo.^> assistant -collectionFile %BUILDDIR%\qthelp\QuickStartWithD.ghc
133 | goto end
134 | )
135 |
136 | if "%1" == "devhelp" (
137 | %SPHINXBUILD% -b devhelp %ALLSPHINXOPTS% %BUILDDIR%/devhelp
138 | if errorlevel 1 exit /b 1
139 | echo.
140 | echo.Build finished.
141 | goto end
142 | )
143 |
144 | if "%1" == "epub" (
145 | %SPHINXBUILD% -b epub %ALLSPHINXOPTS% %BUILDDIR%/epub
146 | if errorlevel 1 exit /b 1
147 | echo.
148 | echo.Build finished. The epub file is in %BUILDDIR%/epub.
149 | goto end
150 | )
151 |
152 | if "%1" == "latex" (
153 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
154 | if errorlevel 1 exit /b 1
155 | echo.
156 | echo.Build finished; the LaTeX files are in %BUILDDIR%/latex.
157 | goto end
158 | )
159 |
160 | if "%1" == "latexpdf" (
161 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
162 | cd %BUILDDIR%/latex
163 | make all-pdf
164 | cd %~dp0
165 | echo.
166 | echo.Build finished; the PDF files are in %BUILDDIR%/latex.
167 | goto end
168 | )
169 |
170 | if "%1" == "latexpdfja" (
171 | %SPHINXBUILD% -b latex %ALLSPHINXOPTS% %BUILDDIR%/latex
172 | cd %BUILDDIR%/latex
173 | make all-pdf-ja
174 | cd %~dp0
175 | echo.
176 | echo.Build finished; the PDF files are in %BUILDDIR%/latex.
177 | goto end
178 | )
179 |
180 | if "%1" == "text" (
181 | %SPHINXBUILD% -b text %ALLSPHINXOPTS% %BUILDDIR%/text
182 | if errorlevel 1 exit /b 1
183 | echo.
184 | echo.Build finished. The text files are in %BUILDDIR%/text.
185 | goto end
186 | )
187 |
188 | if "%1" == "man" (
189 | %SPHINXBUILD% -b man %ALLSPHINXOPTS% %BUILDDIR%/man
190 | if errorlevel 1 exit /b 1
191 | echo.
192 | echo.Build finished. The manual pages are in %BUILDDIR%/man.
193 | goto end
194 | )
195 |
196 | if "%1" == "texinfo" (
197 | %SPHINXBUILD% -b texinfo %ALLSPHINXOPTS% %BUILDDIR%/texinfo
198 | if errorlevel 1 exit /b 1
199 | echo.
200 | echo.Build finished. The Texinfo files are in %BUILDDIR%/texinfo.
201 | goto end
202 | )
203 |
204 | if "%1" == "gettext" (
205 | %SPHINXBUILD% -b gettext %I18NSPHINXOPTS% %BUILDDIR%/locale
206 | if errorlevel 1 exit /b 1
207 | echo.
208 | echo.Build finished. The message catalogs are in %BUILDDIR%/locale.
209 | goto end
210 | )
211 |
212 | if "%1" == "changes" (
213 | %SPHINXBUILD% -b changes %ALLSPHINXOPTS% %BUILDDIR%/changes
214 | if errorlevel 1 exit /b 1
215 | echo.
216 | echo.The overview file is in %BUILDDIR%/changes.
217 | goto end
218 | )
219 |
220 | if "%1" == "linkcheck" (
221 | %SPHINXBUILD% -b linkcheck %ALLSPHINXOPTS% %BUILDDIR%/linkcheck
222 | if errorlevel 1 exit /b 1
223 | echo.
224 | echo.Link check complete; look for any errors in the above output ^
225 | or in %BUILDDIR%/linkcheck/output.txt.
226 | goto end
227 | )
228 |
229 | if "%1" == "doctest" (
230 | %SPHINXBUILD% -b doctest %ALLSPHINXOPTS% %BUILDDIR%/doctest
231 | if errorlevel 1 exit /b 1
232 | echo.
233 | echo.Testing of doctests in the sources finished, look at the ^
234 | results in %BUILDDIR%/doctest/output.txt.
235 | goto end
236 | )
237 |
238 | if "%1" == "coverage" (
239 | %SPHINXBUILD% -b coverage %ALLSPHINXOPTS% %BUILDDIR%/coverage
240 | if errorlevel 1 exit /b 1
241 | echo.
242 | echo.Testing of coverage in the sources finished, look at the ^
243 | results in %BUILDDIR%/coverage/python.txt.
244 | goto end
245 | )
246 |
247 | if "%1" == "xml" (
248 | %SPHINXBUILD% -b xml %ALLSPHINXOPTS% %BUILDDIR%/xml
249 | if errorlevel 1 exit /b 1
250 | echo.
251 | echo.Build finished. The XML files are in %BUILDDIR%/xml.
252 | goto end
253 | )
254 |
255 | if "%1" == "pseudoxml" (
256 | %SPHINXBUILD% -b pseudoxml %ALLSPHINXOPTS% %BUILDDIR%/pseudoxml
257 | if errorlevel 1 exit /b 1
258 | echo.
259 | echo.Build finished. The pseudo-XML files are in %BUILDDIR%/pseudoxml.
260 | goto end
261 | )
262 |
263 | :end
264 |
--------------------------------------------------------------------------------
/docs/source/conf.py:
--------------------------------------------------------------------------------
1 | #!/usr/bin/env python3
2 | # -*- coding: utf-8 -*-
3 | #
4 | # Quick Start With D documentation build configuration file, created by
5 | # sphinx-quickstart on Sun Apr 19 19:37:11 2015.
6 | #
7 | # This file is execfile()d with the current directory set to its
8 | # containing dir.
9 | #
10 | # Note that not all possible configuration values are present in this
11 | # autogenerated file.
12 | #
13 | # All configuration values have a default; values that are commented out
14 | # serve to show the default.
15 |
16 | import sys
17 | import os
18 | import shlex
19 | import sphinx_rtd_theme
20 |
21 | tab_width = 4
22 |
23 | # If extensions (or modules to document with autodoc) are in another directory,
24 | # add these directories to sys.path here. If the directory is relative to the
25 | # documentation root, use os.path.abspath to make it absolute, like shown here.
26 | #sys.path.insert(0, os.path.abspath('.'))
27 |
28 | # -- General configuration ------------------------------------------------
29 |
30 | # If your documentation needs a minimal Sphinx version, state it here.
31 | #needs_sphinx = '1.0'
32 |
33 | # Add any Sphinx extension module names here, as strings. They can be
34 | # extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
35 | # ones.
36 | extensions = [
37 | 'sphinx.ext.autodoc',
38 | ]
39 |
40 | # Add any paths that contain templates here, relative to this directory.
41 | templates_path = ['ntemplates']
42 |
43 | # The suffix(es) of source filenames.
44 | # You can specify multiple suffix as a list of string:
45 | # source_suffix = ['.rst', '.md']
46 | source_suffix = '.rst'
47 |
48 | # The encoding of source files.
49 | #source_encoding = 'utf-8-sig'
50 |
51 | # The master toctree document.
52 | master_doc = 'index'
53 |
54 | # General information about the project.
55 | project = 'Quick Start With D'
56 | copyright = '2015, Ilya Yaroshenko'
57 | author = 'Ilya Yaroshenko'
58 |
59 | # The version info for the project you're documenting, acts as replacement for
60 | # |version| and |release|, also used in various other places throughout the
61 | # built documents.
62 | #
63 | # The short X.Y version.
64 | version = '0.0.2'
65 | # The full version, including alpha/beta/rc tags.
66 | release = '0.0.2'
67 |
68 | # The language for content autogenerated by Sphinx. Refer to documentation
69 | # for a list of supported languages.
70 | #
71 | # This is also used if you do content translation via gettext catalogs.
72 | # Usually you set "language" from the command line for these cases.
73 | language = None
74 |
75 | # There are two options for replacing |today|: either, you set today to some
76 | # non-false value, then it is used:
77 | #today = ''
78 | # Else, today_fmt is used as the format for a strftime call.
79 | #today_fmt = '%B %d, %Y'
80 |
81 | # List of patterns, relative to source directory, that match files and
82 | # directories to ignore when looking for source files.
83 | exclude_patterns = []
84 |
85 | # The reST default role (used for this markup: `text`) to use for all
86 | # documents.
87 | #default_role = None
88 |
89 | # If true, '()' will be appended to :func: etc. cross-reference text.
90 | #add_function_parentheses = True
91 |
92 | # If true, the current module name will be prepended to all description
93 | # unit titles (such as .. function::).
94 | #add_module_names = True
95 |
96 | # If true, sectionauthor and moduleauthor directives will be shown in the
97 | # output. They are ignored by default.
98 | #show_authors = False
99 |
100 | # The name of the Pygments (syntax highlighting) style to use.
101 | pygments_style = 'sphinx'
102 |
103 | # A list of ignored prefixes for module index sorting.
104 | #modindex_common_prefix = []
105 |
106 | # If true, keep warnings as "system message" paragraphs in the built documents.
107 | #keep_warnings = False
108 |
109 | # If true, `todo` and `todoList` produce output, else they produce nothing.
110 | todo_include_todos = False
111 |
112 |
113 | # -- Options for HTML output ----------------------------------------------
114 |
115 | # on_rtd is whether we are on readthedocs.org, this line of code grabbed from docs.readthedocs.org
116 | on_rtd = os.environ.get('READTHEDOCS', None) == 'True'
117 |
118 | if not on_rtd: # only import and set the theme if we're building docs locally
119 | import sphinx_rtd_theme
120 | html_theme = 'sphinx_rtd_theme'
121 | html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
122 |
123 | # otherwise, readthedocs.org uses their theme by default, so no need to specify it
124 |
125 |
126 | # Theme options are theme-specific and customize the look and feel of a theme
127 | # further. For a list of options available for each theme, see the
128 | # documentation.
129 | #html_theme_options = {}
130 |
131 | # Add any paths that contain custom themes here, relative to this directory.
132 | #html_theme_path = []
133 |
134 | # The name for this set of Sphinx documents. If None, it defaults to
135 | # " v documentation".
136 | html_title = "Welcome to Quick Start with D!"
137 |
138 | # A shorter title for the navigation bar. Default is the same as html_title.
139 | html_short_title = "Quick Start with D"
140 |
141 | # The name of an image file (relative to this directory) to place at the top
142 | # of the sidebar.
143 | #html_logo = None
144 |
145 | # The name of an image file (within the static path) to use as favicon of the
146 | # docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
147 | # pixels large.
148 | #html_favicon = None
149 |
150 | # Add any paths that contain custom static files (such as style sheets) here,
151 | # relative to this directory. They are copied after the builtin static files,
152 | # so a file named "default.css" will overwrite the builtin "default.css".
153 | html_static_path = ['nstatic']
154 |
155 | # Add any extra paths that contain custom files (such as robots.txt or
156 | # .htaccess) here, relative to this directory. These files are copied
157 | # directly to the root of the documentation.
158 | #html_extra_path = []
159 |
160 | # If not '', a 'Last updated on:' timestamp is inserted at every page bottom,
161 | # using the given strftime format.
162 | #html_last_updated_fmt = '%b %d, %Y'
163 |
164 | # If true, SmartyPants will be used to convert quotes and dashes to
165 | # typographically correct entities.
166 | #html_use_smartypants = True
167 |
168 | # Custom sidebar templates, maps document names to template names.
169 | #html_sidebars = {}
170 |
171 | # Additional templates that should be rendered to pages, maps page names to
172 | # template names.
173 | #html_additional_pages = {}
174 |
175 | # If false, no module index is generated.
176 | #html_domain_indices = True
177 |
178 | # If false, no index is generated.
179 | #html_use_index = True
180 |
181 | # If true, the index is split into individual pages for each letter.
182 | #html_split_index = False
183 |
184 | # If true, links to the reST sources are added to the pages.
185 | #html_show_sourcelink = True
186 |
187 | # If true, "Created using Sphinx" is shown in the HTML footer. Default is True.
188 | #html_show_sphinx = True
189 |
190 | # If true, "(C) Copyright ..." is shown in the HTML footer. Default is True.
191 | #html_show_copyright = True
192 |
193 | # If true, an OpenSearch description file will be output, and all pages will
194 | # contain a tag referring to it. The value of this option must be the
195 | # base URL from which the finished HTML is served.
196 | #html_use_opensearch = ''
197 |
198 | # This is the file name suffix for HTML files (e.g. ".xhtml").
199 | #html_file_suffix = None
200 |
201 | # Language to be used for generating the HTML full-text search index.
202 | # Sphinx supports the following languages:
203 | # 'da', 'de', 'en', 'es', 'fi', 'fr', 'h', 'it', 'ja'
204 | # 'nl', 'no', 'pt', 'ro', 'r', 'sv', 'tr'
205 | #html_search_language = 'en'
206 |
207 | # A dictionary with options for the search language support, empty by default.
208 | # Now only 'ja' uses this config value
209 | #html_search_options = {'type': 'default'}
210 |
211 | # The name of a javascript file (relative to the configuration directory) that
212 | # implements a search results scorer. If empty, the default will be used.
213 | #html_search_scorer = 'scorer.js'
214 |
215 | # Output file base name for HTML help builder.
216 | htmlhelp_basename = 'QuickStartWithDdoc'
217 |
218 | # -- Options for LaTeX output ---------------------------------------------
219 |
220 | latex_elements = {
221 | # The paper size ('letterpaper' or 'a4paper').
222 | 'papersize': 'a4paper',
223 |
224 | # The font size ('10pt', '11pt' or '12pt').
225 | 'pointsize': '12pt',
226 |
227 | # Additional stuff for the LaTeX preamble.
228 | #'preamble': '',
229 |
230 | # Latex figure (float) alignment
231 | 'figure_align': 'H',
232 |
233 | 'classoptions': ',openany,oneside',
234 |
235 | 'babel': '\\usepackage[english]{babel}',
236 | # 'babel': '\\usepackage[english]{babel}'
237 | }
238 |
239 |
240 | # Grouping the document tree into LaTeX files. List of tuples
241 | # (source start file, target name, title,
242 | # author, documentclass [howto, manual, or own class]).
243 | latex_documents = [
244 | (master_doc, 'QuickStartWithD.tex', 'Quick Start With D',
245 | 'Ilya Yaroshenko', 'manual'),
246 | ]
247 |
248 | # The name of an image file (relative to this directory) to place at the top of
249 | # the title page.
250 | #latex_logo = None
251 |
252 | # For "manual" documents, if this is true, then toplevel headings are parts,
253 | # not chapters.
254 | #latex_use_parts = False
255 |
256 | # If true, show page references after internal links.
257 | # latex_show_pagerefs = True
258 |
259 | # If true, show URL addresses after external links.
260 | latex_show_urls = 'footnote'
261 |
262 | # Documents to append as an appendix to all manuals.
263 | #latex_appendices = []
264 |
265 | # If false, no module index is generated.
266 | latex_domain_indices = False
267 |
268 | # latex_additional_files = ["style.sty"]
269 |
270 | # -- Options for manual page output ---------------------------------------
271 |
272 | # One entry per manual page. List of tuples
273 | # (source start file, name, description, authors, manual section).
274 | man_pages = [
275 | (master_doc, 'quickstartwithd', 'Quick Start With D',
276 | [author], 1)
277 | ]
278 |
279 | # If true, show URL addresses after external links.
280 | #man_show_urls = False
281 |
282 |
283 | # -- Options for Texinfo output -------------------------------------------
284 |
285 | # Grouping the document tree into Texinfo files. List of tuples
286 | # (source start file, target name, title, author,
287 | # dir menu entry, description, category)
288 | texinfo_documents = [
289 | (master_doc, 'QuickStartWithD', 'Quick Start With D',
290 | author, 'QuickStartWithD', 'One line description of project.',
291 | 'Miscellaneous'),
292 | ]
293 |
294 | # Documents to append as an appendix to all manuals.
295 | #texinfo_appendices = []
296 |
297 | # If false, no module index is generated.
298 | #texinfo_domain_indices = True
299 |
300 | # How to display URL addresses: 'footnote', 'no', or 'inline'.
301 | #texinfo_show_urls = 'footnote'
302 |
303 | # If true, do not generate a @detailmenu in the "Top" node's menu.
304 | #texinfo_no_detailmenu = False
305 |
--------------------------------------------------------------------------------
/docs/source/examples.rst:
--------------------------------------------------------------------------------
1 | Examples
2 | ==============================================
3 |
4 | D is a complex multi-paradigm programming language. At the same time, if you know C programming language and you want to start using D then you just need to look through some examples.
5 |
6 |
7 | .. tip:: All examples available on GitHub_.
8 |
9 | .. _GitHub: http://github.com/andralex/thenextafterc
10 |
11 | Hello, World!
12 | ~~~~~~~~~~~~~~
13 |
14 | C programs can be easily translated to D.
15 | The following program prints "Hello, World!" to the standard output.
16 |
17 | .. literalinclude:: ../../examples/helloworld.c
18 | :language: c
19 | :tab-width: 4
20 |
21 |
22 | D `doesn't have a preprocessor `_.
23 | Use ``import core.stdc.MODULE;`` construction to import ``MODULE`` from the `C Standard library`_.
24 |
25 | .. literalinclude:: ../../examples/helloworld1.d
26 | :language: d
27 | :tab-width: 4
28 |
29 | Module ``core.stdc.stdio`` contains the ``puts`` prototype:
30 |
31 | .. code-block:: d
32 |
33 | extern(C) @system nothrow @nogc int puts(in char* s);
34 |
35 | Common D "Hello, World!" program which is based on Phobos looks more simple:
36 |
37 | .. literalinclude:: ../../examples/helloworld2.d
38 | :language: d
39 | :tab-width: 4
40 |
41 | Phobos_ is the standard runtime library that comes with the D language compiler.
42 |
43 | .. seealso:: To find a collection of common C techniques, and to find out how to do the corresponding task in D click `here `_. However most of them can be implemented in C style.
44 |
45 | .. _D: http://dlang.org
46 | .. _C Standard library: http://www.cplusplus.com/reference/clibrary/
47 | .. _Phobos: http://dlang.org/phobos/
48 |
49 |
50 | Simple project with dub
51 | ~~~~~~~~~~~~~~~~~~~~~~~
52 |
53 | DUB_ is a build tool for D projects with support for automatically retrieving dependencies and integrating them in the build process. The design emphasis is on maximum simplicity for simple projects, while providing the opportunity to customize things when needed.
54 |
55 | To create the initial project with name ``component``, run ``dub init component``.
56 |
57 | Remove automatically created ``component/source/app.d`` file
58 | and create the following file structure
59 |
60 | .. code-block:: text
61 |
62 | dub.json
63 | component/
64 | source/
65 | component/
66 | mod.d
67 | package.d
68 |
69 | where ``component/package.d`` is the main module ``component``
70 |
71 | .. literalinclude:: ../../examples/dub-example/component/source/component/package.d
72 | :language: d
73 | :tab-width: 4
74 |
75 | and ``component/mod.d`` is the inner module ``component.mod``
76 |
77 | .. literalinclude:: ../../examples/dub-example/component/source/component/mod.d
78 | :language: d
79 | :tab-width: 4
80 |
81 | To test this module, run ``dub test`` from package's folder.
82 |
83 | ``removeSingleLineComments`` can be imported with ``import component;`` or ``import component.mod;``.
84 | To use *component* package, put the following dependency into your project's dub.json into the dependencies section:
85 |
86 | .. code-block:: js
87 |
88 | {
89 | ...
90 | "dependencies": {
91 | "component": "~master"
92 | }
93 | }
94 |
95 | .. _DUB: http://code.dlang.org/getting_started
96 |
97 | Plotting with matplotlib (python)
98 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
99 |
100 | These are two projects that can be used with the D programming language:
101 |
102 | + Plotcli_ is a command line application written in D that can create plots from text/csv files and from piped data, making it useful during data analysis.
103 | + PLplot_ is a cross-platform software package written in C for creating scientific plots. It includes low-level D bindings.
104 |
105 | But these two are not so convenient to use, in comparison with matplotlib.
106 |
107 | matplotlib_ is a python 2D plotting library which produces publication quality figures in a variety of hardcopy formats and interactive environments across platforms. matplotlib can be used in python scripts, the python and ipython shell, web application servers, and different graphical user interface toolkits. To integrate with python the PyD package can be used.
108 |
109 | PyD_ is a library that provides seamless interoperability between the D programming language and Python.
110 | The minimal configuration file for this example is
111 |
112 | .. literalinclude:: ../../examples/matplotlib/dub.json
113 | :language: json
114 | :tab-width: 4
115 |
116 | .. note:: The `python `_ and matplotlib should be installed. PyD searches the version of the python that is noted in the sub-configuration (``"pyd": "python34"`` in this example). For more information, see `the PyD's dub configuration file `_.
117 |
118 | The `following program `_
119 | reads data from a file and runs ``show_histogram.py``.
120 |
121 | .. literalinclude:: ../../examples/matplotlib/source/app.d
122 | :language: d
123 | :tab-width: 4
124 |
125 | ``show_histogram.py`` is located in ``views/``
126 | folder that is used by dub as a default string import [#stringimport]_ folder.
127 |
128 | .. literalinclude:: ../../examples/matplotlib/views/show_histogram.py
129 | :language: python
130 | :tab-width: 4
131 |
132 | .. image:: /img/hist.png
133 | :alt: Histogram image
134 |
135 | .. [#stringimport] Strings can be imported at compile time.
136 | .. _matplotlib: http://matplotlib.org
137 | .. _Plotcli: https://github.com/BlackEdder/plotd
138 | .. _PyD: http://pyd.readthedocs.org
139 | .. _PLplot: http://plplot.sourceforge.net
140 |
141 | Web Application
142 | ~~~~~~~~~~~~~~~
143 |
144 | Web application is a pretty good example of the last chapters of any book, where the reader is suggested to make use of the means of expression in the language. As a rule, web application is a complex product, both in terms of knowledge of the language and in terms of code complexity of the used libraries.
145 |
146 | And this example is no exception. Then why do people who want to learn D language very quickly still need example of web app? Many of them have a reason and it is that they need to integrate quickly programs written in D with other services, programming languages and databases.
147 |
148 | The article "`Creating a simple restful web app with node.js, Express, and MongoDB `_" by Christopher Buecheler is taken as a basis for this example.
149 |
150 | .. image:: /img/vibed-mongo.png
151 | :alt: vibe.d web app
152 |
153 | Initialization
154 | ^^^^^^^^^^^^^^^
155 |
156 | To create a skeleton web application, run:
157 |
158 | .. code-block:: shell
159 |
160 | $ dub init vibed-mongo vibe.d
161 |
162 | This will make the directory ``vibed-mongo`` with a minimal HTTP server based on vibe.d_.
163 |
164 | .. _vibe.d: http://vibed.org
165 |
166 |
167 | The configuration file ``dub.json`` will look something like this:
168 |
169 | .. literalinclude:: ../../examples/vibed-mongo/dub.json
170 | :language: json
171 | :tab-width: 4
172 |
173 | The version ``"VibeDefaultMain"`` includes the main function defined by default.
174 |
175 | The project has the following structure:
176 |
177 | .. code-block:: text
178 |
179 | dub.json - package information
180 | source/ - D source code
181 | app.d
182 | service.d
183 | views/ - Diet templates
184 | index.dt
185 | layout.dt
186 | public/ - static directories
187 | javascripts/
188 | global.js
189 | styles
190 | style.css
191 | favicon.ico
192 |
193 | After installing MongoDB_, run the server
194 |
195 | .. code-block:: shell
196 |
197 | $ mongod
198 |
199 |
200 | In another console run the Mongo interpreter
201 |
202 | .. code-block:: shell
203 |
204 | $ mongo
205 | > use vibed
206 | switched to db vibed
207 | > db.createCollection("userlist", {autoIndexID : true})
208 | { "ok" : 1 }
209 | > db.userlist.insert({
210 | 'username' : 'test1',
211 | 'email' : 'test1@test.com',
212 | 'fullname' : 'Bob Smith',
213 | 'age' : 27,
214 | 'location' : 'San Francisco',
215 | 'gender' : 'male'
216 | })
217 | WriteResult({ "nInserted" : 1 })
218 | > exit
219 | bye
220 |
221 | The above script creates a ``vibed`` database with a ``userlist`` collection, which will contain one record.
222 |
223 | .. _MongoDB: https://www.mongodb.org
224 |
225 |
226 | Patches
227 | ^^^^^^^^^
228 |
229 | Comparing with the original article ``global.js`` was slightly changed:
230 |
231 | .. literalinclude:: ../../examples/vibed-mongo/public/javascripts/global.js
232 | :language: js
233 | :tab-width: 4
234 | :lines: 96-107
235 |
236 | .. literalinclude:: ../../examples/vibed-mongo/public/javascripts/global.js
237 | :language: js
238 | :tab-width: 4
239 | :lines: 129-138
240 |
241 | Diet Templates
242 | ^^^^^^^^^^^^^^
243 |
244 | `Diet templates`_ are HTML templates which are statically compiled down to native D code.
245 | Diet templates syntax equals that of Jade templates with the exception of some of the advanced syntax features.
246 |
247 | First lines of ``index.dt``:
248 |
249 | .. literalinclude:: ../../examples/vibed-mongo/views/index.dt
250 | :language: d
251 | :tab-width: 4
252 | :lines: 1-12
253 |
254 | .. _Diet templates: http://vibed.org/templates/diet
255 |
256 |
257 | Service
258 | ^^^^^^^^^^^^^
259 |
260 | ``vibe.d`` is a good example of the use of declarative programming with D.
261 | Service performs an *insert*, *select* and *remove* operations for user entries at a mongo collection.
262 |
263 | .. literalinclude:: ../../examples/vibed-mongo/source/service.d
264 | :language: d
265 | :tab-width: 4
266 |
267 | App
268 | ^^^^^^^^^^^^^
269 |
270 | The following static constructor connects ``vibed`` database, creates the HTTP server and implements the error handler.
271 |
272 | .. literalinclude:: ../../examples/vibed-mongo/source/app.d
273 | :language: d
274 | :tab-width: 4
275 |
--------------------------------------------------------------------------------
/docs/source/img/hist.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andralex/thenextafterc/3f33b14fda0848a1992e211ed0461b9edc7a40da/docs/source/img/hist.png
--------------------------------------------------------------------------------
/docs/source/img/vibed-mongo.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andralex/thenextafterc/3f33b14fda0848a1992e211ed0461b9edc7a40da/docs/source/img/vibed-mongo.png
--------------------------------------------------------------------------------
/docs/source/index.rst:
--------------------------------------------------------------------------------
1 | Welcome to Quick Start with D!
2 | ==============================================
3 |
4 | .. toctree::
5 | :maxdepth: 2
6 |
7 | introduction
8 | examples
9 | integration
10 | links
11 |
--------------------------------------------------------------------------------
/docs/source/integration.rst:
--------------------------------------------------------------------------------
1 | Integration with other languages
2 | ==============================================
3 |
4 | C and friends
5 | -------------
6 |
7 | D that `has `_ full support for C ABI [#ABI]_ had recently been significantly improved for `interfacing with C++ `_ (however there is no support for C++ exceptions). Jacob Carlborg did a great job of integrating with Objective-C, which is still waiting to be no less grandiose review by Walter Bright.
8 |
9 | Scripting languages
10 | -------------------
11 |
12 | You are already somehow familiar with the integration of scripting languages on the `example `_ of the use of the matplotlib library and `PyD `_. Since most of them have a C API [#API]_, their integration with D can be performed without problems.
13 |
14 | There is a `realization `_ of the ECMA 262 (Javascript) programming language written by Walter Bright and updated by Dmitry Olshansky.
15 |
16 | It is also worth mentioning the Lua programming language. Unlike many other libraries built on the Lua C API, `LuaD `_ does not expose the Lua stack - instead, it has wrappers for references to Lua objects, and supports seamlessly and directly converting any D type into a Lua type and vice versa.
17 |
18 | .. [#API] Application Programming Interface
19 | .. [#ABI] Application Binary Interface
20 |
--------------------------------------------------------------------------------
/docs/source/introduction.rst:
--------------------------------------------------------------------------------
1 | Introduction
2 | ================
3 |
4 | It was mentioned that students can quickly master the D programming language without a detailed study using mostly its subset, which is close to the C PL.
5 |
6 | Consider a simple program that reads from a file of 10 lines, each containing a single number and prints to the standard output at the same number, but shifted to the mathematician expectation.
7 |
8 | Whereas idiomatic D code looks pretty unusual:
9 |
10 | .. literalinclude:: ../../examples/readdoubles2.d
11 | :language: d
12 | :tab-width: 4
13 |
14 | for many unfamiliar with the language D the same program can be implemented even as more complex, but at the same time more understandable way:
15 |
16 | .. literalinclude:: ../../examples/readdoubles1.d
17 | :language: d
18 | :tab-width: 4
19 |
20 | The present documentation is submitted to the rapid introduction to D for those who are already somehow familiar with the C language and for some reasons do not want to waste time on a consistent study of the D language and related tools.
21 |
22 | If you decide to use the D language in your daily work, you should start immediately with the study of the `official page `_ and of the book `"The D Programming Language" `_ by Andrei Alexandrescu.
23 |
24 | Probably D is the most powerful of the present `system programming languages `_.
25 |
26 | *D is a dragon* [#dragon]_. *Have a nice flight!*
27 |
28 | .. [#dragon] `D is a dragon, or why D matters for Bioinformatics `_ by Pjotr Prins.
29 |
--------------------------------------------------------------------------------
/docs/source/links.rst:
--------------------------------------------------------------------------------
1 | Links
2 | ==============================================
3 |
4 | General:
5 | - http://dlang.org - The D Programming Language
6 | - http://wiki.dlang.org - The D Wiki
7 | - http://code.dlang.org - The D Package Registry
8 | - http://forum.dlang.org - Discussion
9 | - http://dconf.org - The Conference
10 | - http://ddocs.org - Documentation for all packages published at the D Package Registry (temporary unavailable)
11 |
12 | `Books `_:
13 | - **The D Programming Language**, Andrei Alexandrescu, June 12, 2010.
14 |
15 | + `Amazon `_
16 | + `Read chapter 1 online - "D"iving In `_
17 | + `Read chapter 13 online - Concurrency `_
18 | + `Errata `_
19 | - **Programming in D**, Ali Çehreli - `The online book `_
20 | - **D Cookbook**, Adam D. Ruppe, May 26, 2014
21 |
22 | + `Publisher's page `_
23 | + `Amazon `_
24 | - **D Templates: A Tutorial**, Philippe Sigaud - `Free book `_
25 | - **Pragmatic D Tutorial**, Andreas Zwinkau - `Website `_
26 | - **Developing with compile time in mind**, Richard Cattermole, February 17, 2015 - `Website `_
27 | - **D programming**, January 1, 2015 - `Website `_
28 |
29 | `Compilers `_:
30 | - `DMD `_ - The reference D compiler
31 | - `LDC `_ - LLVM D Compiler
32 | - `GDC `_ - GCC D Compiler
33 |
34 |
35 | `Development Environments `_:
36 | - `Visual D `_ - integration into Visual Studio
37 | - `Mono-D `_ - D support to the cross-platform XamarinStudio/MonoDevelop IDE
38 | - `DKit `_ - a package to aid developing D programs using Sublime Text 3
39 | - `DDT `_ - an Eclipse IDE for the D programming language
40 |
--------------------------------------------------------------------------------
/examples/10numbers.txt:
--------------------------------------------------------------------------------
1 | 12.234
2 | 234.12
3 | 3.2134
4 | -123.432
5 | 2.454
6 | 324.234
7 | 0.
8 | 2345.
9 | 2
10 | 2.43
--------------------------------------------------------------------------------
/examples/dub-example/application/.gitignore:
--------------------------------------------------------------------------------
1 | .dub
2 | docs.json
3 | __dummy.html
4 | *.o
5 | *.obj
6 |
--------------------------------------------------------------------------------
/examples/dub-example/application/dub.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "application",
3 | "description": "A minimal D application.",
4 | "copyright": "Copyright © 2015, ilya",
5 | "authors": ["ilya"],
6 | "dependencies": {
7 | "component": "~master"
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/examples/dub-example/application/source/app.d:
--------------------------------------------------------------------------------
1 | import component;
2 |
3 | import std.stdio;
4 |
5 | void main()
6 | {
7 | writeln("Edit source/app.d to start your project.");
8 | }
9 |
--------------------------------------------------------------------------------
/examples/dub-example/component/.gitignore:
--------------------------------------------------------------------------------
1 | .dub
2 | docs.json
3 | __dummy.html
4 | *.o
5 | *.obj
6 |
--------------------------------------------------------------------------------
/examples/dub-example/component/dub.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "component",
3 | }
4 |
--------------------------------------------------------------------------------
/examples/dub-example/component/source/component/mod.d:
--------------------------------------------------------------------------------
1 | /++
2 | Module mod;
3 | +/
4 | module component.mod;
5 |
6 | import std.algorithm, std.ascii, std.range, std.string, std.functional;
7 |
8 | /++
9 | Reads forward range `ir` and removes single line comments.
10 | The result is stored in output range `or`.
11 |
12 | Params:
13 | or = output range
14 | ir = input range
15 | cmt = comment prefix (like // in C or # in Python)
16 | +/
17 | void removeSingleLineComments
18 | (OutputRange, Range1, Range2) // template parameters
19 | (OutputRange or, Range1 ir, Range2 cmt) // function parameters
20 | {
21 | foreach(line; lineSplitter(ir))
22 | {
23 | if(line.save.find!(not!isWhite).startsWith(cmt))
24 | continue; //skips line
25 | put(or, line.until(cmt)); //skips comment
26 | put(or, "\n");
27 | }
28 | }
29 |
30 | /// Unittests with comment appears in documentation.
31 | unittest
32 | {
33 | auto app = appender!string;
34 |
35 | // A string that contains a code with C-like block syntax
36 | // can be framed with `q{` and `}`.
37 | immutable textBefore = q{
38 | // main function
39 | int main()
40 | {
41 | // return statement
42 | return 0; //returns 0
43 | }
44 | };
45 |
46 | immutable textAfter = q{
47 | int main()
48 | {
49 | return 0;
50 | }
51 | }; // Note: "return 0; " ends with a space character.
52 |
53 | removeSingleLineComments(app, textBefore, "//");
54 |
55 | debug
56 | {
57 | import std.stdio;
58 | writeln("text:", app.data);
59 | }
60 |
61 | assert(app.data == textAfter);
62 | }
63 |
--------------------------------------------------------------------------------
/examples/dub-example/component/source/component/package.d:
--------------------------------------------------------------------------------
1 | /++
2 | Pacakge component
3 | +/
4 | module component;
5 |
6 | public import component.mod : removeSingleLineComments;
--------------------------------------------------------------------------------
/examples/helloworld.c:
--------------------------------------------------------------------------------
1 | #include
2 |
3 | const char* const nullTerminatedStrPtr = "Hello, World!";
4 |
5 | int main(void)
6 | {
7 | puts(nullTerminatedStrPtr);
8 | return 0;
9 | }
10 |
--------------------------------------------------------------------------------
/examples/helloworld1.d:
--------------------------------------------------------------------------------
1 | import core.stdc.stdio;
2 |
3 | // terminates with a null character
4 | immutable char[] nullTerminatedStr = "Hello, World!\0";
5 |
6 | int main()
7 | {
8 | // calls external C function
9 | puts(nullTerminatedStr.ptr);
10 | return 0;
11 | }
12 |
--------------------------------------------------------------------------------
/examples/helloworld2.d:
--------------------------------------------------------------------------------
1 | /++
2 | Deduces the type of a declared variable from its initialization
3 | expression.
4 | +/
5 | immutable str = "Hello, World!";
6 |
7 | void main()
8 | {
9 | // Scoped and selective imports can be used.
10 | import std.stdio : writeln;
11 | writeln(str);
12 | }
13 |
--------------------------------------------------------------------------------
/examples/matplotlib/data/data.txt:
--------------------------------------------------------------------------------
1 | 20.2332
2 | 42.3679
3 | 8.86217
4 | 12.6602
5 | 18.6301
6 | 19.4552
7 | 0.596539
8 | 4.86394
9 | 17.5382
10 | 2.9923
11 | 20.6713
12 | 18.9044
13 | 8.35739
14 | 6.79646
15 | 4.0428
16 | 60.177
17 | 6.02727
18 | 13.6762
19 | 5.84531
20 | 40.4126
21 | 5.13454
22 | 14.6628
23 | 19.4957
24 | 45.6331
25 | 8.44498
26 | 5.96829
27 | 3.05569
28 | 1.5556
29 | 27.9239
30 | 12.5619
31 | 14.7378
32 | 16.6311
33 | 24.7833
34 | 11.3087
35 | 14.4783
36 | 6.49317
37 | 4.62596
38 | 13.7038
39 | 8.95803
40 | 24.57
41 | 16.703
42 | 1.06748
43 | 15.7374
44 | 22.8391
45 | 64.7787
46 | 28.1531
47 | 16.6427
48 | 31.9302
49 | 30.6553
50 | 8.31534
51 | 13.9223
52 | 33.1505
53 | 18.359
54 | 8.42114
55 | 5.80173
56 | 16.1024
57 | 4.97669
58 | 24.0913
59 | 12.5104
60 | 5.48508
61 | 9.00047
62 | 12.0428
63 | 28.0805
64 | 24.5652
65 | 17.7609
66 | 27.6687
67 | 4.09912
68 | 0.574227
69 | 13.3386
70 | 9.16918
71 | 1.38957
72 | 25.0816
73 | 29.8923
74 | 34.7454
75 | 23.2631
76 | 20.4283
77 | 27.088
78 | 12.9617
79 | 22.1372
80 | 4.49582
81 | 24.2322
82 | 18.1842
83 | 17.4657
84 | 35.1792
85 | 8.77848
86 | 49.3016
87 | 15.5238
88 | 23.6421
89 | 26.055
90 | 10.9818
91 | 5.39214
92 | 8.57994
93 | 7.27909
94 | 13.8033
95 | 1.71259
96 | 32.2676
97 | 14.9775
98 | 8.27007
99 | 19.301
100 | 29.3468
101 | 21.2332
102 | 32.0917
103 | 1.00105
104 | 5.87151
105 | 17.9665
106 | 8.5988
107 | 9.99566
108 | 33.314
109 | 2.24533
110 | 9.47478
111 | 12.1481
112 | 9.40212
113 | 21.362
114 | 7.66665
115 | 6.00023
116 | 13.8407
117 | 10.4691
118 | 14.4327
119 | 1.9047
120 | 32.2743
121 | 15.9426
122 | 20.5084
123 | 15.2598
124 | 2.21028
125 | 12.8592
126 | 29.185
127 | 8.9787
128 | 17.5206
129 | 6.02423
130 | 27.4147
131 | 26.4296
132 | 5.44287
133 | 24.3384
134 | 20.1848
135 | 20.6515
136 | 19.1501
137 | 19.1692
138 | 33.6576
139 | 20.8475
140 | 23.8625
141 | 7.7405
142 | 30.3496
143 | 6.58158
144 | 6.59286
145 | 4.95699
146 | 11.3303
147 | 8.96458
148 | 28.0819
149 | 12.4702
150 | 29.1527
151 | 29.2539
152 | 2.3941
153 | 33.7811
154 | 8.34931
155 | 20.08
156 | 16.8145
157 | 7.84148
158 | 33.8128
159 | 17.989
160 | 16.5764
161 | 5.71729
162 | 8.4078
163 | 7.31692
164 | 9.83089
165 | 13.2306
166 | 8.35412
167 | 9.86086
168 | 7.50114
169 | 13.0572
170 | 23.4426
171 | 8.10847
172 | 6.35226
173 | 9.47718
174 | 23.744
175 | 6.51479
176 | -0.342704
177 | 19.6106
178 | 25.561
179 | 6.10703
180 | 18.6116
181 | 31.1354
182 | 24.0151
183 | 7.19113
184 | 63.8663
185 | 3.92149
186 | 5.1804
187 | 1.00825
188 | 15.7822
189 | 28.6956
190 | 5.07165
191 | 31.6456
192 | 17.5434
193 | 18.5659
194 | 10.7696
195 | 6.19466
196 | 24.7667
197 | 11.728
198 | 36.3025
199 | 36.7577
200 | 17.4621
201 | 17.8375
202 | 22.2105
203 | 6.05837
204 | 4.03455
205 | 22.1121
206 | 10.2073
207 | 27.7797
208 | 22.1845
209 | 3.30473
210 | 3.80011
211 | 7.54889
212 | 5.7825
213 | 24.4893
214 | 21.5239
215 | 3.56536
216 | 8.2986
217 | 15.8246
218 | 7.4294
219 | 4.71408
220 | 16.3123
221 | 19.6054
222 | 29.3996
223 | 8.31801
224 | 37.5416
225 | 4.36464
226 | 25.0845
227 | 6.37083
228 | 35.7016
229 | 11.2029
230 | 10.9801
231 | 7.27578
232 | 30.8526
233 | 28.1782
234 | 17.5539
235 | 9.38032
236 | 15.8844
237 | 16.757
238 | 4.54032
239 | 15.8104
240 | 7.69895
241 | 1.46097
242 | 38.4163
243 | 41.476
244 | 4.17107
245 | 18.875
246 | 12.8928
247 | 4.98883
248 | 9.63294
249 | 10.7467
250 | 6.3185
251 | 7.7367
252 | 17.197
253 | 7.36418
254 | 26.8324
255 | 32.852
256 | 8.51325
257 | 8.7526
258 | 12.6153
259 | 3.64819
260 | 2.89191
261 | 12.1481
262 | 22.8758
263 | 17.6967
264 | 20.7179
265 | 13.0318
266 | 10.9918
267 | 9.08511
268 | 15.8909
269 | 15.9424
270 | 17.2264
271 | 41.3814
272 | 27.9444
273 | 19.1606
274 | 10.3933
275 | 8.43251
276 | 6.69159
277 | 3.46643
278 | 4.23889
279 | 20.409
280 | 15.8574
281 | 8.24907
282 | 17.0773
283 | 14.9183
284 | 28.644
285 | 28.3452
286 | 4.69101
287 | 45.7932
288 | 12.2867
289 | 10.8471
290 | 7.18071
291 | 29.7106
292 | 23.5648
293 | 2.24729
294 | 10.5767
295 | 15.047
296 | 37.904
297 | 31.5907
298 | 19.051
299 | 18.8525
300 | 13.3756
301 | 7.5217
302 | 16.2996
303 | 6.32676
304 | 11.9035
305 | 7.30354
306 | 2.86444
307 | 29.3753
308 | 29.0452
309 | 2.58665
310 | 7.08017
311 | 25.4153
312 | 32.535
313 | 10.766
314 | 15.3118
315 | 22.7598
316 | 1.54646
317 | -0.36702
318 | 23.1774
319 | 4.26672
320 | 7.17759
321 | 17.4872
322 | 19.0398
323 | 25.9524
324 | 4.61671
325 | 8.87305
326 | 6.96575
327 | 3.67538
328 | 3.38691
329 | 7.22672
330 | 16.4021
331 | 22.2396
332 | 27.4215
333 | 18.0293
334 | 12.4447
335 | 8.98029
336 | 6.00193
337 | 27.3455
338 | 22.712
339 | 11.2992
340 | 22.4949
341 | 9.1243
342 | 26.4443
343 | 52.1557
344 | 20.0321
345 | 13.5482
346 | 2.24068
347 | 8.37184
348 | 21.4386
349 | 19.3106
350 | 29.3063
351 | 13.8445
352 | 16.3164
353 | 4.02751
354 | 10.8609
355 | 6.03863
356 | 9.92485
357 | 22.0833
358 | 11.1234
359 | 11.8045
360 | 5.82869
361 | 9.82669
362 | 10.6536
363 | 19.3599
364 | 0.0792523
365 | 12.9472
366 | 26.9908
367 | 36.5923
368 | 14.7535
369 | 9.55918
370 | 15.0446
371 | 18.337
372 | 26.1297
373 | 8.92572
374 | 19.8416
375 | 3.87365
376 | 14.2021
377 | 27.2262
378 | 5.32707
379 | 24.0215
380 | 11.805
381 | 41.1449
382 | 14.097
383 | 33.838
384 | 9.10244
385 | 2.3694
386 | 33.2596
387 | 5.04095
388 | 5.37379
389 | 18.0808
390 | 12.5449
391 | 12.0503
392 | 30.8417
393 | 25.5466
394 | 37.7807
395 | 7.15764
396 | 5.86213
397 | 24.3955
398 | 16.553
399 | 24.8346
400 | 2.00789
401 | 17.7119
402 | 33.3961
403 | 30.9011
404 | 23.429
405 | 13.4632
406 | 6.21145
407 | 8.07325
408 | 10.8301
409 | 17.8208
410 | 6.49593
411 | 11.6018
412 | 21.5234
413 | 27.5255
414 | 12.9682
415 | 8.89265
416 | 6.35182
417 | 2.71111
418 | 18.7079
419 | 0.228496
420 | 16.997
421 | 7.41794
422 | 15.4716
423 | 14.003
424 | 20.0225
425 | 27.6528
426 | 25.1745
427 | 31.2885
428 | 19.974
429 | 27.6341
430 | 4.08462
431 | 20.3269
432 | 24.7171
433 | 15.5098
434 | 34.8952
435 | 9.4484
436 | 22.6498
437 | 11.5667
438 | 19.9241
439 | 7.84407
440 | 22.2078
441 | 17.2956
442 | 10.0443
443 | 13.8157
444 | 4.1575
445 | 23.8773
446 | 6.14949
447 | 13.7082
448 | 2.55048
449 | 24.6129
450 | 47.5572
451 | 12.3332
452 | 22.5027
453 | 11.5212
454 | 9.00778
455 | 25.106
456 | 5.03414
457 | 5.08422
458 | 8.9926
459 | 40.9082
460 | 39.0168
461 | 22.9897
462 | 23.6525
463 | 1.57794
464 | 10.8001
465 | 8.12631
466 | 20.6967
467 | 7.31989
468 | 6.85265
469 | 35.1205
470 | 20.101
471 | 11.6727
472 | 4.48256
473 | 6.70055
474 | 2.83623
475 | 4.4802
476 | 43.2877
477 | 14.25
478 | 16.8924
479 | 10.0396
480 | 12.259
481 | 17.6253
482 | 10.8843
483 | 0.919847
484 | 9.3649
485 | 4.19444
486 | 4.15295
487 | 21.5506
488 | 31.4199
489 | 27.5669
490 | 5.19802
491 | 39.4475
492 | 10.2799
493 | 21.899
494 | 4.58259
495 | 7.32036
496 | 3.22897
497 | 47.2059
498 | 4.49738
499 | 50.2594
500 | 14.8183
501 | 21.3499
502 | 26.0072
503 | 6.6207
504 | 46.3106
505 | 4.64594
506 | 15.5761
507 | 9.63803
508 | 16.4954
509 | 5.2979
510 | 9.17428
511 | 20.91
512 | 32.4484
513 | 4.70089
514 | 9.24776
515 | 18.8398
516 | 8.11797
517 | 3.21362
518 | 1.5088
519 | 29.0626
520 | 11.0495
521 | 44.879
522 | 15.7012
523 | 27.2765
524 | 3.85452
525 | 24.6606
526 | 3.00864
527 | 7.56087
528 | 4.40037
529 | 9.02417
530 | 18.7853
531 | 8.28062
532 | 2.7434
533 | 11.2429
534 | 7.78561
535 | 22.3684
536 | 4.05457
537 | 6.35269
538 | 8.91942
539 | 18.8726
540 | 11.7345
541 | 13.1961
542 | 27.0297
543 | 10.2763
544 | 8.77465
545 | 9.96937
546 | 11.7031
547 | 12.4693
548 | 24.6715
549 | 12.0192
550 | 15.9471
551 | 30.4509
552 | 27.5617
553 | 7.15049
554 | 63.6309
555 | 9.41706
556 | 9.42921
557 | 25.6
558 | 11.9531
559 | 14.9887
560 | 21.0835
561 | 18.0886
562 | 35.0756
563 | 29.9143
564 | 23.1852
565 | 12.4068
566 | 16.9842
567 | 3.85308
568 | 27.6599
569 | 11.3946
570 | 21.7547
571 | 2.17725
572 | 18.1845
573 | 8.53685
574 | 1.68903
575 | 37.3817
576 | 5.27561
577 | 31.6029
578 | 28.8799
579 | 6.83556
580 | 3.75391
581 | 7.20895
582 | 34.9622
583 | 22.8041
584 | 8.02263
585 | 5.75369
586 | 0.469725
587 | 15.6761
588 | 7.81092
589 | 15.3414
590 | 3.17333
591 | 11.5062
592 | 14.9558
593 |
--------------------------------------------------------------------------------
/examples/matplotlib/dub.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "plotting_example",
3 | "dependencies": {
4 | "pyd": "~>0.9.4",
5 | },
6 | "subConfigurations": {
7 | "pyd": "python34",
8 | },
9 | }
10 |
--------------------------------------------------------------------------------
/examples/matplotlib/source/app.d:
--------------------------------------------------------------------------------
1 | import pyd.pyd;
2 | import pyd.embedded;
3 | import pyd.extra;
4 |
5 | /++
6 | `srcipt` is a string that contains the python code to execute.
7 |
8 | Alternatively, you can put your python code here:
9 |
10 | --------
11 | immutable script = `
12 | YOUR = "PYTHON"; CODE = "HERE"
13 | print(YOUR, CODE)
14 | `;
15 | --------
16 |
17 | where string is framed with backtick character.
18 | +/
19 | immutable script = import("show_histogram.py");
20 |
21 | /++
22 | `d_to_python_numpy_ndarray` converts a D array to numpy.ndarray.
23 | `toNumpyArray` is only an alias.
24 | +/
25 | alias toNumpyArray = d_to_python_numpy_ndarray;
26 |
27 | /++
28 | A static constructor is a function that performs initializations of
29 | thread local data before the `main()` function gets control for the
30 | main thread.
31 |
32 | Shared static constructors are executed before any static
33 | constructors, and are intended for initializing any shared global
34 | data.
35 | +/
36 | shared static this() {
37 | //initializes PyD package.
38 | py_init();
39 | }
40 |
41 | void main()
42 | {
43 | auto pythonContext = new InterpContext();
44 | /+
45 | Uniform Function Call Syntax (UFCS)
46 | is used in the following line of code.
47 |
48 | Equivalent code would be just:
49 | --------
50 | pythonContext.sample = toNumpyArray(readData("data/data.txt"));
51 | --------
52 | +/
53 | pythonContext.sample = "data/data.txt".readData.toNumpyArray;
54 | pythonContext.num_bins = 50;
55 | pythonContext.py_stmts(script);
56 | }
57 |
58 | double[] readData(string file)
59 | {
60 | import std.algorithm.iteration : map, splitter;
61 | import std.array : array;
62 | import std.conv : to;
63 | import std.file : readText;
64 |
65 | return file
66 | .readText //Reads the contents of a text file into a string.
67 | .splitter //Lazily splits words.
68 | .map!(to!double) //Lazily converts words to doubles.
69 | .array; //Creates an array.
70 | }
71 |
--------------------------------------------------------------------------------
/examples/matplotlib/views/show_histogram.py:
--------------------------------------------------------------------------------
1 | # variables `sample` and `num_bins` should be defined in context
2 | import matplotlib.pyplot as plt
3 | n, bins, patches = plt.hist(sample, num_bins, normed=1)
4 | plt.show()
5 |
--------------------------------------------------------------------------------
/examples/readdoubles1.d:
--------------------------------------------------------------------------------
1 | import std.stdio;
2 |
3 | void main()
4 | {
5 | File fin = File("10numbers.txt");
6 | double[] sample;
7 | sample.length = 10;
8 | double mean = 0;
9 | for(int i = 0; i < sample.length; i++)
10 | {
11 | fin.readf("%s", &sample[i]);
12 | if(!fin.eof)
13 | fin.readln();
14 | mean += sample[i];
15 | }
16 | mean /= sample.length;
17 | // prints one element per line
18 | for(int i = 0; i < sample.length; i++)
19 | {
20 | writeln(sample[i] - mean);
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/examples/readdoubles2.d:
--------------------------------------------------------------------------------
1 | import std.algorithm.iteration : map, each;
2 | import std.array : array;
3 | import std.conv : parse;
4 | import std.range : takeExactly, tee;
5 | import std.stdio;
6 |
7 | void main()
8 | {
9 | double mean = 0;
10 | auto sample = File("10numbers.txt")
11 | .byLine
12 | .takeExactly(10)
13 | .map!(line => line.parse!double)
14 | .tee!((x){mean += x;})
15 | .array;
16 | mean /= sample.length;
17 | // prints one element per line
18 | sample.map!(x => x - mean).each!writeln;
19 | }
20 |
--------------------------------------------------------------------------------
/examples/vibed-mongo/.gitignore:
--------------------------------------------------------------------------------
1 | .dub
2 | docs.json
3 | __dummy.html
4 | *.o
5 | *.obj
6 |
--------------------------------------------------------------------------------
/examples/vibed-mongo/dub.json:
--------------------------------------------------------------------------------
1 | {
2 | "name": "vibed-mongo",
3 | "dependencies": {
4 | "vibe-d": "~>0.7.23"
5 | },
6 | "versions": ["VibeDefaultMain"],
7 | "authors": ["Christopher Buecheler", "Ilya Yaroshenko"]
8 | }
9 |
--------------------------------------------------------------------------------
/examples/vibed-mongo/dub.selections.json:
--------------------------------------------------------------------------------
1 | {
2 | "fileVersion": 1,
3 | "versions": {
4 | "memutils": "0.3.4",
5 | "vibe-d": "0.7.23+commit.66.gac6d4ff",
6 | "libevent": "2.0.1+2.0.16",
7 | "openssl": "1.1.4+1.0.1g",
8 | "libev": "5.0.0+4.04",
9 | "libasync": "0.7.1"
10 | }
11 | }
--------------------------------------------------------------------------------
/examples/vibed-mongo/public/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/andralex/thenextafterc/3f33b14fda0848a1992e211ed0461b9edc7a40da/examples/vibed-mongo/public/favicon.ico
--------------------------------------------------------------------------------
/examples/vibed-mongo/public/javascripts/global.js:
--------------------------------------------------------------------------------
1 | // Userlist data array for filling in info box
2 | var userListData = [];
3 |
4 | // DOM Ready =============================================================
5 | $(document).ready(function() {
6 |
7 | // Populate the user table on initial page load
8 | populateTable();
9 |
10 | // Username link click
11 | $('#userList table tbody').on('click', 'td a.linkshowuser', showUserInfo);
12 |
13 | // Add User button click
14 | $('#btnAddUser').on('click', addUser);
15 |
16 | // Delete User link click
17 | $('#userList table tbody').on('click', 'td a.linkdeleteuser', deleteUser);
18 |
19 | });
20 |
21 | // Functions =============================================================
22 |
23 | // Fill table with data
24 | function populateTable() {
25 |
26 | // Empty content string
27 | var tableContent = '';
28 |
29 | // jQuery AJAX call for JSON
30 | $.getJSON( '/users/userlist', function( data ) {
31 |
32 | // Stick our user data array into a userlist variable in the global object
33 | userListData = data;
34 |
35 | // For each item in our JSON, add a table row and cells to the content string
36 | $.each(data, function(){
37 | tableContent += '';
38 | tableContent += '' + this.username + ' | ';
39 | tableContent += '' + this.email + ' | ';
40 | tableContent += 'delete | ';
41 | tableContent += '
';
42 | });
43 |
44 | // Inject the whole content string into our existing HTML table
45 | $('#userList table tbody').html(tableContent);
46 | });
47 | };
48 |
49 | // Show User Info
50 | function showUserInfo(event) {
51 |
52 | // Prevent Link from Firing
53 | event.preventDefault();
54 |
55 | // Retrieve username from link rel attribute
56 | var thisUserName = $(this).attr('rel');
57 |
58 | // Get Index of object based on id value
59 | var arrayPosition = userListData.map(function(arrayItem) { return arrayItem.username; }).indexOf(thisUserName);
60 |
61 | // Get our User Object
62 | var thisUserObject = userListData[arrayPosition];
63 |
64 | //Populate Info Box
65 | $('#userInfoName').text(thisUserObject.fullname);
66 | $('#userInfoAge').text(thisUserObject.age);
67 | $('#userInfoGender').text(thisUserObject.gender);
68 | $('#userInfoLocation').text(thisUserObject.location);
69 |
70 | };
71 |
72 | // Add User
73 | function addUser(event) {
74 | event.preventDefault();
75 |
76 | // Super basic validation - increase errorCount variable if any fields are blank
77 | var errorCount = 0;
78 | $('#addUser input').each(function(index, val) {
79 | if($(this).val() === '') { errorCount++; }
80 | });
81 |
82 | // Check and make sure errorCount's still at zero
83 | if(errorCount === 0) {
84 |
85 | // If it is, compile all user info into one object
86 | var newUser = {
87 | 'username': $('#addUser fieldset input#inputUserName').val(),
88 | 'email': $('#addUser fieldset input#inputUserEmail').val(),
89 | 'fullname': $('#addUser fieldset input#inputUserFullname').val(),
90 | 'age': $('#addUser fieldset input#inputUserAge').val(),
91 | 'location': $('#addUser fieldset input#inputUserLocation').val(),
92 | 'gender': $('#addUser fieldset input#inputUserGender').val()
93 | }
94 |
95 | // Use AJAX to post the object to our adduser service
96 | $.ajax({
97 | type: 'POST',
98 | data: newUser,
99 | url: '/users/adduser',
100 | success: function(data){
101 | $('#addUser fieldset input').val('');
102 | populateTable();
103 | },
104 | error: function(xhr, textStatus, error){
105 | alert(xhr.responseText);
106 | }
107 | });
108 |
109 | }
110 | else {
111 | // If errorCount is more than 0, error out
112 | alert('Please fill in all fields');
113 | return false;
114 | }
115 | };
116 |
117 | // Delete User
118 | function deleteUser(event) {
119 |
120 | event.preventDefault();
121 |
122 | // Pop up a confirmation dialog
123 | var confirmation = confirm('Are you sure you want to delete this user?');
124 |
125 | // Check and make sure the user confirmed
126 | if (confirmation === true) {
127 |
128 | // If they did, do our delete
129 | $.ajax({
130 | type: 'DELETE',
131 | url: '/users/deleteuser/' + $(this).attr('rel'),
132 | success: function(data){
133 | populateTable();
134 | },
135 | error: function(xhr, textStatus, error){
136 | alert(xhr.responseText);
137 | }
138 | });
139 |
140 | }
141 | else {
142 | // If they said no to the confirm, do nothing
143 | return false;
144 | }
145 |
146 | };
--------------------------------------------------------------------------------
/examples/vibed-mongo/public/styles/style.css:
--------------------------------------------------------------------------------
1 | body {
2 | padding: 30px;
3 | font: 14px "Lucida Grande", Helvetica, Arial, sans-serif;
4 | }
5 |
6 | h2 {
7 | margin:0 0 .5em 0;
8 | }
9 |
10 | a {
11 | color: #00B7FF;
12 | }
13 |
14 | #wrapper {
15 | padding-left:312px;
16 | position:relative;
17 | }
18 |
19 | #userList {
20 | margin:0 0 30px 0;
21 | }
22 | #userList table {
23 | border-collapse:separate;
24 | border-spacing:1px;
25 | background:#CCC;
26 | }
27 | #userList table th {
28 | background:#EEE;
29 | font-weight:600;
30 | padding:10px 20px;
31 | text-align:center;
32 | }
33 | #userList table tbody {
34 | padding:0; margin:0;
35 | border-collapse:collapse;
36 | border-spacing:0px;
37 | }
38 | #userList table td {
39 | background:#FFF;
40 | padding:5px 10px;
41 | text-align:center;
42 | }
43 |
44 | #userInfo {
45 | width:250px;
46 | position:absolute;
47 | top:0; left:0;
48 | }
49 | #userInfo p {
50 | padding:15px;
51 | border:1px solid #CCC;
52 | background:rgba(80,120,255,0.05);
53 | }
54 |
55 | fieldset {
56 | border:0;
57 | padding:0; margin:0;
58 | }
--------------------------------------------------------------------------------
/examples/vibed-mongo/source/app.d:
--------------------------------------------------------------------------------
1 | import vibe.d;
2 | import service;
3 |
4 | shared static this()
5 | {
6 | immutable string title = "vibe.d";
7 |
8 | logInfo("Connecting to DB...");
9 | auto db = connectMongoDB("localhost").getDatabase("vibed");
10 | auto collection = db["userlist"];
11 |
12 | logInfo("Creating service...");
13 | auto mongoService = new MongoService(collection, title);
14 | auto mongoServiceSettings = new WebInterfaceSettings;
15 | mongoServiceSettings.urlPrefix = "/users";
16 |
17 |
18 | logInfo("Setup router...");
19 | auto router = new URLRouter;
20 | router.registerWebInterface(mongoService, mongoServiceSettings);
21 | router
22 | .get("/", (req, res)
23 | { res.redirect("/users"); } )
24 | .get("*", serveStaticFiles("public/"));
25 |
26 | logInfo("Setup HTTP server...");
27 | auto settings = new HTTPServerSettings;
28 | with(settings)
29 | {
30 | bindAddresses = ["127.0.0.1"];
31 | port = 8080;
32 | errorPageHandler =
33 | (req, res, error)
34 | {
35 | with(error) res.writeBody(
36 | format("Code: %s\n Message: %s\n Exception: %s",
37 | code,
38 | message,
39 | exception ? exception.msg : ""));
40 | };
41 | }
42 |
43 | //Listening http://127.0.0.1:8080
44 | listenHTTP(settings, router);
45 | }
46 |
--------------------------------------------------------------------------------
/examples/vibed-mongo/source/service.d:
--------------------------------------------------------------------------------
1 | module service;
2 |
3 | import std.conv;
4 | import vibe.d;
5 |
6 | class MongoService
7 | {
8 | private MongoCollection collection;
9 | const string title;
10 |
11 | this(MongoCollection collection, string title = "")
12 | {
13 | this.collection = collection;
14 | this.title = title;
15 | }
16 |
17 | void index()
18 | {
19 | logInfo("MongoService: GET /");
20 | render!("index.dt", title);
21 | }
22 |
23 | void postAdduser(
24 | string username,
25 | string email,
26 | string fullname,
27 | uint age,
28 | string location,
29 | string gender,
30 | HTTPServerResponse res,
31 | )
32 | {
33 | import vibe.utils.validation;
34 |
35 | logInfo(text("MongoService: POST /adduser : ", username));
36 | enforce(age < 200, "wrong age");
37 |
38 | auto bson = Bson.emptyObject;
39 | bson.username = validateUserName(username);
40 | bson.email = validateEmail(email);
41 | bson.fullname = fullname;
42 | bson.age = age;
43 | bson.location = location;
44 | bson.gender = gender.toLower;
45 |
46 | collection.insert(bson);
47 | res.writeBody("");
48 | }
49 |
50 | Json getUserlist()
51 | {
52 | logInfo("MongoService: GET /userlist");
53 | return Json(collection.find!Json.array);
54 | }
55 |
56 | @path("deleteuser/:id")
57 | @method(HTTPMethod.DELETE)
58 | void pullOutUser(BsonObjectID _id, HTTPServerResponse res)
59 | {
60 | logInfo(text("MongoService: GET /deleteuser/", _id));
61 | collection.remove(["_id": _id]);
62 | res.writeBody("");
63 | }
64 | }
65 |
--------------------------------------------------------------------------------
/examples/vibed-mongo/views/index.dt:
--------------------------------------------------------------------------------
1 | extends layout
2 |
3 | block content
4 | - /++
5 | - The main difference is that you write D expressions and
6 | - statements instead of JavaScript.
7 | - +/
8 | - import std.format;
9 | - auto fullTitle = format("%s web app", title);
10 |
11 | h1= fullTitle
12 | p Welcome to our test
13 |
14 | // Wrapper
15 | #wrapper
16 |
17 | // USER INFO
18 | #userInfo
19 | h2 User Info
20 | p
21 | strong Name:
22 | |
23 | br
24 | strong Age:
25 | |
26 | br
27 | strong Gender:
28 | |
29 | br
30 | strong Location:
31 | |
32 | // /USER INFO
33 |
34 | // USER LIST
35 | h2 User List
36 | #userList
37 | table
38 | thead
39 | th UserName
40 | th Email
41 | th Delete?
42 | tbody
43 | // /USER LIST
44 |
45 | // ADD USER
46 | h2 Add User
47 | #addUser
48 | fieldset
49 | input#inputUserName(type='text', placeholder='Username')
50 | input#inputUserEmail(type='text', placeholder='Email')
51 | br
52 | input#inputUserFullname(type='text', placeholder='Full Name')
53 | input#inputUserAge(type='text', placeholder='Age')
54 | br
55 | input#inputUserLocation(type='text', placeholder='Location')
56 | input#inputUserGender(type='text', placeholder='gender')
57 | br
58 | button#btnAddUser Add User
59 | // /ADD USER
60 |
61 | // /WRAPPER
--------------------------------------------------------------------------------
/examples/vibed-mongo/views/layout.dt:
--------------------------------------------------------------------------------
1 | doctype html
2 | html
3 | head
4 | title= title
5 | link(rel='stylesheet', href='/styles/style.css')
6 | body
7 | block content
8 | script(src='http://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js')
9 | script(src='/javascripts/global.js')
--------------------------------------------------------------------------------