utopia 1.8.3 → 1.9.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -0
  3. data/documentation/.bowerrc +4 -0
  4. data/documentation/.rspec +4 -0
  5. data/documentation/Gemfile +27 -0
  6. data/documentation/Rakefile +5 -0
  7. data/documentation/config.ru +50 -0
  8. data/documentation/config/README.md +7 -0
  9. data/documentation/config/environment.rb +10 -0
  10. data/documentation/lib/readme.txt +1 -0
  11. data/documentation/pages/_heading.xnode +2 -0
  12. data/documentation/pages/_page.xnode +28 -0
  13. data/documentation/pages/errors/exception.xnode +5 -0
  14. data/documentation/pages/errors/file-not-found.xnode +5 -0
  15. data/documentation/pages/links.yaml +2 -0
  16. data/documentation/pages/welcome/index.xnode +41 -0
  17. data/documentation/pages/wiki/content.md +7 -0
  18. data/{setup/examples → documentation/pages}/wiki/controller.rb +8 -6
  19. data/documentation/pages/wiki/development-environment-setup/content.md +14 -0
  20. data/{setup/examples → documentation/pages}/wiki/edit.xnode +1 -1
  21. data/documentation/pages/wiki/server-setup/content.md +40 -0
  22. data/documentation/pages/wiki/show.xnode +12 -0
  23. data/documentation/pages/wiki/your-first-page/content.md +31 -0
  24. data/documentation/public +1 -0
  25. data/documentation/spec/website_context.rb +11 -0
  26. data/documentation/spec/website_spec.rb +15 -0
  27. data/documentation/tasks/test.rake +10 -0
  28. data/documentation/tasks/utopia.rake +38 -0
  29. data/lib/utopia/content.rb +2 -2
  30. data/lib/utopia/content/link.rb +5 -1
  31. data/lib/utopia/content/markup.rb +86 -66
  32. data/lib/utopia/content/tag.rb +28 -45
  33. data/lib/utopia/content/transaction.rb +31 -25
  34. data/lib/utopia/controller/actions.rb +1 -0
  35. data/lib/utopia/redirection.rb +4 -4
  36. data/lib/utopia/version.rb +1 -1
  37. data/setup/site/public/_static/site.css +20 -8
  38. data/spec/utopia/content/markup_spec.rb +10 -10
  39. data/spec/utopia/content/tag_spec.rb +36 -0
  40. data/spec/utopia/controller/middleware_spec.ru +4 -1
  41. data/spec/utopia/controller/middleware_spec/controller/controller.rb +2 -0
  42. data/spec/utopia/controller/middleware_spec/controller/nested/controller.rb +2 -0
  43. data/spec/utopia/controller/middleware_spec/redirect/controller.rb +2 -0
  44. data/spec/utopia/controller/middleware_spec/redirect/test/controller.rb +2 -0
  45. data/spec/utopia/controller/respond_spec.ru +5 -2
  46. data/spec/utopia/exceptions/handler_spec.ru +3 -1
  47. data/spec/utopia/exceptions/handler_spec/controller.rb +2 -0
  48. data/spec/utopia/exceptions/mailer_spec.ru +6 -2
  49. data/spec/utopia/localization_spec.rb +2 -2
  50. data/spec/utopia/localization_spec.ru +2 -1
  51. data/spec/utopia/localization_spec/controller.rb +2 -0
  52. data/spec/utopia/performance_spec/config.ru +1 -0
  53. data/spec/utopia/performance_spec/pages/api/controller.rb +1 -1
  54. data/utopia.gemspec +3 -3
  55. metadata +36 -14
  56. data/ext/utopia/xnode/fast_scanner/extconf.rb +0 -6
  57. data/ext/utopia/xnode/fast_scanner/parser.c +0 -289
  58. data/setup/examples/wiki/index.xnode +0 -10
  59. data/setup/examples/wiki/welcome/content.md +0 -3
@@ -1,6 +0,0 @@
1
-
2
- require 'mkmf'
3
-
4
- dir_config('fast_scanner')
5
-
6
- create_makefile("fast_scanner")
@@ -1,289 +0,0 @@
1
- #include "ruby.h"
2
-
3
- #define OPENED_TAG 0
4
- #define CLOSED_TAG 1
5
-
6
- static VALUE rb_XNode;
7
- static VALUE rb_XNode_ScanError;
8
- static VALUE rb_XNode_Scanner;
9
-
10
- static ID rb_XNode_CDATA_Callback;
11
- static ID rb_XNode_BeginTag_Callback;
12
- static ID rb_XNode_FinishTag_Callback;
13
- static ID rb_XNode_Attribute_Callback;
14
- static ID rb_XNode_Comment_Callback;
15
- static ID rb_XNode_Instruction_Callback;
16
- static ID rb_XNode_Comment_Callback;
17
-
18
- #define NewObject(type) (type*)malloc(sizeof(type))
19
-
20
- typedef struct {
21
- VALUE delegate;
22
- VALUE content;
23
- } XNode_Scanner;
24
-
25
- typedef char Character;
26
- typedef Character * Iterator;
27
-
28
- static void XNode_Scanner_Mark(XNode_Scanner * scanner) {
29
- rb_gc_mark(scanner->delegate);
30
- rb_gc_mark(scanner->content);
31
- }
32
-
33
- static void XNode_Scanner_Free(XNode_Scanner * scanner) {
34
- free(scanner);
35
- }
36
-
37
- static VALUE XNode_Scanner_Allocate(VALUE klass) {
38
- XNode_Scanner * scanner = NewObject(XNode_Scanner);
39
-
40
- return Data_Wrap_Struct(klass, XNode_Scanner_Mark, XNode_Scanner_Free, scanner);
41
- }
42
-
43
- static VALUE XNode_Scanner_Initialize(VALUE self, VALUE delegate, VALUE content) {
44
- Check_Type(content, T_STRING);
45
-
46
- XNode_Scanner * scanner;
47
-
48
- Data_Get_Struct(self, XNode_Scanner, scanner);
49
-
50
- scanner->delegate = delegate;
51
- scanner->content = content;
52
-
53
- return Qnil;
54
- }
55
-
56
- static VALUE rb_str_from_iterators(Iterator start, Iterator end) {
57
- return rb_str_new(start, end - start);
58
- }
59
-
60
- static int is_whitespace(Iterator i) {
61
- return (*i == ' ' || *i == '\r' || *i == '\n' || *i == '\t');
62
- }
63
-
64
- static int is_tag_character(Iterator i) {
65
- return (*i == '<' || *i == '>' || *i == '/');
66
- }
67
-
68
- static int is_tag_name(Iterator i) {
69
- return !(is_whitespace(i) || is_tag_character(i));
70
- }
71
-
72
- static Iterator expect_character(XNode_Scanner * scanner, Iterator start, Iterator end, Character c) {
73
- if (start >= end || *start != c) {
74
- VALUE message = rb_str_new2("Expected Character ");
75
- rb_str_cat(message, &c, 1);
76
- VALUE exception = rb_exc_new3(rb_XNode_ScanError, message);
77
- rb_exc_raise(exception);
78
- }
79
-
80
- return start + 1;
81
- }
82
-
83
- static Iterator skip_whitespace(Iterator start, Iterator end) {
84
- while (start < end) {
85
- if (!is_whitespace(start))
86
- break;
87
-
88
- ++start;
89
- }
90
-
91
- return start;
92
- }
93
-
94
- static Iterator XNode_Scanner_Parse_CDATA(XNode_Scanner * scanner, Iterator start, Iterator end) {
95
- Iterator cdata_start = start;
96
-
97
- while (start < end && *start != '<') {
98
- ++start;
99
- }
100
-
101
- Iterator cdata_end = start;
102
-
103
- if (cdata_start != cdata_end) {
104
- VALUE cdata = rb_str_from_iterators(cdata_start, cdata_end);
105
- rb_funcall(scanner->delegate, rb_XNode_CDATA_Callback, 1, cdata);
106
- }
107
-
108
- return start;
109
- }
110
-
111
- static Iterator XNode_Scanner_Parse_Attributes(XNode_Scanner * scanner, Iterator start, Iterator end) {
112
- while (start < end && !is_tag_character(start)) {
113
- start = skip_whitespace(start, end);
114
-
115
- Iterator attribute_name_start = start;
116
-
117
- while (start < end && *start != '=') {
118
- ++start;
119
- }
120
-
121
- Iterator attribute_name_end = start;
122
-
123
- start = expect_character(scanner, start, end, '=');
124
- start = expect_character(scanner, start, end, '"');
125
-
126
- Iterator attribute_value_start = start;
127
-
128
- while (start < end && *start != '"') {
129
- ++start;
130
- }
131
-
132
- Iterator attribute_value_end = start;
133
- start = expect_character(scanner, start, end, '"');
134
-
135
- VALUE attribute_name = rb_str_from_iterators(attribute_name_start, attribute_name_end);
136
- VALUE attribute_value = rb_str_from_iterators(attribute_value_start, attribute_value_end);
137
- rb_funcall(scanner->delegate, rb_XNode_Attribute_Callback, 2, attribute_name, attribute_value);
138
-
139
- start = skip_whitespace(start, end);
140
- }
141
-
142
- return start;
143
- }
144
-
145
- static Iterator XNode_Scanner_Parse_Tag_Normal(XNode_Scanner * scanner, Iterator start, Iterator end, int begin_tag_type) {
146
- Iterator tag_name_start = start;
147
- int finish_tag_type;
148
-
149
- while (start < end && is_tag_name(start)) {
150
- ++start;
151
- }
152
-
153
- Iterator tag_name_end = start;
154
-
155
- VALUE tag_name = rb_str_from_iterators(tag_name_start, tag_name_end);
156
- rb_funcall(scanner->delegate, rb_XNode_BeginTag_Callback, 2, tag_name, INT2FIX(begin_tag_type));
157
-
158
- start = skip_whitespace(start, end);
159
-
160
- if (!is_tag_character(start))
161
- start = XNode_Scanner_Parse_Attributes(scanner, start, end);
162
-
163
- if (*start == '/') {
164
- if (begin_tag_type == CLOSED_TAG) {
165
- VALUE exception = rb_exc_new2(rb_XNode_ScanError, "Tag cannot be closed at both ends!");
166
- rb_exc_raise(exception);
167
- }
168
-
169
- finish_tag_type = CLOSED_TAG;
170
- start += 2;
171
- } else if (*start == '>') {
172
- finish_tag_type = OPENED_TAG;
173
- ++start;
174
- }
175
-
176
- rb_funcall(scanner->delegate, rb_XNode_FinishTag_Callback, 2, INT2FIX(begin_tag_type), INT2FIX(finish_tag_type));
177
-
178
- return start;
179
- }
180
-
181
- static Iterator XNode_Scanner_Parse_Tag_Comment(XNode_Scanner * scanner, Iterator start, Iterator end) {
182
- Iterator comment_start = start;
183
-
184
- while (start < end && *start != '>') {
185
- ++start;
186
- }
187
-
188
- Iterator comment_end = start;
189
-
190
- start = expect_character(scanner, start, end, '>');
191
-
192
- VALUE comment = rb_str_from_iterators(comment_start, comment_end);
193
- rb_funcall(scanner->delegate, rb_XNode_Comment_Callback, 1, comment);
194
-
195
- return start;
196
- }
197
-
198
- static Iterator XNode_Scanner_Parse_Tag_Instruction(XNode_Scanner * scanner, Iterator start, Iterator end) {
199
- Iterator instruction_start = start;
200
-
201
- while ((start+1) < end && *start != '?' && *(start+1) != '>') {
202
- ++start;
203
- }
204
-
205
- Iterator instruction_end = start;
206
-
207
- start = expect_character(scanner, start, end, '?');
208
- start = expect_character(scanner, start, end, '>');
209
-
210
- VALUE instruction = rb_str_from_iterators(instruction_start, instruction_end);
211
- rb_funcall(scanner->delegate, rb_XNode_Instruction_Callback, 1, instruction);
212
-
213
- return start;
214
- }
215
-
216
- static Iterator XNode_Scanner_Parse_Tag(XNode_Scanner * scanner, Iterator start, Iterator end) {
217
- if (*start == '<') {
218
- ++start;
219
-
220
- if (*start == '/') {
221
- ++start;
222
- start = XNode_Scanner_Parse_Tag_Normal(scanner, start, end, CLOSED_TAG);
223
- } else if (*start == '!') {
224
- ++start;
225
- start = XNode_Scanner_Parse_Tag_Comment(scanner, start, end);
226
- } else if (*start == '?') {
227
- ++start;
228
- start = XNode_Scanner_Parse_Tag_Instruction(scanner, start, end);
229
- } else {
230
- start = XNode_Scanner_Parse_Tag_Normal(scanner, start, end, OPENED_TAG);
231
- }
232
- }
233
-
234
- return start;
235
- }
236
-
237
- static Iterator XNode_Scanner_Parse_Document(XNode_Scanner * scanner) {
238
- Iterator current, start, end;
239
-
240
- start = RSTRING(scanner->content)->ptr;
241
- end = start + RSTRING(scanner->content)->len;
242
-
243
- while (start < end) {
244
- current = start;
245
-
246
- current = XNode_Scanner_Parse_CDATA(scanner, current, end);
247
- current = XNode_Scanner_Parse_Tag(scanner, current, end);
248
-
249
- if (current == start) {
250
- /* We did not parse anything! */
251
- VALUE message = rb_str_new2("Parser Stuck at ");
252
-
253
- int len = 10;
254
- if (current + len > end)
255
- len = end - current;
256
-
257
- rb_str_cat(message, current, len);
258
- VALUE exception = rb_exc_new3(rb_XNode_ScanError, message);
259
- rb_exc_raise(exception);
260
- }
261
-
262
- start = current;
263
- }
264
- }
265
-
266
- static VALUE XNode_Scanner_Parse(VALUE self) {
267
- XNode_Scanner * scanner;
268
-
269
- Data_Get_Struct(self, XNode_Scanner, scanner);
270
-
271
- XNode_Scanner_Parse_Document(scanner);
272
- }
273
-
274
- void Init_xnode() {
275
- rb_XNode = rb_define_module("XNode");
276
- rb_XNode_ScanError = rb_define_class_under(rb_XNode, "ScanError", rb_eStandardError);
277
- rb_XNode_Scanner = rb_define_class_under(rb_XNode, "Scanner", rb_cObject);
278
-
279
- rb_define_alloc_func(rb_XNode_Scanner, XNode_Scanner_Allocate);
280
- rb_define_method(rb_XNode_Scanner, "initialize", XNode_Scanner_Initialize, 2);
281
- rb_define_method(rb_XNode_Scanner, "parse", XNode_Scanner_Parse, 0);
282
-
283
- rb_XNode_CDATA_Callback = rb_intern("cdata");
284
- rb_XNode_BeginTag_Callback = rb_intern("begin_tag");
285
- rb_XNode_FinishTag_Callback = rb_intern("finish_tag");
286
- rb_XNode_Attribute_Callback = rb_intern("attribute");
287
- rb_XNode_Comment_Callback = rb_intern("comment");
288
- rb_XNode_Instruction_Callback = rb_intern("instruction");
289
- }
@@ -1,10 +0,0 @@
1
- <page>
2
- <heading>#{self[:page_title]}</heading>
3
-
4
- #{Kramdown::Document.new(self[:content]).to_html}
5
-
6
- <footer>
7
- Last Modified: #{File.mtime(self[:page_file]) rescue "N/A"} &mdash;
8
- <a href="edit">Edit</a>
9
- </footer>
10
- </page>
@@ -1,3 +0,0 @@
1
- Utopia is a Rack framework and build around several key pieces of middleware which provide a MVC architecture for content-centric websites.
2
-
3
- Utopia [provides a command-line](utopia-command-line/)