manveru-ramaze 2008.08 → 2008.09
Sign up to get free protection for your applications and to get access to all the features.
- data/Rakefile +1 -1
- data/bin/ramaze +1 -0
- data/doc/CHANGELOG +966 -0
- data/doc/tutorial/todolist.html +421 -313
- data/doc/tutorial/todolist.mkd +26 -9
- data/examples/helpers/paginate.rb +71 -0
- data/examples/misc/simple_auth.rb +20 -8
- data/lib/proto/controller/init.rb +10 -0
- data/lib/proto/controller/main.rb +1 -3
- data/lib/proto/model/init.rb +4 -0
- data/lib/proto/spec/main.rb +2 -1
- data/lib/proto/start.rb +3 -3
- data/lib/ramaze.rb +6 -1
- data/lib/ramaze/action.rb +2 -2
- data/lib/ramaze/adapter.rb +0 -5
- data/lib/ramaze/adapter/base.rb +24 -7
- data/lib/ramaze/contrib/gzip_filter.rb +22 -9
- data/lib/ramaze/contrib/maruku_uv.rb +59 -0
- data/lib/ramaze/contrib/profiling.rb +1 -1
- data/lib/ramaze/contrib/sequel/create_join.rb +25 -0
- data/lib/ramaze/contrib/sequel/form_field.rb +129 -0
- data/lib/ramaze/contrib/sequel/image.rb +198 -0
- data/lib/ramaze/contrib/sequel/relation.rb +82 -0
- data/lib/ramaze/controller/resolve.rb +1 -1
- data/lib/ramaze/current.rb +60 -20
- data/lib/ramaze/current/response.rb +15 -3
- data/lib/ramaze/dispatcher.rb +9 -3
- data/lib/ramaze/dispatcher/action.rb +2 -3
- data/lib/ramaze/dispatcher/directory.rb +1 -1
- data/lib/ramaze/dispatcher/error.rb +1 -1
- data/lib/ramaze/dispatcher/file.rb +1 -1
- data/lib/ramaze/helper/formatting.rb +33 -0
- data/lib/ramaze/helper/paginate.rb +234 -0
- data/lib/ramaze/option.rb +2 -2
- data/lib/ramaze/reloader.rb +2 -2
- data/lib/ramaze/snippets.rb +13 -0
- data/lib/ramaze/snippets/array/put_within.rb +31 -24
- data/lib/ramaze/snippets/binding/locals.rb +23 -11
- data/lib/ramaze/snippets/kernel/constant.rb +36 -21
- data/lib/ramaze/snippets/kernel/pretty_inspect.rb +12 -6
- data/lib/ramaze/snippets/numeric/filesize_format.rb +24 -17
- data/lib/ramaze/snippets/numeric/time.rb +63 -56
- data/lib/ramaze/snippets/object/__dir__.rb +29 -0
- data/lib/ramaze/snippets/object/acquire.rb +40 -0
- data/lib/ramaze/snippets/object/instance_variable_defined.rb +16 -5
- data/lib/ramaze/snippets/object/pretty.rb +14 -4
- data/lib/ramaze/snippets/object/scope.rb +14 -7
- data/lib/ramaze/snippets/ordered_set.rb +4 -0
- data/lib/ramaze/snippets/proc/locals.rb +17 -9
- data/lib/ramaze/snippets/ramaze/struct.rb +45 -0
- data/lib/ramaze/snippets/string/camel_case.rb +13 -8
- data/lib/ramaze/snippets/string/color.rb +24 -20
- data/lib/ramaze/snippets/string/each.rb +14 -3
- data/lib/ramaze/snippets/string/end_with.rb +17 -6
- data/lib/ramaze/snippets/string/esc.rb +26 -18
- data/lib/ramaze/snippets/string/ord.rb +12 -6
- data/lib/ramaze/snippets/string/snake_case.rb +13 -7
- data/lib/ramaze/snippets/string/start_with.rb +16 -6
- data/lib/ramaze/snippets/string/unindent.rb +23 -15
- data/lib/ramaze/snippets/thread/into.rb +3 -3
- data/lib/ramaze/spec/helper/snippets.rb +8 -0
- data/lib/ramaze/template/ezamar/textpow.syntax +34 -0
- data/lib/ramaze/tool/create.rb +27 -53
- data/lib/ramaze/tool/project_creator.rb +110 -0
- data/lib/ramaze/version.rb +1 -1
- data/rake_tasks/gem.rake +2 -1
- data/rake_tasks/maintenance.rake +38 -0
- data/rake_tasks/release.rake +6 -2
- data/rake_tasks/spec.rake +1 -2
- data/ramaze.gemspec +69 -78
- data/spec/examples/simple_auth.rb +2 -2
- data/spec/examples/templates/template_haml.rb +0 -2
- data/spec/ramaze/current/session.rb +1 -1
- data/spec/ramaze/dispatcher/file.rb +2 -2
- data/spec/ramaze/helper/formatting.rb +13 -0
- data/spec/ramaze/rewrite.rb +1 -1
- data/spec/ramaze/struct.rb +47 -0
- data/spec/ramaze/template/markaby.rb +1 -1
- data/spec/snippets/{kernel → object}/__dir__.rb +0 -0
- data/spec/snippets/{kernel → object}/acquire.rb +0 -0
- metadata +69 -78
- data/examples/app/rammit/spec/rammit.rb +0 -31
- data/examples/app/rammit/src/controller/main.rb +0 -3
- data/examples/app/rammit/src/controller/page.rb +0 -16
- data/examples/app/rammit/src/model.rb +0 -33
- data/examples/app/rammit/start.rb +0 -8
- data/examples/app/rammit/template/index.xhtml +0 -14
- data/examples/app/rammit/template/page/view.xhtml +0 -4
- data/lib/ramaze/snippets/kernel/__dir__.rb +0 -23
- data/lib/ramaze/snippets/kernel/acquire.rb +0 -34
- data/lib/ramaze/snippets/struct/fill.rb +0 -23
- data/lib/ramaze/snippets/struct/values_at.rb +0 -39
- data/lib/ramaze/snippets/symbol/to_proc.rb +0 -24
- data/lib/ramaze/sourcereload.rb +0 -183
- data/spec/snippets/struct/fill.rb +0 -26
- data/spec/snippets/struct/values_at.rb +0 -52
- data/spec/snippets/symbol/to_proc.rb +0 -13
@@ -0,0 +1,40 @@
|
|
1
|
+
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
module Ramaze
|
5
|
+
module CoreExtensions
|
6
|
+
|
7
|
+
# Extensions for Kernel
|
8
|
+
|
9
|
+
module Object
|
10
|
+
|
11
|
+
# Require all .rb and .so files on the given globs, utilizes Dir::[].
|
12
|
+
#
|
13
|
+
# Examples:
|
14
|
+
# # Given following directory structure:
|
15
|
+
# # src/foo.rb
|
16
|
+
# # src/bar.so
|
17
|
+
# # src/foo.yaml
|
18
|
+
# # src/foobar/baz.rb
|
19
|
+
# # src/foobar/README
|
20
|
+
#
|
21
|
+
# # requires all files in 'src':
|
22
|
+
# acquire 'src/*'
|
23
|
+
#
|
24
|
+
# # requires all files in 'src' recursive:
|
25
|
+
# acquire 'src/**/*'
|
26
|
+
#
|
27
|
+
# # require 'src/foo.rb' and 'src/bar.so' and 'src/foobar/baz.rb'
|
28
|
+
# acquire 'src/*', 'src/foobar/*'
|
29
|
+
|
30
|
+
def acquire *globs
|
31
|
+
globs.flatten.each do |glob|
|
32
|
+
Dir[glob].each do |file|
|
33
|
+
require file if file =~ /\.(rb|so)$/
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
end
|
40
|
+
end
|
@@ -1,8 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
module Ramaze
|
5
|
+
module CoreExtensions
|
6
|
+
|
7
|
+
# Extensions for Object
|
8
|
+
module Object
|
9
|
+
# Available in 1.8.6 and later.
|
10
|
+
|
11
|
+
unless ::Object.method_defined?(:instance_variable_defined?)
|
12
|
+
def instance_variable_defined?(variable)
|
13
|
+
instance_variables.include?(variable.to_s)
|
14
|
+
end
|
15
|
+
end
|
6
16
|
end
|
17
|
+
|
7
18
|
end
|
8
19
|
end
|
@@ -1,6 +1,16 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
1
|
+
module Ramaze
|
2
|
+
module CoreExtensions
|
3
|
+
|
4
|
+
# Extensions for Object
|
5
|
+
module Object
|
6
|
+
|
7
|
+
# Returns the string that #pretty_inspect would yield
|
8
|
+
|
9
|
+
def pretty s = ''
|
10
|
+
PP.pp(self, s)
|
11
|
+
s
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
end
|
6
16
|
end
|
@@ -1,11 +1,18 @@
|
|
1
|
-
|
1
|
+
module Ramaze
|
2
|
+
module CoreExtensions
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
#
|
4
|
+
# Extensions for Object
|
5
|
+
module Object
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
7
|
+
# returns a new clean binding for this object
|
8
|
+
# usage: eval 'self', object.scope #=> returns object
|
9
|
+
#
|
10
|
+
|
11
|
+
def scope
|
12
|
+
lambda{}
|
13
|
+
end
|
10
14
|
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
11
18
|
end
|
@@ -5,6 +5,10 @@ require(File.join(File.dirname(__FILE__), 'blankslate'))
|
|
5
5
|
|
6
6
|
# Basically an Set, but with Order, ain't that obivous?
|
7
7
|
class OrderedSet < BlankSlate
|
8
|
+
def self.[](*args)
|
9
|
+
new(*args)
|
10
|
+
end
|
11
|
+
|
8
12
|
# Create new instances, optionally pass the first set
|
9
13
|
def initialize(*args)
|
10
14
|
if args.size == 1
|
@@ -1,11 +1,19 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
def locals
|
8
|
-
instance_eval('binding').locals
|
9
|
-
end
|
1
|
+
module Ramaze
|
2
|
+
module CoreExtensions
|
3
|
+
|
4
|
+
# Extensions for Proc
|
5
|
+
|
6
|
+
module Proc
|
10
7
|
|
8
|
+
# returns a hash of localvar/localvar-values from proc, useful for template
|
9
|
+
# engines that do not accept bindings/proc and force passing locals via
|
10
|
+
# hash
|
11
|
+
# usage: x = 42; p Proc.new.locals #=> {'x'=> 42}
|
12
|
+
|
13
|
+
def locals
|
14
|
+
instance_eval('binding').locals
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
11
19
|
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
|
2
|
+
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
3
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
4
|
+
|
5
|
+
module Ramaze
|
6
|
+
class Struct < ::Struct
|
7
|
+
|
8
|
+
# Makes it possible to access the keys directly by their name, not only
|
9
|
+
# their index. The original Struct#values_at tries to call #to_int on the
|
10
|
+
# arguments.
|
11
|
+
# in Ruby < 1.9 this would lead to a quite unintuitive IndexError, while
|
12
|
+
# in 1.9 it will say outright that it cannot convert Symbol into Integer.
|
13
|
+
# I think this is neither useful nor expected, so we extend
|
14
|
+
# Struct#values_at to recognize valid members of the Struct passed into
|
15
|
+
# the method and return their values in the same order, just like
|
16
|
+
# Hash#values_at.
|
17
|
+
#
|
18
|
+
# Example:
|
19
|
+
# Point = Struct.new(:x, :y)
|
20
|
+
# point = Point.new(15, 10)
|
21
|
+
#
|
22
|
+
# # Old behaviour:
|
23
|
+
# point.values_at(0, 1)
|
24
|
+
# # => [15, 10]
|
25
|
+
# point.values_at(0..1)
|
26
|
+
# # => [15, 10]
|
27
|
+
# point.values_at(:y, :x)
|
28
|
+
# # => IndexError: offset 20697 too large for struct(size:2)
|
29
|
+
#
|
30
|
+
# # Added new behaviour:
|
31
|
+
# point.values_at(:y, :x)
|
32
|
+
# # => [10, 15]
|
33
|
+
|
34
|
+
def values_at(*keys)
|
35
|
+
keys.map do |key|
|
36
|
+
case key
|
37
|
+
when String, Symbol
|
38
|
+
self[key]
|
39
|
+
else
|
40
|
+
return super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -1,16 +1,21 @@
|
|
1
1
|
# Copyright (c) 2008 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
|
-
|
4
|
+
module Ramaze
|
5
|
+
module CoreExtensions
|
5
6
|
|
6
|
-
|
7
|
+
# Extensions for String
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
module String
|
10
|
+
|
11
|
+
# simple transformation to CamelCase from snake_case
|
12
|
+
#
|
13
|
+
# 'foo_bar'.camel_case # => 'FooBar'
|
14
|
+
|
15
|
+
def camel_case
|
16
|
+
split('_').map{|e| e.capitalize}.join
|
17
|
+
end
|
18
|
+
end
|
11
19
|
|
12
|
-
def camel_case
|
13
|
-
split('_').map{|e| e.capitalize}.join
|
14
20
|
end
|
15
21
|
end
|
16
|
-
|
@@ -1,27 +1,31 @@
|
|
1
1
|
# Copyright (c) 2008 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
|
-
|
4
|
+
module Ramaze
|
5
|
+
module CoreExtensions
|
6
|
+
# Extensions for String
|
5
7
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
8
|
+
module String
|
9
|
+
{ :reset => 0,
|
10
|
+
:bold => 1,
|
11
|
+
:dark => 2,
|
12
|
+
:underline => 4,
|
13
|
+
:blink => 5,
|
14
|
+
:negative => 7,
|
15
|
+
:black => 30,
|
16
|
+
:red => 31,
|
17
|
+
:green => 32,
|
18
|
+
:yellow => 33,
|
19
|
+
:blue => 34,
|
20
|
+
:magenta => 35,
|
21
|
+
:cyan => 36,
|
22
|
+
:white => 37,
|
23
|
+
}.each do |key, value|
|
24
|
+
define_method key do
|
25
|
+
"\e[#{value}m" + self + "\e[0m"
|
26
|
+
end
|
27
|
+
end
|
24
28
|
end
|
29
|
+
|
25
30
|
end
|
26
31
|
end
|
27
|
-
|
@@ -1,8 +1,19 @@
|
|
1
1
|
# Copyright (c) 2008 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
|
-
|
4
|
+
module Ramaze
|
5
|
+
module CoreExtensions
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
# Extensions for String
|
8
|
+
|
9
|
+
module String
|
10
|
+
# 1.9 Compatibility with 1.8
|
11
|
+
|
12
|
+
unless ''.respond_to?(:each)
|
13
|
+
def each(*args, &block)
|
14
|
+
each_line(*args, &block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
8
19
|
end
|
@@ -1,9 +1,20 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
1
|
+
# Copyright (c) 2008 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
module Ramaze
|
5
|
+
module CoreExtensions
|
6
|
+
|
7
|
+
# Extensions for String
|
8
|
+
|
9
|
+
module String
|
10
|
+
unless ''.respond_to?(:end_with?)
|
11
|
+
# Compatibility with 1.9
|
12
|
+
def end_with?(other)
|
13
|
+
other = other.to_s
|
14
|
+
self[-other.size, other.size] == other
|
15
|
+
end
|
16
|
+
end
|
7
17
|
end
|
18
|
+
|
8
19
|
end
|
9
20
|
end
|
@@ -1,26 +1,34 @@
|
|
1
1
|
require 'cgi'
|
2
2
|
require 'uri'
|
3
3
|
|
4
|
-
|
4
|
+
module Ramaze
|
5
|
+
module CoreExtensions
|
5
6
|
|
6
|
-
|
7
|
-
# it suports
|
8
|
-
# '<div>foo bar</div>'.esc(:html)
|
9
|
-
# 'foo bar'.esc(:uri)
|
10
|
-
# 'foo bar'.esc(:cgi)
|
7
|
+
# Extensions for String
|
11
8
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
9
|
+
module String
|
10
|
+
|
11
|
+
# String#escape is an extensible escaping mechanism for string. currently
|
12
|
+
# it suports
|
13
|
+
# '<div>foo bar</div>'.esc(:html)
|
14
|
+
# 'foo bar'.esc(:uri)
|
15
|
+
# 'foo bar'.esc(:cgi)
|
16
|
+
|
17
|
+
def escape which = :html
|
18
|
+
case which
|
19
|
+
when :html
|
20
|
+
Rack::Utils.escape_html(self)
|
21
|
+
when :cgi
|
22
|
+
Rack::Utils.escape(self)
|
23
|
+
when :uri
|
24
|
+
::URI.escape(self)
|
25
|
+
else
|
26
|
+
raise ArgumentError, "do not know how to escape '#{ which }'"
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
alias_method 'esc', 'escape'
|
22
31
|
end
|
23
|
-
end
|
24
32
|
|
25
|
-
|
33
|
+
end
|
26
34
|
end
|
@@ -1,15 +1,21 @@
|
|
1
1
|
# Copyright (c) 2008 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
|
-
|
4
|
+
module Ramaze
|
5
|
+
module CoreExtensions
|
5
6
|
|
6
|
-
|
7
|
-
unless method_defined?(:ord)
|
7
|
+
# Extensions for String
|
8
8
|
|
9
|
-
|
9
|
+
module String
|
10
|
+
unless ''.respond_to?(:ord)
|
10
11
|
|
11
|
-
|
12
|
-
|
12
|
+
# compatibility with Ruby 1.9
|
13
|
+
|
14
|
+
def ord
|
15
|
+
self[0]
|
16
|
+
end
|
17
|
+
end
|
13
18
|
end
|
19
|
+
|
14
20
|
end
|
15
21
|
end
|
@@ -1,15 +1,21 @@
|
|
1
1
|
# Copyright (c) 2008 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
|
-
|
4
|
+
module Ramaze
|
5
|
+
module CoreExtensions
|
5
6
|
|
6
|
-
|
7
|
+
# Extensions for String
|
7
8
|
|
8
|
-
|
9
|
-
|
10
|
-
|
9
|
+
module String
|
10
|
+
|
11
|
+
# convert to snake_case from CamelCase
|
12
|
+
#
|
13
|
+
# 'FooBar'.snake_case # => 'foo_bar'
|
14
|
+
|
15
|
+
def snake_case
|
16
|
+
gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
|
17
|
+
end
|
18
|
+
end
|
11
19
|
|
12
|
-
def snake_case
|
13
|
-
gsub(/\B[A-Z][^A-Z]/, '_\&').downcase.gsub(' ', '_')
|
14
20
|
end
|
15
21
|
end
|