vanilla 1.12.5 → 1.13.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +3 -4
- data/config.example.yml +1 -0
- data/config.ru +0 -14
- data/lib/tasks/vanilla.rake +13 -50
- data/lib/vanilla/app.rb +0 -3
- data/lib/vanilla/dynasnips/comments.rb +16 -47
- data/lib/vanilla/dynasnips/index.rb +2 -2
- data/lib/vanilla/request.rb +0 -16
- data/lib/vanilla/snips/system/layout.snip +19 -0
- data/lib/vanilla/snips/{start.rb → system/start.snip} +3 -6
- data/lib/vanilla/snips/system/system.snip +17 -0
- data/lib/vanilla/snips/tutorial/bad_dynasnip.snip +8 -0
- data/lib/vanilla/snips/tutorial/hello_world.snip +20 -0
- data/lib/vanilla/snips/tutorial/markdown_example.snip +13 -0
- data/lib/vanilla/snips/tutorial/snip.snip +9 -0
- data/lib/vanilla/snips/tutorial/soup.snip +5 -0
- data/lib/vanilla/snips/tutorial/test.snip +30 -0
- data/lib/vanilla/snips/tutorial/textile_example.snip +11 -0
- data/lib/vanilla/snips/tutorial/tutorial-another-snip.snip +1 -0
- data/lib/vanilla/snips/tutorial/tutorial-basic-snip-inclusion.snip +1 -0
- data/lib/vanilla/snips/tutorial/vanilla-rb-tutorial.snip +73 -0
- data/lib/vanilla/snips/tutorial/vanilla-rb.snip +16 -0
- data/lib/vanilla/snips/tutorial/vanilla.snip +8 -0
- data/lib/vanilla.rb +4 -0
- data/test/tmp/config.yml +1 -1
- data/test/tmp/soup/current_snip.snip +2 -2
- metadata +28 -42
- data/lib/defensio.rb +0 -59
- data/lib/vanilla/authentication/warden.rb +0 -58
- data/lib/vanilla/authentication.rb +0 -24
- data/lib/vanilla/dynasnips/edit.rb +0 -59
- data/lib/vanilla/dynasnips/edit_link.rb +0 -20
- data/lib/vanilla/dynasnips/logout.rb +0 -8
- data/lib/vanilla/dynasnips/new.rb +0 -12
- data/lib/vanilla/snips/system.rb +0 -84
- data/lib/vanilla/snips/tutorial.rb +0 -244
- data/public/javascripts/jquery.autogrow-textarea.js +0 -54
- data/public/javascripts/jquery.js +0 -4376
- data/public/javascripts/vanilla.js +0 -22
@@ -1,244 +0,0 @@
|
|
1
|
-
app = Vanilla::App.new(ENV['VANILLA_CONFIG'])
|
2
|
-
tutorial = app.snip(:name => 'vanilla-rb-tutorial')
|
3
|
-
tutorial.render_as = "Markdown"
|
4
|
-
tutorial.content = <<-END_OF_TUTORIAL
|
5
|
-
Basic Concepts
|
6
|
-
------------
|
7
|
-
|
8
|
-
Every piece of information displayed here is stored as a {link_to snip}. Snips, within their contents, can also reference other snips. When you request a snip, it will render into a page (or another kind of response), and also render any snips that it internally references.
|
9
|
-
|
10
|
-
For example, consider the snip {link_to tutorial-basic-snip-inclusion}:
|
11
|
-
|
12
|
-
{raw tutorial-basic-snip-inclusion}
|
13
|
-
|
14
|
-
When this snip is rendered, it appears like this:
|
15
|
-
|
16
|
-
{tutorial-basic-snip-inclusion}
|
17
|
-
|
18
|
-
Notice the use of curly brackets to reference one snip from inside another. Vanilla.rb finds these references to snips, then renders that snip and replaces it in the first snip. Neat!
|
19
|
-
|
20
|
-
Renderers
|
21
|
-
--------
|
22
|
-
|
23
|
-
The way that a snip is rendered depends on whether or not it has a `render_as` attribute set. For instance, the `render_as` property of this snip ({link_to vanilla-rb}) is "Markdown". This means that the `content` of this snip will be passed through `Vanilla::Renderers::Markdown` before it is then rendered to the page. There are several different renders provided by Vanilla.rb at the moment:
|
24
|
-
|
25
|
-
* Markdown - as described above
|
26
|
-
* Textile - which performs similarly for Textile. This means that you can mix how you write the content of snips!
|
27
|
-
* Raw - which simply returns the content of the snip, as-is. If you attach a `.raw` extension to this url, you'll see it in action
|
28
|
-
* Bold - simply wraps the content in bold. It's a demo, essentially.
|
29
|
-
* Erb - passes the snip contents through Ruby's `Erb` library. It also makes some information available for use by ruby code within the snip's contents
|
30
|
-
* Ruby - parses the snips content as Ruby itself.
|
31
|
-
|
32
|
-
It's using this last renderer that a second concept of Vanilla is implemented - dynasnips.
|
33
|
-
|
34
|
-
|
35
|
-
Dynasnips
|
36
|
-
--------
|
37
|
-
|
38
|
-
Because the curly braces simply cause a snip to be rendered, we can use this in conjunction with the Ruby renderer to run actual code. For instance, in the snip above:
|
39
|
-
|
40
|
-
{raw tutorial-basic-snip-inclusion}
|
41
|
-
|
42
|
-
we can see a reference to the `link_to` snip - <tt>{link\_to snip}</tt>.
|
43
|
-
|
44
|
-
Lets look at the raw content of `link_to`:
|
45
|
-
|
46
|
-
{raw link_to}
|
47
|
-
|
48
|
-
As you can see, it simply refers to the Ruby class `LinkTo`, which is contained within the vanilla-rb codebase. When the Ruby renderer is called, expects the given code to evaulate to a Ruby class. It then instantiates the class, and calls a `handle` method on the instance, passing it any other arguments from the snip inclusion. So, in the case of <tt>{link\_to snip}</tt>, the only argument is `snip`.
|
49
|
-
|
50
|
-
Vanilla.rb includes a number of dynasnips by default. Here are a couple:
|
51
|
-
|
52
|
-
* `rand`, which generates a random number (a silly demo really); {link_to rand}, or an example: {rand}
|
53
|
-
* `link_to`, to produce a link to another snip
|
54
|
-
* `kind`, which selects and renders sets of snips based on their `kind` attribute (this is how the blog is currently implemented)
|
55
|
-
* `raw`, which displays the raw contents of a snip
|
56
|
-
* `edit`, which implements the editor
|
57
|
-
* `index`, which shows all of the available snips: {link_to index}
|
58
|
-
* ... and several others.
|
59
|
-
|
60
|
-
While dynasnip classes can be provided as part of the vanilla codebase, it's envisioned that much of these will be created by end users in their own sites, either by refering to local classes, or defining the classes directly as the content. Here's an example of that, as the raw content of {link_to hello\_world}:
|
61
|
-
|
62
|
-
{raw hello_world}
|
63
|
-
|
64
|
-
which, when rendered, gives:
|
65
|
-
|
66
|
-
{hello_world}
|
67
|
-
|
68
|
-
Note that the `handle` method can take one (optional) argument. Lets try including it with <tt>{hello\_world Dave}</tt>:
|
69
|
-
|
70
|
-
{hello_world Dave}
|
71
|
-
|
72
|
-
Anyway - that should be enough to get you started.
|
73
|
-
END_OF_TUTORIAL
|
74
|
-
|
75
|
-
tutorial.save
|
76
|
-
|
77
|
-
tutorial_basic_snip_inclusion = app.snip(:name => 'tutorial-basic-snip-inclusion')
|
78
|
-
tutorial_basic_snip_inclusion.content = <<-EOS
|
79
|
-
This is a snip, which includes another {link_to snip}: {tutorial-another-snip}
|
80
|
-
EOS
|
81
|
-
tutorial_basic_snip_inclusion.save
|
82
|
-
|
83
|
-
tutorial_another_snip = app.snip(:name => 'tutorial-another-snip')
|
84
|
-
tutorial_another_snip.content = "this is another snip!"
|
85
|
-
tutorial_another_snip.save
|
86
|
-
|
87
|
-
hello_world = app.snip(:name => 'hello_world', :render_as => "Ruby")
|
88
|
-
hello_world.content = <<-END_OF_RUBY
|
89
|
-
class HelloWorld
|
90
|
-
# although the name doesn't need to match the snip name,
|
91
|
-
# it's simple to follow that convention where appropriate
|
92
|
-
|
93
|
-
def handle(name=nil)
|
94
|
-
if name
|
95
|
-
"Hey \#{name} - Hello World!"
|
96
|
-
else
|
97
|
-
"Hello World!"
|
98
|
-
end
|
99
|
-
end
|
100
|
-
|
101
|
-
# note that this code must evaluate to a class. One way of achieving that is by
|
102
|
-
# putting 'self' at the end of the class definition.
|
103
|
-
self
|
104
|
-
end
|
105
|
-
# Another way is by referring to the class at the end of the content. Either works fine.
|
106
|
-
HelloWorld
|
107
|
-
END_OF_RUBY
|
108
|
-
hello_world.save
|
109
|
-
|
110
|
-
snip = app.snip(:name => 'snip', :render_as => "Markdown")
|
111
|
-
snip.content = <<-EOS
|
112
|
-
A snip is the basic building block of information for {link_to vanilla-rb}. Essentially, it is a piece of content with arbitrary attributes. Vanilla anticipates the presence of some key attributes:
|
113
|
-
|
114
|
-
* `name` - the name of the snip, which is how it will be referred to. The `name` of this snip is _snip_.
|
115
|
-
* `content` - the default part of the snip to render. You can see the `content` of this snip <a href="/snip/content.raw">here</a>.
|
116
|
-
* `render_as` - the name of the renderer to use when rendering the content. The `render_as` of this snip is {snip.render_as}.
|
117
|
-
|
118
|
-
One implementation of the snip store is {link_to soup}.
|
119
|
-
EOS
|
120
|
-
snip.save
|
121
|
-
|
122
|
-
soup = app.snip(:name => 'soup')
|
123
|
-
soup.content = <<-EOS
|
124
|
-
Soup is a data store supporting the {link_to snip}-space that {link_to vanilla-rb} expects.
|
125
|
-
|
126
|
-
It's hosted on github <a href="http://github.com/lazyatom/soup">here</a>.
|
127
|
-
EOS
|
128
|
-
soup.save
|
129
|
-
|
130
|
-
vanilla_rb = app.snip(:name => 'vanilla-rb', :render_as => "Markdown")
|
131
|
-
vanilla_rb.content = <<-EOS
|
132
|
-
Vanilla.rb is the software powering this site. It's a sort-of wiki/bliki thing, based on {link_to vanilla}.
|
133
|
-
|
134
|
-
Here's the [introductory blog post][3].
|
135
|
-
|
136
|
-
It's developed on [github][1], and has a [lighthouse bug tracker][2]. At the moment it's not very well documented, since I'm exploring how the concept might work and the internals are subject to change. However, please do play around with it.
|
137
|
-
|
138
|
-
Here's the tutorial (helpfully included from {link_to vanilla-rb-tutorial}).
|
139
|
-
|
140
|
-
{vanilla-rb-tutorial}
|
141
|
-
|
142
|
-
|
143
|
-
[1]: http://github.com/lazyatom/vanilla
|
144
|
-
[2]: http://lazyatom.lighthouseapp.com/projects/11797-vanilla/tickets
|
145
|
-
[3]: http://interblah.net/introducing-vanilla-rb
|
146
|
-
EOS
|
147
|
-
vanilla_rb.save
|
148
|
-
|
149
|
-
vanilla = app.snip(:name => 'vanilla', :render_as => "Markdown")
|
150
|
-
vanilla.content = <<-EOS
|
151
|
-
The bliki upon which {link_to vanilla-rb} is based, writen by [Christian Langreiter][1]
|
152
|
-
|
153
|
-
[Official Web HQ][2]
|
154
|
-
|
155
|
-
[1]: http://www.langreiter.com
|
156
|
-
[2]: http://www.vanillasite.at
|
157
|
-
EOS
|
158
|
-
vanilla.save
|
159
|
-
|
160
|
-
test = app.snip(:name => "test")
|
161
|
-
test.content =<<EOF
|
162
|
-
Linking is good: {link_to bold}
|
163
|
-
Here's a bold snip: {bold}
|
164
|
-
|
165
|
-
- Here's a random number between 5 and 15: {rand 5,15}
|
166
|
-
- Here's a random number between 1 and 90 (the default min): {rand 90}
|
167
|
-
- Here's a random number between 1 and 100 (the default range): {rand}
|
168
|
-
|
169
|
-
And lets include some textile:
|
170
|
-
|
171
|
-
{textile_example}
|
172
|
-
|
173
|
-
The source for that was
|
174
|
-
|
175
|
-
{pre textile_example}
|
176
|
-
|
177
|
-
And lets include some markdown!:
|
178
|
-
|
179
|
-
{markdown_example}
|
180
|
-
|
181
|
-
The source for that was
|
182
|
-
|
183
|
-
{pre markdown_example}
|
184
|
-
|
185
|
-
How about some {link_to debug} information: {debug}
|
186
|
-
|
187
|
-
What about a missing snip? Lets try to include one: {monkey}
|
188
|
-
|
189
|
-
And an error when running? {bad_dynasnip}
|
190
|
-
|
191
|
-
EOF
|
192
|
-
test.render_as = "Markdown"
|
193
|
-
test.save
|
194
|
-
|
195
|
-
bold = app.snip(:name => "bold")
|
196
|
-
bold.content =<<EOF
|
197
|
-
Snip2 in da house!
|
198
|
-
EOF
|
199
|
-
bold.render_as = "Bold"
|
200
|
-
bold.save
|
201
|
-
|
202
|
-
textile = app.snip(:name => "textile_example")
|
203
|
-
textile.content =<<EOF
|
204
|
-
|
205
|
-
# testing lists
|
206
|
-
# because lists are common things
|
207
|
-
|
208
|
-
monkey
|
209
|
-
|
210
|
-
what the *hell* are __you__ looking at?
|
211
|
-
|
212
|
-
"Beyotch":http://example.com
|
213
|
-
|
214
|
-
EOF
|
215
|
-
textile.render_as = "Textile"
|
216
|
-
textile.save
|
217
|
-
|
218
|
-
textile = app.snip(:name => "markdown_example")
|
219
|
-
textile.content =<<EOF
|
220
|
-
|
221
|
-
# testing header
|
222
|
-
|
223
|
-
so, how are you?
|
224
|
-
|
225
|
-
- item one
|
226
|
-
- item two
|
227
|
-
- item three
|
228
|
-
|
229
|
-
|
230
|
-
what the *hell* are looking at, [beyotch](http://example.com)?
|
231
|
-
EOF
|
232
|
-
textile.render_as = "Markdown"
|
233
|
-
textile.save
|
234
|
-
|
235
|
-
bad_dynasnip = app.snip(:name => "bad_dynasnip", :render_as => "Ruby")
|
236
|
-
bad_dynasnip.content = <<EOF
|
237
|
-
class BadDynasnip
|
238
|
-
def get(*args)
|
239
|
-
raise "Oh no"
|
240
|
-
end
|
241
|
-
end
|
242
|
-
BadDynasnip
|
243
|
-
EOF
|
244
|
-
bad_dynasnip.save
|
@@ -1,54 +0,0 @@
|
|
1
|
-
(function($) {
|
2
|
-
|
3
|
-
/*
|
4
|
-
* Auto-growing textareas; technique ripped from Facebook
|
5
|
-
*/
|
6
|
-
$.fn.autogrow = function(options) {
|
7
|
-
|
8
|
-
this.filter('textarea').each(function() {
|
9
|
-
|
10
|
-
var $this = $(this),
|
11
|
-
minHeight = $this.height(),
|
12
|
-
lineHeight = $this.css('lineHeight');
|
13
|
-
|
14
|
-
var shadow = $('<div></div>').css({
|
15
|
-
position: 'absolute',
|
16
|
-
top: -10000,
|
17
|
-
left: -10000,
|
18
|
-
width: $(this).width() - parseInt($this.css('paddingLeft')) - parseInt($this.css('paddingRight')),
|
19
|
-
fontSize: $this.css('fontSize'),
|
20
|
-
fontFamily: $this.css('fontFamily'),
|
21
|
-
lineHeight: $this.css('lineHeight'),
|
22
|
-
resize: 'none'
|
23
|
-
}).appendTo(document.body);
|
24
|
-
|
25
|
-
var update = function() {
|
26
|
-
|
27
|
-
var times = function(string, number) {
|
28
|
-
for (var i = 0, r = ''; i < number; i ++) r += string;
|
29
|
-
return r;
|
30
|
-
};
|
31
|
-
|
32
|
-
var val = this.value.replace(/</g, '<')
|
33
|
-
.replace(/>/g, '>')
|
34
|
-
.replace(/&/g, '&')
|
35
|
-
.replace(/\n$/, '<br/> ')
|
36
|
-
.replace(/\n/g, '<br/>')
|
37
|
-
.replace(/ {2,}/g, function(space) { return times(' ', space.length -1) + ' ' });
|
38
|
-
|
39
|
-
shadow.html(val);
|
40
|
-
$(this).css('height', Math.max(shadow.height() + 20, minHeight));
|
41
|
-
|
42
|
-
}
|
43
|
-
|
44
|
-
$(this).change(update).keyup(update).keydown(update);
|
45
|
-
|
46
|
-
update.apply(this);
|
47
|
-
|
48
|
-
});
|
49
|
-
|
50
|
-
return this;
|
51
|
-
|
52
|
-
}
|
53
|
-
|
54
|
-
})(jQuery);
|