ramaze 0.1.4 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +26 -6
- data/bin/ramaze +8 -1
- data/doc/AUTHORS +13 -11
- data/doc/CHANGELOG +472 -13
- data/doc/LEGAL +22 -0
- data/doc/README +1 -4
- data/doc/TODO +7 -2
- data/doc/changes.txt +472 -13
- data/doc/changes.xml +472 -13
- data/doc/meta/announcement.txt +21 -23
- data/doc/readme_chunks/appendix.txt +0 -3
- data/doc/readme_chunks/features.txt +1 -1
- data/examples/auth/auth.rb +49 -0
- data/examples/auth/template/layout.haml +20 -0
- data/examples/auth/template/login.haml +16 -0
- data/examples/blog/spec/blog.rb +1 -0
- data/examples/caching.rb +5 -6
- data/examples/css.rb +37 -0
- data/examples/layout.rb +3 -17
- data/examples/simple_auth.rb +23 -0
- data/examples/sourceview/public/images/file.gif +0 -0
- data/examples/sourceview/public/images/folder.gif +0 -0
- data/examples/sourceview/public/images/tv-collapsable-last.gif +0 -0
- data/examples/sourceview/public/images/tv-collapsable.gif +0 -0
- data/examples/sourceview/public/images/tv-expandable-last.gif +0 -0
- data/examples/sourceview/public/images/tv-expandable.gif +0 -0
- data/examples/sourceview/public/images/tv-item-last.gif +0 -0
- data/examples/sourceview/public/images/tv-item.gif +0 -0
- data/examples/sourceview/public/jquery.js +11 -0
- data/examples/sourceview/public/jquery.treeview.css +47 -0
- data/examples/sourceview/public/jquery.treeview.js +223 -0
- data/examples/sourceview/public/sourceview.js +16 -0
- data/examples/sourceview/sourceview.rb +74 -0
- data/examples/sourceview/template/index.haml +43 -0
- data/examples/templates/template/external.nag +28 -0
- data/examples/templates/template/external.xsl +57 -0
- data/examples/templates/template_amrita2.rb +2 -4
- data/examples/templates/template_erubis.rb +1 -1
- data/examples/templates/template_haml.rb +1 -1
- data/examples/templates/template_liquid.rb +2 -4
- data/examples/templates/template_markaby.rb +2 -4
- data/examples/templates/template_nagoro.rb +53 -0
- data/examples/templates/template_remarkably.rb +2 -4
- data/examples/templates/template_xslt.rb +52 -0
- data/examples/whywiki/spec/whywiki.rb +63 -0
- data/examples/whywiki/start.rb +11 -13
- data/examples/whywiki/template/edit.xhtml +3 -3
- data/examples/whywiki/template/show.xhtml +5 -8
- data/examples/wikore/spec/wikore.rb +115 -0
- data/examples/wikore/src/controller.rb +81 -0
- data/examples/wikore/src/model.rb +51 -0
- data/examples/wikore/start.rb +6 -0
- data/examples/wikore/template/index.xhtml +8 -0
- data/examples/wiktacular/spec/wiktacular.rb +1 -0
- data/examples/wiktacular/src/controller.rb +1 -1
- data/lib/ramaze.rb +6 -3
- data/lib/ramaze/action.rb +2 -13
- data/lib/ramaze/action/render.rb +36 -18
- data/lib/ramaze/adapter.rb +1 -1
- data/lib/ramaze/adapter/cgi.rb +0 -3
- data/lib/ramaze/adapter/evented_mongrel.rb +7 -0
- data/lib/ramaze/adapter/mongrel.rb +4 -13
- data/lib/ramaze/adapter/swiftiplied_mongrel.rb +7 -0
- data/lib/ramaze/cache.rb +12 -7
- data/lib/ramaze/contrib.rb +22 -0
- data/lib/ramaze/contrib/auto_params.rb +128 -0
- data/lib/ramaze/contrib/auto_params/get_args.rb +56 -0
- data/lib/ramaze/contrib/gzip_filter.rb +57 -0
- data/lib/ramaze/contrib/route.rb +40 -0
- data/lib/ramaze/contrib/sequel/fill.rb +12 -0
- data/lib/ramaze/controller.rb +17 -6
- data/lib/ramaze/controller/resolve.rb +51 -14
- data/lib/ramaze/dispatcher.rb +15 -13
- data/lib/ramaze/dispatcher/action.rb +4 -3
- data/lib/ramaze/dispatcher/directory.rb +3 -3
- data/lib/ramaze/dispatcher/error.rb +1 -1
- data/lib/ramaze/dispatcher/file.rb +17 -6
- data/lib/ramaze/error.rb +3 -0
- data/lib/ramaze/gestalt.rb +28 -8
- data/lib/ramaze/global.rb +26 -6
- data/lib/ramaze/global/globalstruct.rb +31 -6
- data/lib/ramaze/helper.rb +2 -1
- data/lib/ramaze/helper/aspect.rb +2 -2
- data/lib/ramaze/helper/auth.rb +6 -9
- data/lib/ramaze/helper/cache.rb +89 -9
- data/lib/ramaze/helper/cgi.rb +2 -2
- data/lib/ramaze/helper/formatting.rb +44 -0
- data/lib/ramaze/helper/link.rb +7 -5
- data/lib/ramaze/helper/partial.rb +6 -4
- data/lib/ramaze/helper/redirect.rb +24 -9
- data/lib/ramaze/helper/stack.rb +6 -1
- data/lib/ramaze/inform/growl.rb +1 -1
- data/lib/ramaze/inform/informer.rb +2 -1
- data/lib/ramaze/inform/informing.rb +6 -0
- data/lib/ramaze/inform/syslog.rb +1 -0
- data/lib/ramaze/snippets/array/put_within.rb +24 -0
- data/lib/ramaze/snippets/dictionary.rb +499 -0
- data/lib/ramaze/snippets/numeric/filesize_format.rb +19 -0
- data/lib/ramaze/snippets/ordered_set.rb +31 -0
- data/lib/ramaze/snippets/string/DIVIDE.rb +1 -1
- data/lib/ramaze/snippets/string/snake_case.rb +1 -1
- data/lib/ramaze/snippets/struct/values_at.rb +5 -1
- data/lib/ramaze/snippets/thread/into.rb +25 -0
- data/lib/ramaze/sourcereload.rb +39 -19
- data/lib/ramaze/spec/helper.rb +4 -1
- data/lib/ramaze/spec/helper/{context.rb → browser.rb} +3 -0
- data/lib/ramaze/spec/helper/layout.rb +3 -0
- data/lib/ramaze/spec/helper/minimal.rb +3 -0
- data/lib/ramaze/spec/helper/mock_http.rb +8 -5
- data/lib/ramaze/spec/helper/requester.rb +4 -1
- data/lib/ramaze/spec/helper/wrap.rb +15 -7
- data/lib/ramaze/template.rb +5 -1
- data/lib/ramaze/template/ezamar/engine.rb +2 -3
- data/lib/ramaze/template/ezamar/morpher.rb +26 -45
- data/lib/ramaze/template/nagoro.rb +53 -0
- data/lib/ramaze/template/none.rb +14 -0
- data/lib/ramaze/template/xslt.rb +96 -0
- data/lib/ramaze/tool.rb +0 -1
- data/lib/ramaze/tool/localize.rb +7 -2
- data/lib/ramaze/trinity/request.rb +1 -0
- data/lib/ramaze/trinity/session.rb +3 -3
- data/lib/ramaze/version.rb +2 -2
- data/rake_tasks/conf.rake +1 -2
- data/rake_tasks/{maintaince.rake → maintenance.rake} +25 -17
- data/spec/contrib/auto_params.rb +97 -0
- data/spec/contrib/route.rb +60 -0
- data/spec/contrib/sequel/fill.rb +46 -0
- data/spec/examples/caching.rb +1 -2
- data/spec/examples/css.rb +12 -0
- data/spec/examples/element.rb +0 -1
- data/spec/examples/hello.rb +0 -1
- data/spec/examples/simple.rb +0 -1
- data/spec/helper.rb +3 -2
- data/spec/ramaze/action/cache.rb +24 -7
- data/spec/ramaze/action/layout.rb +19 -11
- data/spec/ramaze/action/template/sub/sub_wrapper.xhtml +1 -0
- data/spec/ramaze/controller.rb +11 -0
- data/spec/ramaze/controller/template_resolving.rb +28 -27
- data/spec/ramaze/dispatcher.rb +32 -0
- data/spec/ramaze/dispatcher/directory.rb +2 -1
- data/spec/ramaze/element.rb +1 -1
- data/spec/ramaze/gestalt.rb +28 -0
- data/spec/ramaze/helper/aspect.rb +14 -3
- data/spec/ramaze/helper/cache.rb +78 -13
- data/spec/ramaze/helper/formatting.rb +20 -0
- data/spec/ramaze/helper/link.rb +2 -0
- data/spec/ramaze/helper/partial.rb +12 -1
- data/spec/ramaze/helper/redirect.rb +44 -8
- data/spec/ramaze/helper/stack.rb +3 -3
- data/spec/ramaze/helper/template/loop.xhtml +3 -0
- data/spec/ramaze/helper/template/num.xhtml +1 -0
- data/spec/ramaze/helper/template/recursive.xhtml +8 -0
- data/spec/ramaze/morpher.rb +25 -6
- data/spec/ramaze/params.rb +6 -2
- data/spec/ramaze/request.rb +5 -2
- data/spec/ramaze/session.rb +19 -0
- data/spec/ramaze/template.rb +2 -2
- data/spec/ramaze/template/amrita2.rb +2 -2
- data/spec/ramaze/template/erubis.rb +2 -2
- data/spec/ramaze/template/ezamar.rb +6 -3
- data/spec/ramaze/template/haml.rb +3 -3
- data/spec/ramaze/template/liquid.rb +1 -1
- data/spec/ramaze/template/markaby.rb +1 -1
- data/spec/ramaze/template/nagoro.rb +65 -0
- data/spec/ramaze/template/nagoro/another/long/action.nag +1 -0
- data/spec/ramaze/template/nagoro/combined.nag +1 -0
- data/spec/ramaze/template/nagoro/file_only.nag +1 -0
- data/spec/ramaze/template/nagoro/index.nag +1 -0
- data/spec/ramaze/template/nagoro/nested.nag +1 -0
- data/spec/ramaze/template/nagoro/some__long__action.nag +1 -0
- data/spec/ramaze/template/nagoro/sum.nag +1 -0
- data/spec/ramaze/template/remarkably.rb +1 -1
- data/spec/ramaze/template/sass.rb +1 -1
- data/spec/ramaze/template/xslt.rb +93 -0
- data/spec/ramaze/template/xslt/concat_words.xsl +16 -0
- data/spec/ramaze/template/xslt/index.xsl +14 -0
- data/spec/ramaze/template/xslt/products.xsl +32 -0
- data/spec/ramaze/template/xslt/ruby_version.xsl +14 -0
- data/spec/snippets/array/put_within.rb +32 -0
- data/spec/snippets/numeric/filesize_format.rb +12 -0
- data/spec/snippets/ordered_set.rb +56 -0
- data/spec/snippets/ramaze/caller_lines.rb +6 -3
- data/spec/snippets/string/snake_case.rb +3 -0
- metadata +118 -22
- data/doc/README.html +0 -737
- data/examples/fcgi.rb +0 -13
- data/lib/ramaze/snippets/numeric/human_readable_filesize_format.rb +0 -33
- data/lib/ramaze/tool/tidy.rb +0 -104
- data/spec/ramaze/controller/template/edit.xhtml +0 -1
- data/spec/ramaze/controller/template/edit/content.xhtml +0 -1
- data/spec/ramaze/tidy.rb +0 -12
- data/spec/snippets/numeric/human_readable_filesize_format.rb +0 -11
data/examples/whywiki/start.rb
CHANGED
|
@@ -6,29 +6,31 @@
|
|
|
6
6
|
require 'ramaze'
|
|
7
7
|
require 'bluecloth'
|
|
8
8
|
|
|
9
|
-
|
|
9
|
+
Db = Ramaze::YAMLStoreCache.new('wiki.yaml') unless defined?(Db)
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
class WikiController < Ramaze::Controller
|
|
12
|
+
map :/
|
|
13
|
+
engine :Nagoro
|
|
12
14
|
|
|
13
|
-
class WikiController < Controller
|
|
14
15
|
def index
|
|
15
|
-
redirect
|
|
16
|
+
redirect R(:show, 'Home')
|
|
16
17
|
end
|
|
17
18
|
|
|
18
19
|
def show page = 'Home'
|
|
19
|
-
@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
|
-
|
|
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 =
|
|
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
|
|
45
|
+
redirect Rs(:show, url_encode(page))
|
|
44
46
|
end
|
|
45
47
|
end
|
|
46
48
|
|
|
47
|
-
|
|
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("< Home", :href => R(self)) }
|
|
6
5
|
<body>
|
|
7
6
|
<h1>Edit #{@page}</h1>
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
#{ A("< 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("< Home", :href => R(self)) unless @page == "Home" }
|
|
10
9
|
<body>
|
|
10
|
+
<a href="/show/Home" unless="@page == 'Home'">< Home</a>
|
|
11
11
|
<h1>#{@page}</h1>
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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
|
data/lib/ramaze.rb
CHANGED
|
@@ -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
|
-
|
|
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)
|
data/lib/ramaze/action.rb
CHANGED
|
@@ -105,20 +105,9 @@ module Ramaze
|
|
|
105
105
|
File.basename((self[:method] || self[:template]).to_s).split('.').first
|
|
106
106
|
end
|
|
107
107
|
|
|
108
|
-
#
|
|
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 ||=
|
|
110
|
+
@extended_path ||= Array[path, *params].join('/')
|
|
122
111
|
end
|
|
123
112
|
|
|
124
113
|
# Hook for AspectHelper
|
data/lib/ramaze/action/render.rb
CHANGED
|
@@ -12,7 +12,7 @@ module Ramaze
|
|
|
12
12
|
# #> 'bar'
|
|
13
13
|
|
|
14
14
|
def render
|
|
15
|
-
Inform.
|
|
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(
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
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
|