mirah 0.0.4-java → 0.0.5-java
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +23 -0
- data/README.txt +13 -5
- data/Rakefile +30 -2
- data/bin/duby +16 -0
- data/bin/dubyc +16 -0
- data/bin/dubyp +16 -0
- data/bin/jrubyp +16 -0
- data/bin/mirah +17 -1
- data/bin/mirah.cmd +15 -0
- data/bin/mirahc +17 -1
- data/bin/mirahc.cmd +16 -1
- data/bin/mirahp +17 -1
- data/bin/mirahp.cmd +16 -1
- data/examples/appengine/Rakefile +17 -2
- data/examples/appengine/src/org/mirah/MirahApp.mirah +15 -0
- data/examples/bintrees.mirah +15 -0
- data/examples/construction.mirah +15 -0
- data/examples/dynamic.mirah +15 -0
- data/examples/edb.mirah +15 -0
- data/examples/fib.mirah +15 -0
- data/examples/fields.mirah +15 -0
- data/examples/fractal.mirah +15 -0
- data/examples/java_thing.mirah +15 -0
- data/examples/plugins/appengine/Rakefile +19 -4
- data/examples/plugins/appengine/lib/com/google/appengine/ext/duby/db/datastore.rb +21 -6
- data/examples/plugins/appengine/src/com/google/appengine/ext/duby/db/Model.duby +15 -0
- data/examples/plugins/appengine/test/com/google/appengine/ext/duby/db/ModelTest.duby +15 -0
- data/examples/simple_class.mirah +16 -1
- data/examples/sort_closure.mirah +15 -0
- data/examples/swing.mirah +17 -2
- data/examples/tak.mirah +15 -0
- data/examples/wiki/Rakefile +17 -2
- data/examples/wiki/src/org/mirah/wiki/MirahWiki.duby +15 -0
- data/examples/wiki/war/src/org/mirah/wiki/MirahWiki.duby +339 -0
- data/examples/wiki/war/src/org/mirah/wiki/edit.eduby.html +42 -0
- data/examples/wiki/war/src/org/mirah/wiki/error.eduby.html +2 -0
- data/examples/wiki/war/src/org/mirah/wiki/layout.eduby.html +69 -0
- data/examples/wiki/war/src/org/mirah/wiki/parser.eduby.html +7 -0
- data/examples/wiki/war/src/org/mirah/wiki/view.eduby.html +15 -0
- data/javalib/mirah-bootstrap.jar +0 -0
- data/javalib/mirah-parser.jar +0 -0
- data/lib/duby.rb +15 -0
- data/lib/mirah/appengine_tasks.rb +20 -6
- data/lib/mirah/ast/call.rb +19 -4
- data/lib/mirah/ast/class.rb +19 -4
- data/lib/mirah/ast/flow.rb +16 -1
- data/lib/mirah/ast/intrinsics.rb +36 -21
- data/lib/mirah/ast/literal.rb +16 -1
- data/lib/mirah/ast/local.rb +16 -1
- data/lib/mirah/ast/method.rb +18 -3
- data/lib/mirah/ast/scope.rb +19 -4
- data/lib/mirah/ast/structure.rb +16 -1
- data/lib/mirah/ast/type.rb +24 -9
- data/lib/mirah/ast.rb +24 -9
- data/lib/mirah/compiler.rb +16 -1
- data/lib/mirah/env.rb +16 -1
- data/lib/mirah/jvm/base.rb +18 -3
- data/lib/mirah/jvm/compiler.rb +35 -21
- data/lib/mirah/jvm/method_lookup.rb +16 -1
- data/lib/mirah/jvm/source_compiler.rb +29 -14
- data/lib/mirah/jvm/source_generator/builder.rb +21 -6
- data/lib/mirah/jvm/source_generator/loops.rb +16 -1
- data/lib/mirah/jvm/source_generator/precompile.rb +17 -2
- data/lib/mirah/jvm/source_generator/typer.rb +17 -2
- data/lib/mirah/jvm/typer.rb +19 -4
- data/lib/mirah/jvm/types/basic_types.rb +16 -1
- data/lib/mirah/jvm/types/boolean.rb +17 -2
- data/lib/mirah/jvm/types/enumerable.rb +21 -6
- data/lib/mirah/jvm/types/extensions.rb +16 -1
- data/lib/mirah/jvm/types/factory.rb +18 -3
- data/lib/mirah/jvm/types/floats.rb +16 -1
- data/lib/mirah/jvm/types/integers.rb +22 -7
- data/lib/mirah/jvm/types/intrinsics.rb +29 -14
- data/lib/mirah/jvm/types/literals.rb +16 -1
- data/lib/mirah/jvm/types/methods.rb +24 -9
- data/lib/mirah/jvm/types/number.rb +16 -1
- data/lib/mirah/jvm/types.rb +23 -4
- data/lib/mirah/nbcompiler.rb +19 -4
- data/lib/mirah/plugin/edb.rb +18 -3
- data/lib/mirah/plugin/gwt.rb +22 -7
- data/lib/mirah/plugin/java.rb +18 -3
- data/lib/mirah/transform.rb +35 -20
- data/lib/mirah/transform2.rb +20 -5
- data/lib/mirah/typer.rb +23 -8
- data/lib/mirah/version.rb +18 -0
- data/lib/mirah.rb +101 -50
- data/lib/mirah_task.rb +27 -12
- data/test/test_ast.rb +16 -1
- data/test/test_compilation.rb +18 -3
- data/test/test_env.rb +26 -11
- data/test/test_gwt.rb +18 -3
- data/test/test_java_typer.rb +27 -12
- data/test/test_javac_compiler.rb +17 -2
- data/test/test_jvm_compiler.rb +44 -14
- data/test/test_typer.rb +16 -1
- metadata +203 -193
@@ -1,3 +1,18 @@
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
1
16
|
module AppEngine
|
2
17
|
class DubyDatastorePlugin
|
3
18
|
@models = {}
|
@@ -51,7 +66,7 @@ module AppEngine
|
|
51
66
|
}
|
52
67
|
|
53
68
|
class ModelState
|
54
|
-
include
|
69
|
+
include Mirah::AST
|
55
70
|
attr_reader :kind, :query, :read, :save, :transformer
|
56
71
|
|
57
72
|
def initialize(transformer, klass, parent, position, ast)
|
@@ -109,7 +124,7 @@ module AppEngine
|
|
109
124
|
self
|
110
125
|
end
|
111
126
|
EOF
|
112
|
-
[
|
127
|
+
[Mirah::AST.type(nil, 'com.google.appengine.ext.duby.db.DQuery'),
|
113
128
|
eval(classdef, queryinit)]
|
114
129
|
end
|
115
130
|
ast << @query
|
@@ -131,7 +146,7 @@ module AppEngine
|
|
131
146
|
end
|
132
147
|
EOF
|
133
148
|
@get_properties = get_properties.body.children[1] =
|
134
|
-
|
149
|
+
Mirah::AST::Body.new(get_properties.body, position)
|
135
150
|
ast << get_properties
|
136
151
|
update = eval(parent, <<-EOF)
|
137
152
|
def update(properties:Map)
|
@@ -260,7 +275,7 @@ module AppEngine
|
|
260
275
|
end
|
261
276
|
|
262
277
|
def self.find_class(node)
|
263
|
-
node = node.parent until
|
278
|
+
node = node.parent until Mirah::AST::ClassDefinition === node
|
264
279
|
node
|
265
280
|
end
|
266
281
|
|
@@ -296,7 +311,7 @@ module AppEngine
|
|
296
311
|
type = type.name
|
297
312
|
type = 'Long' if type == 'Integer'
|
298
313
|
|
299
|
-
result =
|
314
|
+
result = Mirah::AST::ScopedBody.new(parent, fcall.position) {[]}
|
300
315
|
result.static_scope = fcall.scope.static_scope
|
301
316
|
klass = find_class(parent)
|
302
317
|
unless @models[klass]
|
@@ -371,5 +386,5 @@ module AppEngine
|
|
371
386
|
@models = {}
|
372
387
|
end
|
373
388
|
end
|
374
|
-
::
|
389
|
+
::Mirah.plugins << DubyDatastorePlugin
|
375
390
|
end
|
@@ -1,3 +1,18 @@
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
1
16
|
import java.util.ConcurrentModificationException
|
2
17
|
|
3
18
|
import com.google.appengine.api.datastore.DatastoreServiceFactory
|
@@ -1,3 +1,18 @@
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
1
16
|
import com.google.appengine.tools.development.testing.LocalDatastoreServiceTestConfig
|
2
17
|
import com.google.appengine.tools.development.testing.LocalServiceTestConfig
|
3
18
|
import com.google.appengine.tools.development.testing.LocalServiceTestHelper
|
data/examples/simple_class.mirah
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
1
16
|
class Foo
|
2
17
|
def initialize
|
3
18
|
puts 'constructor'
|
@@ -9,4 +24,4 @@ class Foo
|
|
9
24
|
end
|
10
25
|
end
|
11
26
|
|
12
|
-
Foo.new.hello('
|
27
|
+
Foo.new.hello('Mirah')
|
data/examples/sort_closure.mirah
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
1
16
|
import java.util.Collections
|
2
17
|
import java.util.ArrayList
|
3
18
|
|
data/examples/swing.mirah
CHANGED
@@ -1,10 +1,25 @@
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
1
16
|
import javax.swing.JFrame
|
2
17
|
import javax.swing.JButton
|
3
18
|
|
4
19
|
# FIXME blocks need to be inside a MethodDefinition, but main doesn't
|
5
20
|
# have one.
|
6
21
|
def self.run
|
7
|
-
frame = JFrame.new "Welcome to
|
22
|
+
frame = JFrame.new "Welcome to Mirah"
|
8
23
|
frame.setSize 300, 300
|
9
24
|
frame.setVisible true
|
10
25
|
|
@@ -13,7 +28,7 @@ def self.run
|
|
13
28
|
frame.show
|
14
29
|
|
15
30
|
button.addActionListener do |event|
|
16
|
-
JButton(event.getSource).setText "
|
31
|
+
JButton(event.getSource).setText "Mirah Rocks!"
|
17
32
|
end
|
18
33
|
end
|
19
34
|
|
data/examples/tak.mirah
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
1
16
|
def tak(x:fixnum, y:fixnum, z:fixnum)
|
2
17
|
unless y < x
|
3
18
|
z
|
data/examples/wiki/Rakefile
CHANGED
@@ -1,3 +1,18 @@
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
1
16
|
# Hack to use the latest version instead of the gems when developing Mirah
|
2
17
|
if File.exist?('../../lib/mirah.rb')
|
3
18
|
$: << File.expand_path('../../lib')
|
@@ -9,8 +24,8 @@ require 'mirah/appengine_tasks'
|
|
9
24
|
|
10
25
|
appengine_app :app
|
11
26
|
|
12
|
-
DUBY_APP = "#{
|
13
|
-
Templates = Dir.glob("#{
|
27
|
+
DUBY_APP = "#{Mirah.dest_path}/org/mirah/wiki/MirahWiki.class"
|
28
|
+
Templates = Dir.glob("#{Mirah.source_path}/org/mirah/wiki/*.eduby.html")
|
14
29
|
|
15
30
|
Rake::Task[DUBY_APP].enhance(Templates)
|
16
31
|
|
@@ -1,3 +1,18 @@
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
1
16
|
import javax.servlet.http.HttpServlet
|
2
17
|
import javax.servlet.http.HttpServletRequest
|
3
18
|
import javax.servlet.Filter
|
@@ -0,0 +1,339 @@
|
|
1
|
+
# Copyright (c) 2010 The Mirah project authors. All Rights Reserved.
|
2
|
+
# All contributing project authors may be found in the NOTICE file.
|
3
|
+
#
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
5
|
+
# you may not use this file except in compliance with the License.
|
6
|
+
# You may obtain a copy of the License at
|
7
|
+
#
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
9
|
+
#
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
13
|
+
# See the License for the specific language governing permissions and
|
14
|
+
# limitations under the License.
|
15
|
+
|
16
|
+
import javax.servlet.http.HttpServlet
|
17
|
+
import javax.servlet.http.HttpServletRequest
|
18
|
+
import javax.servlet.Filter
|
19
|
+
import com.google.appengine.ext.duby.db.Model
|
20
|
+
import com.google.appengine.api.datastore.Text
|
21
|
+
import java.util.Date
|
22
|
+
import org.pegdown.PegDownProcessorStub
|
23
|
+
import com.google.appengine.api.users.UserServiceFactory
|
24
|
+
import com.google.appengine.api.users.User
|
25
|
+
import java.util.ArrayList
|
26
|
+
import java.util.List
|
27
|
+
|
28
|
+
class Page < Model
|
29
|
+
property 'title', String
|
30
|
+
property 'body', Text
|
31
|
+
property 'userid', String
|
32
|
+
property 'user', User
|
33
|
+
property 'nickname', String
|
34
|
+
property 'comment', String
|
35
|
+
property 'created', Date
|
36
|
+
property 'version', Long
|
37
|
+
property 'locked', Boolean
|
38
|
+
end
|
39
|
+
|
40
|
+
class Helper < HttpServlet
|
41
|
+
def markdown(text:String)
|
42
|
+
return "" unless text
|
43
|
+
flags = 0x5ff
|
44
|
+
if @allow_html
|
45
|
+
flags |= 0x200 unless @allow_html
|
46
|
+
@html_markdown ||= PegDownProcessorStub.new(flags)
|
47
|
+
@html_markdown.markdownToHtml(text)
|
48
|
+
else
|
49
|
+
@nohtml_markdown ||= PegDownProcessorStub.new(flags)
|
50
|
+
@nohtml_markdown.markdownToHtml(text)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def html=(enabled:boolean)
|
55
|
+
@allow_html = enabled
|
56
|
+
end
|
57
|
+
|
58
|
+
def page_name(name:String)
|
59
|
+
if name.nil?
|
60
|
+
return "Main"
|
61
|
+
else
|
62
|
+
name = name.replaceAll("\\W", "")
|
63
|
+
end
|
64
|
+
if name.equals("")
|
65
|
+
"Main"
|
66
|
+
else
|
67
|
+
name
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def h(text:String)
|
72
|
+
return "" unless text
|
73
|
+
text = text.replace("&", "&")
|
74
|
+
text = text.replace("<", "<")
|
75
|
+
text = text.replace(">", ">")
|
76
|
+
text = text.replace("\"", """)
|
77
|
+
text.replace("'", "'")
|
78
|
+
end
|
79
|
+
|
80
|
+
def h(o:Object)
|
81
|
+
h(o.toString)
|
82
|
+
end
|
83
|
+
|
84
|
+
def_edb(layout, 'org/mirah/wiki/layout.eduby.html')
|
85
|
+
|
86
|
+
def with_layout(content:String)
|
87
|
+
@content = content
|
88
|
+
layout
|
89
|
+
end
|
90
|
+
|
91
|
+
def title
|
92
|
+
@title
|
93
|
+
end
|
94
|
+
|
95
|
+
def title=(title:String)
|
96
|
+
@title = title
|
97
|
+
end
|
98
|
+
|
99
|
+
def users
|
100
|
+
@users ||= UserServiceFactory.getUserService()
|
101
|
+
end
|
102
|
+
|
103
|
+
macro def admin?
|
104
|
+
quote { users.isUserAdmin }
|
105
|
+
end
|
106
|
+
|
107
|
+
def user
|
108
|
+
users.getCurrentUser
|
109
|
+
end
|
110
|
+
|
111
|
+
def nickname
|
112
|
+
user.getNickname.replaceAll('@.*', '')
|
113
|
+
end
|
114
|
+
|
115
|
+
def extra_links
|
116
|
+
@links ||= ArrayList.new
|
117
|
+
end
|
118
|
+
|
119
|
+
def url
|
120
|
+
'/'
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
class ViewPage < Helper
|
125
|
+
def_edb(view, 'org/mirah/wiki/view.eduby.html')
|
126
|
+
|
127
|
+
def doGet(request, response)
|
128
|
+
@url = request.getRequestURI
|
129
|
+
self.title = @name = page_name(request.getPathInfo)
|
130
|
+
canonical = "/" + @name
|
131
|
+
unless canonical.equals(request.getPathInfo)
|
132
|
+
response.sendRedirect(canonical)
|
133
|
+
return
|
134
|
+
end
|
135
|
+
|
136
|
+
@page = Page.get(@name)
|
137
|
+
self.html = @page.locked if @page
|
138
|
+
response.getWriter.write(with_layout(view))
|
139
|
+
end
|
140
|
+
|
141
|
+
def url
|
142
|
+
@url
|
143
|
+
end
|
144
|
+
|
145
|
+
def extra_links
|
146
|
+
links = ArrayList.new
|
147
|
+
if @page
|
148
|
+
can_edit = admin?
|
149
|
+
can_edit = true unless @page.locked
|
150
|
+
if can_edit
|
151
|
+
links.add(["Edit", "/edit/#{@page.title}"])
|
152
|
+
end
|
153
|
+
end
|
154
|
+
links.add(["New Page", "javascript:void(newPage())"])
|
155
|
+
links
|
156
|
+
end
|
157
|
+
end
|
158
|
+
|
159
|
+
import java.util.logging.Logger
|
160
|
+
|
161
|
+
class EditPage < Helper
|
162
|
+
def_edb(edit, 'org/mirah/wiki/edit.eduby.html')
|
163
|
+
def_edb(error, 'org/mirah/wiki/error.eduby.html')
|
164
|
+
|
165
|
+
def logger
|
166
|
+
@logger ||= Logger.getLogger("EditPage")
|
167
|
+
end
|
168
|
+
|
169
|
+
def render(content:String)
|
170
|
+
@response.setContentType("text/html; charset=utf-8")
|
171
|
+
@response.getWriter.write(with_layout(content))
|
172
|
+
end
|
173
|
+
|
174
|
+
def url
|
175
|
+
@url
|
176
|
+
end
|
177
|
+
|
178
|
+
def doGet(request, response)
|
179
|
+
@url = request.getRequestURI
|
180
|
+
@response = response
|
181
|
+
@error = String(nil)
|
182
|
+
@name = page_name(request.getPathInfo)
|
183
|
+
@page = Page.get(@name)
|
184
|
+
if @page && @page.locked
|
185
|
+
unless admin?
|
186
|
+
@error = "You are not authorized to edit this page"
|
187
|
+
response.setStatus(403)
|
188
|
+
render(error)
|
189
|
+
return
|
190
|
+
end
|
191
|
+
end
|
192
|
+
render(edit)
|
193
|
+
end
|
194
|
+
|
195
|
+
def doPost(_request, _response)
|
196
|
+
@error = nil
|
197
|
+
@response = _response
|
198
|
+
@url = _request.getRequestURI
|
199
|
+
|
200
|
+
# TODO scope inside blocks is not quite right
|
201
|
+
this = self
|
202
|
+
request = _request
|
203
|
+
response = _response
|
204
|
+
is_admin = admin?
|
205
|
+
|
206
|
+
name = page_name(request.getPathInfo)
|
207
|
+
|
208
|
+
begin
|
209
|
+
edit_version = Long.parseLong(String(request.getParameter("version")))
|
210
|
+
rescue NumberFormatException
|
211
|
+
response.sendError(
|
212
|
+
400, "Invalid version '#{request.getParameter("version")}'")
|
213
|
+
return
|
214
|
+
end
|
215
|
+
|
216
|
+
Model.transaction do
|
217
|
+
orig_page = Page.get(name)
|
218
|
+
current_version = orig_page ? orig_page.version : long(0)
|
219
|
+
if current_version != edit_version
|
220
|
+
@error = <<EOS
|
221
|
+
Version conflict. You are trying to edit version #{edit_version}, but
|
222
|
+
the current version is #{current_version}.
|
223
|
+
EOS
|
224
|
+
@page = orig_page
|
225
|
+
@name = name
|
226
|
+
response.setStatus(409)
|
227
|
+
this.render(this.edit)
|
228
|
+
return
|
229
|
+
end
|
230
|
+
if orig_page && orig_page.locked
|
231
|
+
unless is_admin
|
232
|
+
@error = "You are not authorized to edit this page"
|
233
|
+
response.setStatus(403)
|
234
|
+
this.render(this.error)
|
235
|
+
return
|
236
|
+
end
|
237
|
+
end
|
238
|
+
|
239
|
+
this.save_old_version(orig_page) if orig_page
|
240
|
+
|
241
|
+
if orig_page
|
242
|
+
page = orig_page
|
243
|
+
page.version = page.version + 1
|
244
|
+
else
|
245
|
+
page = Page.new(name)
|
246
|
+
page.title = name
|
247
|
+
page.version = 1
|
248
|
+
end
|
249
|
+
|
250
|
+
locked = is_admin && "locked".equals(request.getParameter("locked"))
|
251
|
+
page.body = String(request.getParameter("body"))
|
252
|
+
page.nickname = String(request.getParameter("nickname"))
|
253
|
+
page.comment = String(request.getParameter("comment"))
|
254
|
+
page.user = this.user
|
255
|
+
page.userid = this.user.getUserId
|
256
|
+
page.created = Date.new
|
257
|
+
page.locked = locked
|
258
|
+
page.save
|
259
|
+
response.sendRedirect("/wiki/" + name)
|
260
|
+
end
|
261
|
+
end
|
262
|
+
|
263
|
+
def save_old_version(orig_page:Page)
|
264
|
+
old_version = Page.new(orig_page)
|
265
|
+
old_version.title = orig_page.title
|
266
|
+
old_version.body = orig_page.body
|
267
|
+
old_version.userid = orig_page.userid
|
268
|
+
old_version.user = orig_page.user
|
269
|
+
old_version.nickname = orig_page.nickname
|
270
|
+
old_version.comment = orig_page.comment
|
271
|
+
old_version.created = orig_page.created
|
272
|
+
old_version.version = orig_page.version
|
273
|
+
old_version.locked = orig_page.locked
|
274
|
+
old_version.save
|
275
|
+
end
|
276
|
+
end
|
277
|
+
|
278
|
+
import test.MirahParser
|
279
|
+
import jmeta.BaseParser
|
280
|
+
class MirahParserPage < Helper
|
281
|
+
def_edb(render, 'org/mirah/wiki/parser.eduby.html')
|
282
|
+
|
283
|
+
def initialize
|
284
|
+
self.title = "Mirah Parser Test"
|
285
|
+
end
|
286
|
+
|
287
|
+
def doGet(request, response)
|
288
|
+
doPost(request, response)
|
289
|
+
end
|
290
|
+
|
291
|
+
def doPost(request, response)
|
292
|
+
@code = String(request.getParameter("code")) || "puts 'Hello, world!'"
|
293
|
+
parser = MirahParser.new
|
294
|
+
begin
|
295
|
+
@parsed = BaseParser.print_r(parser.parse(@code))
|
296
|
+
rescue => ex
|
297
|
+
@parsed = ex.getMessage
|
298
|
+
end
|
299
|
+
response.getWriter.write(with_layout(render))
|
300
|
+
end
|
301
|
+
end
|
302
|
+
|
303
|
+
class FederatedLogin < Helper
|
304
|
+
def doGet(request, response)
|
305
|
+
provider = request.getPathInfo
|
306
|
+
if provider && provider.length > 1
|
307
|
+
provider = provider.substring(1)
|
308
|
+
else
|
309
|
+
provider = 'www.google.com/accounts/o8/id'
|
310
|
+
end
|
311
|
+
continue = String(request.getParameter('continue')) || '/'
|
312
|
+
url = users.createLoginURL(continue, nil, provider, nil)
|
313
|
+
response.sendRedirect(url)
|
314
|
+
end
|
315
|
+
end
|
316
|
+
|
317
|
+
class LoginRequired < Helper
|
318
|
+
def doGet(request, response)
|
319
|
+
# This should be a page allowing people to select an OpenID provider.
|
320
|
+
# But I'm lazy so I'll just force them to use gmail...
|
321
|
+
continue = String(request.getParameter('continue'))
|
322
|
+
url = users.createLoginURL(continue, nil, 'www.google.com/accounts/o8/id', nil)
|
323
|
+
response.sendRedirect(url)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
|
327
|
+
class MainFilter; implements Filter
|
328
|
+
def init(arg); end
|
329
|
+
def destroy; end
|
330
|
+
def doFilter(request, response, filters)
|
331
|
+
if "/".equals(HttpServletRequest(request).getRequestURI)
|
332
|
+
request.getRequestDispatcher('/wiki/Main').forward(request, response)
|
333
|
+
nil
|
334
|
+
else
|
335
|
+
filters.doFilter(request, response)
|
336
|
+
nil
|
337
|
+
end
|
338
|
+
end
|
339
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<div>
|
2
|
+
<% if @error %>
|
3
|
+
<div id=error><%=h @error %></div>
|
4
|
+
<% end %>
|
5
|
+
<div>
|
6
|
+
<form method=post>
|
7
|
+
<textarea id=body name=body style="width:95%;font-family:monospace" rows=5
|
8
|
+
><% if @page && @page.body %><%=h @page.body %><% end
|
9
|
+
%></textarea><br>
|
10
|
+
Your Name: <input name=nickname value="<%=h nickname %>"><br>
|
11
|
+
Comment: <input name=comment value=<% if @page %>
|
12
|
+
"Edited Page"
|
13
|
+
<% else %>
|
14
|
+
"Created Page"
|
15
|
+
<% end %>><br>
|
16
|
+
<input type=hidden name=version value="<%= @page ? @page.version : long(0) %>">
|
17
|
+
<% if admin? %>
|
18
|
+
Locked: <input name=locked value=locked type=checkbox <%= "checked" if @page && @page.locked%>><br>
|
19
|
+
<% end %>
|
20
|
+
<input type=submit name=Save>
|
21
|
+
</form>
|
22
|
+
</div>
|
23
|
+
<hr style="clear:all">
|
24
|
+
<div id=preview class="wmd-preview"></div>
|
25
|
+
<script>
|
26
|
+
(function(){
|
27
|
+
var ta = document.getElementById("body");
|
28
|
+
var sh = 0;
|
29
|
+
function resize() {
|
30
|
+
var nsh = ta.scrollHeight;
|
31
|
+
if (nsh != sh) {
|
32
|
+
ta.style.height = 0;
|
33
|
+
ta.style.height = (nsh + 100) + "px";
|
34
|
+
sh = ta.scrollHeight;
|
35
|
+
}
|
36
|
+
setTimeout(resize, 250);
|
37
|
+
}
|
38
|
+
resize();
|
39
|
+
})();
|
40
|
+
wmd_options={output:"markdown"};
|
41
|
+
</script>
|
42
|
+
<script type="text/javascript" src="/wmd/wmd.js""></script>
|