raw 0.49.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (148) hide show
  1. data/doc/CONTRIBUTORS +106 -0
  2. data/doc/LICENSE +32 -0
  3. data/doc/coding_conventions.txt +11 -0
  4. data/lib/raw.rb +42 -0
  5. data/lib/raw/adapter.rb +113 -0
  6. data/lib/raw/adapter/cgi.rb +41 -0
  7. data/lib/raw/adapter/fastcgi.rb +48 -0
  8. data/lib/raw/adapter/mongrel.rb +146 -0
  9. data/lib/raw/adapter/script.rb +94 -0
  10. data/lib/raw/adapter/webrick.rb +144 -0
  11. data/lib/raw/adapter/webrick/vcr.rb +91 -0
  12. data/lib/raw/cgi.rb +323 -0
  13. data/lib/raw/cgi/cookie.rb +47 -0
  14. data/lib/raw/cgi/http.rb +62 -0
  15. data/lib/raw/compiler.rb +138 -0
  16. data/lib/raw/compiler/filter/cleanup.rb +21 -0
  17. data/lib/raw/compiler/filter/elements.rb +166 -0
  18. data/lib/raw/compiler/filter/elements/element.rb +210 -0
  19. data/lib/raw/compiler/filter/localization.rb +23 -0
  20. data/lib/raw/compiler/filter/markup.rb +32 -0
  21. data/lib/raw/compiler/filter/morph.rb +123 -0
  22. data/lib/raw/compiler/filter/morph/each.rb +34 -0
  23. data/lib/raw/compiler/filter/morph/for.rb +11 -0
  24. data/lib/raw/compiler/filter/morph/if.rb +26 -0
  25. data/lib/raw/compiler/filter/morph/selected_if.rb +43 -0
  26. data/lib/raw/compiler/filter/morph/standard.rb +55 -0
  27. data/lib/raw/compiler/filter/morph/times.rb +27 -0
  28. data/lib/raw/compiler/filter/script.rb +116 -0
  29. data/lib/raw/compiler/filter/squeeze.rb +16 -0
  30. data/lib/raw/compiler/filter/static_include.rb +74 -0
  31. data/lib/raw/compiler/filter/template.rb +121 -0
  32. data/lib/raw/compiler/reloader.rb +96 -0
  33. data/lib/raw/context.rb +154 -0
  34. data/lib/raw/context/flash.rb +157 -0
  35. data/lib/raw/context/global.rb +88 -0
  36. data/lib/raw/context/request.rb +338 -0
  37. data/lib/raw/context/response.rb +57 -0
  38. data/lib/raw/context/session.rb +198 -0
  39. data/lib/raw/context/session/drb.rb +11 -0
  40. data/lib/raw/context/session/file.rb +15 -0
  41. data/lib/raw/context/session/memcached.rb +13 -0
  42. data/lib/raw/context/session/memory.rb +12 -0
  43. data/lib/raw/context/session/og.rb +15 -0
  44. data/lib/raw/context/session/pstore.rb +13 -0
  45. data/lib/raw/control.rb +18 -0
  46. data/lib/raw/control/attribute.rb +91 -0
  47. data/lib/raw/control/attribute/checkbox.rb +25 -0
  48. data/lib/raw/control/attribute/datetime.rb +21 -0
  49. data/lib/raw/control/attribute/file.rb +20 -0
  50. data/lib/raw/control/attribute/fixnum.rb +26 -0
  51. data/lib/raw/control/attribute/float.rb +26 -0
  52. data/lib/raw/control/attribute/options.rb +38 -0
  53. data/lib/raw/control/attribute/password.rb +16 -0
  54. data/lib/raw/control/attribute/text.rb +16 -0
  55. data/lib/raw/control/attribute/textarea.rb +16 -0
  56. data/lib/raw/control/none.rb +16 -0
  57. data/lib/raw/control/relation.rb +59 -0
  58. data/lib/raw/control/relation/belongs_to.rb +0 -0
  59. data/lib/raw/control/relation/has_many.rb +97 -0
  60. data/lib/raw/control/relation/joins_many.rb +0 -0
  61. data/lib/raw/control/relation/many_to_many.rb +0 -0
  62. data/lib/raw/control/relation/refers_to.rb +29 -0
  63. data/lib/raw/controller.rb +37 -0
  64. data/lib/raw/controller/publishable.rb +160 -0
  65. data/lib/raw/dispatcher.rb +209 -0
  66. data/lib/raw/dispatcher/format.rb +108 -0
  67. data/lib/raw/dispatcher/format/atom.rb +31 -0
  68. data/lib/raw/dispatcher/format/css.rb +0 -0
  69. data/lib/raw/dispatcher/format/html.rb +42 -0
  70. data/lib/raw/dispatcher/format/json.rb +31 -0
  71. data/lib/raw/dispatcher/format/rss.rb +33 -0
  72. data/lib/raw/dispatcher/format/xoxo.rb +31 -0
  73. data/lib/raw/dispatcher/mounter.rb +60 -0
  74. data/lib/raw/dispatcher/router.rb +111 -0
  75. data/lib/raw/errors.rb +19 -0
  76. data/lib/raw/helper.rb +86 -0
  77. data/lib/raw/helper/benchmark.rb +23 -0
  78. data/lib/raw/helper/buffer.rb +60 -0
  79. data/lib/raw/helper/cookie.rb +32 -0
  80. data/lib/raw/helper/debug.rb +28 -0
  81. data/lib/raw/helper/default.rb +16 -0
  82. data/lib/raw/helper/feed.rb +451 -0
  83. data/lib/raw/helper/form.rb +284 -0
  84. data/lib/raw/helper/javascript.rb +59 -0
  85. data/lib/raw/helper/layout.rb +40 -0
  86. data/lib/raw/helper/navigation.rb +87 -0
  87. data/lib/raw/helper/pager.rb +305 -0
  88. data/lib/raw/helper/table.rb +247 -0
  89. data/lib/raw/helper/xhtml.rb +218 -0
  90. data/lib/raw/helper/xml.rb +125 -0
  91. data/lib/raw/mixin/magick.rb +35 -0
  92. data/lib/raw/mixin/sweeper.rb +71 -0
  93. data/lib/raw/mixin/thumbnails.rb +1 -0
  94. data/lib/raw/mixin/webfile.rb +165 -0
  95. data/lib/raw/render.rb +271 -0
  96. data/lib/raw/render/builder.rb +26 -0
  97. data/lib/raw/render/caching.rb +81 -0
  98. data/lib/raw/render/call.rb +43 -0
  99. data/lib/raw/render/send_file.rb +46 -0
  100. data/lib/raw/render/stream.rb +39 -0
  101. data/lib/raw/scaffold.rb +13 -0
  102. data/lib/raw/scaffold/controller.rb +25 -0
  103. data/lib/raw/scaffold/model.rb +157 -0
  104. data/lib/raw/test.rb +5 -0
  105. data/lib/raw/test/assertions.rb +169 -0
  106. data/lib/raw/test/context.rb +55 -0
  107. data/lib/raw/test/testcase.rb +79 -0
  108. data/lib/raw/util/attr.rb +128 -0
  109. data/lib/raw/util/encode_uri.rb +149 -0
  110. data/lib/raw/util/html_filter.rb +538 -0
  111. data/lib/raw/util/markup.rb +130 -0
  112. data/test/glue/tc_webfile.rb +1 -0
  113. data/test/nitro/CONFIG.rb +3 -0
  114. data/test/nitro/adapter/raw_post1.bin +9 -0
  115. data/test/nitro/adapter/tc_webrick.rb +16 -0
  116. data/test/nitro/cgi/tc_cookie.rb +14 -0
  117. data/test/nitro/cgi/tc_request.rb +61 -0
  118. data/test/nitro/compiler/tc_client_morpher.rb +47 -0
  119. data/test/nitro/compiler/tc_compiler.rb +25 -0
  120. data/test/nitro/dispatcher/tc_mounter.rb +47 -0
  121. data/test/nitro/helper/tc_feed.rb +135 -0
  122. data/test/nitro/helper/tc_navbar.rb +74 -0
  123. data/test/nitro/helper/tc_pager.rb +35 -0
  124. data/test/nitro/helper/tc_table.rb +68 -0
  125. data/test/nitro/helper/tc_xhtml.rb +19 -0
  126. data/test/nitro/tc_caching.rb +19 -0
  127. data/test/nitro/tc_cgi.rb +222 -0
  128. data/test/nitro/tc_context.rb +17 -0
  129. data/test/nitro/tc_controller.rb +103 -0
  130. data/test/nitro/tc_controller_aspect.rb +32 -0
  131. data/test/nitro/tc_controller_params.rb +885 -0
  132. data/test/nitro/tc_dispatcher.rb +109 -0
  133. data/test/nitro/tc_element.rb +85 -0
  134. data/test/nitro/tc_flash.rb +59 -0
  135. data/test/nitro/tc_helper.rb +47 -0
  136. data/test/nitro/tc_render.rb +119 -0
  137. data/test/nitro/tc_router.rb +61 -0
  138. data/test/nitro/tc_server.rb +35 -0
  139. data/test/nitro/tc_session.rb +66 -0
  140. data/test/nitro/tc_template.rb +71 -0
  141. data/test/nitro/util/tc_encode_url.rb +87 -0
  142. data/test/nitro/util/tc_markup.rb +31 -0
  143. data/test/public/blog/another/very_litle/index.xhtml +1 -0
  144. data/test/public/blog/inc1.xhtml +2 -0
  145. data/test/public/blog/inc2.xhtml +1 -0
  146. data/test/public/blog/list.xhtml +9 -0
  147. data/test/public/dummy_mailer/registration.xhtml +5 -0
  148. metadata +244 -0
@@ -0,0 +1,25 @@
1
+ require "raw/control/attribute"
2
+
3
+ module Raw
4
+
5
+ # A Control used to edit boolean attributes.
6
+
7
+ class CheckboxControl < AttributeControl
8
+ setting :style, :default => '', :doc => 'The default style'
9
+
10
+ def render
11
+ checked = @value == true ? ' checked="checked"' : ''
12
+ %{
13
+ <input type="checkbox" id="#{control_id}" name="#{@attribute}" #{emit_style}#{checked}#{emit_disabled} />&nbsp;#{emit_label}
14
+ }
15
+ end
16
+
17
+ def emit_label
18
+ return '' if @options[:no_label]
19
+ title = @anno[:title] || @options[:label] || @attribute.to_s.humanize
20
+ %{<label for="#{@attribute}" style="display: inline">#{title}</label>}
21
+ end
22
+
23
+ end
24
+
25
+ end
@@ -0,0 +1,21 @@
1
+ require "raw/control/attribute"
2
+
3
+ module Raw
4
+
5
+ # A Control used to edit datetime attributes.
6
+ #--
7
+ # TODO: implement me!
8
+ #++
9
+
10
+ class DatetimeControl < AttributeControl
11
+ setting :style, :default => '', :doc => 'The default style'
12
+
13
+ def render
14
+ %{
15
+ NOT IMPLEMENTED
16
+ }
17
+ end
18
+
19
+ end
20
+
21
+ end
@@ -0,0 +1,20 @@
1
+ require "raw/control/attribute"
2
+
3
+ module Raw
4
+
5
+ # Usage note:
6
+ # don't forget to set form :method to :multipart
7
+ # or :method to :post and :enctype to 'multipart/form-data'
8
+
9
+ class FileControl < AttributeControl
10
+ setting :style, :default => 'width: 250px', :doc => 'The default style'
11
+
12
+ def render
13
+ %{
14
+ #{emit_label}
15
+ <input type="file" id="#{control_id}" name="#{@attribute}" value="#{@object.send(@attribute)}"#{emit_style}#{emit_disabled} />
16
+ }
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,26 @@
1
+ require "raw/control/attribute"
2
+
3
+ module Raw
4
+
5
+ # Controls a Fixnum attribute.
6
+
7
+ class FixnumControl < AttributeControl
8
+ setting :style, :default => 'width: 100px', :doc => 'The default style'
9
+
10
+ def render
11
+ style = @anno[:control_style] || self.class.style
12
+ %{
13
+ #{emit_label}
14
+ <input type="text" id="#{control_id}" name="#{@attribute}" value="#{value}"#{emit_style}#{emit_disabled} />
15
+ <a href="#" onclick="el=document.getElementById('#{control_id}'); el.value=(parseInt(el.value) || 0)+#{step}; return false;">+</a>
16
+ <a href="#" onclick="el=document.getElementById('#{control_id}'); el.value=(parseInt(el.value) || 0)-#{step}; return false;">-</a>
17
+ }
18
+ end
19
+
20
+ def step
21
+ 1
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,26 @@
1
+ require "raw/control/attribute"
2
+
3
+ module Raw
4
+
5
+ # Controls a Float attribute.
6
+
7
+ class FloatControl < AttributeControl
8
+ setting :style, :default => 'width: 100px', :doc => 'The default style'
9
+
10
+ def render
11
+ style = @anno[:control_style] || self.class.style
12
+ %{
13
+ #{emit_label}
14
+ <input type="text" id="#{control_id}" name="#{@attribute}" value="#{value}"#{emit_style}#{emit_disabled} />
15
+ <a href="#" onclick="el=document.getElementById('#{control_id}'); el.value=(parseInt(el.value) || 0)+#{step}; return false;">+</a>
16
+ <a href="#" onclick="el=document.getElementById('#{control_id}'); el.value=(parseInt(el.value) || 0)-#{step}; return false;">-</a>
17
+ }
18
+ end
19
+
20
+ def step
21
+ 0.5
22
+ end
23
+
24
+ end
25
+
26
+ end
@@ -0,0 +1,38 @@
1
+ require "raw/control/attribute"
2
+
3
+ module Raw
4
+
5
+ # Controls a Fixnum attribute that can contain discreet values
6
+ # (options).
7
+ #
8
+ # === Example
9
+ #
10
+ # Pass a 'reverse' dictionary. Reverse to reuse the has for
11
+ # easy rendering of labels. Dictionary to allow for ordered
12
+ # keys.
13
+ #
14
+ # PRIORITY_VALUES = Dictionary[
15
+ # 0, :trivial,
16
+ # 1, :minor,
17
+ # 2, :major,
18
+ # 3, :blocker
19
+ # ]
20
+ #
21
+ # attr_accessor :priority, Fixnum, :control => :options, :options_data => PRIORITY_VALUES
22
+
23
+ class OptionsControl < AttributeControl
24
+ setting :style, :default => 'width: 100px', :doc => 'The default style'
25
+
26
+ def render
27
+ style = @anno[:control_style] || self.class.style
28
+ data = @anno[:options_data]
29
+ %{
30
+ #{emit_label}
31
+ <select id="#{control_id}" name="#{@attribute}">
32
+ #{options :labels => data.values, :values => data.keys, :selected => value}
33
+ </select>
34
+ }
35
+ end
36
+ end
37
+
38
+ end
@@ -0,0 +1,16 @@
1
+ require "raw/control/attribute"
2
+
3
+ module Raw
4
+
5
+ class PasswordControl < AttributeControl
6
+ setting :style, :default => 'width: 250px', :doc => 'The default style'
7
+
8
+ def render
9
+ %{
10
+ #{emit_label}
11
+ <input type="password" id="#{control_id}" name="#{@attribute}" value="#{@object.send(@attribute)}"#{emit_style}#{emit_disabled} />
12
+ }
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ require "raw/control/attribute"
2
+
3
+ module Raw
4
+
5
+ class TextControl < AttributeControl
6
+ setting :style, :default => 'width: 250px', :doc => 'The default style'
7
+
8
+ def render
9
+ %{
10
+ #{emit_label}
11
+ <input type="text" id="#{control_id}" name="#{@attribute}" value="#{@object.send(@attribute)}"#{emit_style}#{emit_disabled} />
12
+ }
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ require "raw/control/attribute"
2
+
3
+ module Raw
4
+
5
+ class TextareaControl < AttributeControl
6
+ setting :style, :default => 'width: 500px; height: 100px', :doc => 'The default style'
7
+
8
+ def render
9
+ %{
10
+ #{emit_label}
11
+ <textarea id="#{control_id}" name="#{@attribute}"#{emit_style}#{emit_disabled}>#{@object.send(@attribute)}</textarea>
12
+ }
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,16 @@
1
+ require "raw/control/attribute"
2
+
3
+ module Raw
4
+
5
+ class NoneControl < AttributeControl
6
+ def render
7
+ %{
8
+ #{emit_label}<br />
9
+ <div class="none_ctl_container">
10
+ No control available
11
+ </div>
12
+ }
13
+ end
14
+ end
15
+
16
+ end
@@ -0,0 +1,59 @@
1
+ require "raw/control/attribute"
2
+
3
+ module Raw
4
+
5
+ # The base class for controls used to inspect object
6
+ # relations.
7
+ #--
8
+ # FIXME: this is a temp hack.
9
+ # TODO: Fix mismatches with attributes.
10
+ #++
11
+
12
+ class RelationControl < AttributeControl
13
+
14
+ # === Input
15
+ #
16
+ # * object = the object to inspect
17
+ # * symbol = the relation symbol
18
+ # * anno = the relation annotations
19
+ # * options = additional options
20
+
21
+ def initialize object, rel, options
22
+ @object = object
23
+ @anno = rel
24
+ @value = options[:value] || object.send(rel.name.to_sym)
25
+ @options = options
26
+ end
27
+
28
+ def symbol
29
+ @anno[:symbol]
30
+ end
31
+
32
+ def rel
33
+ @anno
34
+ end
35
+
36
+ private
37
+
38
+ # Used as id attribute in HTML markup.
39
+ def control_id
40
+ "#{rel.name}_ctl"
41
+ end
42
+
43
+
44
+ # Emit the label for this control.
45
+ # The label is skipped if the control is created with the
46
+ # option :no_label set to true.
47
+ #--
48
+ # TODO: reuse attribute control version.
49
+ #++
50
+
51
+ def emit_label
52
+ return '' if @options[:no_label]
53
+ title = @anno[:title] || @options[:label] || @anno[:name].to_s.humanize
54
+ %{<label for="#{control_id}">#{title}</label>}
55
+ end
56
+
57
+ end
58
+
59
+ end
File without changes
@@ -0,0 +1,97 @@
1
+ require "raw/control/relation"
2
+
3
+ module Raw
4
+
5
+ # HasMany, ManyToMany and JoinsMany
6
+
7
+ class HasManyControl < RelationControl
8
+
9
+ #pre :do_this, :on => :populate_object
10
+
11
+ def render
12
+ str = "#{emit_label}"
13
+ str << emit_container_start
14
+ str << emit_js
15
+ if selected_items.empty?
16
+ str << emit_selector(:removable => false)
17
+ else
18
+ removable = selected_items.size != 1 ? true : false
19
+ selected_items.each do |item|
20
+ str << emit_selector(:selected => item.pk)
21
+ end
22
+ end
23
+ str << emit_container_end
24
+ end
25
+
26
+ private
27
+
28
+ # these parts are seperated from render to make it easier
29
+ # to extend and customise the HasManyControl
30
+
31
+ def all_items
32
+ return @all_items unless @all_items.nil?
33
+ @all_items = rel.target_class.all
34
+ end
35
+
36
+ def selected_items
37
+ if @object.saved?
38
+ values
39
+ else
40
+ [] # gmosx, THINK: this is a hack fix!
41
+ end
42
+ end
43
+
44
+ def emit_container_start
45
+ %{<div class="many_to_many_container">}
46
+ end
47
+
48
+ def emit_container_end
49
+ '</div>'
50
+ end
51
+
52
+ # :removable controls wether the minus button is active
53
+ # :selected denotes the oid to flag as selected in the list
54
+
55
+ def emit_selector(options={})
56
+ removable = options.fetch(:removable, true)
57
+ selected = options.fetch(:selected, nil)
58
+ %{
59
+ <div>
60
+ <select class="has_many_ctl" name="#{rel.name}[]" id="#{control_id}" #{emit_style}#{emit_disabled}>
61
+ <option value="">None</option>
62
+ #{options(:labels => all_items.map{|o| o.to_s}, :values => all_items.map{|o| o.pk}, :selected => selected)}
63
+ </select>
64
+ <input type="button" class="#{rel.name}_remove_btn" value=" - " onclick="rm_#{rel.name}_rel(this);" #{'disabled="disabled"' unless removable} />
65
+ <input type="button" class="#{rel.name}_add_btn" value=" + " onclick="add_#{rel.name}_rel(this);"#{emit_disabled} />
66
+ </div>
67
+ }
68
+ end
69
+
70
+ # Inline script: override this to change behavior
71
+
72
+ def emit_js
73
+ %{
74
+ <script type="text/javascript">
75
+ rm_#{rel.name}_rel = function(el){
76
+ ctl=el.parentNode;
77
+ container=ctl.parentNode;
78
+ container.removeChild(ctl);
79
+ inputTags = container.getElementsByTagName('input');
80
+ if(inputTags.length==2)
81
+ inputTags[0].disabled='disabled';
82
+ }
83
+ add_#{rel.name}_rel = function(el){
84
+ ctl=el.parentNode;
85
+ container=ctl.parentNode;
86
+ node=ctl.cloneNode(true);
87
+ node.getElementsByTagName('input')[0].removeAttribute('disabled');
88
+ if(container.lastChild==ctl) container.appendChild(node);
89
+ else container.insertBefore(node, ctl.nextSibling);
90
+ if(container.childNodes.length>1) container.getElementsByTagName('input')[0].disabled='';
91
+ }
92
+ </script>
93
+ }
94
+ end
95
+ end
96
+
97
+ end
File without changes
@@ -0,0 +1,29 @@
1
+ require "raw/control/relation"
2
+
3
+ module Raw
4
+
5
+ # RefersTo. Also used for BelongsTo.
6
+
7
+ class RefersToControl < RelationControl
8
+
9
+ def render
10
+ %{
11
+ #{emit_label}
12
+ <select id="#{control_id}" name="#{rel.name}"#{emit_disabled}>
13
+ #{emit_options}
14
+ </select>
15
+ }
16
+ end
17
+
18
+ def emit_options
19
+ objs = rel.target_class.all
20
+ selected = selected.pk if selected = value
21
+ %{
22
+ <option value="">--</option>
23
+ #{options(:labels => objs.map{|o| o.to_s}, :values => objs.map{|o| o.pk}, :selected => selected)}
24
+ }
25
+ end
26
+
27
+ end
28
+
29
+ end
@@ -0,0 +1,37 @@
1
+ require "raw/controller/publishable"
2
+
3
+ module Raw
4
+
5
+ # The Controller part in the MVC paradigm. The controller's
6
+ # published methods are called actrions. The controller class
7
+ # contains the Publishable mixin and additional helper mixins.
8
+
9
+ class Controller
10
+ include Publishable
11
+
12
+ # This callback is called after the Controller is mounted.
13
+
14
+ def self.mounted(path)
15
+ end
16
+
17
+ # Returns the current controller from the context thread local
18
+ # variable.
19
+
20
+ def self.current
21
+ Thread.current[:CURRENT_CONTROLLER]
22
+ end
23
+
24
+ #--
25
+ # Replaces the current controller (helper for render).
26
+ # This is an internal method.
27
+ #++
28
+
29
+ def self.replace_current(controller) # :nodoc:
30
+ old = Thread.current[:CURRENT_CONTROLLER]
31
+ Thread.current[:CURRENT_CONTROLLER] = controller
32
+ return old
33
+ end
34
+
35
+ end
36
+
37
+ end