Compare commits

...
Sign in to create a new pull request.

52 commits

Author SHA1 Message Date
konqoro
0bd0bd3877 Fix handling of operators (#49)
Currently it fails with error message:
```
Do not know how to get basename of (AccQuoted
  Ident !"$")
`$`
```
2016-12-16 12:44:59 -05:00
konqoro
a04d029226 Add the return type of constructor (#48) 2016-11-23 11:41:14 -05:00
konqoro
587098c158 Fix exporting classes
This commit removes checking for missing base object in favour of being able to export a class.
2016-11-18 18:39:31 -05:00
Flaviu Tamas
6f16960ec2 Fix #39 (#40)
Add wording clarifying how sequences work. Thanks to cheatfate from #nim for the feedback and the "argument by value", "argument by reference" wording.
2016-11-13 12:03:37 -05:00
Flaviu Tamas
e58dee0113 Clarify generics example
Resolve #36. Thanks @zachaysan for bringing it to my attention.
2016-11-13 11:01:13 -05:00
konqoro
775e950be5 Fix defining a constructor proc inside class (#45) 2016-11-13 10:48:54 -05:00
Flaviu Tamas
0d0aaa7e29 Update build badge 2016-11-07 15:50:30 -05:00
Flaviu Tamas
89c4bb2625 Fix deploy 2016-11-07 15:45:37 -05:00
konqoro
0cd37a40ef Port the class macro from deprecated: stmt, expr (#42)
* Port the class macro from deprecated: stmt, expr

* Made changes

* Address comments

* Update oop_macro.md
2016-11-07 11:18:23 -05:00
Flaviu Tamas
62aa71babf Fix deploy 2016-11-02 17:57:31 -04:00
Fabio Riga
a6cec6fe80 Update import in if_else_while.md example
This example doesn't compile with nim-0.15. Importing *random* instead of *math* made the trick for me.
2016-11-01 14:19:01 -04:00
Flaviu Tamas
106efcb56b Confirm code is correct 2016-04-07 16:27:54 -04:00
Flaviu Tamas
b4c5e06295 Fix bad code 2016-04-07 16:26:47 -04:00
Dominik Picheta
382641aed8 Merge pull request #38 from Gurpartap/patch-1
minor typo
2015-10-08 22:04:05 +01:00
Gurpartap Singh
a133539b15 minor typo 2015-10-08 23:16:52 +05:30
Dominik Picheta
aa25b732f5 Merge pull request #37 from tmm1/patch-1
Fix minor typo
2015-09-21 09:27:37 +01:00
Aman Gupta
618906f3f2 fix typo 2015-09-20 22:53:22 -07:00
Flaviu Tamas
f0587c9a8f Merge pull request #35 from Peaker/patch-1
Update getting_started.md
2015-06-01 17:53:34 -04:00
Eyal Lotem
b541d04623 Update getting_started.md
Update stale link git://github.com/nim-code/csources to git://github.com/nim-lang/csources
2015-06-01 19:32:22 +03:00
Flaviu Tamas
2a67799c8a Implement dark mode 2015-05-31 19:20:07 -04:00
Flaviu Tamas
54b6e49fdc Simplify css 2015-05-31 18:27:45 -04:00
Flaviu Tamas
a440c07e35 Inline CSS
this gets google to stfu about performance issues
2015-05-31 18:20:55 -04:00
Flaviu Tamas
8337b4b817 Optimize load time 2015-05-31 18:07:37 -04:00
Flaviu Tamas
81856ba7d9 Use cloudflare for MathJax
Makes load times faster by not requiring a connection be established with
another server
2015-05-31 16:35:40 -04:00
Flaviu Tamas
32ff8d601f Add next-prev buttons
Fixes #22
2015-05-31 16:09:37 -04:00
Flaviu Tamas
0c7010e381 Make site more usable on desktop 2015-05-27 18:46:34 -04:00
Flaviu Tamas
7fa4dd3ed5 Update valid validcodehashes 2015-05-26 16:02:25 -04:00
Flaviu Tamas
edfe80ca13 Nimrod -> Nim pt. 2 2015-05-26 16:01:35 -04:00
Flaviu Tamas
989058e4d7 Add subtype test 2015-05-26 16:00:15 -04:00
Flaviu Tamas
c6417fb0d3 Nimrod -> Nim 2015-05-26 15:04:18 -04:00
Flaviu Tamas
3b3ab43856 Change footer 2015-05-26 14:43:35 -04:00
Flaviu Tamas
112eef2a3f Fix footer position 2015-05-26 14:43:04 -04:00
Flaviu Tamas
a57027acdd Lots of big formatting changes 2015-05-26 14:37:30 -04:00
Flaviu Tamas
5986e1f090 Delete opengl assets 2015-05-25 19:44:01 -04:00
Flaviu Tamas
4e36057f75 Merge pull request #33 from jrenner/patch-1
fix typo
2015-05-23 10:12:16 -04:00
Jon Renner
b71202faf2 fix typo 2015-05-22 23:25:05 -05:00
Flaviu Tamas
62b6e46702 Disable hyphenation
`pre code span` is hyphenated, even though it is below a `pre` element. This
might be a bug in Hyphenate.js
2015-04-27 18:17:50 -04:00
Flaviu Tamas
063a45c1da Fix code shadows
Shadows were getting clipped, fix it.
2015-04-27 18:00:25 -04:00
Flaviu Tamas
0fd94db2e6 Expand on strings
See #21
2015-04-27 17:52:54 -04:00
Flaviu Tamas
9c62e0e844 Delete dead page 2015-04-27 17:44:02 -04:00
Flaviu Tamas
440cba53d3 Add hyphenation 2015-04-27 17:15:48 -04:00
Flaviu Tamas
dfd0f80a19 Handle compiler failure on windows
Fixes #32
2015-04-27 16:14:16 -04:00
Flaviu Tamas
cdb74e8e4f Fixed mixed content 2015-04-27 16:11:39 -04:00
Flaviu Tamas
e253f79698 Make statement clearer 2015-04-27 16:00:29 -04:00
Flaviu Tamas
4fe1376fce Remove personal configuration 2015-04-27 15:54:14 -04:00
Flaviu Tamas
651fb40bb6 Merge pull request #30 from pyloor/typo-fix-1
typo fix in oop.md
2015-03-14 22:59:53 -04:00
pyloor
07cc8f6600 Update oop.md 2015-03-15 02:35:51 +01:00
Flaviu Tamas
a7b8116357 Rename nimrod-by-example.sublime-project to nim-by-example.sublime-project 2015-02-08 16:21:41 -05:00
Flaviu Tamas
4ed8b34d0f Fix #20
See #20 for context:

> allows the procedure to be stored in a variable and called correctly (even with default parameters).
> As said by Araq on IRC:
>> 'procvar' doesn't do much [...] it's just another check for semantic checking. codegen is not affected.
2015-02-01 20:14:08 -05:00
Flaviu Tamas
9fcb01c621 Merge pull request #28 from elpres/patch-1
Added missing word
2015-02-01 20:10:26 -05:00
Flaviu Tamas
375db8c398 Make base types object of RootObj
Thanks to @jyapayne for noticing this in #29!
2015-02-01 20:09:55 -05:00
elpres
d073c81deb Added missing word 2015-01-28 11:19:33 +01:00
55 changed files with 705 additions and 656 deletions

View file

@ -1,4 +1,4 @@
[![wercker status](https://app.wercker.com/status/389477226e537a45143ea91336dca281/m "wercker status")](https://app.wercker.com/project/bykey/389477226e537a45143ea91336dca281)
[![wercker status](https://app.wercker.com/status/8d96ab89960da21d87a545a25acae54c/m/master "wercker status")](https://app.wercker.com/project/byKey/8d96ab89960da21d87a545a25acae54c)
This repo contains the sources for the Nim by Example book.

50
Rules
View file

@ -13,35 +13,59 @@
# item, use the pattern “/about/*/”; “/about/*” will also select the parent,
# because “*” matches zero or more characters.
compile '*' do
if item.identifier == '/toc/'
compile '/assets/css/*' do
filter :erb
filter :rainpress if File.basename(item[:content_filename], ".*") == 'all'
end
compile '/assets/js/*' do
filter :erb
:uglify_js if File.basename(item[:content_filename], ".*") == 'all'
end
compile '/content/*' do
if item.identifier.to_s == '/content/toc/'
filter :kramdown
layout 'blank'
elsif item.identifier.to_s == '/content/footer/'
layout 'blank'
elsif item[:extension] == 'md'
filter :kramdown, {:input => 'GFM'}
filter :colorize_syntax, :default_colorizer => :pygmentize
filter :relativize_paths, :type => :html
layout 'default'
elsif item[:extension] == 'css'
# don’t filter stylesheets
elsif item.binary?
# don’t filter binary items
else
filter :erb
layout 'default'
end
end
route '*' do
if item[:extension] == 'css'
# Write item with identifier /foo/ to /foo.css
item.identifier.chop + '.css'
elsif item.binary?
route '/assets/css/*' do
# if not debug mode, only let all.css through
unless @config[:debug]
item.identifier.to_s.chop + '.css' if File.basename(item[:content_filename], ".*") == 'all'
else
item.identifier.to_s.chop + '.css'
end
end
route '/assets/js/*' do
# if not debug mode, only let all.js through
unless @config[:debug]
item.identifier.to_s.chop + '.js' if File.basename(item[:content_filename], ".*") == 'all'
else
item.identifier.to_s.chop + '.js'
end
end
route '/content/*' do
if item.binary?
# Write item with identifier /foo/ to /foo.ext
item.identifier.chop + '.' + item[:extension]
item.identifier.to_s.sub("/content", "").chop + '.' + item[:extension]
else
# Write item with identifier /foo/ to /foo/index.html
item.identifier + 'index.html'
item.identifier.to_s.sub("/content", "") + 'index.html'
end
end

View file

@ -0,0 +1 @@
<%= all_css @config[:stylesheets] %>

View file

@ -0,0 +1,72 @@
/* pygments-css colorful */
code[class^='language-'] .gp {
color: #c65d09;
font-weight: bold;
/* NOTE: Hacks to allow copy-paste */
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
} /* Generic.Prompt */
body:not(.darkmode) code[class^='language-'] .hll { background-color: #ffffcc }
body:not(.darkmode) code[class^='language-'] .c { color: #808080 } /* Comment */
body:not(.darkmode) code[class^='language-'] .err { color: #F00000; background-color: #F0A0A0 } /* Error */
body:not(.darkmode) code[class^='language-'] .k { color: #008000; font-weight: bold } /* Keyword */
body:not(.darkmode) code[class^='language-'] .o { color: #303030 } /* Operator */
body:not(.darkmode) code[class^='language-'] .cm { color: #808080 } /* Comment.Multiline */
body:not(.darkmode) code[class^='language-'] .cp { color: #507090 } /* Comment.Preproc */
body:not(.darkmode) code[class^='language-'] .c1 { color: #808080 } /* Comment.Single */
body:not(.darkmode) code[class^='language-'] .cs { color: #cc0000; font-weight: bold } /* Comment.Special */
body:not(.darkmode) code[class^='language-'] .gd { color: #A00000 } /* Generic.Deleted */
body:not(.darkmode) code[class^='language-'] .ge { font-style: italic } /* Generic.Emph */
body:not(.darkmode) code[class^='language-'] .gr { color: #FF0000 } /* Generic.Error */
body:not(.darkmode) code[class^='language-'] .gh { color: #000080; font-weight: bold } /* Generic.Heading */
body:not(.darkmode) code[class^='language-'] .gi { color: #00A000 } /* Generic.Inserted */
body:not(.darkmode) code[class^='language-'] .go { color: #808080 } /* Generic.Output */
body:not(.darkmode) code[class^='language-'] .gs { font-weight: bold } /* Generic.Strong */
body:not(.darkmode) code[class^='language-'] .gu { color: #800080; font-weight: bold } /* Generic.Subheading */
body:not(.darkmode) code[class^='language-'] .gt { color: #0040D0 } /* Generic.Traceback */
body:not(.darkmode) code[class^='language-'] .kc { color: #008000; font-weight: bold } /* Keyword.Constant */
body:not(.darkmode) code[class^='language-'] .kd { color: #008000; font-weight: bold } /* Keyword.Declaration */
body:not(.darkmode) code[class^='language-'] .kn { color: #008000; font-weight: bold } /* Keyword.Namespace */
body:not(.darkmode) code[class^='language-'] .kp { color: #003080; font-weight: bold } /* Keyword.Pseudo */
body:not(.darkmode) code[class^='language-'] .kr { color: #008000; font-weight: bold } /* Keyword.Reserved */
body:not(.darkmode) code[class^='language-'] .kt { color: #303090; font-weight: bold } /* Keyword.Type */
body:not(.darkmode) code[class^='language-'] .m { color: #6000E0; font-weight: bold } /* Literal.Number */
body:not(.darkmode) code[class^='language-'] .s { background-color: #fff0f0 } /* Literal.String */
body:not(.darkmode) code[class^='language-'] .na { color: #0000C0 } /* Name.Attribute */
body:not(.darkmode) code[class^='language-'] .nb { color: #007020 } /* Name.Builtin */
body:not(.darkmode) code[class^='language-'] .nc { color: #B00060; font-weight: bold } /* Name.Class */
body:not(.darkmode) code[class^='language-'] .no { color: #003060; font-weight: bold } /* Name.Constant */
body:not(.darkmode) code[class^='language-'] .nd { color: #505050; font-weight: bold } /* Name.Decorator */
body:not(.darkmode) code[class^='language-'] .ni { color: #800000; font-weight: bold } /* Name.Entity */
body:not(.darkmode) code[class^='language-'] .ne { color: #F00000; font-weight: bold } /* Name.Exception */
body:not(.darkmode) code[class^='language-'] .nf { color: #0060B0; font-weight: bold } /* Name.Function */
body:not(.darkmode) code[class^='language-'] .nl { color: #907000; font-weight: bold } /* Name.Label */
body:not(.darkmode) code[class^='language-'] .nn { color: #0e84b5; font-weight: bold } /* Name.Namespace */
body:not(.darkmode) code[class^='language-'] .nt { color: #007000 } /* Name.Tag */
body:not(.darkmode) code[class^='language-'] .nv { color: #906030 } /* Name.Variable */
body:not(.darkmode) code[class^='language-'] .ow { color: #000000; font-weight: bold } /* Operator.Word */
body:not(.darkmode) code[class^='language-'] .w { color: #bbbbbb } /* Text.Whitespace */
body:not(.darkmode) code[class^='language-'] .mf { color: #6000E0; font-weight: bold } /* Literal.Number.Float */
body:not(.darkmode) code[class^='language-'] .mh { color: #005080; font-weight: bold } /* Literal.Number.Hex */
body:not(.darkmode) code[class^='language-'] .mi { color: #0000D0; font-weight: bold } /* Literal.Number.Integer */
body:not(.darkmode) code[class^='language-'] .mo { color: #4000E0; font-weight: bold } /* Literal.Number.Oct */
body:not(.darkmode) code[class^='language-'] .sb { background-color: #fff0f0 } /* Literal.String.Backtick */
body:not(.darkmode) code[class^='language-'] .sc { color: #0040D0 } /* Literal.String.Char */
body:not(.darkmode) code[class^='language-'] .sd { color: #D04020 } /* Literal.String.Doc */
body:not(.darkmode) code[class^='language-'] .s2 { background-color: #fff0f0 } /* Literal.String.Double */
body:not(.darkmode) code[class^='language-'] .se { color: #606060; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
body:not(.darkmode) code[class^='language-'] .sh { background-color: #fff0f0 } /* Literal.String.Heredoc */
body:not(.darkmode) code[class^='language-'] .si { background-color: #e0e0e0 } /* Literal.String.Interpol */
body:not(.darkmode) code[class^='language-'] .sx { color: #D02000; background-color: #fff0f0 } /* Literal.String.Other */
body:not(.darkmode) code[class^='language-'] .sr { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
body:not(.darkmode) code[class^='language-'] .s1 { background-color: #fff0f0 } /* Literal.String.Single */
body:not(.darkmode) code[class^='language-'] .ss { color: #A06000 } /* Literal.String.Symbol */
body:not(.darkmode) code[class^='language-'] .bp { color: #007020 } /* Name.Builtin.Pseudo */
body:not(.darkmode) code[class^='language-'] .vc { color: #306090 } /* Name.Variable.Class */
body:not(.darkmode) code[class^='language-'] .vg { color: #d07000; font-weight: bold } /* Name.Variable.Global */
body:not(.darkmode) code[class^='language-'] .vi { color: #3030B0 } /* Name.Variable.Instance */
body:not(.darkmode) code[class^='language-'] .il { color: #0000D0; font-weight: bold } /* Literal.Number.Integer.Long */

View file

@ -0,0 +1,8 @@
#main code, code * { color: #675D69; }
code[class^='language-'] .k { color: #143A77; }
code[class^='language-'] .kp { color: #8C5DC7; }
code[class^='language-'] .kd { color: #8C5DC7; }
code[class^='language-'] .mi { color: #8C5DC7; }
code[class^='language-'] .s { color: #0060B0; }
code[class^='language-'] .c { color: #91B9A3; }
code[class^='language-'] .o { color: #009DE7; }

133
content/assets/css/main.css Normal file
View file

@ -0,0 +1,133 @@
body {
background: #F5F7F6;
color: #000000;
margin: 0; padding: 0;
max-width: 720px;
text-rendering: optimizelegibility;
font-family: Palatino, serif;
line-height: 20px;
}
#sidebar {
margin: 15px;
float: left;
width: 205px;
padding: 10px 0;
background-color: #FFF;
box-shadow: 0px 0px 5px 0px rgba(0,0,0,0.5);
transition: margin-left 1s;
}
#sidebar.collapsed { margin-left: -180px; }
#sidebar ul { padding: 0 1em; margin: 0; list-style-type: none; }
#sidebar li:before { content: '⁃'; padding-right: 0.5em; color: black; }
#sidebar li.visited:before { content: '✔'; padding-right: 0.2em; color: green; }
.abs-hamburger {
position: relative;
width: 0; height: 0;
}
.nav-toggle {
position: absolute;
left: 175px;
width: 25px; height: 25px;
cursor: pointer;
margin-right: 5px;
margin-bottom: 5px;
}
.nav-toggle span,
.nav-toggle span:before,
.nav-toggle span:after {
border-radius: 1px;
height: 5px;
width: 25px;
background: white;
position: absolute;
display: block;
content: '';
box-shadow: inset 0px 0px 2px 0px #000;
}
.nav-toggle span:before { top: -8px; }
.nav-toggle span:after { bottom: -8px; }
.nav-toggle span { margin-top: 9.5px; }
#nextprev {
overflow: hidden;
padding: .5em 1em;
}
.text-icon { font-size: 5em; }
#arrow-prev { float: left; }
#arrow-next { float: right; }
article {
margin: 15px;
transition: max-width 1s;
}
article.expanded { max-width: 680px; }
a { text-decoration: none; }
a:link, a:visited { color: #B45D47; }
a:hover { color: #FE3B3B; }
a.disabled, a:link.disabled, a:visited.disabled { color: #999; pointer-events: none; }
a:hover.disabled { color: #888; }
pre, code { font-family: Monaco, Menlo, Consolas, "Courier New", monospace; }
code {
border-radius: 1px;
background-color: #FFF;
padding: 0.2em;
}
pre code {
display: block;
padding: 1em;
white-space: pre-wrap;
}
h1, h2, h3, h4, h5, h6 { line-height: 125%; }
footer {
margin-top: 50px;
clear: both;
text-align: center;
color: #777;
}
footer ul { list-style: none; margin: 0; padding: 0; }
footer li { display: inline; }
footer li+li:before { content: '|'; }
footer a:link, footer a:visited { color: #777; }
footer a:hover { color: #999; }
.notransition {
-webkit-transition: none !important;
-moz-transition: none !important;
-o-transition: none !important;
-ms-transition: none !important;
transition: none !important;
}
@media screen and (min-width: 925px) {
body { margin: 0 auto; }
body #sidebar.collapsed, body #sidebar { margin-left: -205px; }
body article.expanded, body article { max-width: none; width: none; min-width: none; }
}
@media screen and (max-width: 1200px) {
body { margin-right: 0; }
}

View file

@ -0,0 +1,64 @@
body.darkmode code[class^='language-'] { background-color: #333; color: #f8f8f2}
body.darkmode code[class^='language-'] .hll { background-color: #49483e }
body.darkmode code[class^='language-'] .c { color: #75715e } /* Comment */
body.darkmode code[class^='language-'] .err { color: #960050; background-color: #1e0010 } /* Error */
body.darkmode code[class^='language-'] .k { color: #66d9ef } /* Keyword */
body.darkmode code[class^='language-'] .l { color: #ae81ff } /* Literal */
body.darkmode code[class^='language-'] .n { color: #f8f8f2 } /* Name */
body.darkmode code[class^='language-'] .o { color: #f92672 } /* Operator */
body.darkmode code[class^='language-'] .p { color: #f8f8f2 } /* Punctuation */
body.darkmode code[class^='language-'] .cm { color: #75715e } /* Comment.Multiline */
body.darkmode code[class^='language-'] .cp { color: #75715e } /* Comment.Preproc */
body.darkmode code[class^='language-'] .c1 { color: #75715e } /* Comment.Single */
body.darkmode code[class^='language-'] .cs { color: #75715e } /* Comment.Special */
body.darkmode code[class^='language-'] .ge { font-style: italic } /* Generic.Emph */
body.darkmode code[class^='language-'] .gs { font-weight: bold } /* Generic.Strong */
body.darkmode code[class^='language-'] .kc { color: #66d9ef } /* Keyword.Constant */
body.darkmode code[class^='language-'] .kd { color: #66d9ef } /* Keyword.Declaration */
body.darkmode code[class^='language-'] .kn { color: #f92672 } /* Keyword.Namespace */
body.darkmode code[class^='language-'] .kp { color: #66d9ef } /* Keyword.Pseudo */
body.darkmode code[class^='language-'] .kr { color: #66d9ef } /* Keyword.Reserved */
body.darkmode code[class^='language-'] .kt { color: #66d9ef } /* Keyword.Type */
body.darkmode code[class^='language-'] .ld { color: #e6db74 } /* Literal.Date */
body.darkmode code[class^='language-'] .m { color: #ae81ff } /* Literal.Number */
body.darkmode code[class^='language-'] .s { color: #e6db74 } /* Literal.String */
body.darkmode code[class^='language-'] .na { color: #a6e22e } /* Name.Attribute */
body.darkmode code[class^='language-'] .nb { color: #f8f8f2 } /* Name.Builtin */
body.darkmode code[class^='language-'] .nc { color: #a6e22e } /* Name.Class */
body.darkmode code[class^='language-'] .no { color: #66d9ef } /* Name.Constant */
body.darkmode code[class^='language-'] .nd { color: #a6e22e } /* Name.Decorator */
body.darkmode code[class^='language-'] .ni { color: #f8f8f2 } /* Name.Entity */
body.darkmode code[class^='language-'] .ne { color: #a6e22e } /* Name.Exception */
body.darkmode code[class^='language-'] .nf { color: #a6e22e } /* Name.Function */
body.darkmode code[class^='language-'] .nl { color: #f8f8f2 } /* Name.Label */
body.darkmode code[class^='language-'] .nn { color: #f8f8f2 } /* Name.Namespace */
body.darkmode code[class^='language-'] .nx { color: #a6e22e } /* Name.Other */
body.darkmode code[class^='language-'] .py { color: #f8f8f2 } /* Name.Property */
body.darkmode code[class^='language-'] .nt { color: #f92672 } /* Name.Tag */
body.darkmode code[class^='language-'] .nv { color: #f8f8f2 } /* Name.Variable */
body.darkmode code[class^='language-'] .ow { color: #f92672 } /* Operator.Word */
body.darkmode code[class^='language-'] .w { color: #f8f8f2 } /* Text.Whitespace */
body.darkmode code[class^='language-'] .mf { color: #ae81ff } /* Literal.Number.Float */
body.darkmode code[class^='language-'] .mh { color: #ae81ff } /* Literal.Number.Hex */
body.darkmode code[class^='language-'] .mi { color: #ae81ff } /* Literal.Number.Integer */
body.darkmode code[class^='language-'] .mo { color: #ae81ff } /* Literal.Number.Oct */
body.darkmode code[class^='language-'] .sb { color: #e6db74 } /* Literal.String.Backtick */
body.darkmode code[class^='language-'] .sc { color: #e6db74 } /* Literal.String.Char */
body.darkmode code[class^='language-'] .sd { color: #e6db74 } /* Literal.String.Doc */
body.darkmode code[class^='language-'] .s2 { color: #e6db74 } /* Literal.String.Double */
body.darkmode code[class^='language-'] .se { color: #ae81ff } /* Literal.String.Escape */
body.darkmode code[class^='language-'] .sh { color: #e6db74 } /* Literal.String.Heredoc */
body.darkmode code[class^='language-'] .si { color: #e6db74 } /* Literal.String.Interpol */
body.darkmode code[class^='language-'] .sx { color: #e6db74 } /* Literal.String.Other */
body.darkmode code[class^='language-'] .sr { color: #e6db74 } /* Literal.String.Regex */
body.darkmode code[class^='language-'] .s1 { color: #e6db74 } /* Literal.String.Single */
body.darkmode code[class^='language-'] .ss { color: #e6db74 } /* Literal.String.Symbol */
body.darkmode code[class^='language-'] .bp { color: #f8f8f2 } /* Name.Builtin.Pseudo */
body.darkmode code[class^='language-'] .vc { color: #f8f8f2 } /* Name.Variable.Class */
body.darkmode code[class^='language-'] .vg { color: #f8f8f2 } /* Name.Variable.Global */
body.darkmode code[class^='language-'] .vi { color: #f8f8f2 } /* Name.Variable.Instance */
body.darkmode code[class^='language-'] .il { color: #ae81ff } /* Literal.Number.Integer.Long */
body.darkmode code[class^='language-'] .gh { } /* Generic Heading & Diff Header */
body.darkmode code[class^='language-'] .gu { color: #75715e; } /* Generic.Subheading & Diff Unified/Comment? */
body.darkmode code[class^='language-'] .gd { color: #f92672; } /* Generic.Deleted & Diff Deleted */
body.darkmode code[class^='language-'] .gi { color: #a6e22e; } /* Generic.Inserted & Diff Inserted */

1
content/assets/css/normalize.css vendored Normal file
View file

@ -0,0 +1 @@
/*! normalize.css v3.0.3 | MIT License | github.com/necolas/normalize.css */html{font-family:sans-serif;-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%}body{margin:0}article,aside,details,figcaption,figure,footer,header,hgroup,main,menu,nav,section,summary{display:block}audio,canvas,progress,video{display:inline-block;vertical-align:baseline}audio:not([controls]){display:none;height:0}[hidden],template{display:none}a{background-color:transparent}a:active,a:hover{outline:0}abbr[title]{border-bottom:1px dotted}b,strong{font-weight:bold}dfn{font-style:italic}h1{font-size:2em;margin:.67em 0}mark{background:#ff0;color:#000}small{font-size:80%}sub,sup{font-size:75%;line-height:0;position:relative;vertical-align:baseline}sup{top:-0.5em}sub{bottom:-0.25em}img{border:0}svg:not(:root){overflow:hidden}figure{margin:1em 40px}hr{box-sizing:content-box;height:0}pre{overflow:auto}code,kbd,pre,samp{font-family:monospace,monospace;font-size:1em}button,input,optgroup,select,textarea{color:inherit;font:inherit;margin:0}button{overflow:visible}button,select{text-transform:none}button,html input[type="button"],input[type="reset"],input[type="submit"]{-webkit-appearance:button;cursor:pointer}button[disabled],html input[disabled]{cursor:default}button::-moz-focus-inner,input::-moz-focus-inner{border:0;padding:0}input{line-height:normal}input[type="checkbox"],input[type="radio"]{box-sizing:border-box;padding:0}input[type="number"]::-webkit-inner-spin-button,input[type="number"]::-webkit-outer-spin-button{height:auto}input[type="search"]{-webkit-appearance:textfield;box-sizing:content-box}input[type="search"]::-webkit-search-cancel-button,input[type="search"]::-webkit-search-decoration{-webkit-appearance:none}fieldset{border:1px solid silver;margin:0 2px;padding:.35em .625em .75em}legend{border:0;padding:0}textarea{overflow:auto}optgroup{font-weight:bold}table{border-collapse:collapse;border-spacing:0}td,th{padding:0}

1
content/assets/js/all.js Normal file
View file

@ -0,0 +1 @@
<%= all_js @config[:scripts] %>

87
content/assets/js/main.js Normal file
View file

@ -0,0 +1,87 @@
function setVisibleTags(){
var tocLinks = document.querySelectorAll("#sidebar a:link, a:visited");
for(var i = 0; i < tocLinks.length; i++){
if(localStorage.getItem(tocLinks[i].getAttribute("href")) != null){
tocLinks[i].parentNode.classList.add("visited");
}
}
}
function updateSidebar(notransition) {
if (notransition) {
document.querySelectorAll("#sidebar")[0].classList.add("notransition");
document.querySelectorAll("article")[0].classList.add("notransition");
}
localStorage.setItem("openside", window.sidebarExpanded);
if (!window.sidebarExpanded) {
document.querySelectorAll("#sidebar")[0].classList.add("collapsed");
document.querySelectorAll("article")[0].classList.add("expanded");
} else {
document.querySelectorAll("#sidebar")[0].classList.remove("collapsed");
document.querySelectorAll("article")[0].classList.remove("expanded");
}
if (notransition) {
setTimeout(function(){
document.querySelectorAll("#sidebar")[0].classList.remove("notransition");
document.querySelectorAll("article")[0].classList.remove("notransition");
}, 100);
}
}
function sidebarClick() {
window.sidebarExpanded = !window.sidebarExpanded;
updateSidebar(false);
}
function getNextPrev() {
// thanks iznogoodd from #nim @ freenode.net
var links = document.querySelectorAll('#sidebar a[href]');
var nav = {prev: null, next: null};
for(var i = 0; i < links.length; i++){
var item = links.item(i);
if(item && item.getAttribute('href') === window.location.pathname){
nav.prev = links.item(i - 1) && links.item(i - 1).getAttribute('href');
nav.next = links.item(i + 1) && links.item(i + 1).getAttribute('href');
return nav;
}
}
}
function updateNextPrevButtons() {
var nav = getNextPrev();
var prev = document.getElementById("arrow-prev");
var next = document.getElementById("arrow-next");
if (nav.prev != null) { prev.classList.remove("disabled"); prev.href = nav.prev; }
if (nav.next != null) { next.classList.remove("disabled"); next.href = nav.next; }
}
var darkmodeOn = (localStorage.getItem("darkmode") === "true");
function toggleDarkMode() {
darkmodeOn = !darkmodeOn;
document.getElementsByTagName("body")[0].classList.toggle("darkmode");
localStorage.setItem("darkmode", darkmodeOn);
}
function initDarkMode() {
if (darkmodeOn)
document.getElementsByTagName("body")[0].classList.add("darkmode");
}
var isMobile = window.screen.width < 720;
if (localStorage.getItem("openside") === null) {
window.sidebarExpanded = !isMobile;
} else {
window.sidebarExpanded = (localStorage.getItem("openside") === "true");
}
localStorage.setItem(window.location.pathname, true);
window.onload = function(){
updateSidebar(true);
initDarkMode();
setVisibleTags();
updateNextPrevButtons();
}

View file

@ -4,7 +4,7 @@ title: Arrays
# Arrays
The arrays in Nim are like classic C arrays, their size is specified at compile-time and cannot given or changed at runtime.
The arrays in Nim are like classic C arrays, their size is specified at compile-time and cannot be given or changed at runtime.
``` nimrod
type

View file

@ -6,11 +6,11 @@ title: Blocks
Blocks can be introduced in two different ways: by indenting statements or with `()`s.
The first way ist to use indenting, e.g. using `if-elif-else`, `while`, `for` statements, or the `block` statement.
The first way is to use indenting, e.g. using `if-elif-else`, `while`, `for` statements, or the `block` statement.
``` nimrod
if true:
echo "Nimrod is great!"
echo "Nim is great!"
while false:
echo "This line is never output!"

View file

@ -54,7 +54,7 @@ Another feature of case statements is that the possible values are narrowed, mea
``` nimrod
let x = 2
case (x and 3) + 7:
case (x and 0b11) + 7:
of 7: echo "A"
of 8: echo "B"
of 9: echo "C"

View file

@ -0,0 +1,2 @@
<li><a href="https://github.com/flaviut/nim-by-example">Contribute</a></li><li
><a href="#" onclick="toggleDarkMode(); return false;">Toggle dark mode</a></li>

View file

@ -7,7 +7,7 @@ When installing Nim, you have two options: downloading a copy directly from git,
## Downloading a Nim Distribution
To get started with Nim, head over to the [downloads page](http://nim-lang.org/download.html) and download the version you'd like.
The Windows distribution comes with the MinGW compiler, which is recommended, but if you'd like to use your own compiler, download the version without MinGW.
The Windows distribution comes with the MinGW compiler, which is recommended, but if you'd like to use your own compiler, download the version without MinGW. If you get an error like `Error: unhandled exception: The system cannot find the file specified.`, then make sure that the C compiler is on your path.
On Mac and Linux, it is recommended to use either GCC or Clang.
@ -17,9 +17,9 @@ Once you have downloaded the appropriate distribution and extracted the files so
To install Nim from git, ensure that you have gcc installed on Windows, Linux, and BSDs and clang on Mac. Afterwards, run the following series of commands to download and bootstrap Nim:
```console
$ git clone -b master git://github.com/Araq/Nimrod.git
$ cd Nimrod
$ git clone --depth 1 git://github.com/nimrod-code/csources
$ git clone -b master git://github.com/Araq/Nim.git
$ cd Nim
$ git clone --depth 1 git://github.com/nim-lang/csources
$ cd csources
$ sh build.sh # Replace with build.bat on windows
$ cd ..

View file

@ -11,7 +11,7 @@ When inside a loop, `continue` can be used to skip the rest of the loop body and
Along with [its other uses](/block/), the `block` statement can be used to create a label so that it's possible to break out of nested loops.
<!--skip-->``` nim
import strutils, math
import strutils, random
randomize()
let answer = random(10) + 1

View file

@ -4,7 +4,7 @@ title: Object Oriented Programming
# Object Oriented Programming
Object oriented programming is supported through inheritance and methods, which are virtual procedures. Methods work in the same was as [procs](/procs/), including UFCS, but the runtime type of the object that a method is called with is used to determine which version to call.
Object oriented programming is supported through inheritance and methods, which are virtual procedures. Methods work in the same way as [procs](/procs/), including UFCS, but the runtime type of the object that a method is called with is used to determine which version to call.
Inheritance is created with the `of` keyword in the type declaration of an object. A method is overridden by creating a new method with parameter types of the subtype.
@ -38,3 +38,19 @@ woof
meow
10
```
## Testing subtypes
It is also possible to check if an object is of a given subtype with the `of` keyword. For example,
``` nimrod
echo(animals[0] of Dog)
echo(animals[0] of Cat)
echo(animals[0] of Animal)
```
``` console
$ nim c -r of_op.nim
true
false
true
```

View file

@ -43,20 +43,16 @@ To get that nice notation, we can use a macro:
```nimrod
import macros
macro class*(head: expr, body: stmt): stmt {.immediate.} =
# The macro is immediate so that it doesn't
# resolve identifiers passed to it
macro class*(head, body: untyped): untyped =
# The macro is immediate, since all its parameters are untyped.
# This means, it doesn't resolve identifiers passed to it.
var typeName, baseName: PNimrodNode
var typeName, baseName: NimNode
if head.kind == nnkIdent:
# `head` is expression `typeName`
# echo head.treeRepr
# --------------------
# Ident !"Animal"
typeName = head
# flag if object should be exported
var exported: bool
elif head.kind == nnkInfix and $head[0] == "of":
if head.kind == nnkInfix and head[0].ident == !"of":
# `head` is expression `typeName of baseClass`
# echo head.treeRepr
# --------------------
@ -67,9 +63,57 @@ macro class*(head: expr, body: stmt): stmt {.immediate.} =
typeName = head[1]
baseName = head[2]
elif head.kind == nnkInfix and head[0].ident == !"*" and
head[2].kind == nnkPrefix and head[2][0].ident == !"of":
# `head` is expression `typeName* of baseClass`
# echo head.treeRepr
# --------------------
# Infix
# Ident !"*"
# Ident !"Animal"
# Prefix
# Ident !"of"
# Ident !"RootObj"
typeName = head[1]
baseName = head[2][1]
exported = true
else:
quit "Invalid node: " & head.lispRepr
# The following prints out the AST structure:
#
# import macros
# dumptree:
# type X = ref object of Y
# z: int
# --------------------
# StmtList
# TypeSection
# TypeDef
# Ident !"X"
# Empty
# RefTy
# ObjectTy
# Empty
# OfInherit
# Ident !"Y"
# RecList
# IdentDefs
# Ident !"z"
# Ident !"int"
# Empty
# create a type section in the result
result =
if exported:
# mark `typeName` with an asterisk
quote do:
type `typeName`* = ref object of `baseName`
else:
quote do:
type `typeName` = ref object of `baseName`
# echo treeRepr(body)
# --------------------
# StmtList
@ -105,22 +149,26 @@ macro class*(head: expr, body: stmt): stmt {.immediate.} =
# Ident !"this"
# Ident !"age"
# create a new stmtList for the result
result = newStmtList()
# var declarations will be turned into object fields
var recList = newNimNode(nnkRecList)
# expected name of constructor
let ctorName = newIdentNode("new" & $typeName)
# Iterate over the statements, adding `this: T`
# to the parameters of functions
# to the parameters of functions, unless the
# function is a constructor
for node in body.children:
case node.kind:
of nnkMethodDef, nnkProcDef:
# inject `this: T` into the arguments
let p = copyNimTree(node.params)
p.insert(1, newIdentDefs(ident"this", typeName))
node.params = p
# check if it is the ctor proc
if node.name.kind != nnkAccQuoted and node.name.basename == ctorName:
# specify the return type of the ctor proc
node.params[0] = typeName
else:
# inject `self: T` into the arguments
node.params.insert(1, newIdentDefs(ident("self"), typeName))
result.add(node)
of nnkVarSection:
@ -131,56 +179,25 @@ macro class*(head: expr, body: stmt): stmt {.immediate.} =
else:
result.add(node)
# The following prints out the AST structure:
#
# import macros
# dumptree:
# type X = ref object of Y
# z: int
# --------------------
# TypeSection
# TypeDef
# Ident !"X"
# Empty
# RefTy
# ObjectTy
# Empty
# OfInherit
# Ident !"Y"
# RecList
# IdentDefs
# Ident !"z"
# Ident !"int"
# Empty
result.insert(0,
if baseName == nil:
quote do:
type `typeName` = ref object
else:
quote do:
type `typeName` = ref object of `baseName`
)
# Inspect the tree structure:
#
# echo result.treeRepr
# --------------------
# StmtList
# StmtList
# TypeSection
# TypeDef
# Ident !"Animal"
# Empty
# RefTy
# ObjectTy
# Empty
# OfInherit
# Ident !"RootObj"
# Empty <= We want to replace this
# MethodDef
# ...
# TypeSection
# TypeDef
# Ident !"Animal"
# Empty
# RefTy
# ObjectTy
# Empty
# OfInherit
# Ident !"RootObj"
# Empty <= We want to replace this
# MethodDef
# ...
result[0][0][0][2][0][2] = recList
result[0][0][2][0][2] = recList
# Lets inspect the human-readable version of the output
# echo repr(result)
@ -190,26 +207,45 @@ macro class*(head: expr, body: stmt): stmt {.immediate.} =
# name: string
# age: int
#
# method vocalize(this: Animal): string =
# method vocalize(this: Animal): string {.base.} =
# "..."
#
# method age_human_yrs(this: Animal): int =
# method age_human_yrs(this: Animal): int {.base.} =
# this.age
# ...
#
# type
# Rabbit = ref object of Animal
#
# proc newRabbit(name: string; age: int): Rabbit =
# result = Rabbit(name: name, age: age)
#
# method vocalize(this: Rabbit): string =
# "meep"
# ---
class Animal of RootObj:
var name: string
var age: int
method vocalize: string = "..."
method age_human_yrs: int = this.age # `this` is injected
method vocalize: string {.base.} = "..." # use `base` pragma to annonate base methods
method age_human_yrs: int {.base.} = this.age # `this` is injected
proc `$`: string = "animal:" & this.name & ":" & $this.age
class Dog of Animal:
method vocalize: string = "woof"
method age_human_yrs: int = this.age * 7
proc `$`: string = "dog:" & this.name & ":" & $this.age
class Cat of Animal:
method vocalize: string = "meow"
proc `$`: string = "cat:" & this.name & ":" & $this.age
class Rabbit of Animal:
proc newRabbit(name: string, age: int) = # the constructor doesn't need a return type
result = Rabbit(name: name, age: age)
method vocalize: string = "meep"
proc `$`: string = "rabbit:" & this.name & ":" & $this.age
# ---
@ -220,6 +256,11 @@ animals.add(Cat(name: "Mitten", age: 10))
for a in animals:
echo a.vocalize()
echo a.age_human_yrs()
let r = newRabbit("Fluffy", 3)
echo r.vocalize()
echo r.age_human_yrs()
echo r
```
``` console
$ nim c -r oopmacro.nim
@ -227,4 +268,7 @@ woof
70
meow
10
meep
3
rabbit:Fluffy:3
```

View file

@ -57,7 +57,7 @@ echo([[1, 2], [3, 4]]) # See varargs for
# how echo works
proc `^&*^@%`(a, b: string): string =
## An confusingly named useless operator
## A confusingly named useless operator
result = a[0] & b[high(b)]
assert("foo" ^&*^@% "bar" == "fr")
@ -78,7 +78,7 @@ proc `+`(a, b: string): string =
proc `*`[T](a: T, b: int): T =
result = zero
for i in 0..b:
result = result + a
result = result + a # calls `+` from line 3
assert("a" * 10 == "aaaaaaaaaaa")
```

View file

@ -20,10 +20,10 @@ $ nim c -r filterclosure.nim
@[64, 128, 256]
```
Existing procedures can also be passed as functions, but only if they are annotated with the `{.procvar.}` pragma.
Existing procedures can also be passed as functions, but only if they are annotated with the `{.procvar.}` pragma. This is because there may be default parameters, which must be specially handled by the compiler.
``` nimrod
proc greaterThan32(x: int): bool {.procvar.} = x > 32
echo powersOfTwo.filter(greaterThan32)
```
```

View file

@ -19,14 +19,14 @@ for i, v in a:
for i in 4..100:
b.add(i * i)
b.delete(0) # takes «O(n)» time
b.delete(0) # takes O(n) time
b = a[0] & b # Same as original b
```
## Immutability
While sequences are dynamiclly allocated, they are still immutable.
Sequences are dynamiclly allocated (i.e. allocated on the heap, not the stack), but they are immutable unless marked as `var`. That means
``` nimrod
let a = @[1, 2, 3]
@ -40,7 +40,16 @@ var b = @[1, 2, 3]
b.add(4)
```
will work without any problems. If wanted, a seq can be passed to a method with the `var` or `ref` annotation to make it modifiable, so
will work without any problems. Sequences passed as "argument by value" are not modifiable. For example, the following will fail to compile.
``` nimrod
def do_something(mySeq: seq[int]) =
mySeq[0] = 2 # this is a compile-time error
var testSeq = [1, 2, 3]
do_something(testSeq)
```
`seq` arguments can be mutable if they are passed as "argument by reference", ie. the parameter is annotated with the `var` or `ref`:
``` nimrod
proc foo(mySeq: var seq[int]) =
@ -51,3 +60,15 @@ foo(thisSeq)
assert thisSeq[9] == 999
```
You can copy a sequence passed as "argument by value" and modify the copy:
``` nimrod
def do_something(mySeq: seq[int]) =
var varMySeq = mySeq # copy the seq
varMySeq[0] = 999
assert varMySeq[0] == 999
var testSeq = [1, 2, 3]
do_something(testSeq)
assert testSeq[0] == 1
```

View file

@ -16,7 +16,7 @@ echo """
proc re(s: string): string = s
echo r" "" "
echo r".""."
echo re"\b[a-z]++\b"
```
``` console
@ -29,17 +29,23 @@ words words words ⚑
<body>
<body/>
<html/>
"
.".
\b[a-z]++\b
```
There are several types of strings literals:
There are several types of string literals:
- Quoted Strings: Created by wrapping the body in triple quotes, they never interpret escape codes
- Raw Strings: created by prefixing the string with an `r`. There are no escape sequences don't work, except for `"`, which can be escaped as `""`
- Proc Strings: raw strings, but the method name that prefixes the string is called
- Raw Strings: created by prefixing the string with an `r`. They do not interpret escape sequences, except for `""`, which is interpreted as `"`. This means that `r"\b[a-z]\b"` is interpreted as `\b[a-z]\b` instead of failing to compile with a syntax error.
- Proc Strings: raw strings, but the method name that prefixes the string is called, so that `foo"12\"` -> `foo(r"12\")`.
Strings are null-terminated, so that `cstring("foo")` requires zero copying. However, you should be careful that the lifetime of the cstring does not exceed the lifetime of the string it is based upon.
Strings can also almost be thought of as `seq[char]` with respect to assignment semantics. See [seqs][]
[seqs]: /seqs/#immutability
## A note about unicode
Unicode symbols are allowed in strings, but are not treated in any special way, so if you want count glyphs or uppercase unicode symbols, you must use the `unicode` module.
Strings are generally considered to be encoded as UTF-8, so because of unicode's backwards compatibility, can be treated exactly as ASCII, with all values above 127 ignored.
Strings are generally considered to be encoded as UTF-8, so because of unicode's backwards compatibility, can be treated exactly as ASCII, with all values above 127 ignored.

View file

@ -1,5 +1,3 @@
## Pages
* [Getting Started](/getting_started/)
* [Hello World](/hello_world/)
* [Variables](/variables/)
@ -24,5 +22,4 @@
* [Object Oriented Programming](/oop/)
* [OOP Macro](/oop_macro/)
<!-- * OpenGL * [Triangle](/opengl/triangle/)-->
{: #toc-list}

View file

@ -26,7 +26,7 @@ let joe = Animal(name : "Joe",
species : "H. sapiens",
age : 23)
assert not carl.dead
assert(not carl.dead)
for i in 0..10:
carl.sleep()
assert carl.dead
@ -54,9 +54,9 @@ You might ask whether there is a more concise way of initializing reference typ
``` nimrod
type
PAnimal* = ref Animal
AnimalRef* = ref Animal
let spot = PAnimal(name: "Spot",
let spot = AnimalRef(name: "Spot",
species: "C. lupus",
age: 1)
```
@ -67,4 +67,4 @@ In many cases it is only wanted to have the object be a reference type, which is
type
Thing* = ref object
positionX*, positionY*: int
```
```

Binary file not shown.

View file

@ -1,14 +0,0 @@
<?xml version="1.0" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN" "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<svg xmlns="http://www.w3.org/2000/svg">
<metadata>Copyright (C) 2014 by original authors @ fontello.com</metadata>
<defs>
<font id="fontello" horiz-adv-x="1000" >
<font-face font-family="fontello" font-weight="400" font-stretch="normal" units-per-em="1000" ascent="850" descent="-150" />
<missing-glyph horiz-adv-x="1000" />
<glyph glyph-name="check" unicode="&#xe800;" d="m932 534q0-22-15-38l-404-404-76-76q-16-15-38-15t-38 15l-76 76-202 202q-15 16-15 38t15 38l76 76q16 16 38 16t38-16l164-165 366 367q16 16 38 16t38-16l76-76q15-16 15-38z" horiz-adv-x="1000" />
<glyph glyph-name="star" unicode="&#xe801;" d="m634 290l171 165-235 35-106 213-105-213-236-35 171-165-41-235 211 111 211-111z m295 199q0-12-15-27l-203-197 48-279q1-4 1-12 0-28-23-28-10 0-22 7l-251 132-250-132q-13-7-23-7-11 0-17 9t-6 19q0 4 1 12l48 279-203 197q-14 15-14 27 0 21 31 26l280 40 126 254q11 23 27 23t28-23l125-254 280-40q32-5 32-26z" horiz-adv-x="928.6" />
<glyph glyph-name="fork" unicode="&#xe802;" d="m161 29q0 22-16 38t-38 15-38-15-15-38 15-38 38-16 38 16 16 38z m0 642q0 23-16 38t-38 16-38-16-15-38 15-38 38-15 38 15 16 38z m357-71q0 22-16 38t-38 16-38-16-15-38 15-38 38-16 38 16 16 38z m53 0q0-29-14-54t-39-39q-1-160-126-231-38-21-114-45-71-22-94-39t-23-56v-15q24-14 39-39t14-53q0-45-31-76t-76-32-76 32-31 76q0 29 15 53t39 39v458q-25 14-39 39t-15 53q0 45 31 76t76 32 76-32 31-76q0-29-14-53t-39-39v-278q30 15 86 32 30 10 49 17t39 17 33 22 22 29 16 38 5 51q-25 14-39 39t-15 54q0 45 31 76t76 31 76-31 31-76z" horiz-adv-x="571.4" />
</font>
</defs>
</svg>

Before

Width:  |  Height:  |  Size: 1.6 KiB

Binary file not shown.

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 105 KiB

View file

@ -1,132 +0,0 @@
---
title: OpenGL - Triangle
---
# OpenGL: Triangle
The following code depends on the ``opengl`` and ``nim-glfw`` packages which
can be installed via babel by executing ``babel install opengl@#head nim-glfw@#head``.
You will need the GLFW DLL in order to run this on Windows.
![Triangle Windows](https://nim-by-example.github.io/images/triangle.png)
One thing to keep in mind when writing OpenGL code in Nim is that ``float``
is actually ``float64``. But vertices must be ``float32`` so you must explicitly
specify that by casting or using ``'f32`` as is done in the example.
```nimrod
import os, glfw/glfw, opengl, times, math
proc assertShader(shader: GLuint) =
var status: GLint
glGetShaderiv(shader, GL_COMPILE_STATUS, addr status)
if status != GL_TRUE:
var buff: array[512, char]
glGetShaderInfoLog(shader, 512, nil, buff)
echo(buff)
assert false
const
vertexSource = """
#version 150
in vec2 position;
in vec3 color;
out vec3 Color;
void main()
{
Color = color;
gl_Position = vec4(position, 0.0, 1.0);
}
"""
fragmentSource = """
#version 150
in vec3 Color;
out vec4 outColor;
void main()
{
outColor = vec4(Color, 1.0);
}
"""
proc setup(shaderProgram: var TGLUint) =
var vertices = [
0.0'f32, 0.5, 1, 0, 0,
0.5, -0.5, 0, 1, 0,
-0.5, -0.5, 0, 0, 1
]
echo(vertices.repr)
var vertexBuffer: GLuint
glGenBuffers(1, addr vertexBuffer)
echo("Verter Buff: ", vertexBuffer)
var vertexArray: GLuint
glGenVertexArrays(1, addr vertexArray)
glBindVertexArray(vertexArray)
glBindBuffer(GL_ARRAY_BUFFER, vertexBuffer)
glBufferData(GL_ARRAY_BUFFER, sizeof(vertices).int32, addr vertices,
GL_STATIC_DRAW)
var vertexShader = glCreateShader(GL_VERTEX_SHADER)
var vertexSrcArray = [vertexSource.cstring]
glShaderSource(vertexShader, 1, cast[cstringArray](addr vertexSrcArray), nil)
glCompileShader(vertexShader)
assertShader(vertexShader)
var fragmentShader = glCreateShader(GL_FRAGMENT_SHADER)
var fragmentSrcArray = [fragmentSource.cstring]
glShaderSource(fragmentShader, 1, cast[cstringArray](addr fragmentSrcArray),
nil)
glCompileShader(fragmentShader)
assertShader(fragmentShader)
shaderProgram = glCreateProgram()
glAttachShader(shaderProgram, vertexShader)
glAttachShader(shaderProgram, fragmentShader)
# Apparently this is not necessary according to http://open.gl
glBindFragDataLocation(shaderProgram, 0, "outColor")
glLinkProgram(shaderProgram)
glUseProgram(shaderProgram)
# Vertex data <-> attributes
var posAttrib = glGetAttribLocation(shaderProgram, "position").gluint
glEnableVertexAttribArray(posAttrib)
glVertexAttribPointer(posAttrib, 2, cGL_FLOAT, false,
5*sizeof(GLFloat).int32, nil)
var colAttrib = glGetAttribLocation(shaderProgram, "color").gluint
glEnableVertexAttribArray(colAttrib)
glVertexAttribPointer(colAttrib, 3, cGL_FLOAT, false,
5*sizeof(GLFloat).int32,
cast[pointer](2*sizeof(GLFloat)))
when isMainModule:
glfw.init()
var win = newWin()
win.makeContextCurrent()
loadExtensions()
var shaderProgram: TGLuint
setup(shaderProgram)
while not win.shouldClose:
glClear(GL_COLOR_BUFFER_BIT or GL_DEPTH_BUFFER_BIT)
glDrawArrays(GL_TRIANGLES, 0, 3)
win.swapBufs()
pollEvents()
win.destroy()
glfw.terminate()
```

View file

@ -1,72 +0,0 @@
/* pygments-css colorful */
code[class^='language-'] .hll:not([id^='MathJax']) { background-color: #ffffcc }
code[class^='language-'] .c:not([id^='MathJax']) { color: #808080 } /* Comment */
code[class^='language-'] .err:not([id^='MathJax']) { color: #F00000; background-color: #F0A0A0 } /* Error */
code[class^='language-'] .k:not([id^='MathJax']) { color: #008000; font-weight: bold } /* Keyword */
code[class^='language-'] .o:not([id^='MathJax']) { color: #303030 } /* Operator */
code[class^='language-'] .cm:not([id^='MathJax']) { color: #808080 } /* Comment.Multiline */
code[class^='language-'] .cp:not([id^='MathJax']) { color: #507090 } /* Comment.Preproc */
code[class^='language-'] .c1:not([id^='MathJax']) { color: #808080 } /* Comment.Single */
code[class^='language-'] .cs:not([id^='MathJax']) { color: #cc0000; font-weight: bold } /* Comment.Special */
code[class^='language-'] .gd:not([id^='MathJax']) { color: #A00000 } /* Generic.Deleted */
code[class^='language-'] .ge:not([id^='MathJax']) { font-style: italic } /* Generic.Emph */
code[class^='language-'] .gr:not([id^='MathJax']) { color: #FF0000 } /* Generic.Error */
code[class^='language-'] .gh:not([id^='MathJax']) { color: #000080; font-weight: bold } /* Generic.Heading */
code[class^='language-'] .gi:not([id^='MathJax']) { color: #00A000 } /* Generic.Inserted */
code[class^='language-'] .go:not([id^='MathJax']) { color: #808080 } /* Generic.Output */
code[class^='language-'] .gp:not([id^='MathJax']) {
color: #c65d09;
font-weight: bold;
/* NOTE: Hacks to allow copy-paste */
-webkit-touch-callout: none;
-webkit-user-select: none;
-khtml-user-select: none;
-moz-user-select: none;
-ms-user-select: none;
user-select: none;
} /* Generic.Prompt */
code[class^='language-'] .gs:not([id^='MathJax']) { font-weight: bold } /* Generic.Strong */
code[class^='language-'] .gu:not([id^='MathJax']) { color: #800080; font-weight: bold } /* Generic.Subheading */
code[class^='language-'] .gt:not([id^='MathJax']) { color: #0040D0 } /* Generic.Traceback */
code[class^='language-'] .kc:not([id^='MathJax']) { color: #008000; font-weight: bold } /* Keyword.Constant */
code[class^='language-'] .kd:not([id^='MathJax']) { color: #008000; font-weight: bold } /* Keyword.Declaration */
code[class^='language-'] .kn:not([id^='MathJax']) { color: #008000; font-weight: bold } /* Keyword.Namespace */
code[class^='language-'] .kp:not([id^='MathJax']) { color: #003080; font-weight: bold } /* Keyword.Pseudo */
code[class^='language-'] .kr:not([id^='MathJax']) { color: #008000; font-weight: bold } /* Keyword.Reserved */
code[class^='language-'] .kt:not([id^='MathJax']) { color: #303090; font-weight: bold } /* Keyword.Type */
code[class^='language-'] .m:not([id^='MathJax']) { color: #6000E0; font-weight: bold } /* Literal.Number */
code[class^='language-'] .s:not([id^='MathJax']) { background-color: #fff0f0 } /* Literal.String */
code[class^='language-'] .na:not([id^='MathJax']) { color: #0000C0 } /* Name.Attribute */
code[class^='language-'] .nb:not([id^='MathJax']) { color: #007020 } /* Name.Builtin */
code[class^='language-'] .nc:not([id^='MathJax']) { color: #B00060; font-weight: bold } /* Name.Class */
code[class^='language-'] .no:not([id^='MathJax']) { color: #003060; font-weight: bold } /* Name.Constant */
code[class^='language-'] .nd:not([id^='MathJax']) { color: #505050; font-weight: bold } /* Name.Decorator */
code[class^='language-'] .ni:not([id^='MathJax']) { color: #800000; font-weight: bold } /* Name.Entity */
code[class^='language-'] .ne:not([id^='MathJax']) { color: #F00000; font-weight: bold } /* Name.Exception */
code[class^='language-'] .nf:not([id^='MathJax']) { color: #0060B0; font-weight: bold } /* Name.Function */
code[class^='language-'] .nl:not([id^='MathJax']) { color: #907000; font-weight: bold } /* Name.Label */
code[class^='language-'] .nn:not([id^='MathJax']) { color: #0e84b5; font-weight: bold } /* Name.Namespace */
code[class^='language-'] .nt:not([id^='MathJax']) { color: #007000 } /* Name.Tag */
code[class^='language-'] .nv:not([id^='MathJax']) { color: #906030 } /* Name.Variable */
code[class^='language-'] .ow:not([id^='MathJax']) { color: #000000; font-weight: bold } /* Operator.Word */
code[class^='language-'] .w:not([id^='MathJax']) { color: #bbbbbb } /* Text.Whitespace */
code[class^='language-'] .mf:not([id^='MathJax']) { color: #6000E0; font-weight: bold } /* Literal.Number.Float */
code[class^='language-'] .mh:not([id^='MathJax']) { color: #005080; font-weight: bold } /* Literal.Number.Hex */
code[class^='language-'] .mi:not([id^='MathJax']) { color: #0000D0; font-weight: bold } /* Literal.Number.Integer */
code[class^='language-'] .mo:not([id^='MathJax']) { color: #4000E0; font-weight: bold } /* Literal.Number.Oct */
code[class^='language-'] .sb:not([id^='MathJax']) { background-color: #fff0f0 } /* Literal.String.Backtick */
code[class^='language-'] .sc:not([id^='MathJax']) { color: #0040D0 } /* Literal.String.Char */
code[class^='language-'] .sd:not([id^='MathJax']) { color: #D04020 } /* Literal.String.Doc */
code[class^='language-'] .s2:not([id^='MathJax']) { background-color: #fff0f0 } /* Literal.String.Double */
code[class^='language-'] .se:not([id^='MathJax']) { color: #606060; font-weight: bold; background-color: #fff0f0 } /* Literal.String.Escape */
code[class^='language-'] .sh:not([id^='MathJax']) { background-color: #fff0f0 } /* Literal.String.Heredoc */
code[class^='language-'] .si:not([id^='MathJax']) { background-color: #e0e0e0 } /* Literal.String.Interpol */
code[class^='language-'] .sx:not([id^='MathJax']) { color: #D02000; background-color: #fff0f0 } /* Literal.String.Other */
code[class^='language-'] .sr:not([id^='MathJax']) { color: #000000; background-color: #fff0ff } /* Literal.String.Regex */
code[class^='language-'] .s1:not([id^='MathJax']) { background-color: #fff0f0 } /* Literal.String.Single */
code[class^='language-'] .ss:not([id^='MathJax']) { color: #A06000 } /* Literal.String.Symbol */
code[class^='language-'] .bp:not([id^='MathJax']) { color: #007020 } /* Name.Builtin.Pseudo */
code[class^='language-'] .vc:not([id^='MathJax']) { color: #306090 } /* Name.Variable.Class */
code[class^='language-'] .vg:not([id^='MathJax']) { color: #d07000; font-weight: bold } /* Name.Variable.Global */
code[class^='language-'] .vi:not([id^='MathJax']) { color: #3030B0 } /* Name.Variable.Instance */
code[class^='language-'] .il:not([id^='MathJax']) { color: #0000D0; font-weight: bold } /* Literal.Number.Integer.Long */

View file

@ -1,8 +0,0 @@
#main code, code * { color: #675D69; }
code[class^='language-'] .k:not([id^='MathJax']) { color: #143A77; }
code[class^='language-'] .kp:not([id^='MathJax']) { color: #8C5DC7; }
code[class^='language-'] .kd:not([id^='MathJax']) { color: #8C5DC7; }
code[class^='language-'] .mi:not([id^='MathJax']) { color: #8C5DC7; }
code[class^='language-'] .s:not([id^='MathJax']) { color: #0060B0; }
code[class^='language-'] .c:not([id^='MathJax']) { color: #91B9A3; }
code[class^='language-'] .o:not([id^='MathJax']) { color: #009DE7; }

View file

@ -1,30 +0,0 @@
@font-face {
font-family: 'fontello';
src: url('/fonts/fontelloe.eot?23005170');
src: url('/fonts/fontelloe.eot?23005170#iefix') format('embedded-opentype'),
url('/fonts/fontellow.woff?23005170') format('woff'),
url('/fonts/fontellot.ttf?23005170') format('truetype'),
url('/fonts/fontellos.svg?23005170#fontello') format('svg');
font-weight: normal;
font-style: normal;
}
[class^="icon-"]:before, [class*=" icon-"]:before {
font-family: "fontello";
font-style: normal;
font-weight: normal;
speak: none;
display: inline-block;
text-decoration: inherit;
width: 1em;
margin-right: .2em;
text-align: center;
font-variant: normal;
text-transform: none;
}
.icon-check:before { content: '\e800'; } /* '' */
.icon-star:before { content: '\e801'; } /* '' */
.icon-fork:before { content: '\e802'; } /* '' */

View file

@ -1,192 +0,0 @@
* {
margin: 0;
padding: 0;
font-family: Palatino, serif;
box-sizing: border-box;
}
body {
background: #F5F7F6;
color: black;
line-height: 20px;
text-rendering: optimizelegibility;
}
a {
text-decoration: none;
}
a:link, a:visited{
color: #B45D47;
}
a:hover {
color: #FE3B3B;
}
#main {
position: absolute;
left: 255px;
max-width: 600px;
margin-bottom: 50px;
}
#main #gh-buttons {
float: right;
margin-bottom: 22px;
}
#main #starcount {
line-height: 20px;
font-size: 15px;
text-align: center;
color: #000;
position: absolute;
display: block;
float: right;
right: 5px;
width: 3em;
background: #FFF;
border: 1px solid #CCC;
border-radius: 3px;
height: 20px;
}
#main hr {
background: #CCC;
border: none;
margin: 1em;
margin-bottom: 1.3em;
height: 1px;
}
#main h1 {
font-size: 40px;
font-weight: normal;
line-height: 40px;
letter-spacing: -1px;
margin-bottom: 0.75em;
}
#main h2 {
margin-top: 1em;
}
#main p {
margin: 20px 0px;
margin-right: 1em;
line-height: 20px;
}
#main ul, #main ol {
margin: 20px;
}
#main ul li {
list-style-type: square;
}
#main table, th, td {
border-collapse: collapse;
border: 1px solid #CCC;
background-color: #FFF;
padding: 3px;
}
#main table {
box-shadow: 1px 3px 12px #BBB;
margin: 20px 10px 20px 0px;
}
#main code, code * {
font-family: Monaco, Menlo, Consolas, "Courier New", monospace;
}
#main code {
background: #FFFFFF;
padding: 0px 3px;
}
#main pre code { /* Block Code */
display: block;
word-wrap: break-word;
overflow: auto;
white-space: pre-wrap; /* css-3 */
white-space: -moz-pre-wrap; /* Mozilla, since 1999 */
white-space: -pre-wrap; /* Opera 4-6 */
white-space: -o-pre-wrap; /* Opera 7 */
word-wrap: break-word; /* Internet Explorer 5.5+ */
border-radius: 3px;
background:#FFF;
box-shadow: 1px 3px 12px #BBB;
padding: 10px 15px;
margin: 5px 10px 10px 5px;
}
#main span.line-numbers {
display: none;
}
#sidebar {
float: left;
margin-top: 20px;
margin-left: 20px;
width: 211px;
padding: 20px;
padding-left: 30px;
border-right: 1px solid #ccc;
font-size: 90%;
line-height: 20px;
box-sizing: border-box;
}
#sidebar h2 {
text-transform: uppercase;
font-size: 16px;
color: #470000;
letter-spacing: 1px;
line-height: 20px;
}
#sidebar ul {
position: relative;
left: 20px;
list-style: decimal-leading-zero;
list-style-position: outside;
}
#sidebar ul li ul {
width: 100px
}
#sidebar #toc-list {
left: 20px;
}
#sidebar a.visited:before { /* selected with JS */
content: "";
font-family: "fontello";
position: absolute;
left: -43px;
color: #EEE;
text-shadow: -1px 0 #2B2B2B, 0 1px #2B2B2B, 1px 0 #2B2B2B, 0 -1px #2B2B2B
}
/* Chrome */
@media screen and (-webkit-min-device-pixel-ratio:0) {
#sidebar ul { text-indent: -5px; }
#sidebar #toc-list { left: 25px; }
}

View file

@ -1,71 +1,55 @@
<!DOCTYPE HTML>
<html lang="en">
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<html lang="en-US">
<head>
<meta charset="utf-8">
<title>Nim by Example - <%= @item[:title] %></title>
<link rel="stylesheet" type="text/css" href="http://necolas.github.io/normalize.css/3.0.1/normalize.css">
<link rel="stylesheet" href="<%= @items['/stylesheets/main/'].path %>">
<link rel="stylesheet" href="<%= @items['/stylesheets/colorful/'].path %>" title="colorful">
<link rel="stylesheet" href="<%= @items['/stylesheets/fontello/'].path %>">
<script type="text/x-mathjax-config">
MathJax.Hub.Config({tex2jax: {inlineMath: [['«', '»']]}});
MathJax.Hub.config.tex2jax.skipTags = ["script", "noscript", "style", "textarea", "annotation", "annotation-xml"];
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS_HTML" async></script>
<% if @config[:debug] %>
<% for file in @config[:stylesheets] %>
<link rel="stylesheet" type="text/css" href="/assets/css/<%= File.basename(file, ".*") %>.css">
<% end %>
<% for file in @config[:scripts] %>
<script async src="/assets/js/<%= file %>"></script>
<% end %>
<% else %>
<style>
<%= @items["/assets/css/all/"].compiled_content() %>
</style>
<script async src="/assets/js/all.js"></script>
<% end %>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-58002512-1', 'auto');
ga('require', 'displayfeatures');
ga('send', 'pageview');
</script>
<title>Nim by Example - <%= @item[:title] %></title>
<meta name="generator" content="nanoc <%= Nanoc::VERSION %>">
<meta http-equiv="Default-Style" content="colorful">
<meta name=viewport content="width=device-width, initial-scale=1">
</head>
<body>
<div id="sidebar">
<%= @items["/toc/"].compiled_content(:snapshot => :last) %>
<div class="abs-hamburger"><div class="nav-toggle" onclick="javascript:sidebarClick();"><span></span></div></div>
<nav>
<%= @items["/content/toc/"].compiled_content(snapshot: :last) %>
</nav>
</div>
<div id="main">
<h1 id="gh-buttons"><a class="icon-fork" href="https://github.com/flaviut/nim-by-example/"></a> <a class="icon-star" href="https://github.com/flaviut/nim-by-example/stargazers" /><div id="starcount"></div></a></h1>
<script>
function setVisibleTags(){
var tocLinks = document.querySelectorAll("#sidebar a:link, a:visited");
for(var i = 0; i < tocLinks.length; i++){
if(localStorage.getItem(tocLinks[i].getAttribute("href")) != null){
tocLinks[i].classList.add("visited");
}
}
}
var starcount_elem = document.getElementById("starcount");
function updateStarCounter(){
if(localStorage.getItem("_watchers") != null){
starcount_elem.innerHTML = localStorage.getItem("_watchers");
}
var request = new XMLHttpRequest();
// horrible hack... but stargazer output is capped at 30 per request.
request.open("GET", "https://api.github.com/search/repositories?q=nim-by-example", true);
request.onload = function (e) {
var searchResults = JSON.parse(request.responseText);
var starcount = searchResults.items[0].stargazers_count;
starcount_elem.innerHTML = starcount;
localStorage.setItem("_watchers", starcount)
};
request.onerror = function (e) {
console.error(request.statusText);
};
request.send(null);
}
updateStarCounter()
localStorage.setItem(window.location.pathname, true);
setVisibleTags()
</script>
<article>
<%= yield %>
</article>
<div id=nextprev>
<a id=arrow-prev class="text-icon disabled" href="https://please-enable-js/">↽</a>
<a id=arrow-next class="text-icon disabled" href="https://please-enable-js/">⇁</a>
</div>
<footer>
<%= @items["/content/footer/"].compiled_content(snapshot: :last) %>
</footer>
</body>
</html>

19
lib/helpers.rb Normal file
View file

@ -0,0 +1,19 @@
def all_js(files)
js_arr = []
for file in files
item = @items.find{|i| i.identifier == "/assets/js/#{file}/"}
puts "File #{file} doesn't exist!" unless item
js_arr << item.compiled_content
end
js_arr.join("\n")
end
def all_css(files)
css_arr = []
for file in files
item = @items.find{|i| i.identifier == "/assets/css/#{file}/"}
puts "File #{file} doesn't exist!" unless item
css_arr << item.compiled_content
end
css_arr.join("\n")
end

View file

@ -29,6 +29,8 @@ prune:
# .git, .svn etc.
exclude: [ '.git', '.hg', '.svn', 'CVS' ]
string_pattern_type: legacy
# The data sources where nanoc loads its data from. This is an array of
# hashes; each array element represents a single data source. By default,
# there is only a single data source that reads data from the “content/” and
@ -38,6 +40,8 @@ data_sources:
# The type is the identifier of the data source. By default, this will be
# `filesystem_unified`.
type: filesystem_unified
identifier_type: legacy
encoding: utf-c8
# The path where items should be mounted (comparable to mount points in
# Unix-like systems). This is “/” by default, meaning that items will have
@ -60,3 +64,15 @@ data_sources:
# The default encoding for all files in `content/` and `layouts/`.
encoding: utf-8
debug: false
scripts:
- main
stylesheets:
- normalize
- colorful
- main
- monokai

View file

@ -1,29 +0,0 @@
{
"folders":
[
{ "path": "content" },
{ "path": "layouts" },
{ "path": "lib" },
{
"path": "./",
"folder_exclude_patterns": ["output",
"tmp",
"content",
"layouts",
"lib"]
}
],
"build_systems":
[
{
"name": "View",
"cmd": ["./view"],
"working_dir": "$project_path/"
},
{
"name": "Compile",
"cmd": ["nanoc"],
"working_dir": "$project_path/"
}
]
}

View file

@ -1,10 +1,13 @@
import md5, re, os, strutils, osproc
let
markdownFilesGlob = getCurrentDir() / "content" / "*.md"
markdownFilesGlob = getCurrentDir() / "content" / "content"
configFilePath = getCurrentDir() / "validcodehashes.txt"
for filePath in walkFiles(markdownFilesGlob):
for filePath in walkDirRec(markdownFilesGlob):
if filePath.splitFile.ext != ".md":
continue
let file = open(filePath, fmRead)
let fileContents = file.readAll()
file.close()

View file

@ -1,18 +1,23 @@
489fd1e2356eb85f81bac48e45b186a7
260d9667bbbc34ce79da5d60efecef02
ade4a4b3b6973bbb44f2e74aee1954f7
ef380e36bcc0ebf11902cefaa10ec31b
a043c1e16c84d2f1be0a9a6193d30ac0
26ded9e69879069fb8970403e87a24c9
b243592b06e93bb3cf1f7d62a25abaa3
3f3dfdee017d0c329d594e9fe038ed9f
cf09b588bb8b3c6979d24dcaff932c68
4d390aa1b44e1bb953e12e210985c85a
4bb57235ab6f4f0dd1eea58a769570c5
394ca46d1bf22dedef7e6e753bd033c8
8afe80a509d316a3feb3caa1c985760a
0bdba4c56b6172c86726f424b4186baf
9551565b83418876b5211869acbcf7cc
ac4fe7f722b390100501e638ce8a9750
f770b25468d042a02822e90df0848f35
24614b0b8792a9afc184e4d63e345981
d20fe9a9133bee2ef13c3b19ef540958
217de4ce8743609c7592a3d75264b17d
36c0a24d4e54348f950ff421a33dcd38
08b581ad308e3614335426ad8188b1ef
10ae94a28a0d8f23aff5afaa0367cf27
1865b827bef365e6422beb6bc076a25d
398863bccd3691b42500dfa143a3230b
@ -21,18 +26,31 @@ b8875a112bc13ea83556bcf385c1160b
bee0509ab4bcf36510a85081d563057b
30111c31170d8cd9979ae7d88fa276e7
0e641a70cbd7b3e955bb29bde934f36e
ad9e1e896361b0313c3ba66f793f4e6b
9c6750cad12656f497e5e6eb6896f5a1
d599ef057eaaac83139eb8f949cef356
e0e0e0b5724e296371d1704996096343
2d60def87d4fa95e26b9f8eade4b0baa
180c2775b35bd48de55453713ccb5828
d10f498d7a0d1e8693f7e1612822405f
d01dfb20f1d8c1741eef320e82bfcdc2
4f19f7a7103d8aec86dd2ab995e5a0a8
fbb7977d27de5251fa736a627aaa8311
847d1c4525d9056206a1e4f4855a9e10
e4b29a303e0a22cab1f2bfb769ce66c5
260d9667bbbc34ce79da5d60efecef02
24614b0b8792a9afc184e4d63e345981
217de4ce8743609c7592a3d75264b17d
36c0a24d4e54348f950ff421a33dcd38
0b0bdbed7863d3ec82d2d8cb628562ed
9eec8a1ad6f93080de5bcff05d8c5949
d62e74f9c0aa9077ec40ea4d038927d0
bf5bdad17535aa70efc569742eb1101f
c3da4dbe65a64c00ebc210a71e821ed9
02b30eadfb0591b8f723dd9277def002
d2657654df16c22a97903846ae9b3eec
84daadf080ac9b00870727cbb04f4758
deea30998a85ce603a7a38bb017de77b
a79167cf1a4c8d0347a55cb2676ffae3
9c16fb893a312d6bd6b260625a4b9b0c
b98257acda2d22827ed107f58c8a5ed8
f770b25468d042a02822e90df0848f35
397f231567a0f2ccd17a1a2b460d1c89
1cf49f03f1017f8babc9c517829266ae
4749fe1ac61b589a786fee5466bb4a52
abbe9a423e8c585e66f98deb6f7c303b
0e4bc99af4cd0c36e5af48ab2f5a5aa3
3dec7aae6d5b68e432c47200850be8fc

View file

@ -1,13 +1,14 @@
box: flaviut/nim-by-example-build-vm@0.0.6
box: flaviut/nim-by-example-build-vm:0.1.2
build:
steps:
- script:
name: build
code: |
source /home/ubuntu/.rvm/scripts/rvm
git remote add publish $GIT_CREDENTIALS
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
source /usr/local/rvm/scripts/rvm
git remote add publish 'git@github.com:nim-by-example/nim-by-example.github.io.git'
git config --global user.email 'nim-by-example.github.io'
git config --global user.name 'Builder'
git config --global push.default simple
git checkout master
nanoc
cp -r ./output/. ./
@ -16,7 +17,15 @@ build:
git commit -am'Build Site'
deploy:
steps:
- script:
name: ssh-keys
code: |
mkdir -p ~/.ssh/
echo 'github.com ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAq2A7hRGmdnm9tUDbO9IDSwBK6TbQa+PXYPCPy6rbTrTtw7PHkccKrpp0yVhp5HdEIcKr6pLlVDBfOLX9QUsyCOV0wzfjIJNlGEYsdlLJizHhbn2mUjvSAHQqZETYP81eFzLQNnPHt4EVVUh7VfDESU84KezmD5QlWpXLmvU31/yMf+Se8xhHTvKSCZIFImWwoG6mbUoWf9nzpIoaSjB+weqqUUmpaaasXVal72J+UX2B+2RPW3RcT0eOzQgqlJL3RKrTJvdsjE3JEAvGq3lGHSZXy28G3skua2SmVi/w4yCE6gbODqnTWlg7+wC604ydGXA8VJiS5ap43JXiUFFAaQ==' > ~/.ssh/known_hosts
echo -e "$GIT_CREDENTIALS" > ~/.ssh/id_rsa
chmod 0600 ~/.ssh/id_rsa
chmod 0644 ~/.ssh/known_hosts
- script:
name: deploy
code: |
git push --force publish > /dev/null 2>&1
git push --force publish