ramaze 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (192) hide show
  1. data/Rakefile +26 -6
  2. data/bin/ramaze +8 -1
  3. data/doc/AUTHORS +13 -11
  4. data/doc/CHANGELOG +472 -13
  5. data/doc/LEGAL +22 -0
  6. data/doc/README +1 -4
  7. data/doc/TODO +7 -2
  8. data/doc/changes.txt +472 -13
  9. data/doc/changes.xml +472 -13
  10. data/doc/meta/announcement.txt +21 -23
  11. data/doc/readme_chunks/appendix.txt +0 -3
  12. data/doc/readme_chunks/features.txt +1 -1
  13. data/examples/auth/auth.rb +49 -0
  14. data/examples/auth/template/layout.haml +20 -0
  15. data/examples/auth/template/login.haml +16 -0
  16. data/examples/blog/spec/blog.rb +1 -0
  17. data/examples/caching.rb +5 -6
  18. data/examples/css.rb +37 -0
  19. data/examples/layout.rb +3 -17
  20. data/examples/simple_auth.rb +23 -0
  21. data/examples/sourceview/public/images/file.gif +0 -0
  22. data/examples/sourceview/public/images/folder.gif +0 -0
  23. data/examples/sourceview/public/images/tv-collapsable-last.gif +0 -0
  24. data/examples/sourceview/public/images/tv-collapsable.gif +0 -0
  25. data/examples/sourceview/public/images/tv-expandable-last.gif +0 -0
  26. data/examples/sourceview/public/images/tv-expandable.gif +0 -0
  27. data/examples/sourceview/public/images/tv-item-last.gif +0 -0
  28. data/examples/sourceview/public/images/tv-item.gif +0 -0
  29. data/examples/sourceview/public/jquery.js +11 -0
  30. data/examples/sourceview/public/jquery.treeview.css +47 -0
  31. data/examples/sourceview/public/jquery.treeview.js +223 -0
  32. data/examples/sourceview/public/sourceview.js +16 -0
  33. data/examples/sourceview/sourceview.rb +74 -0
  34. data/examples/sourceview/template/index.haml +43 -0
  35. data/examples/templates/template/external.nag +28 -0
  36. data/examples/templates/template/external.xsl +57 -0
  37. data/examples/templates/template_amrita2.rb +2 -4
  38. data/examples/templates/template_erubis.rb +1 -1
  39. data/examples/templates/template_haml.rb +1 -1
  40. data/examples/templates/template_liquid.rb +2 -4
  41. data/examples/templates/template_markaby.rb +2 -4
  42. data/examples/templates/template_nagoro.rb +53 -0
  43. data/examples/templates/template_remarkably.rb +2 -4
  44. data/examples/templates/template_xslt.rb +52 -0
  45. data/examples/whywiki/spec/whywiki.rb +63 -0
  46. data/examples/whywiki/start.rb +11 -13
  47. data/examples/whywiki/template/edit.xhtml +3 -3
  48. data/examples/whywiki/template/show.xhtml +5 -8
  49. data/examples/wikore/spec/wikore.rb +115 -0
  50. data/examples/wikore/src/controller.rb +81 -0
  51. data/examples/wikore/src/model.rb +51 -0
  52. data/examples/wikore/start.rb +6 -0
  53. data/examples/wikore/template/index.xhtml +8 -0
  54. data/examples/wiktacular/spec/wiktacular.rb +1 -0
  55. data/examples/wiktacular/src/controller.rb +1 -1
  56. data/lib/ramaze.rb +6 -3
  57. data/lib/ramaze/action.rb +2 -13
  58. data/lib/ramaze/action/render.rb +36 -18
  59. data/lib/ramaze/adapter.rb +1 -1
  60. data/lib/ramaze/adapter/cgi.rb +0 -3
  61. data/lib/ramaze/adapter/evented_mongrel.rb +7 -0
  62. data/lib/ramaze/adapter/mongrel.rb +4 -13
  63. data/lib/ramaze/adapter/swiftiplied_mongrel.rb +7 -0
  64. data/lib/ramaze/cache.rb +12 -7
  65. data/lib/ramaze/contrib.rb +22 -0
  66. data/lib/ramaze/contrib/auto_params.rb +128 -0
  67. data/lib/ramaze/contrib/auto_params/get_args.rb +56 -0
  68. data/lib/ramaze/contrib/gzip_filter.rb +57 -0
  69. data/lib/ramaze/contrib/route.rb +40 -0
  70. data/lib/ramaze/contrib/sequel/fill.rb +12 -0
  71. data/lib/ramaze/controller.rb +17 -6
  72. data/lib/ramaze/controller/resolve.rb +51 -14
  73. data/lib/ramaze/dispatcher.rb +15 -13
  74. data/lib/ramaze/dispatcher/action.rb +4 -3
  75. data/lib/ramaze/dispatcher/directory.rb +3 -3
  76. data/lib/ramaze/dispatcher/error.rb +1 -1
  77. data/lib/ramaze/dispatcher/file.rb +17 -6
  78. data/lib/ramaze/error.rb +3 -0
  79. data/lib/ramaze/gestalt.rb +28 -8
  80. data/lib/ramaze/global.rb +26 -6
  81. data/lib/ramaze/global/globalstruct.rb +31 -6
  82. data/lib/ramaze/helper.rb +2 -1
  83. data/lib/ramaze/helper/aspect.rb +2 -2
  84. data/lib/ramaze/helper/auth.rb +6 -9
  85. data/lib/ramaze/helper/cache.rb +89 -9
  86. data/lib/ramaze/helper/cgi.rb +2 -2
  87. data/lib/ramaze/helper/formatting.rb +44 -0
  88. data/lib/ramaze/helper/link.rb +7 -5
  89. data/lib/ramaze/helper/partial.rb +6 -4
  90. data/lib/ramaze/helper/redirect.rb +24 -9
  91. data/lib/ramaze/helper/stack.rb +6 -1
  92. data/lib/ramaze/inform/growl.rb +1 -1
  93. data/lib/ramaze/inform/informer.rb +2 -1
  94. data/lib/ramaze/inform/informing.rb +6 -0
  95. data/lib/ramaze/inform/syslog.rb +1 -0
  96. data/lib/ramaze/snippets/array/put_within.rb +24 -0
  97. data/lib/ramaze/snippets/dictionary.rb +499 -0
  98. data/lib/ramaze/snippets/numeric/filesize_format.rb +19 -0
  99. data/lib/ramaze/snippets/ordered_set.rb +31 -0
  100. data/lib/ramaze/snippets/string/DIVIDE.rb +1 -1
  101. data/lib/ramaze/snippets/string/snake_case.rb +1 -1
  102. data/lib/ramaze/snippets/struct/values_at.rb +5 -1
  103. data/lib/ramaze/snippets/thread/into.rb +25 -0
  104. data/lib/ramaze/sourcereload.rb +39 -19
  105. data/lib/ramaze/spec/helper.rb +4 -1
  106. data/lib/ramaze/spec/helper/{context.rb → browser.rb} +3 -0
  107. data/lib/ramaze/spec/helper/layout.rb +3 -0
  108. data/lib/ramaze/spec/helper/minimal.rb +3 -0
  109. data/lib/ramaze/spec/helper/mock_http.rb +8 -5
  110. data/lib/ramaze/spec/helper/requester.rb +4 -1
  111. data/lib/ramaze/spec/helper/wrap.rb +15 -7
  112. data/lib/ramaze/template.rb +5 -1
  113. data/lib/ramaze/template/ezamar/engine.rb +2 -3
  114. data/lib/ramaze/template/ezamar/morpher.rb +26 -45
  115. data/lib/ramaze/template/nagoro.rb +53 -0
  116. data/lib/ramaze/template/none.rb +14 -0
  117. data/lib/ramaze/template/xslt.rb +96 -0
  118. data/lib/ramaze/tool.rb +0 -1
  119. data/lib/ramaze/tool/localize.rb +7 -2
  120. data/lib/ramaze/trinity/request.rb +1 -0
  121. data/lib/ramaze/trinity/session.rb +3 -3
  122. data/lib/ramaze/version.rb +2 -2
  123. data/rake_tasks/conf.rake +1 -2
  124. data/rake_tasks/{maintaince.rake → maintenance.rake} +25 -17
  125. data/spec/contrib/auto_params.rb +97 -0
  126. data/spec/contrib/route.rb +60 -0
  127. data/spec/contrib/sequel/fill.rb +46 -0
  128. data/spec/examples/caching.rb +1 -2
  129. data/spec/examples/css.rb +12 -0
  130. data/spec/examples/element.rb +0 -1
  131. data/spec/examples/hello.rb +0 -1
  132. data/spec/examples/simple.rb +0 -1
  133. data/spec/helper.rb +3 -2
  134. data/spec/ramaze/action/cache.rb +24 -7
  135. data/spec/ramaze/action/layout.rb +19 -11
  136. data/spec/ramaze/action/template/sub/sub_wrapper.xhtml +1 -0
  137. data/spec/ramaze/controller.rb +11 -0
  138. data/spec/ramaze/controller/template_resolving.rb +28 -27
  139. data/spec/ramaze/dispatcher.rb +32 -0
  140. data/spec/ramaze/dispatcher/directory.rb +2 -1
  141. data/spec/ramaze/element.rb +1 -1
  142. data/spec/ramaze/gestalt.rb +28 -0
  143. data/spec/ramaze/helper/aspect.rb +14 -3
  144. data/spec/ramaze/helper/cache.rb +78 -13
  145. data/spec/ramaze/helper/formatting.rb +20 -0
  146. data/spec/ramaze/helper/link.rb +2 -0
  147. data/spec/ramaze/helper/partial.rb +12 -1
  148. data/spec/ramaze/helper/redirect.rb +44 -8
  149. data/spec/ramaze/helper/stack.rb +3 -3
  150. data/spec/ramaze/helper/template/loop.xhtml +3 -0
  151. data/spec/ramaze/helper/template/num.xhtml +1 -0
  152. data/spec/ramaze/helper/template/recursive.xhtml +8 -0
  153. data/spec/ramaze/morpher.rb +25 -6
  154. data/spec/ramaze/params.rb +6 -2
  155. data/spec/ramaze/request.rb +5 -2
  156. data/spec/ramaze/session.rb +19 -0
  157. data/spec/ramaze/template.rb +2 -2
  158. data/spec/ramaze/template/amrita2.rb +2 -2
  159. data/spec/ramaze/template/erubis.rb +2 -2
  160. data/spec/ramaze/template/ezamar.rb +6 -3
  161. data/spec/ramaze/template/haml.rb +3 -3
  162. data/spec/ramaze/template/liquid.rb +1 -1
  163. data/spec/ramaze/template/markaby.rb +1 -1
  164. data/spec/ramaze/template/nagoro.rb +65 -0
  165. data/spec/ramaze/template/nagoro/another/long/action.nag +1 -0
  166. data/spec/ramaze/template/nagoro/combined.nag +1 -0
  167. data/spec/ramaze/template/nagoro/file_only.nag +1 -0
  168. data/spec/ramaze/template/nagoro/index.nag +1 -0
  169. data/spec/ramaze/template/nagoro/nested.nag +1 -0
  170. data/spec/ramaze/template/nagoro/some__long__action.nag +1 -0
  171. data/spec/ramaze/template/nagoro/sum.nag +1 -0
  172. data/spec/ramaze/template/remarkably.rb +1 -1
  173. data/spec/ramaze/template/sass.rb +1 -1
  174. data/spec/ramaze/template/xslt.rb +93 -0
  175. data/spec/ramaze/template/xslt/concat_words.xsl +16 -0
  176. data/spec/ramaze/template/xslt/index.xsl +14 -0
  177. data/spec/ramaze/template/xslt/products.xsl +32 -0
  178. data/spec/ramaze/template/xslt/ruby_version.xsl +14 -0
  179. data/spec/snippets/array/put_within.rb +32 -0
  180. data/spec/snippets/numeric/filesize_format.rb +12 -0
  181. data/spec/snippets/ordered_set.rb +56 -0
  182. data/spec/snippets/ramaze/caller_lines.rb +6 -3
  183. data/spec/snippets/string/snake_case.rb +3 -0
  184. metadata +118 -22
  185. data/doc/README.html +0 -737
  186. data/examples/fcgi.rb +0 -13
  187. data/lib/ramaze/snippets/numeric/human_readable_filesize_format.rb +0 -33
  188. data/lib/ramaze/tool/tidy.rb +0 -104
  189. data/spec/ramaze/controller/template/edit.xhtml +0 -1
  190. data/spec/ramaze/controller/template/edit/content.xhtml +0 -1
  191. data/spec/ramaze/tidy.rb +0 -12
  192. data/spec/snippets/numeric/human_readable_filesize_format.rb +0 -11
@@ -6,29 +6,31 @@
6
6
  require 'ramaze'
7
7
  require 'bluecloth'
8
8
 
9
- include Ramaze
9
+ Db = Ramaze::YAMLStoreCache.new('wiki.yaml') unless defined?(Db)
10
10
 
11
- Db = YAMLStoreCache.new('wiki.yaml')
11
+ class WikiController < Ramaze::Controller
12
+ map :/
13
+ engine :Nagoro
12
14
 
13
- class WikiController < Controller
14
15
  def index
15
- redirect(R(:show, 'Home'))
16
+ redirect R(:show, 'Home')
16
17
  end
17
18
 
18
19
  def show page = 'Home'
19
- @page = CGI.unescape(page)
20
+ @page = url_decode(page)
20
21
  @text = Db[page].to_s
22
+ @edit_link = "/edit/#{page}"
21
23
 
22
24
  @text.gsub!(/\[\[(.*?)\]\]/) do |m|
23
25
  exists = Db[$1] ? 'exists' : 'nonexists'
24
- link( R(self, :show, CGI.escape($1)), :title => $1, :class => exists)
26
+ A($1, :href => Rs(:show, url_encode($1)), :class => exists)
25
27
  end
26
28
 
27
29
  @text = BlueCloth.new(@text).to_html
28
30
  end
29
31
 
30
32
  def edit page = 'Home'
31
- @page = CGI.unescape(page)
33
+ @page = url_decode(page)
32
34
  @text = Db[page]
33
35
  end
34
36
 
@@ -40,12 +42,8 @@ class WikiController < Controller
40
42
 
41
43
  Db[page] = text
42
44
 
43
- redirect R(self, :show, CGI.escape(page))
45
+ redirect Rs(:show, url_encode(page))
44
46
  end
45
47
  end
46
48
 
47
- Global.adapter = :mongrel
48
- #Global.tidy = true
49
- Global.mapping = {'/' => WikiController}
50
-
51
- Ramaze.start
49
+ Ramaze.start :adapter => :mongrel
@@ -2,11 +2,11 @@
2
2
  <head>
3
3
  <title>MicroWiki Edit #{@page}</title>
4
4
  </head>
5
- #{ A("&lt; Home", :href => R(self)) }
6
5
  <body>
7
6
  <h1>Edit #{@page}</h1>
8
- <form method="POST" action="#{R(self, :save)}">
9
- <input type="hidden" name="page" value="#{CGI.escape(@page)}" />
7
+ #{ A("&lt; Home", :href => Rs()) }
8
+ <form method="POST" action="#{Rs(:save)}">
9
+ <input type="hidden" name="page" value="#{url_encode(@page)}" />
10
10
  <textarea name="text" style="width: 90%; height: 20em;">#{@text}</textarea>
11
11
  <input type="submit" />
12
12
  </form>
@@ -6,16 +6,13 @@
6
6
  a.nonexists{ color: #f00; }
7
7
  </style>
8
8
  </head>
9
- #{ A("&lt; Home", :href => R(self)) unless @page == "Home" }
10
9
  <body>
10
+ <a href="/show/Home" unless="@page == 'Home'">&lt; Home</a>
11
11
  <h1>#{@page}</h1>
12
- <?r if @text.empty? ?>
13
- #{ A("Create #{@page}?",:href => R(self, :edit, CGI.escape(@page))) }
14
- <?r else ?>
15
- <div>
16
- #{ A("Edit #{@page}?", :href => R(self, :edit, CGI.escape(@page))) }
17
- #{@text}
12
+ <a href="#@edit_link" if="@text.empty?">Create #@page</a>
13
+ <div unless="@text.empty?">
14
+ <a href="#@edit_link">Edit #@page</a>
15
+ #@text
18
16
  </div>
19
- <?r end ?>
20
17
  </body>
21
18
  </html>
@@ -0,0 +1,115 @@
1
+ require 'ramaze'
2
+ require 'ramaze/spec/helper'
3
+
4
+ # if these libraries are missing there is no sense in running the tests,
5
+ # cause they won't work at all.
6
+ testcase_requires 'hpricot'
7
+
8
+ $:.unshift __DIR__/'../'
9
+ require 'start'
10
+
11
+ describe 'Wikore' do
12
+ def should_redirect to = '/'
13
+ response = yield
14
+ response.status.should == 303
15
+ response.body.should =~ /<a href="#{to}">/
16
+ end
17
+
18
+ def page_should_exist(name, *matches)
19
+ page = get("/#{name}")
20
+ page.status.should == 200
21
+ matches.each do |match|
22
+ page.body.should =~ match
23
+ end
24
+ end
25
+
26
+ before :all do
27
+ ramaze :template_root => (__DIR__/'../template')
28
+ end
29
+
30
+ it 'should have no Main page' do
31
+ page = get('/Main')
32
+ page.status.should == 200
33
+ page.body.should =~ /No Page known as 'Main'/
34
+ end
35
+
36
+ it 'should create a Main page' do
37
+ should_redirect '/Main' do
38
+ post('/page/create', 'title' => 'Main', 'text' => 'Newly created Main page')
39
+ end
40
+
41
+ matches = [
42
+ /Newly created Main page/,
43
+ /Version: 1/
44
+ ]
45
+ page_should_exist('Main', *matches)
46
+ end
47
+
48
+ it 'should update Main page' do
49
+ should_redirect '/Main' do
50
+ post('/page/save', 'title' => 'Main', 'text' => 'Newly updated Main page')
51
+ end
52
+
53
+ matches = [
54
+ /Newly updated Main page/,
55
+ /Version: 2/
56
+ ]
57
+ page_should_exist('Main', *matches)
58
+ end
59
+
60
+ it 'should maintain a backup' do
61
+ matches = [
62
+ /Newly created Main page/,
63
+ /Version: 1/
64
+ ]
65
+ page_should_exist('Main/1', *matches)
66
+ end
67
+
68
+ it 'should revert' do
69
+ get('/page/revert/Main')
70
+
71
+ matches = [
72
+ /Newly created Main page/,
73
+ /Version: 1/
74
+ ]
75
+ page_should_exist('Main', *matches)
76
+ end
77
+
78
+
79
+ it 'should incrememt version of Main page' do
80
+ (2..4).each do |n|
81
+ post('/page/save', 'title' => 'Main', 'text' => 'updated Main page')
82
+
83
+ matches = [ /updated Main page/, /Version: #{n}/ ]
84
+ page_should_exist('Main', *matches)
85
+ end
86
+ end
87
+
88
+ it 'should rename Main page to Other and back' do
89
+ should_redirect '/Other' do
90
+ get('/page/rename/Main/Other')
91
+ end
92
+ should_redirect '/Main' do
93
+ get('/page/rename/Other/Main')
94
+ end
95
+ end
96
+
97
+ it 'should delete Main page' do
98
+ get('/page/delete/Main')
99
+
100
+ page_should_exist('Main', /No Page known as 'Main'/)
101
+ end
102
+
103
+ it 'should fail if create/save is not POSTed to' do
104
+ should_redirect '/' do
105
+ get('/page/save', 'title' => 'Main', 'text' => 'Newly updated Main page')
106
+ end
107
+ should_redirect '/' do
108
+ get('/page/create', 'title' => 'Main', 'text' => 'Newly updated Main page')
109
+ end
110
+ end
111
+
112
+ after :all do
113
+ FileUtils.rm('wikore.db')
114
+ end
115
+ end
@@ -0,0 +1,81 @@
1
+ class Ramaze::Controller
2
+ Page = Model::Page
3
+ OldPage = Model::OldPage
4
+ end
5
+
6
+ class MainController < Ramaze::Controller
7
+ def index(title = 'Main', version = nil)
8
+ query = {:title => title}
9
+ query[:version] = version.to_i if version
10
+ model = version ? OldPage : Page
11
+
12
+ if page = model[query]
13
+ @text, @version = page.text, page.version
14
+ else
15
+ @text = "No Page known as '#{title}'"
16
+ @version = false
17
+ end
18
+ end
19
+ end
20
+
21
+ class PageController < Ramaze::Controller
22
+ map '/page'
23
+
24
+ helper :aspect
25
+
26
+ def create
27
+ change "Created Page '%s'" do |title, text|
28
+ Page.create(:title => title, :text => text, :version => 1)
29
+ redirect R(MainController, title)
30
+ end
31
+ end
32
+
33
+ def save
34
+ change "Updated Page '%s'" do |title, text|
35
+ page = Page[:title => title]
36
+ page.backup
37
+ page.text = text
38
+ page.version += 1
39
+ page.save
40
+ redirect R(MainController, title)
41
+ end
42
+ end
43
+
44
+ def delete(title)
45
+ page = Page[:title => title]
46
+ page.backup
47
+ page.delete
48
+ end
49
+
50
+ def rename(title, to)
51
+ change("Renamed #{title} to '%s'", to) do |title, text|
52
+ page = Page[:title => title]
53
+ page.backup
54
+ page.title = to
55
+ page.version += 1
56
+ page.save
57
+ end
58
+ end
59
+
60
+ def revert(title)
61
+ page = Page[:title => title]
62
+ p page
63
+ page.revert
64
+ redirect R(MainController, title)
65
+ end
66
+
67
+ before :create, :save do
68
+ redirect_referer unless request.post?
69
+ end
70
+
71
+ private
72
+
73
+ def change(message, redirect_to = '/')
74
+ if title = request['title'] and text = request['text']
75
+ yield(title, text)
76
+ message % title
77
+ end
78
+
79
+ redirect(R(MainController, redirect_to))
80
+ end
81
+ end
@@ -0,0 +1,51 @@
1
+ require 'sequel'
2
+ require 'sequel/sqlite'
3
+
4
+ case $wikore_db
5
+ when :memory
6
+ DB = Sequel('sqlite:/')
7
+ else
8
+ DB = Sequel('sqlite:///wikore.db')
9
+ end
10
+
11
+ module Model
12
+ PAGE_SCHEMA = lambda{
13
+ }
14
+
15
+ class Page < Sequel::Model(:page)
16
+ set_schema do
17
+ primary_key :id
18
+ text :title, :unique => true, :null => false
19
+ boolean :active, :default => true
20
+ text :text
21
+ integer :version
22
+ end
23
+
24
+ def backup
25
+ hash = @values.dup
26
+ hash.delete :id
27
+ OldPage.create(hash)
28
+ end
29
+
30
+ def revert
31
+ backup = OldPage[:title => title].values.dup
32
+ backup.delete :id
33
+ delete
34
+ self.class.create(backup)
35
+ end
36
+ end
37
+
38
+ class OldPage < Sequel::Model(:old_page)
39
+ set_schema do
40
+ primary_key :id
41
+ text :title, :unique => false, :null => false
42
+ boolean :active, :default => true
43
+ text :text
44
+ integer :version
45
+ end
46
+ end
47
+
48
+ [Page, OldPage].each do |klass|
49
+ klass.create_table unless klass.table_exists?
50
+ end
51
+ end
@@ -0,0 +1,6 @@
1
+ require 'ramaze'
2
+
3
+ $wikore = {}
4
+
5
+ require 'src/model'
6
+ require 'src/controller'
@@ -0,0 +1,8 @@
1
+ <div id="text">
2
+ #@text
3
+ </div>
4
+ <?r if @version ?>
5
+ <div id="version">
6
+ Version: #@version
7
+ </div>
8
+ <?r end ?>
@@ -1,3 +1,4 @@
1
+ require 'ramaze'
1
2
  require 'ramaze/spec/helper'
2
3
 
3
4
  # if these libraries are missing there is no sense in running the tests,
@@ -51,5 +51,5 @@ class MainController < Ramaze::Controller
51
51
  }.join("\n")
52
52
  end
53
53
 
54
- layout :html_layout
54
+ layout '/html_layout'
55
55
  end
@@ -1,6 +1,8 @@
1
1
  # Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
2
2
  # All files in this distribution are subject to the terms of the Ruby license.
3
3
 
4
+ require 'fileutils'
5
+
4
6
  begin
5
7
  require 'rubygems'
6
8
  rescue LoadError
@@ -10,6 +12,7 @@ end
10
12
  module Ramaze
11
13
  BASEDIR = File.dirname(File.expand_path(__FILE__))
12
14
  SEEED = $0.dup
15
+ APPDIR = File.dirname(File.expand_path($0))
13
16
  $:.unshift BASEDIR
14
17
  end
15
18
 
@@ -46,12 +49,12 @@ module Ramaze
46
49
  # each class in trait[:essentials] by calling ::startup on them.
47
50
 
48
51
  def startup options = {}
49
- Inform.info("Starting up Ramaze (Version #{VERSION})")
50
-
51
- starter = caller[0].split(':').first
52
+ starter = options.fetch(:runner, caller[0].split(':').first)
52
53
 
53
54
  if $0 == starter or options.delete(:force)
55
+ Inform.info("Starting up Ramaze (Version #{VERSION})")
54
56
  SEEED.replace(starter)
57
+ APPDIR.replace(File.dirname(File.expand_path(starter)))
55
58
 
56
59
  trait[:essentials].each do |obj|
57
60
  obj.startup(options)
@@ -105,20 +105,9 @@ module Ramaze
105
105
  File.basename((self[:method] || self[:template]).to_s).split('.').first
106
106
  end
107
107
 
108
- # TODO: find good names for this method.
109
-
110
- def basepath
111
- @basepath ||= "#{controller.mapping}/#{name}".gsub(/^\/+/, '/')
112
- end
113
-
114
- # TODO: find good names for this method.
115
- def fullpath
116
- "#{path}/#{params.join('/')}".gsub(/^\/+/, '/')
117
- end
118
-
119
- # TODO: find good names for this method.
108
+ # combined path to current action, from path and params
120
109
  def extended_path
121
- @extended_path ||= File.join(path, *params)
110
+ @extended_path ||= Array[path, *params].join('/')
122
111
  end
123
112
 
124
113
  # Hook for AspectHelper
@@ -12,7 +12,7 @@ module Ramaze
12
12
  # #> 'bar'
13
13
 
14
14
  def render
15
- Inform.debug("The Action: #{self}")
15
+ Inform.dev("The Action: #{self}")
16
16
  Thread.current[:action] = self
17
17
 
18
18
  if should_cache?
@@ -22,6 +22,8 @@ module Ramaze
22
22
  end
23
23
  end
24
24
 
25
+ private
26
+
25
27
  # Return the cached output of the action if it exists, otherwise do a
26
28
  # normal Action#uncached_render and store the output in the Cache.actions.
27
29
  # Action#cached_render is only called if Action#should_cache? returns
@@ -38,27 +40,36 @@ module Ramaze
38
40
  def cached_render_file
39
41
  rendered = uncached_render
40
42
 
41
- global_epath = Global.public_root/extended_path
43
+ global_epath = Global.public_root/self.controller.mapping/extended_path
42
44
  FileUtils.mkdir_p(File.dirname(global_epath))
43
- File.open( global_epath, 'w+'){|fp| fp.print(rendered) }
44
-
45
- meta_epath = Global.file_cache_meta_dir/extended_path
46
- FileUtils.mkdir_p(File.dirname(meta_epath))
47
- File.open( meta_epath, 'w+'){|fp| fp.print(Time.now.to_i) }
45
+ File.open(global_epath, 'w+') {|fp| fp.print(rendered) }
48
46
 
49
47
  rendered
50
48
  end
51
49
 
52
50
  def cached_render_memory
53
51
  action_cache = Cache.actions
52
+ full_path = self.controller.mapping/extended_path
53
+
54
+ # backwards compat with trait :actions_cached => []
55
+ cache_opts = actions_cached.is_a?(Hash) ? actions_cached[path.to_sym] : {}
56
+
57
+ if cache_opts[:key]
58
+ action_cache[full_path] ||= {}
59
+ cache = action_cache[full_path][ cache_opts[:key].call ] ||= {}
60
+ else
61
+ cache = action_cache[full_path] ||= {}
62
+ end
54
63
 
55
- if out = action_cache[relaxed_hash]
64
+ if cache.size > 0 and (cache_opts[:ttl].nil? or cache[:time] + cache_opts[:ttl] > Time.now)
56
65
  Inform.debug("Using Cached version")
57
- return out
66
+ Response.current['Content-Type'] = cache[:type]
67
+ else
68
+ Inform.debug("Compiling Action")
69
+ cache.replace({ :time => Time.now, :content => uncached_render, :type => Response.current['Content-Type'] })
58
70
  end
59
71
 
60
- Inform.debug("Compiling Action")
61
- action_cache[relaxed_hash] = uncached_render
72
+ cache[:content]
62
73
  end
63
74
 
64
75
  # The 'normal' rendering process. Passes the Action instance to
@@ -66,16 +77,19 @@ module Ramaze
66
77
  # Layout will be found and rendered in this step after self was rendered.
67
78
 
68
79
  def uncached_render
69
- bp = before_process
70
- content = engine.transform(self)
71
- ap = after_process
80
+ content = [before_process,
81
+ engine.transform(self),
82
+ after_process].join
72
83
 
73
- if tlayout = layout
84
+ if path and tlayout = layout
74
85
  instance.instance_variable_set("@content", content)
75
86
  content = tlayout.render
87
+
88
+ # restore Action.current after render above
76
89
  Thread.current[:action] = self
77
90
  end
78
- [bp, content, ap].join
91
+
92
+ content
79
93
  end
80
94
 
81
95
  # Determine whether or not we have a layout to process and sets it up
@@ -99,20 +113,24 @@ module Ramaze
99
113
  layout_action.binding = binding
100
114
  layout_action.controller = controller
101
115
  layout_action.instance = instance
116
+ layout_action.path = nil
102
117
  layout_action
103
118
  end
104
119
  end
105
120
 
121
+ def actions_cached
122
+ controller.trait[:actions_cached]
123
+ end
124
+
106
125
  # return true if the action is flagged for caching. Called by
107
126
  # Action#render.
108
127
 
109
128
  def should_cache?
110
129
  ctrait = controller.trait
111
- actions_cached = ctrait[:actions_cached]
112
130
 
113
131
  [ Global.cache_all,
114
132
  ctrait[:cache_all],
115
- actions_cached.map{|k| k.to_s}.include?(method),
133
+ actions_cached.map{|k,v| k.to_s}.include?(method),
116
134
  ].any?
117
135
  end
118
136
  end