ramaze 0.1.4 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- 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/spec/ramaze/template.rb
CHANGED
@@ -20,8 +20,8 @@ end
|
|
20
20
|
|
21
21
|
class TCTemplateController < Ramaze::Controller
|
22
22
|
map '/'
|
23
|
-
|
24
|
-
template_root
|
23
|
+
engine :TestTemplate
|
24
|
+
template_root __DIR__/:template/:ramaze
|
25
25
|
|
26
26
|
def index *args
|
27
27
|
end
|
@@ -6,8 +6,8 @@ require 'spec/helper'
|
|
6
6
|
testcase_requires 'amrita2'
|
7
7
|
|
8
8
|
class TCTemplateAmritaController < Ramaze::Controller
|
9
|
-
template_root
|
10
|
-
|
9
|
+
template_root __DIR__/:amrita2
|
10
|
+
engine :Amrita2
|
11
11
|
|
12
12
|
def title
|
13
13
|
"hello world"
|
@@ -6,8 +6,8 @@ require 'spec/helper'
|
|
6
6
|
testcase_requires 'erubis'
|
7
7
|
|
8
8
|
class TCTemplateErubisController < Ramaze::Controller
|
9
|
-
template_root
|
10
|
-
|
9
|
+
template_root __DIR__/:erubis
|
10
|
+
engine :Erubis
|
11
11
|
|
12
12
|
def index
|
13
13
|
'Erubis Index'
|
@@ -4,8 +4,9 @@
|
|
4
4
|
require 'spec/helper'
|
5
5
|
|
6
6
|
class TCTemplateController < Ramaze::Controller
|
7
|
-
|
8
|
-
|
7
|
+
map :/
|
8
|
+
template_root __DIR__/:ezamar
|
9
|
+
engine :Ezamar
|
9
10
|
|
10
11
|
def index text
|
11
12
|
@text = text
|
@@ -31,7 +32,9 @@ end
|
|
31
32
|
|
32
33
|
|
33
34
|
describe "Ezamar" do
|
34
|
-
|
35
|
+
before(:all) do
|
36
|
+
ramaze
|
37
|
+
end
|
35
38
|
|
36
39
|
it "hello world" do
|
37
40
|
get('/World').body.should == 'Hello, World!'
|
@@ -6,9 +6,9 @@ require 'spec/helper'
|
|
6
6
|
testcase_requires 'ramaze/template/haml'
|
7
7
|
|
8
8
|
class TCTemplateHamlController < Ramaze::Controller
|
9
|
-
map
|
10
|
-
template_root
|
11
|
-
|
9
|
+
map :/
|
10
|
+
template_root __DIR__/:haml
|
11
|
+
engine :Haml
|
12
12
|
|
13
13
|
helper :link
|
14
14
|
|
@@ -0,0 +1,65 @@
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
require 'spec/helper'
|
5
|
+
testcase_requires 'nagoro'
|
6
|
+
|
7
|
+
class TCTemplateNagoroController < Ramaze::Controller
|
8
|
+
map :/
|
9
|
+
template_root __DIR__/:nagoro
|
10
|
+
engine :Nagoro
|
11
|
+
|
12
|
+
def index text
|
13
|
+
@text = text
|
14
|
+
end
|
15
|
+
|
16
|
+
def sum num1, num2
|
17
|
+
@num1, @num2 = num1.to_i, num2.to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
def nested key, value
|
21
|
+
instance_variable_set("@#{key}", value)
|
22
|
+
end
|
23
|
+
|
24
|
+
def internal *args
|
25
|
+
@args = args
|
26
|
+
'<?r i = 2 ?>#{i * i} #{@args.inspect} on the table'
|
27
|
+
end
|
28
|
+
|
29
|
+
def combined
|
30
|
+
@a = 'boo'
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
|
35
|
+
describe "Nagoro" do
|
36
|
+
before(:all) do
|
37
|
+
ramaze
|
38
|
+
end
|
39
|
+
|
40
|
+
it "hello world" do
|
41
|
+
get('/World').body.should == 'Hello, World!'
|
42
|
+
get('/You').body.should == 'Hello, You!'
|
43
|
+
end
|
44
|
+
|
45
|
+
it "summing" do
|
46
|
+
get('/sum/1/2').body.should == '3'
|
47
|
+
end
|
48
|
+
|
49
|
+
it "nasty nested stuff" do
|
50
|
+
get('/nested/foo/bar').body.should == 'bar'
|
51
|
+
end
|
52
|
+
|
53
|
+
it "template inside controller" do
|
54
|
+
get('/internal').body.should == '4 [] on the table'
|
55
|
+
get('/internal/foo').body.should == '4 ["foo"] on the table'
|
56
|
+
end
|
57
|
+
|
58
|
+
it "without method" do
|
59
|
+
get('/file_only').body.should == "This is only the file"
|
60
|
+
end
|
61
|
+
|
62
|
+
it "combined" do
|
63
|
+
get('/combined').body.should == 'boo'
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
another long action
|
@@ -0,0 +1 @@
|
|
1
|
+
#{@a}
|
@@ -0,0 +1 @@
|
|
1
|
+
This is only the file
|
@@ -0,0 +1 @@
|
|
1
|
+
Hello, #{@text}!
|
@@ -0,0 +1 @@
|
|
1
|
+
#@foo
|
@@ -0,0 +1 @@
|
|
1
|
+
some long action
|
@@ -0,0 +1 @@
|
|
1
|
+
#{@num1 + @num2}
|
@@ -0,0 +1,93 @@
|
|
1
|
+
# Copyright (c) 2006 Michael Fellinger m.fellinger@gmail.com
|
2
|
+
# All files in this distribution are subject to the terms of the Ruby license.
|
3
|
+
|
4
|
+
require 'spec/helper'
|
5
|
+
|
6
|
+
testcase_requires 'xml/libxml'
|
7
|
+
testcase_requires 'xml/xslt'
|
8
|
+
testcase_requires 'ramaze/gestalt'
|
9
|
+
testcase_requires 'rexml/document'
|
10
|
+
|
11
|
+
class TCTemplateXSLTController < Ramaze::Controller
|
12
|
+
template_root 'spec/ramaze/template/xslt/'
|
13
|
+
engine :XSLT
|
14
|
+
trait :xslt_options => { :fun_xmlns => 'urn:test' }
|
15
|
+
|
16
|
+
def index
|
17
|
+
gestalt {
|
18
|
+
hi 'tobi'
|
19
|
+
}
|
20
|
+
end
|
21
|
+
|
22
|
+
def ruby_version
|
23
|
+
@version = RUBY_VERSION
|
24
|
+
|
25
|
+
gestalt {
|
26
|
+
document
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def xslt_get_ruby_version
|
31
|
+
@version
|
32
|
+
end
|
33
|
+
|
34
|
+
def products
|
35
|
+
gestalt {
|
36
|
+
order {
|
37
|
+
first
|
38
|
+
items
|
39
|
+
}
|
40
|
+
}
|
41
|
+
end
|
42
|
+
|
43
|
+
def xslt_get_products
|
44
|
+
REXML::Document.new \
|
45
|
+
gestalt {
|
46
|
+
list {
|
47
|
+
%w[Onion Bacon].each { |product|
|
48
|
+
item product
|
49
|
+
}
|
50
|
+
}
|
51
|
+
}
|
52
|
+
end
|
53
|
+
|
54
|
+
def concat_words
|
55
|
+
gestalt {
|
56
|
+
document
|
57
|
+
}
|
58
|
+
end
|
59
|
+
|
60
|
+
def xslt_concat(*args)
|
61
|
+
args.to_s
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def gestalt &block
|
67
|
+
Ramaze::Gestalt.new(&block).to_s
|
68
|
+
end
|
69
|
+
|
70
|
+
end
|
71
|
+
|
72
|
+
describe "XSLT" do
|
73
|
+
ramaze(:mapping => {'/' => TCTemplateXSLTController})
|
74
|
+
|
75
|
+
it "index" do
|
76
|
+
get('/').body.should == "hi tobi"
|
77
|
+
end
|
78
|
+
|
79
|
+
it "ruby_version through external functions" do
|
80
|
+
get('/ruby_version').body.should == RUBY_VERSION
|
81
|
+
end
|
82
|
+
|
83
|
+
it "external functions returning XML data" do
|
84
|
+
get('/products').body.
|
85
|
+
gsub(/<\?.+\?>/, '').strip.
|
86
|
+
should == '<result><first>Onion</first><item>Onion</item><item>Bacon</item></result>'
|
87
|
+
end
|
88
|
+
|
89
|
+
it "parameters" do
|
90
|
+
get('/concat_words').body.should == 'oneonetwoonetwothree'
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<xsl:stylesheet version="1.0"
|
3
|
+
xmlns:test="urn:test"
|
4
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
5
|
+
exclude-result-prefixes="test xsl">
|
6
|
+
|
7
|
+
<xsl:output method="text"
|
8
|
+
encoding="utf-8"/>
|
9
|
+
|
10
|
+
<xsl:template match="/document">
|
11
|
+
<xsl:value-of select="test:concat('one')"/>
|
12
|
+
<xsl:value-of select="test:concat('one', 'two')"/>
|
13
|
+
<xsl:value-of select="test:concat('one', 'two', 'three')"/>
|
14
|
+
</xsl:template>
|
15
|
+
|
16
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<xsl:stylesheet version="1.0"
|
3
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
|
4
|
+
|
5
|
+
<xsl:output method="text"
|
6
|
+
encoding="utf-8"/>
|
7
|
+
|
8
|
+
<xsl:template match="/*">
|
9
|
+
<xsl:value-of select="name(.)"/>
|
10
|
+
<xsl:text> </xsl:text>
|
11
|
+
<xsl:apply-templates/>
|
12
|
+
</xsl:template>
|
13
|
+
|
14
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<xsl:stylesheet version="1.0"
|
3
|
+
xmlns:test="urn:test"
|
4
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
5
|
+
exclude-result-prefixes="test xsl">
|
6
|
+
|
7
|
+
<xsl:output method="xml"
|
8
|
+
encoding="utf-8"/>
|
9
|
+
|
10
|
+
<xsl:template match="order">
|
11
|
+
<result>
|
12
|
+
<xsl:apply-templates/>
|
13
|
+
</result>
|
14
|
+
</xsl:template>
|
15
|
+
|
16
|
+
<xsl:template match="first">
|
17
|
+
<first>
|
18
|
+
<xsl:value-of select="test:get-products()/item[1]"/>
|
19
|
+
</first>
|
20
|
+
</xsl:template>
|
21
|
+
|
22
|
+
<xsl:template match="items">
|
23
|
+
<xsl:apply-templates select="test:get-products()" mode="list"/>
|
24
|
+
</xsl:template>
|
25
|
+
|
26
|
+
<xsl:template match="item" mode="list">
|
27
|
+
<item>
|
28
|
+
<xsl:apply-templates mode="list"/>
|
29
|
+
</item>
|
30
|
+
</xsl:template>
|
31
|
+
|
32
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<xsl:stylesheet version="1.0"
|
3
|
+
xmlns:test="urn:test"
|
4
|
+
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
|
5
|
+
exclude-result-prefixes="test xsl">
|
6
|
+
|
7
|
+
<xsl:output method="text"
|
8
|
+
encoding="utf-8"/>
|
9
|
+
|
10
|
+
<xsl:template match="/document">
|
11
|
+
<ruby-version><xsl:value-of select="test:get-ruby-version()"/></ruby-version>
|
12
|
+
</xsl:template>
|
13
|
+
|
14
|
+
</xsl:stylesheet>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
describe 'Array#put_within' do
|
4
|
+
it 'should put a given object at a well-described position' do
|
5
|
+
array = [:foo, :bar, :baz]
|
6
|
+
array.put_within(:foobar, :after => :bar, :before => :baz)
|
7
|
+
array.should == [:foo, :bar, :foobar, :baz]
|
8
|
+
end
|
9
|
+
|
10
|
+
it 'should raise on uncertainity' do
|
11
|
+
array = [:foo, :bar, :baz]
|
12
|
+
lambda{
|
13
|
+
array.put_within(:foobar, :after => :foo, :before => :baz)
|
14
|
+
}.should raise_error(ArgumentError, "Too many elements within constrain")
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe 'Array#put_after' do
|
19
|
+
it 'should put a given object at a well-described position' do
|
20
|
+
array = [:foo, :bar, :baz]
|
21
|
+
array.put_after(:bar, :foobar)
|
22
|
+
array.should == [:foo, :bar, :foobar, :baz]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
describe 'Array#put_within' do
|
27
|
+
it 'should put a given object at a well-described position' do
|
28
|
+
array = [:foo, :bar, :baz]
|
29
|
+
array.put_before(:bar, :foobar)
|
30
|
+
array.should == [:foo, :foobar, :bar, :baz]
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
describe "Numeric#filesize_format" do
|
4
|
+
it 'it should convert filesizes to human readable format' do
|
5
|
+
1.filesize_format.should == '1'
|
6
|
+
1024.filesize_format.should == '1.0K'
|
7
|
+
(1 << 20).filesize_format.should == '1.0M'
|
8
|
+
(1 << 20).filesize_format.should == '1.0M'
|
9
|
+
(1 << 30).filesize_format.should == '1.0G'
|
10
|
+
(1 << 40).filesize_format.should == '1.0T'
|
11
|
+
end
|
12
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'spec/helper'
|
2
|
+
|
3
|
+
describe 'OrderedSet' do
|
4
|
+
os = OrderedSet.new(1,2,3,1)
|
5
|
+
|
6
|
+
it 'should create sets' do
|
7
|
+
OrderedSet.new.should == []
|
8
|
+
os.should == OrderedSet.new([1,2,3,1])
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'should not contain duplicates' do
|
12
|
+
os.should == [1,2,3]
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'should not duplicate entries' do
|
16
|
+
os << 4
|
17
|
+
os.should == [1,2,3,4]
|
18
|
+
|
19
|
+
os << 4
|
20
|
+
os.should == [1,2,3,4]
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'should append with push and prepend with unshift' do
|
24
|
+
os.push 1
|
25
|
+
os.should == [2,3,4,1]
|
26
|
+
|
27
|
+
os.unshift 1
|
28
|
+
os.should == [1,2,3,4]
|
29
|
+
|
30
|
+
os.push [1,2]
|
31
|
+
os.should == [1,2,3,4,[1,2]]
|
32
|
+
|
33
|
+
os.unshift [1,2]
|
34
|
+
os.should == [[1,2],1,2,3,4]
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should support Array#[]=' do
|
38
|
+
os = OrderedSet.new(1)
|
39
|
+
os.should == [1]
|
40
|
+
|
41
|
+
os[0] = 1
|
42
|
+
os.should == [1]
|
43
|
+
|
44
|
+
os[1,0] = [3,4,5,1]
|
45
|
+
os.should == [3,4,5,1]
|
46
|
+
|
47
|
+
os[0,0] = [1,2]
|
48
|
+
os.should == [1,2,3,4,5]
|
49
|
+
|
50
|
+
os[5..5] = [7,8,1,2]
|
51
|
+
os.should == [3,4,5,7,8,1,2]
|
52
|
+
|
53
|
+
os[1..2] = 3
|
54
|
+
os.should == [3,7,8,1,2]
|
55
|
+
end
|
56
|
+
end
|