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,218 @@
1
+ module Raw
2
+
3
+ # A helper mixin for programmatically building XHTML
4
+ # blocks.
5
+
6
+ module XhtmlHelper
7
+
8
+ # Creates the href of an Object.
9
+ #--
10
+ # gmosx: this duplicates R functionality, merge!
11
+ #++
12
+
13
+ def href_of(obj, base = nil)
14
+ if obj.is_a?(Symbol) or obj.is_a?(String)
15
+ href = obj.to_s
16
+ elsif obj.respond_to? :to_href
17
+ href = obj.to_href
18
+ else
19
+ href = "#{obj.class.name.pluralize.underscore}/#{obj.oid}"
20
+ end
21
+
22
+ if base
23
+ base += '/'
24
+ else
25
+ base = "#{self.class.mount_path}/".squeeze
26
+ end
27
+
28
+ return "#{base}#{href}"
29
+ end
30
+
31
+ # Creates a link to an Object.
32
+
33
+ def link_to(obj, base = nil)
34
+ %|<a href="#{href_of(obj, base)}">#{obj}</a>|
35
+ end
36
+
37
+ # Render select options. The parameter is a hash of options.
38
+ #
39
+ # [+labels+]
40
+ # The option labels.
41
+ #
42
+ # [+values+]
43
+ # The corresponding values.
44
+ #
45
+ # [+labels_values+]
46
+ # Use when labels == values.
47
+ #
48
+ # [+selected+]
49
+ # The value of the selected option.
50
+ #
51
+ # === Examples
52
+ #
53
+ # labels = ['Male', 'Female']
54
+ # o.select(:name => 'sex') {
55
+ # o.options(:labels => labels, :selected => 1)
56
+ # }
57
+ #
58
+ # or
59
+ #
60
+ # #{options :labels => labels, :values => [..], :selected => 1}
61
+ # #{build :options, :labels => labels, :values => [..], :selected => 1}
62
+
63
+ def options(options = {})
64
+ if labels = options[:labels] || options[:labels_values]
65
+ str = ''
66
+
67
+ values = options[:values] || options[:labels_values] || (0...labels.size).to_a
68
+
69
+ selected = options[:selected]
70
+ selected = selected.to_s if selected
71
+
72
+ labels.each_with_index do |label, idx|
73
+ value = values[idx]
74
+ if options[:style]
75
+ style = if options[:style].is_a?(Array)
76
+ options[:style][idx]
77
+ else
78
+ options[:style]
79
+ end
80
+ style = %{ style="#{style}"}
81
+ end
82
+ if value.to_s == selected
83
+ str << %|<option value="#{value}" selected="selected"#{style}>#{label}</option>|
84
+ else
85
+ str << %|<option value="#{value}"#{style}>#{label}</option>|
86
+ end
87
+ end
88
+
89
+ return str
90
+ else
91
+ raise ArgumentError.new('No labels provided')
92
+ end
93
+ end
94
+
95
+ # Convert a collection of objects to options.
96
+
97
+ def objects_to_options(objs, params = {})
98
+ labels = []
99
+ values = []
100
+ for obj in objs
101
+ labels << obj.to_s
102
+ values << obj.pk
103
+ end
104
+ params[:labels] = labels
105
+ params[:values] = values
106
+ options(params)
107
+ end
108
+
109
+ # Render a hidden form input.
110
+
111
+ def hidden(name, value)
112
+ # opts = options.collect { |k, v| %[#{k}="#{v}"] }.join(' ')
113
+ %[<input type="hidden" name="#{name}" value="#{value}" />]
114
+ end
115
+
116
+ # Render a submit input.
117
+
118
+ def submit(label, options = nil)
119
+ str = ''
120
+
121
+ label = options.delete(:value) unless label
122
+
123
+ str << '<input type="submit"'
124
+ str << %[ value="#{label}"] if label
125
+
126
+ unless options.empty?
127
+ opts = options.collect { |k, v| %[#{k}="#{v}"] }.join(' ')
128
+ str << %[ #{opts} ]
129
+ end
130
+
131
+ str << ' />'
132
+
133
+ return str
134
+ end
135
+
136
+ # Render a date select. Override to customize this.
137
+ #
138
+ # === Example
139
+ #
140
+ # #{date_select date, :name => 'brithday'}
141
+
142
+ def date_select(date, options = {})
143
+ raise 'No name provided to date_select' unless name = options[:name]
144
+ date ||= Time.now
145
+ %{
146
+ <select id="#{name}.day" name="#{name}.day">
147
+ #{options(:labels_values => (1..31).to_a, :selected => date.day)}
148
+ </select>&nbsp;
149
+ <select id="#{name}.month" name="#{name}.month">
150
+ #{options(:labels => Date::MONTHNAMES[1..12], :values => (1..12).to_a, :selected => (date.month))}
151
+ </select>&nbsp;
152
+ <select id="#{name}.year" name="#{name}.year">
153
+ #{options(:labels_values => ((Time.now.year-10)..(Time.now.year+10)).to_a, :selected => date.year)}
154
+ </select>}
155
+ end
156
+
157
+ # Render a time select. Override to customize this.
158
+
159
+ def time_select(time, options = {})
160
+ raise 'No name provided to time_select' unless name = options[:name]
161
+ time ||= Time.now
162
+ %{
163
+ <select id="#{name}.hour" name="#{name}.hour">
164
+ #{options(:labels_values => (1..60).to_a, :selected => time.hour)}
165
+ </select>&nbsp;
166
+ <select id="#{name}.min" name="#{name}.min">
167
+ #{options(:labels_values => (1..60).to_a, :selected => time.min)}
168
+ </select>}
169
+ end
170
+
171
+ # Render a datetime select. Override to customize this.
172
+
173
+ def datetime_select(time, options)
174
+ date_select(time, options) + '&nbsp;at&nbsp;' + time_select(time, options)
175
+ end
176
+
177
+
178
+ # gmosx: keep the leading / to be IE friendly.
179
+
180
+ def js_popup(options = {})
181
+ o = {
182
+ :width => 320,
183
+ :height => 240,
184
+ :title => 'Popup',
185
+ :resizable => false,
186
+ :scrollbars => false,
187
+ }.merge(options)
188
+
189
+ poptions = (o[:resizable] ? 'resizable=yes,' : 'resizable=no,')
190
+ poptions << (o[:scrollbars] ? 'scrollbars=yes' : 'scrollbars=no')
191
+
192
+ uri = o[:url] || o[:uri]
193
+
194
+ %[javascript: var pwl = (screen.width - #{o[:width]}) / 2; var pwt = (screen.height - #{o[:height]}) / 2; window.open('#{uri}', '#{o[:title]}', 'width=#{o[:width]},height=#{o[:height]},top='+pwt+',left='+pwl+', #{poptions}'); return false;"]
195
+ end
196
+
197
+ # === Example
198
+ #
199
+ # <a href="#" #{onclick_popup 'add-comment', :scrollbars => true}>Hello</a>
200
+
201
+ def onclick_popup(options = {})
202
+ %|onclick="#{js_popup(options)}"|
203
+ end
204
+
205
+ # Emit a link that spawns a popup window.
206
+ #
207
+ # === Example
208
+ #
209
+ # <a href="#" #{onclick :text => 'Hello', :uri => 'add-comment', :scrollbars => true}>Hello</a>
210
+
211
+ def popup(options = {})
212
+ %|<a href="#" #{onclick_popup(options)}>#{options[:text] || 'Popup'}</a>|
213
+ end
214
+
215
+ end
216
+
217
+ end
218
+
@@ -0,0 +1,125 @@
1
+ module Raw
2
+
3
+ # A helper mixin for programmatically building XML
4
+ # blocks.
5
+ #--
6
+ # gmosx, INVESTIGATE: is this used or deprecated?
7
+ #++
8
+
9
+ module XmlHelper
10
+
11
+ def method_missing(tag, *args, &block)
12
+ self.class.module_eval <<-"end_eval", __FILE__, __LINE__
13
+ def #{tag}(*args)
14
+ attrs = args.last.is_a?(Hash) ? args.pop : nil
15
+
16
+ if block_given?
17
+ start_tag!('#{tag}', attrs)
18
+ yield
19
+ end_tag!('#{tag}')
20
+ elsif (!args.empty?)
21
+ start_tag!('#{tag}', attrs)
22
+ self << args.first
23
+ end_tag!('#{tag}')
24
+ else
25
+ start_tag!('#{tag}', attrs, false)
26
+ self << ' />'
27
+ end
28
+ end
29
+ end_eval
30
+
31
+ self.send(tag, *args, &block)
32
+ end
33
+
34
+ # Emit the start (opening) tag of an element.
35
+
36
+ def start_tag!(tag, attributes = nil, close = true)
37
+ unless attributes
38
+ if close
39
+ self << "<#{tag}>"
40
+ else
41
+ self << "<#{tag}"
42
+ end
43
+ else
44
+ self << "<#{tag}"
45
+ for name, value in attributes
46
+ if value
47
+ self << %| #{name}="#{value}"|
48
+ else
49
+ self << %| #{name}="1"|
50
+ end
51
+ end
52
+ self << ">" if close
53
+ end
54
+
55
+ return self
56
+ end
57
+
58
+ # Emit the end (closing) tag of an element.
59
+
60
+ def end_tag!(tag)
61
+ self << "</#{tag}>"
62
+
63
+ return self
64
+ end
65
+
66
+ # Emit a text string.
67
+
68
+ def text!(str)
69
+ self << str
70
+
71
+ return self
72
+ end
73
+ alias_method :print, :text!
74
+
75
+ # Emit a comment.
76
+
77
+ def comment!(str)
78
+ self << "<!-- #{str} -->"
79
+
80
+ return self
81
+ end
82
+
83
+ # Emit a processing instruction.
84
+
85
+ def processing_instruction!(name, attributes = nil)
86
+ unless attributes
87
+ self << "<?#{name} ?>"
88
+ else
89
+ self << "<?#{name} "
90
+ attributes.each do |a, v|
91
+ self << %[#{a}="#{v}" ]
92
+ end
93
+ self << "?>"
94
+ end
95
+ end
96
+ alias_method :pi!, :processing_instruction!
97
+
98
+ end
99
+
100
+ # A class that encapsulats the XML generation
101
+ # functionality. Utilizes duck typing to redirect
102
+ # output to a target buffer.
103
+
104
+ class Glue::XmlBuilder
105
+ include XmlHelper
106
+
107
+ # The target receives the generated xml,
108
+ # should respond_to :<<
109
+
110
+ attr_accessor :target
111
+
112
+ def initialize(target = '')
113
+ @target = target
114
+ end
115
+
116
+ def << (str)
117
+ @target << str
118
+ end
119
+
120
+ def to_s
121
+ @target.to_s
122
+ end
123
+ end
124
+
125
+ end
@@ -0,0 +1,35 @@
1
+ require "RMagick"
2
+
3
+ module Raw::Mixin
4
+
5
+ # Magick transformation.
6
+ #--
7
+ # TODO: pass generalized RMagick command.
8
+ #++
9
+
10
+ module Thumbnails
11
+
12
+ # Default thumbnail width.
13
+
14
+ setting :width, :default => 128, :doc => 'Default thumbnail width'
15
+
16
+ # Default thumbnail height.
17
+
18
+ setting :height, :default => 128, :doc => 'Default thumbnail height'
19
+
20
+ def self.generate_thumbnail(src, tname, geostring)
21
+ ext = File.extname(src)
22
+ dst = "#{File.join(File.dirname(src), File.basename(src, ext))}_#{tname}#{ext}"
23
+
24
+ thumb = Magick::Image.read(File.join(Nitro::Server.public_root, src)).first
25
+ thumb.change_geometry!(geostring) do |cols, rows, thumb|
26
+ thumb.resize!(cols, rows)
27
+ end
28
+ thumb.write(File.join(Nitro::Server.public_root, dst))
29
+
30
+ return dst
31
+ end
32
+
33
+ end
34
+
35
+ end
@@ -0,0 +1,71 @@
1
+ require "raw/render/caching"
2
+ require "raw/util/encode_uri"
3
+
4
+ module Raw::Mixin
5
+
6
+ # This module adds cleanup functionality to managed
7
+ # classes. Override and implement sweep_affected.
8
+ # Typically used to cleanup output caching files from
9
+ # the filesystem. But you can also use it to clean up
10
+ # temp objects in the database or other temp files.
11
+ #--
12
+ # FIXME: find a better name.
13
+ #++
14
+
15
+ module Sweeper
16
+ extend Raw::Caching
17
+ extend Raw::EncodeURI
18
+
19
+ #--
20
+ # Inject the sweepers *after* the event to have a valid
21
+ # oid.
22
+ #++
23
+
24
+ before :og_insert do
25
+ sweep_affected(:insert) unless $sweeper_dissabled
26
+ end
27
+
28
+ before :og_update do
29
+ sweep_affected(:update) unless $sweeper_dissabled
30
+ end
31
+
32
+ before :og_delete do
33
+ sweep_affected(:delete) unless $sweeper_dissabled
34
+ end
35
+
36
+ private
37
+
38
+ # If needed pass the calling action symbol to allow
39
+ # for conditional expiration.
40
+ # Action takes values from { :insert, :delete, :update }
41
+ # or your own custom enumeration.
42
+ #
43
+ # Generally add lines like the following:
44
+ #
45
+ # expire_output("file_to_expire")
46
+ # expire_output(Controller, :action)
47
+ # expire_output(obj) # uses obj.to_href
48
+
49
+ def sweep_affected(action = :all)
50
+ end
51
+ alias_method :expire_affected, :sweep_affected
52
+
53
+ # Called from an action that modifies the model to expire
54
+ # affected (dependend) cached pages. Generally you don't
55
+ # override this method.
56
+
57
+ def expire_affected_output(*args)
58
+ Sweeper.send(:expire_output, *args)
59
+ end
60
+ alias_method :expire_output, :expire_affected_output
61
+
62
+ # Expire affected cached fragments.
63
+
64
+ def expire_affected_fragment(name, options = {})
65
+ # TODO
66
+ end
67
+ alias_method :expire_fragment, :expire_affected_fragment
68
+
69
+ end
70
+
71
+ end